fix some indentation and the default cutoff day
[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     #it would be better if this had to be turned on, its confusing
24     'externalid' => { 'name'   => 'Optional External ID',
25                       'default' => '',
26                     },
27   },
28   'fieldorder' => [ 'setup_fee', 'recur_fee', 'cutoff_day', 'externalid' ],
29   'fieldorder' => [ 'setup_fee', 'recur_fee','cutoff_day'],
30   'freq' => 'm',
31   'weight' => 30,
32 );
33
34 sub calc_recur {
35   my($self, $cust_pkg, $sdate ) = @_;
36   my $cutoff_day = $self->option('cutoff_day') || 1;
37   my $mnow = $$sdate;
38   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
39
40   if ( $mday < $cutoff_day ) {
41      if ($mon==0) {$mon=11;$year--;}
42      else {$mon--;}
43   }
44
45   $$sdate = timelocal(0,0,0,$cutoff_day,$mon,$year);
46
47   $self->option('recur_fee');
48 }
49
50 1;