X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Ftorrus_Common.pm;h=b32deab04d43fab2edbfca6fbb940f44b7be578f;hb=57bb423fe457ba4e13726877f53bcdf944f828f8;hp=38e5499dad095abc0f6bbf4da2548e27258d954c;hpb=b608648e0c400ea4ecf85c00601e13ee54c906d5;p=freeside.git diff --git a/FS/FS/part_pkg/torrus_Common.pm b/FS/FS/part_pkg/torrus_Common.pm index 38e5499da..b32deab04 100644 --- a/FS/FS/part_pkg/torrus_Common.pm +++ b/FS/FS/part_pkg/torrus_Common.pm @@ -7,6 +7,15 @@ our %info = ( 'disabled' => 1 ); #torrus_Common not a usable price plan directly our $DEBUG = 1; +sub recur_temporality { 'preceding'; } + +sub price_info { + my $self = shift; + my $str = $self->SUPER::price_info(@_); + $str .= " plus usage" if $str; + $str; +} + sub calc_recur { my $self = shift; my($cust_pkg, $sdate, $details, $param ) = @_; @@ -30,9 +39,12 @@ sub calc_usage { my $self = shift; my($cust_pkg, $sdate, $details, $param ) = @_; - my @sdate = localtime($$sdate); - my $rep_date = ($sdate[5]+1900). '-'. ($sdate[4]+1). '-01'; + #sdate is next bill date, but we want the report from last month + my($m, $y) = ($sdate[4], $sdate[5]+1900); + if ( $m == 0 ) { $m=12; $y--; } + $m = "0$m" if length($m) == 1; + my $rep_date = "$y-$m-01"; warn "searching for MonthlyUsage report for $rep_date\n" if $DEBUG; my $rep_sql = " SELECT id FROM reports WHERE rep_date = ? @@ -50,7 +62,7 @@ sub calc_usage { SELECT value FROM reportfields WHERE rep_id = $rep_id AND name = ? - AND servciceid = ? + AND serviceid = ? "; my $total = 0; @@ -71,14 +83,15 @@ sub calc_usage { $max -= $inc; next if $max < 0; - my $amount = sprintf('%.2f', $self->option($self->_torrus_rate) * $max ); + my $rate = $self->option($self->_torrus_rate); + my $amount = sprintf('%.2f', $rate * $max ); $total += $amount; #add usage details to invoice my $l = $self->_torrus_label; - my $d = "Last month's usage for $serviceid: $max$l"; + my $d = "Last month's usage for $serviceid: ". sprintf('%.2f',$max). $l; $d .= " (". ($max+$inc). "$l - $inc$l included)" if $inc; - $d .= ": $money_char$amount"; + $d .= " @ $money_char$rate/$l: $money_char$amount"; push @$details, $d;