0ed9782058bf69a0a767db3eff514a04176cc04d
[freeside.git] / FS / FS / part_pkg / subscription.pm
1 package FS::part_pkg::subscription;
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 full charge, then flat-rate (selectable billing day)',
13   'fields' => {
14     'setup_fee' => { 'name' => 'Setup fee for this package',
15                      'default' => 0,
16                    },
17     'recur_fee' => { 'name' => 'Recurring fee for this package',
18                      'default' => 0,
19                            },
20     'cutoff_day' => { 'name' => 'billing day',
21                       'default' => 1,
22                     },
23     'seconds'       => { 'name' => 'Time limit for this package',
24                          'default' => '',
25                        },
26     'upbytes'       => { 'name' => 'Upload limit for this package',
27                          'default' => '',
28                          'format' => \&FS::UI::bytecount::display_bytecount,
29                          'parse' => \&FS::UI::bytecount::parse_bytecount,
30                        },
31     'downbytes'     => { 'name' => 'Download limit for this package',
32                          'default' => '',
33                          'format' => \&FS::UI::bytecount::display_bytecount,
34                          'parse' => \&FS::UI::bytecount::parse_bytecount,
35                        },
36     'totalbytes'    => { 'name' => 'Transfer limit for this package',
37                          'default' => '',
38                          'format' => \&FS::UI::bytecount::display_bytecount,
39                          'parse' => \&FS::UI::bytecount::parse_bytecount,
40                        },
41     'recharge_amount'       => { 'name' => 'Cost of recharge for this package',
42                          'default' => '',
43                        },
44     'recharge_seconds'      => { 'name' => 'Recharge time for this package',
45                          'default' => '',
46                        },
47     'recharge_upbytes'      => { 'name' => 'Recharge upload for this package',
48                          'default' => '',
49                          'format' => \&FS::UI::bytecount::display_bytecount,
50                          'parse' => \&FS::UI::bytecount::parse_bytecount,
51                        },
52     'recharge_downbytes'    => { 'name' => 'Recharge download for this package',                         'default' => '',
53                          'format' => \&FS::UI::bytecount::display_bytecount,
54                          'parse' => \&FS::UI::bytecount::parse_bytecount,
55                        },
56     'recharge_totalbytes'   => { 'name' => 'Recharge transfer for this package',                         'default' => '',
57                          'format' => \&FS::UI::bytecount::display_bytecount,
58                          'parse' => \&FS::UI::bytecount::parse_bytecount,
59                        },
60     #it would be better if this had to be turned on, its confusing
61     'externalid' => { 'name'   => 'Optional External ID',
62                       'default' => '',
63                     },
64   },
65   'fieldorder' => [ 'setup_fee', 'recur_fee', 'cutoff_day', 'seconds',
66                     'upbytes', 'downbytes', 'totalbytes',
67                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
68                     'recharge_downbytes', 'recharge_totalbytes',
69                     'externalid' ],
70   'fieldorder' => [ 'setup_fee', 'recur_fee','cutoff_day', 'seconds',
71                     'upbytes', 'downbytes', 'totalbytes',
72                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
73                     'recharge_downbytes', 'recharge_totalbytes',
74                    ],
75   'freq' => 'm',
76   'weight' => 30,
77 );
78
79 sub calc_recur {
80   my($self, $cust_pkg, $sdate ) = @_;
81   my $cutoff_day = $self->option('cutoff_day', 1) || 1;
82   my $mnow = $$sdate;
83   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
84
85   if ( $mday < $cutoff_day ) {
86      if ($mon==0) {$mon=11;$year--;}
87      else {$mon--;}
88   }
89
90   $$sdate = timelocal(0,0,0,$cutoff_day,$mon,$year);
91
92   $self->reset_usage($cust_pkg);
93
94   $self->option('recur_fee');
95 }
96
97 1;