start of settlement CDR processing, RT#5495
[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 %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 tie %recur_method, 'Tie::IxHash',
12   'anniversary'  => 'Charge the recurring fee at the frequency specified above',
13   'prorate'      => 'Charge a prorated fee the first time (selectable billing date)',
14   'subscription' => 'Charge the full fee for the first partial period (selectable billing date)',
15 ;
16
17 sub calc_recur_Common {
18   my $self = shift;
19   my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param
20
21   my $charges = 0;
22
23   if ( $param->{'increment_next_bill'} ) {
24
25     my $recur_method = $self->option('recur_method', 1) || 'anniversary';
26                   
27     if ( $recur_method eq 'prorate' ) {
28
29       $charges = $self->SUPER::calc_recur(@_);
30
31     } else {
32
33       $charges = $self->option('recur_fee');
34
35       if ( $recur_method eq 'subscription' ) {
36
37         my $cutoff_day = $self->option('cutoff_day', 1) || 1;
38         my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ];
39
40         if ( $day < $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       }#$recur_method eq 'subscription'
48
49     }#$recur_method eq 'prorate'
50
51   }#increment_next_bill
52
53   $charges;
54
55 }
56
57 1;