|
Posted by Steve on 09/07/07 14:34
> For every 7 nites they stay, they get 1 free, and that free one should be
> the
> cheapest night (1 value nite, 6 premium nites, they should get the value
> nite
> free)
i'm assuming they must be consecutive nights and not cumulative. why are you
going through all of that rig-a-ma-role for a straight algorhytmic
calculation? who cares what night it is? all you should need to look at is
how many times should you "comp" the lowest rated night...based on your
info. i have no earthly idea why you're splitting up each night as vnites,
rnites, and pnites.
let's assume every monday is a discounted night, while tuesday through
thursday is a standard rate, and friday through sunday is premium pricing.
it is as simple as this:
$nights = 14;
$discounted = $nights / 7;
$nightBilled = array(
'2007-09-03' => 100;
'2007-09-04' => 200;
'2007-09-05' => 200;
'2007-09-06' => 200;
'2007-09-07' => 200;
'2007-09-08' => 300;
'2007-09-09' => 300;
'2007-09-10' => 100;
'2007-09-11' => 200;
'2007-09-12' => 200;
'2007-09-13' => 200;
'2007-09-14' => 200;
'2007-09-15' => 300;
'2007-09-16' => 300;
);
$discount = array();
foreach ($nightBilled as $date => $price)
{
if (!$discounted){ break; }
$dateInfo = getdate($date);
if ($dateInfo['wday'] == 0)
{
$discount[$date] = $price;
$discounted--;
}
}
print_r($discount, true);
you could do this same thing just knowing the arrival date and the number of
nights they stayed.
there are several "business" problems i see with your method of discounting
(it doesn't benefit the business as much as it could nor is your code
extendable when you figure out why).
as for the code you want fixed...i'm telling you why it doesn't do what you
want. i submit the above as a better use of cpu cycles and maintenance.
[Back to original message]
|