Akopia Akopia Services

[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 Sydney Urshan <urshan@nethollywood.net>     ******

Bill,

I just installed this script (at http://nethollywood.net) to check it 
out (on the last day of the month).  The new result is $1 no matter 
what the item costs.  (Which is better than $0!)

Instead, a $20 item today should be $.67 and a $5 item should be 
$.17.  If this month had a different # days, then the results would 
be different by a few cents.  The example below was $1 on the last 
day because, for simplicity sake, it was a $30 item in a 30 day 
month.  Can you help me tweak it to get it working right?

Thanks,

Sydney

p.s.  I created the new newsgroup "alt.webhosting".  It is also a 
mailing list.  (alt.webhosting@nethollywood.net)  If anyone is 
interested, The Web Host Directory posted a Press Release about it 
which has more details:

http://www.webhostdir.com/news/press_releases/NETHOLLYWOOD_20000630.asp





>******    message to minivend-users from Bill Randle 
><billr@exgate.tek.com>     ******
>
>Sydney,
>
>Try this for the calculation:
>         $s - ($s - 1) * ($n - 1) / ($mon{$month} - 1);
>
>I tried it for a few test cases and it seems to work for me. You could,
>of course, build the length-Of_month-1 value into your month table.
>Also, for a little less overhead, you could use localtime() directly,
>rather than calling $Tag->time(), as you don't need the formating. E.g.:
>         my ($sec, $min, $hr, $mday, $mon) = localtime;
>If you do that, remember that $mon goes from 0 to 11.
>
>         -Bill
>
>
>Sydney Urshan wrote:
>  >
>  > Well, if it's a $30 item in a 30 day month, day 30 should be $1, day
>  > 29 should be $2...day 2 should be $29, and the first day of the month
>  > should be $30 with everything else in between adjusted accordingly.
>  >
>  > >Sydney Urshan wrote:
>  > >>
>  > >>  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


Search for: Match: Format: Sort by: