This commit was manufactured by cvs2svn to create branch
[freeside.git] / FS / FS / part_pkg / prorate.pm
1 package FS::part_pkg::prorate;
2
3 use strict;
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;
8
9 @ISA = qw(FS::part_pkg::flat);
10
11 %info = (
12   'name' => 'First partial month pro-rated, then flat-rate (selectable billing day)',
13   'shortname' => 'Prorate (Nth of month billing)',
14   'fields' => {
15     'setup_fee' => { 'name' => 'Setup fee for this package',
16                      'default' => 0,
17                    },
18     'recur_fee' => { 'name' => 'Recurring fee for this package',
19                      'default' => 0,
20                     },
21     'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
22                                    ' of service at cancellation',
23                          'type' => 'checkbox',
24                        },
25     'cutoff_day' => { 'name' => 'Billing Day (1 - 28)',
26                       'default' => 1,
27                     },
28     'seconds'       => { 'name' => 'Time limit for this package',
29                          'default' => '',
30                          'check' => sub { shift =~ /^\d*$/ },
31                        },
32     'upbytes'       => { 'name' => 'Upload limit for this package',
33                          'default' => '',
34                          'check' => sub { shift =~ /^\d*$/ },
35                          'format' => \&FS::UI::bytecount::display_bytecount,
36                          'parse' => \&FS::UI::bytecount::parse_bytecount,
37                        },
38     'downbytes'     => { 'name' => 'Download limit for this package',
39                          'default' => '',
40                          'check' => sub { shift =~ /^\d*$/ },
41                          'format' => \&FS::UI::bytecount::display_bytecount,
42                          'parse' => \&FS::UI::bytecount::parse_bytecount,
43                        },
44     'totalbytes'    => { 'name' => 'Transfer limit for this package',
45                          'default' => '',
46                          'check' => sub { shift =~ /^\d*$/ },
47                          'format' => \&FS::UI::bytecount::display_bytecount,
48                          'parse' => \&FS::UI::bytecount::parse_bytecount,
49                        },
50     'recharge_amount'       => { 'name' => 'Cost of recharge for this package',
51                          'default' => '',
52                          'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
53                        },
54     'recharge_seconds'      => { 'name' => 'Recharge time for this package',
55                          'default' => '',
56                          'check' => sub { shift =~ /^\d*$/ },
57                        },
58     'recharge_upbytes'      => { 'name' => 'Recharge upload for this package',
59                          'default' => '',
60                          'check' => sub { shift =~ /^\d*$/ },
61                          'format' => \&FS::UI::bytecount::display_bytecount,
62                          'parse' => \&FS::UI::bytecount::parse_bytecount,
63                        },
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,
68                        },
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,
73                        },
74     'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
75                                     'over into current period',
76                           'type' => 'checkbox',
77                         },
78     'recharge_reset' => { 'name' => 'Reset usage to these values on manual '.
79                                     'package recharge',
80                           'type' => 'checkbox',
81                         },
82     'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
83                                     'for one full period after that',
84                           'type' => 'checkbox',
85                         },
86     'prorate_round_day'=> {
87                           'name' => 'When prorating first month, round to '.
88                                     'the nearest full day',
89                           'type' => 'checkbox',
90                         },
91
92     #it would be better if this had to be turned on, its confusing
93     'externalid' => { 'name'   => 'Optional External ID',
94                       'default' => '',
95                     },
96   },
97   'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'cutoff_day',
98                     'seconds', 'upbytes', 'downbytes', 'totalbytes',
99                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
100                     'recharge_downbytes', 'recharge_totalbytes',
101                     'usage_rollover', 'recharge_reset', 'add_full_period',
102                     'prorate_round_day', 'externalid', ],
103   'freq' => 'm',
104   'weight' => 20,
105 );
106
107 sub calc_recur {
108   my $self = shift;
109   my $cutoff_day = $self->option('cutoff_day') || 1;
110   return $self->calc_prorate(@_, $cutoff_day) - $self->calc_discount(@_);
111 }
112
113 1;