shorter names and rearranged weights for a brighter tommorow^W^Wbetter price plan...
[freeside.git] / FS / FS / part_pkg / prorate_delayed.pm
1 package FS::part_pkg::prorate_delayed;
2
3 use strict;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch qsearchs);
6 use FS::part_pkg;
7
8 @ISA = qw(FS::part_pkg::prorate);
9
10 %info = (
11   'name' => 'Free (or setup fee) for X days, then prorate, then flat-rate ' .
12          '(1st of month billing)',
13   'shortname' => 'Prorate (Nth of month billing), with intro period', #??
14   'fields' =>  {
15     'setup_fee' => { 'name' => 'Setup fee for this package',
16                      'default' => 0,
17                    },
18     'free_days' => { 'name' => 'Initial free days',
19                      'default' => 0,
20                    },
21     'recur_fee' => { 'name' => 'Recurring fee for this package',
22                      'default' => 0,
23                     },
24     'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
25                                    ' of service at cancellation',
26                          'type' => 'checkbox',
27                        },
28   },
29   'fieldorder' => [ 'free_days', 'setup_fee', 'recur_fee', 'unused_credit' ],
30   #'setup' => '\'my $d = $cust_pkg->bill || $time; $d += 86400 * \' + what.free_days.value + \'; $cust_pkg->bill($d); $cust_pkg_mod_flag=1; \' + what.setup_fee.value',
31   #'recur' => 'what.recur_fee.value',
32   'weight' => 22,
33 );
34
35 sub calc_setup {
36   my($self, $cust_pkg, $time ) = @_;
37
38   my $d = $cust_pkg->bill || $time;
39   $d += 86400 * $self->option('free_days');
40   $cust_pkg->bill($d);
41   
42   $self->option('setup_fee');
43 }
44
45 sub calc_remain {
46   my ($self, $cust_pkg, %options) = @_;
47   my $next_bill = $cust_pkg->getfield('bill') || 0;
48   my $last_bill = $cust_pkg->last_bill || 0;
49   my $free_days = $self->option('free_days');
50
51   return 0 if    $last_bill + (86400 * $free_days) == $next_bill
52               && $last_bill == $cust_pkg->setup;
53
54   return 0 if    ! $self->base_recur
55               || ! $self->option('unused_credit', 1)
56               || ! $last_bill
57               || ! $next_bill;
58
59   return $self->SUPER::calc_remain($cust_pkg, %options);
60 }
61
62 1;