- if($cutoff_day) {
- # only works for freq >= 1 month; probably can't be fixed
- my $mnow = $$sdate;
- my ($sec, $min, $hour, $mday, $mon, $year) = (localtime($mnow))[0..5];
- if ( $self->option('prorate_round_day',1) ) {
- $mday++ if $hour >= 12;
- $mnow = timelocal(0,0,0,$mday,$mon,$year);
- }
- my $mend;
- my $mstart;
- if ( $mday >= $cutoff_day ) {
- $mend =
- timelocal(0,0,0,$cutoff_day,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));
- $mstart =
- timelocal(0,0,0,$cutoff_day,$mon,$year);
+ if ( $self->option('prorate_verbose',1) and $months > 0 ) {
+ if ( $months < $self->freq ) {
+ # we are billing a fractional period only
+ # # (though maybe not a fractional month)
+ my $period_end = $self->add_freq($mstart);
+ push @$details,
+ 'Prorated (' . time2str('%b %d', $mnow) .
+ ' - ' . time2str('%b %d', $period_end) . '): ' . $money_char .
+ sprintf('%.2f', $permonth * $months + 0.00000001 );
+
+ } elsif ( $months > $self->freq ) {
+ # we are billing MORE than a full period
+ push @$details,
+
+ 'Prorated (' . time2str('%b %d', $mnow) .
+ ' - ' . time2str('%b %d', $mend) . '): ' . $money_char .
+ sprintf('%.2f', $permonth * ($months - $self->freq + 0.0000001)),
+
+ 'First full period: ' . $money_char .
+ sprintf('%.2f', $permonth * $self->freq);
+ } # else $months == $self->freq, and no prorating has happened
+ }
+
+ $param->{'months'} = $months;
+ #so 1.005 rounds to 1.01
+ $charge = sprintf('%.2f', $permonth * $months + 0.00000001 );
+
+ return sprintf('%.2f', $charge);
+}
+
+=item prorate_setup CUST_PKG SDATE
+
+Set up the package. This only has an effect if prorate_defer_bill is
+set, in which case it postpones the next bill to the cutoff day.
+
+=cut
+
+sub prorate_setup {
+ my $self = shift;
+ my ($cust_pkg, $sdate) = @_;
+ my @cutoff_days = $self->cutoff_day($cust_pkg);
+ if ( ! $cust_pkg->bill
+ and $self->option('prorate_defer_bill',1)
+ and @cutoff_days
+ ) {
+ my ($mnow, $mend, $mstart) = $self->_endpoints($sdate, @cutoff_days);
+ # If today is the cutoff day, set the next bill and setup both to
+ # midnight today, so that the customer will be billed normally for a
+ # month starting today.
+ if ( $mnow - $mstart < 86400 ) {
+ $cust_pkg->setup($mstart);
+ $cust_pkg->bill($mstart);