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 (1 - 28)',
27 'seconds' => { 'name' => 'Time limit for this package',
29 'check' => sub { shift =~ /^\d*$/ },
31 'upbytes' => { 'name' => 'Upload limit for this package',
33 'check' => sub { shift =~ /^\d*$/ },
34 'format' => \&FS::UI::bytecount::display_bytecount,
35 'parse' => \&FS::UI::bytecount::parse_bytecount,
37 'downbytes' => { 'name' => 'Download limit for this package',
39 'check' => sub { shift =~ /^\d*$/ },
40 'format' => \&FS::UI::bytecount::display_bytecount,
41 'parse' => \&FS::UI::bytecount::parse_bytecount,
43 'totalbytes' => { 'name' => 'Transfer limit for this package',
45 'check' => sub { shift =~ /^\d*$/ },
46 'format' => \&FS::UI::bytecount::display_bytecount,
47 'parse' => \&FS::UI::bytecount::parse_bytecount,
49 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
51 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
53 'recharge_seconds' => { 'name' => 'Recharge time for this package',
55 'check' => sub { shift =~ /^\d*$/ },
57 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
59 'check' => sub { shift =~ /^\d*$/ },
60 'format' => \&FS::UI::bytecount::display_bytecount,
61 'parse' => \&FS::UI::bytecount::parse_bytecount,
63 'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
64 'check' => sub { shift =~ /^\d*$/ },
65 'format' => \&FS::UI::bytecount::display_bytecount,
66 'parse' => \&FS::UI::bytecount::parse_bytecount,
68 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
69 'check' => sub { shift =~ /^\d*$/ },
70 'format' => \&FS::UI::bytecount::display_bytecount,
71 'parse' => \&FS::UI::bytecount::parse_bytecount,
73 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
74 'over into current period',
77 'recharge_reset' => { 'name' => 'Reset usage to these values on manual '.
82 #it would be better if this had to be turned on, its confusing
83 'externalid' => { 'name' => 'Optional External ID',
87 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'cutoff_day',
88 'seconds', 'upbyte', 'downbytes', 'totalbytes',
89 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
90 'recharge_downbytes', 'recharge_totalbytes',
91 'usage_rollover', 'recharge_reset', 'externalid', ],
97 my($self, $cust_pkg, $sdate ) = @_;
98 my $cutoff_day = $self->option('cutoff_day', 1) || 1;
100 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
104 if ( $mday >= $cutoff_day ) {
106 timelocal(0,0,0,$cutoff_day, $mon == 11 ? 0 : $mon+1, $year+($mon==11));
108 timelocal(0,0,0,$cutoff_day,$mon,$year);
111 $mend = timelocal(0,0,0,$cutoff_day, $mon, $year);
112 if ($mon==0) {$mon=11;$year--;} else {$mon--;}
113 $mstart= timelocal(0,0,0,$cutoff_day,$mon,$year);
117 my $permonth = $self->option('recur_fee') / $self->freq;
119 $permonth * ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );