X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-daily;h=603da12b8534fb935bcc2a50f57229f75f91521b;hb=8f5c91d6c7a8dc85a8b6768a149b4c7b3e144c38;hp=db6b971282e8099673c6f40fe8cc2a54b098aa91;hpb=2358bebdb617840f9a635187a71491ed4d16f614;p=freeside.git diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index db6b97128..603da12b8 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -10,7 +10,7 @@ use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v $opt_p $opt_s $opt_y); +use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y); getopts("p:a:d:vsy:"); my $user = shift or die &usage; @@ -43,10 +43,16 @@ my $where_bill_event = <<"END"; 0 < ( select count(*) from cust_bill where cust_main.custnum = cust_bill.custnum and 0 < charged - - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) + - coalesce( + ( select sum(amount) from cust_bill_pay + where cust_bill.invnum = cust_bill_pay.invnum ) + ,0 + ) + - coalesce( + ( select sum(amount) from cust_credit_bill + where cust_bill.invnum = cust_credit_bill.invnum ) + ,0 + ) and 0 < ( select count(*) from part_bill_event where payby = cust_main.payby and ( disabled is null or disabled = '' ) @@ -61,7 +67,7 @@ my $where_bill_event = <<"END"; ) END -my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "$where_pkg OR $where_bill_event"; +my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "( $where_pkg OR $where_bill_event )"; my @cust_main; if ( @ARGV ) { @@ -83,6 +89,19 @@ foreach $cust_main ( @cust_main ) { $cust_main->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 + } + $cust_main->ncancelled_pkgs + ) { + my $error = $cust_pkg->suspend; + warn "Error suspending package ". $cust_pkg->pkgnum. + " for custnum ". $cust_main->custnum. + ": $error" + if $error; + } my $error = $cust_main->bill( 'time' => $time, 'resetup' => $opt_s, );