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)',
13 'shortname' => 'Prorate (Nth of month billing)',
15 'setup_fee' => { 'name' => 'Setup fee for this package',
18 'recur_fee' => { 'name' => 'Recurring fee for this package',
21 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
22 ' of service at cancellation',
25 'cutoff_day' => { 'name' => 'Billing Day (1 - 28)',
28 'seconds' => { 'name' => 'Time limit for this package',
30 'check' => sub { shift =~ /^\d*$/ },
32 'upbytes' => { 'name' => 'Upload limit for this package',
34 'check' => sub { shift =~ /^\d*$/ },
35 'format' => \&FS::UI::bytecount::display_bytecount,
36 'parse' => \&FS::UI::bytecount::parse_bytecount,
38 'downbytes' => { 'name' => 'Download limit for this package',
40 'check' => sub { shift =~ /^\d*$/ },
41 'format' => \&FS::UI::bytecount::display_bytecount,
42 'parse' => \&FS::UI::bytecount::parse_bytecount,
44 'totalbytes' => { 'name' => 'Transfer limit for this package',
46 'check' => sub { shift =~ /^\d*$/ },
47 'format' => \&FS::UI::bytecount::display_bytecount,
48 'parse' => \&FS::UI::bytecount::parse_bytecount,
50 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
52 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
54 'recharge_seconds' => { 'name' => 'Recharge time for this package',
56 'check' => sub { shift =~ /^\d*$/ },
58 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
60 'check' => sub { shift =~ /^\d*$/ },
61 'format' => \&FS::UI::bytecount::display_bytecount,
62 'parse' => \&FS::UI::bytecount::parse_bytecount,
64 'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
65 'check' => sub { shift =~ /^\d*$/ },
66 'format' => \&FS::UI::bytecount::display_bytecount,
67 'parse' => \&FS::UI::bytecount::parse_bytecount,
69 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
70 'check' => sub { shift =~ /^\d*$/ },
71 'format' => \&FS::UI::bytecount::display_bytecount,
72 'parse' => \&FS::UI::bytecount::parse_bytecount,
74 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
75 'over into current period',
78 'recharge_reset' => { 'name' => 'Reset usage to these values on manual '.
83 #it would be better if this had to be turned on, its confusing
84 'externalid' => { 'name' => 'Optional External ID',
88 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'cutoff_day',
89 'seconds', 'upbyte', 'downbytes', 'totalbytes',
90 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
91 'recharge_downbytes', 'recharge_totalbytes',
92 'usage_rollover', 'recharge_reset', 'externalid', ],
98 my($self, $cust_pkg, $sdate ) = @_;
99 my $cutoff_day = $self->option('cutoff_day', 1) || 1;
101 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
105 if ( $mday >= $cutoff_day ) {
107 timelocal(0,0,0,$cutoff_day, $mon == 11 ? 0 : $mon+1, $year+($mon==11));
109 timelocal(0,0,0,$cutoff_day,$mon,$year);
112 $mend = timelocal(0,0,0,$cutoff_day, $mon, $year);
113 if ($mon==0) {$mon=11;$year--;} else {$mon--;}
114 $mstart= timelocal(0,0,0,$cutoff_day,$mon,$year);
118 my $permonth = $self->option('recur_fee') / $self->freq;
120 $permonth * ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );