avoid breaking recur_Common dependency
[freeside.git] / FS / FS / part_pkg / recur_Common.pm
1 package FS::part_pkg::recur_Common;
2
3 use strict;
4 use vars qw( @ISA %info %recur_method );
5 use Tie::IxHash;
6 use Time::Local;
7 use FS::part_pkg::prorate;
8
9 @ISA = qw(FS::part_pkg::prorate);
10
11 %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly
12
13 tie %recur_method, 'Tie::IxHash',
14   'anniversary'  => 'Charge the recurring fee at the frequency specified above',
15   'prorate'      => 'Charge a prorated fee the first time (selectable billing date)',
16   'subscription' => 'Charge the full fee for the first partial period (selectable billing date)',
17 ;
18
19 sub calc_recur_Common {
20   my $self = shift;
21   my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param
22
23   my $charges = 0;
24
25   if ( $param->{'increment_next_bill'} ) {
26
27     my $recur_method = $self->option('recur_method', 1) || 'anniversary';
28                   
29     if ( $recur_method eq 'prorate' 
30         or ($recur_method eq 'anniversary' and $self->option('sync_bill_date',1))
31       ) {
32       $charges = $self->calc_prorate(@_);
33     } 
34     else {
35
36       $charges = $self->option('recur_fee');
37
38       if ( $recur_method eq 'subscription' ) {
39
40         my $cutoff_day = $self->option('cutoff_day', 1) || 1;
41         my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ];
42
43         if ( $day < $cutoff_day ) {
44           if ( $mon == 0 ) { $mon=11; $year--; }
45           else { $mon--; }
46         }
47
48         $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year);
49
50       }#$recur_method eq 'subscription'
51     $charges -= $self->calc_discount( $cust_pkg, $sdate, $details, $param );
52
53     }#$recur_method eq 'prorate' or ...
54   }#increment_next_bill
55
56   return $charges;
57
58 }
59
60 1;