my($time)= $opt{'d'} ? str2time($opt{'d'}) : $^T;
$time += $opt{'y'} * 86400 if $opt{'y'};
+ my $invoice_time = $opt{'n'} ? $^T : $time;
+
# select * from cust_main where
my $where_pkg = <<"END";
0 < ( select count(*) from cust_pkg
and ( setup is null or setup = 0
or bill is null or bill <= $time
or ( expire is not null and expire <= $^T )
+ or ( adjourn is not null and adjourn <= $^T )
)
)
END
my($cust_main,%saw);
foreach $cust_main ( @cust_main ) {
+
+ my $custnum = $cust_main->custnum;
# $^T not $time because -d is for pre-printing invoices
foreach my $cust_pkg (
grep { $_->expire && $_->expire <= $^T } $cust_main->ncancelled_pkgs
) {
my $error = $cust_pkg->cancel;
- warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ".
- $cust_main->custnum. ": $error"
+ warn "Error cancelling expired pkg ". $cust_pkg->pkgnum.
+ " for custnum $custnum: $error"
if $error;
}
# $^T not $time because -d is for pre-printing invoices
foreach my $cust_pkg (
- grep { $_->part_pkg->is_prepaid
- && $_->bill && $_->bill < $^T && ! $_->susp
+ grep { ( $_->part_pkg->is_prepaid && $_->bill && $_->bill < $^T
+ || $_->adjourn && $_->adjourn <= $^T
+ )
+ && ! $_->susp
}
$cust_main->ncancelled_pkgs
) {
my $error = $cust_pkg->suspend;
warn "Error suspending package ". $cust_pkg->pkgnum.
- " for custnum ". $cust_main->custnum.
- ": $error"
+ " for custnum $custnum: $error"
if $error;
}
- my $error = $cust_main->bill( 'time' => $time,
- 'resetup' => $opt{'s'},
+ my $error = $cust_main->bill( 'time' => $time,
+ 'invoice_time' => $invoice_time,
+ 'resetup' => $opt{'s'},
);
- warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error;
+ warn "Error billing, custnum $custnum: $error" if $error;
- $cust_main->apply_payments_and_credits;
+ $error = $cust_main->apply_payments_and_credits;
+ warn "Error applying payments and credits, custnum $custnum: $error"
+ if $error;
$error = $cust_main->collect( 'invoice_time' => $time,
'freq' => $opt{'freq'},
);
- warn "Error collecting, custnum". $cust_main->custnum. ": $error" if $error;
+ warn "Error collecting, custnum $custnum: $error" if $error;
}