joesaddigh Posted October 21, 2010 Share Posted October 21, 2010 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 https://forums.phpfreaks.com/topic/216510-array-of-discounts-to-be-applied-based-on-the-weeks-booked-all-at-different-rate/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.