I would first calculate the daily/monthly rate for the month that falls in a particular time period, then find out how many users logged on during that month, then distribute the cost evenly to the users. The following is a sample I quickly pulled together to show how to calculate daily rate. To calculate the monthly rate, say, you just need to accumulate the totals for the month.

use strict; use Date::Calc qw(:all); use Data::Dumper; my $rates = [ ['01/01/1990', '09/01/2003', 105], ['08/01/2003', '10/01/2003', 190], ['10/01/2003', '01/01/2007', 140], ]; my $new_rates = initrates($rates); # print Dumper($new_rates); my %date = ( '07/01/2003', 20, # date, no. user '09/01/2003', 10, '10/01/2003', 20, '12/12/2003', 12); foreach (sort keys %date) { my $rate = getdailyrate($_); my $per_user = sprintf "%.2f", $rate / $date{$_}; print "Daily rate for $_ is $rate, $date{$_} users, every user pay + \$$per_user\n"; } # date in dd/mm/yy sub getdailyrate { my $datestr = shift; my ($y, $m, $d) = getymd($datestr); my $date = Mktime($y, $m, $d, 0, 0, 0); foreach(@$new_rates) { return $_->[3] if $date >= $_->[0] && $date < $_->[1]; } return(0); } sub initrates { my $rates = shift; my @rates; foreach (@$rates) { my ($y1, $m1, $d1) = getymd($_->[0]); my ($y2, $m2, $d2) = getymd($_->[1]); my $total = $_->[2]; my $dd = Delta_Days($y1,$m1,$d1,$y2,$m2,$d2); my $rate = sprintf "%.02f", $total / $dd; # print "$dd days - wanted $total - rate \$$rate per day\n"; my $t1 = Mktime($y1, $m1, $d1, 0, 0, 0); my $t2 = Mktime($y2, $m2, $d2, 0, 0, 0); push @rates, [ $t1, $t2, $total, $rate ]; } return \@rates; } sub getymd { my $datestr = shift; my ($day, $mon, $year) = $datestr =~ m[(\d+)/(\d+)/(\d+)]; # or Pa +rse_Date return ($year, $mon, $day); }
And the output is -
Daily rate for 07/01/2003 is 0.02, 20 users, every user pay $0.00 Daily rate for 09/01/2003 is 95.00, 10 users, every user pay $9.50 Daily rate for 10/01/2003 is 0.10, 20 users, every user pay $0.01 Daily rate for 12/12/2003 is 0.10, 12 users, every user pay $0.01
Note that I have $0.00 in the output, that's due to the rounding with sprintf (for printing only). Remove the sprintf and you will get more accurate daily per person payment amount.


In reply to Re: Membership Dues Application bugs by Roger
in thread Membership Dues Application bugs by caedes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.