X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-prepaidd;h=cb831543597c806dc424c4e89f04483d83684327;hp=e51a56350752b2535797b1b6ed63f32105a5a662;hb=ac8410cdb67639afeb84c84e975fffadf3e6cce1;hpb=0186436eb38e70da0a015e49dab67cec5f1a3467 diff --git a/FS/bin/freeside-prepaidd b/FS/bin/freeside-prepaidd index e51a56350..cb8315435 100644 --- a/FS/bin/freeside-prepaidd +++ b/FS/bin/freeside-prepaidd @@ -3,7 +3,8 @@ use strict; use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm); use FS::UID qw(adminsuidsetup); -use FS::Record qw(qsearch); # qsearchs); +use FS::Record qw(qsearch qsearchs); +use FS::Conf; use FS::cust_pkg; my $user = shift or die &usage; @@ -15,7 +16,7 @@ drop_root(); adminsuidsetup($user); -logfile( "/usr/local/etc/freeside/prepaidd-log.". $FS::UID::datasrc ); +logfile( "%%%FREESIDE_LOG%%%/prepaidd-log.". $FS::UID::datasrc ); daemonize2(); @@ -37,15 +38,57 @@ while (1) { " AND ( cancel IS NULL OR cancel = 0)" } ) ) { - my $error = $cust_pkg->suspend; - warn "Error suspended package ". $cust_pkg->pkgnum. - " for custnum ". $cust_pkg->custnum. + + my $work_cust_pkg = $cust_pkg; + + my $cust_main = $cust_pkg->cust_main; + + #insurance: somehow winding up here without things properly applied... + my $a_error = $cust_main->apply_payments_and_credits; + if ( $a_error ) { + warn "Error applying payments&credits, customer #". $cust_main->custnum; + next; + } + + if ( ( $cust_main->total_unapplied_payments > 0 + || $cust_main->total_unapplied_credits > 0 + ) + && ! FS::Conf->new->exists('prepaid-never_renew') + ) + { + + #this needs a flag to say only do the prepaid packages... + # and only try em if the renewal price matches.. but this will do for now + my $b_error = $cust_main->bill; + if ( $b_error ) { + warn "Error billing customer #". $cust_main->custnum; + next; + } + $b_error = $cust_main->apply_payments_and_credits; + if ( $b_error ) { + warn "Error applying payments&credits, customer #". $cust_main->custnum; + next; + } + + $work_cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $work_cust_pkg->pkgnum } ); + + next + if $cust_main->balance <= 0 + and $work_cust_pkg->bill >= time; + } + + my $action = $work_cust_pkg->part_pkg->option('recur_action') || 'suspend'; + + my $error = $work_cust_pkg->$action(); + + warn "Error ${action}ing package ". $work_cust_pkg->pkgnum. + " for custnum ". $work_cust_pkg->custnum. ": $error\n" if $error; } die "exiting" if sigterm() || sigint(); - sleep 5; + sleep 60; } @@ -65,8 +108,8 @@ freeside-prepaidd - Real-time daemon for prepaid packages =head1 DESCRIPTION -Runs continuously and suspendes any prepaid customer packages which have -passed their renewal date (next bill date). +Runs continuously and suspends or cancels any prepaid customer packages which +have passed their renewal date (next bill date). =head1 SEE ALSO