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