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>     ******

This works perfect:

[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 * (1 - 1 / $mon{$month}) * ($n - 1) / 
($mon{$month} - 1);
}
return $s;
[/discount]
[/loop]

Now to the next step...

I need this exact *result* to work on the if-loop pages (index.html, 
etc.) *before* a product is selected.  Here is a make-shift solution 
I used, but for obvious reasons, it will not always work without 
manual changes (like the month).

[if-loop-field monthly]
<B>[currency][calc][loop-field monthly] - ([loop-field monthly] / 31 
* [tag time]%d[/tag]) [/calc][/currency]</B></font><BR>
<FONT FACE="Arial" SIZE="2" COLOR=blue><B>Startup Cost Automatically 
Prorated [currency][calc][loop-field monthly] - ([loop-field monthly] 
- ([loop-field monthly] / 31 * [tag time]%d[/tag])) 
[/calc][/currency]!</B>
[else]
<B>[currency][loop-field setup][/currency]</B></font><BR>
<FONT FACE="Arial" SIZE="2" COLOR=blue><B>Not Prorated</B>
[/else]
[/if-loop-field]

Basically, I need the first example to work on index.html before a 
product is selected.  To see where this would go, see 
http://nethollywood.net where it says "See Checkout for Prorated 
Amount".  (I do not have any calculation script there at this time.)

Thanks again,

Sydney Urshan

Please cc to urshan@nethollywood.net


>Sydney,
>
>Now I understand! I thought everything was being prorated down to $1.00
>at the end of the month. This equation, though a bit more complicated,
>should do the trick:
>
>	$s - $s * (1 - 1 / $mon{$month}) * ($n - 1) / ($mon{$month} - 1);
>
>[<start lesson> Derivation (from simple algebra):
>   step 1, offset the days by 1 so they become zero-based as it
>     simplifies the derivation
>   step 2, draw a graph of price vs. time
>
>	|
>	|\   <-- starting price s
>price	| \
>	|  \
>	|   \
>	|    \ <-- ending price e
>	|----------> day-in-month - 1
>        day    ^
>	0    day (mdays - 1)
>
>   ending price (e) = starting price (s) / mdays
>   slope of the line (m) = (e - s) / (mdays - 1)
>
>   step 3, plug the numbers into the standard equation of a line: y = mx + b
>     in this case, y is the price and x is the day number (zero-based); b is
>     the value on day 0 (which is the initial price). So (using p for
>     the price, n for the 1-based day number, mdays for days in a month),
>	p = ((e - s) / (mdays - 1)) * (n - 1) + s
>     substitue for e:
>	p = ((s/mdays - s) / (mdays - 1)) * (n - 1) + s
>     factor out -s:
>	p = -s * ((-1/mdays + 1) / (mdays - 1)) * (n - 1) + s
>     rearrange the order:
>	p = s - s * (1 - 1/mdays) * (n - 1) / (mdays - 1)
>
><end of lesson>]
>
>	-Bill
>
>
>On Jun 30,  2:33pm, Sydney Urshan wrote:
>} Subject: 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
>}
>} >******    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
>}-- End of excerpt from Sydney Urshan

-
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: