Jump to content

Array of discounts to be applied based on the weeks booked all at different rate


joesaddigh

Recommended Posts

Array of discounts to be applied based on the weeks booked all at different rate

 

 

Hi,

 

Sorry about the title, it will hopefully become clearer when I explain my problem. OK the problem is as follows:

 

BACKGROUND INFORMATION

Admin - add a course and apply some discounts. There can be multiple discounts per course.

The format of a discount is:

(NAME-WEEKS-DISCOUNT)

NAME = The name of the discount - pointless mentioning

WEEKS = The discount will be applied for subsequent weeks after this value ( if WEEKS = 2 and user books for 3 then the DISCOUNT will be applied for weeks after this value ).

DISCOUNT = a decimal format for a discount rate which should be applied e.g. 10 OR 20 OR 50.6 etc NO MORE THAN 100 and more than 0.

 

The above is all implemented. I have a course calculator which will use this information quoted above:

For example: User picks a course and a duration ( 10 weeks )

 

When this is submitted I need to give them a price.

 

As the weeks booked is variable and the amount of discounts for the chosen course is variable I would like to know the best way of calculating this. I currently have some code to do this and it seems to work but without a debugger I can't truely check it is accurate ( I think it might be doing something suttely wrong and if not the code is messy and hard to understand)

 

Can anybody give me a good solution mathmatically which I can implement where by I can work out how much the total will be:

 

Scenario in pseudo sort of code:

 

$weeksbooked = 30

 

// Get the discounts from db

// There are 3 so store these in array?

// Example of array contents

// Discount rate - qualifier(after how many weeks) - course price

array[ 0 ] = 10%-5-£100

array[ 1 ] = 20%-10-£100

array[ 2 ] = 30%-15-£100

 

So I would need to do the following maths:

5 weeks at normal price £100

5 weeks at £100 - 10%

5 weeks at £100 - 20%

THE REMAINING weeks at £100 - 30%

 

( £500 + £450 + £400 ) + REMAINING WEEKS at 30% discount ( £1350 + 1050 )

£2400

 

Please any ideas would be greatly received:

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.