1 package FS::part_pkg::recur_Common;
2 use base qw( FS::part_pkg::flat );
5 use vars qw( %info %recur_method );
9 %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly
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)',
19 $self->option('recur_fee', 1) || 0;
23 # moved from all descendant packages which just had $self->option('setup_fee')
24 my($self, $cust_pkg, $sdate, $details, $param) = @_;
26 return 0 if $self->prorate_setup($cust_pkg, $sdate);
28 my $charge = $self->option('setup_fee');
32 $param->{'setup_charge'} = $charge;
33 $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
34 delete $param->{'setup_charge'};
37 sprintf('%.2f', $charge - $discount);
41 # prorate/subscription only; we don't support sync_bill_date here
42 my( $self, $cust_pkg ) = @_;
43 my $recur_method = $self->option('recur_method',1) || 'anniversary';
44 return () unless $recur_method eq 'prorate'
45 || $recur_method eq 'subscription';
47 #false laziness w/prorate.pm::cutoff_day
48 my $prorate_day = $cust_pkg->cust_main->prorate_day;
49 $prorate_day ? ( $prorate_day )
50 : split(/\s*,\s*/, $self->option('cutoff_day', 1) || '1');
53 sub calc_recur_Common {
55 my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param
59 if ( $param->{'increment_next_bill'} ) {
61 my $recur_method = $self->option('recur_method', 1) || 'anniversary';
62 my @cutoff_day = $self->cutoff_day($cust_pkg);
64 $charges = $self->base_recur($cust_pkg, $sdate, $details, $param);
65 $charges += $param->{'override_charges'} if $param->{'override_charges'};
67 if ( $recur_method eq 'prorate' ) {
69 $charges = $self->calc_prorate(@_, @cutoff_day);
70 $charges += $param->{'override_charges'} if $param->{'override_charges'};
72 } elsif ( $recur_method eq 'subscription' ) {
74 my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ];
76 if ( $day < $cutoff_day[0] ) {
77 if ( $mon == 0 ) { $mon=11; $year--; }
81 $$sdate = timelocal(0, 0, 0, $cutoff_day[0], $mon, $year);
85 $charges -= $self->calc_discount( $cust_pkg, $sdate, $details, $param );