[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Prorate discount script bug
****** message to minivend-users from Bill Randle <billr@exgate.tek.com> ******
Sydney Urshan wrote:
>
> ****** message to minivend-users from Sydney Urshan <urshan@nethollywood.net> ******
>
> The following discount script works perfect until the last day of the
> month at which time the result is 0. Can someone help me out on this
> one?
>
> [loop list='2001 2002 3001 3002']
> [discount [loop-code]]
> my $bit = $Tag->time('', {}, '%m %d');
> my ($month, $n) = split /\s+/, $bit;
> $n =~ s/^0//;
> my %mon = (
> '01' => 31,
> '02' => 29,
> '03' => 31,
> '04' => 30,
> '05' => 31,
> '06' => 30,
> '07' => 31,
> '08' => 31,
> '09' => 30,
> '10' => 31,
> '11' => 30,
> '12' => 31,
> );
> if ($mon{$month} and $n > 1) {
> return ($s - ($s / $mon{$month} * $n));
> }
> return $s;
> [/discount]
> [/loop]
>
> Thanks,
>
> Sydney Urshan
Look at your calculation again:
$s - ($s / days_in_month * day_of_month);
This is equivalent to saying:
$s - $s * (days_in_month / day_of_month);
when day_of_month is the same as days_in_month, you get
$s - $s * 1;
which is 0.
What did you intend the prorate to be at the end of the month?
-Bill
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list