import torrus 1.0.9
[freeside.git] / FS / FS / part_pkg / incomplete / billoneday.pm
1 package FS::part_pkg::billoneday;
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' => 'charge a full month  every (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
24   },
25   'fieldorder' => [ 'setup_fee', 'recur_fee','cutoff_day'],
26   #'setup' => 'what.setup_fee.value',
27   #'recur' => '\'my $mnow = $sdate; my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($sdate) )[0,1,2,3,4,5]; $sdate = timelocal(0,0,0,$self->option('cutoff_day'),$mon,$year); \' + what.recur_fee.value',
28   'freq' => 'm',
29   'weight' => 30,
30 );
31
32 sub calc_recur {
33   my($self, $cust_pkg, $sdate ) = @_;
34
35   my $mnow = $$sdate;
36   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
37   my $mstart = timelocal(0,0,0,$self->option('cutoff_day'),$mon,$year);
38   my $mend = timelocal(0,0,0,$self->option('cutoff_day'), $mon == 11 ? 0 : $mon+1, $year+($mon==11));
39
40   if($mday > $self->option('cutoff_date') and $mstart != $mnow ) {
41     $$sdate = timelocal(0,0,0,$self->option('cutoff_day'), $mon == 11 ? 0 : $mon+1,  $year+($mon==11));
42   }
43   else{
44     $$sdate = timelocal(0,0,0,$self->option('cutoff_day'), $mon, $year);
45   }
46   $self->option('recur_fee');
47 }
48 1;