1 package FS::part_pkg::prorate;
4 use vars qw(@ISA %info);
5 use Time::Local qw(timelocal);
6 #use FS::Record qw(qsearch qsearchs);
7 use FS::part_pkg::flat;
9 @ISA = qw(FS::part_pkg::flat);
12 'name' => 'First partial month pro-rated, then flat-rate (selectable billing day)',
14 'setup_fee' => { 'name' => 'Setup fee for this package',
17 'recur_fee' => { 'name' => 'Recurring fee for this package',
20 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
21 ' of service at cancellation',
24 'cutoff_day' => { 'name' => 'billing day',
27 'seconds' => { 'name' => 'Time limit for this package',
30 'upbytes' => { 'name' => 'Upload limit for this package',
33 'downbytes' => { 'name' => 'Download limit for this package',
36 'totalbytes' => { 'name' => 'Transfer limit for this package',
39 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
42 'recharge_seconds' => { 'name' => 'Recharge time for this package',
45 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
48 'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
50 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
52 #it would be better if this had to be turned on, its confusing
53 'externalid' => { 'name' => 'Optional External ID',
57 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'cutoff_day',
58 'seconds', 'upbyte', 'downbytes', 'totalbytes',
59 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
60 'recharge_downbytes', 'recharge_totalbytes',
67 my($self, $cust_pkg, $sdate ) = @_;
68 my $cutoff_day = $self->option('cutoff_day', 1) || 1;
70 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
74 $self->reset_usage($cust_pkg);
76 if ( $mday >= $cutoff_day ) {
78 timelocal(0,0,0,$cutoff_day, $mon == 11 ? 0 : $mon+1, $year+($mon==11));
80 timelocal(0,0,0,$cutoff_day,$mon,$year);
83 $mend = timelocal(0,0,0,$cutoff_day, $mon, $year);
84 if ($mon==0) {$mon=11;$year--;} else {$mon--;}
85 $mstart= timelocal(0,0,0,$cutoff_day,$mon,$year);
89 my $permonth = $self->option('recur_fee') / $self->freq;
91 $permonth * ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );