- my($self, $cust_pkg) = @_;
- $self->reset_usage($cust_pkg);
- $self->base_recur($cust_pkg);
+ my $self = shift;
+ my($cust_pkg, $sdate, $details, $param ) = @_;
+
+ #my $last_bill = $cust_pkg->last_bill;
+ my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup
+
+ return 0
+ if $self->recur_temporality eq 'preceding' && $last_bill == 0;
+
+ my $charge = $self->base_recur($cust_pkg, $sdate);
+ if ( my $cutoff_day = $self->cutoff_day($cust_pkg) ) {
+ $charge = $self->calc_prorate(@_, $cutoff_day);
+ }
+ elsif ( $param->{freq_override} ) {
+ # XXX not sure if this should be mutually exclusive with sync_bill_date.
+ # Given the very specific problem that freq_override is meant to 'solve',
+ # it probably should.
+ $charge *= $param->{freq_override} if $param->{freq_override};
+ }
+
+ my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
+ return sprintf('%.2f', $charge - $discount);
+}
+
+sub cutoff_day {
+ my $self = shift;
+ my $cust_pkg = shift;
+ if ( $self->option('sync_bill_date',1) ) {
+ my $next_bill = $cust_pkg->cust_main->next_bill_date;
+ if ( defined($next_bill) ) {
+ return (localtime($next_bill))[3];
+ }
+ }
+ return 0;