This commit was generated by cvs2svn to compensate for changes in r12472,
[freeside.git] / FS / FS / part_pkg / delayed_Mixin.pm
1 package FS::part_pkg::delayed_Mixin;
2
3 use strict;
4 use vars qw(%info);
5
6 %info = (
7   'disabled' => 1,
8   'fields' => {
9     'free_days' => { 'name' => 'Initial free days',
10                      'default' => 0,
11                    },
12     'delay_setup' => { 'name' => 'Delay setup fee in addition to recurring fee',
13                        'type' => 'checkbox',
14                      },
15     'recur_notify' => { 'name' => 'Number of days before recurring billing'.
16                                   ' commences to notify customer. (0 means'.
17                                   ' no warning)',
18                      'default' => 0,
19                     },
20   },
21   'fieldorder' => [ 'free_days', 'delay_setup', 'recur_notify', ],
22 );
23
24 sub calc_setup {
25   my($self, $cust_pkg, $time ) = @_;
26
27   unless ( $self->option('delay_setup', 1) ) {
28     my $d = $cust_pkg->bill || $time;
29     $d += 86400 * $self->option('free_days');
30     $cust_pkg->bill($d);
31   }
32   
33   $self->option('setup_fee');
34 }
35
36 sub calc_remain {
37   my ($self, $cust_pkg, %options) = @_;
38
39   unless ( $self->option('delay_setup', 1) ) {
40     my $last_bill = $cust_pkg->last_bill || 0;
41     my $next_bill = $cust_pkg->getfield('bill') || 0;
42     my $free_days = $self->option('free_days');
43
44     return 0 if    $last_bill + (86400 * $free_days) == $next_bill
45                 && $last_bill == $cust_pkg->setup;
46   }
47
48   return $self->SUPER::calc_remain($cust_pkg, %options);
49 }
50
51 sub can_start_date { ! shift->option('delay_setup', 1) }
52
53 1;