X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fprorate.pm;h=09561cf51f9046950592965e9ff08d509e4485c0;hb=e6820a61a43c840ef08a11bdda41507dac2a9ff7;hp=3dfab37ba8e771f3877eb1c05a01235f1d49b467;hpb=5de882c01159bfcc5f3d91c7cdfb4c707ff2516f;p=freeside.git diff --git a/FS/FS/part_pkg/prorate.pm b/FS/FS/part_pkg/prorate.pm index 3dfab37ba..09561cf51 100644 --- a/FS/FS/part_pkg/prorate.pm +++ b/FS/FS/part_pkg/prorate.pm @@ -10,6 +10,7 @@ use FS::part_pkg::flat; %info = ( 'name' => 'First partial month pro-rated, then flat-rate (selectable billing day)', + 'shortname' => 'Prorate (Nth of month billing)', 'fields' => { 'setup_fee' => { 'name' => 'Setup fee for this package', 'default' => 0, @@ -74,22 +75,27 @@ use FS::part_pkg::flat; 'over into current period', 'type' => 'checkbox', }, + 'recharge_reset' => { 'name' => 'Reset usage to these values on manual '. + 'package recharge', + 'type' => 'checkbox', + }, + #it would be better if this had to be turned on, its confusing 'externalid' => { 'name' => 'Optional External ID', 'default' => '', }, }, 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'cutoff_day', - 'seconds', 'upbyte', 'downbytes', 'totalbytes', + 'seconds', 'upbytes', 'downbytes', 'totalbytes', 'recharge_amount', 'recharge_seconds', 'recharge_upbytes', 'recharge_downbytes', 'recharge_totalbytes', - 'usage_rollover', 'externalid', ], + 'usage_rollover', 'recharge_reset', 'externalid', ], 'freq' => 'm', 'weight' => 20, ); sub calc_recur { - my($self, $cust_pkg, $sdate ) = @_; + my($self, $cust_pkg, $sdate, $details, $param ) = @_; my $cutoff_day = $self->option('cutoff_day', 1) || 1; my $mnow = $$sdate; my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5]; @@ -111,7 +117,12 @@ sub calc_recur { $$sdate = $mstart; my $permonth = $self->option('recur_fee') / $self->freq; - $permonth * ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) ); + my $months = ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) ); + + $param->{'months'} = $months; + my $discount = $self->calc_discount( $cust_pkg, $sdate, $details, $param); + + sprintf('%.2f', $permonth * $months - $discount); } 1;