summaryrefslogtreecommitdiff
path: root/FS/FS/cust_pay.pm
diff options
context:
space:
mode:
authorivan <ivan>2001-10-09 23:10:17 +0000
committerivan <ivan>2001-10-09 23:10:17 +0000
commit4bbf90e800406ff75a5fed09ba5cd71293cda542 (patch)
treefd0e96a0b2c0d47f6d3aa2181953341b7eecb254 /FS/FS/cust_pay.pm
parent2e1ca65dcfcf6a8ef41a10e15e3d20200ffc871a (diff)
add `unsuspendauto' config file: enable the automatic unsuspension of suspended
packages when a customer's balance due changes from positive to zero or negative as the result of a payment or credit add cust_pkg.manual_flag to disable this behaviour per customer package (no UI to set this yet)
Diffstat (limited to 'FS/FS/cust_pay.pm')
-rw-r--r--FS/FS/cust_pay.pm29
1 files changed, 26 insertions, 3 deletions
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 42ca0b0..daf5b52 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -1,15 +1,24 @@
package FS::cust_pay;
use strict;
-use vars qw( @ISA );
+use vars qw( @ISA $conf $unsuspendauto );
use Business::CreditCard;
-use FS::Record qw( dbh qsearch qsearchs );
+use FS::UID qw( dbh );
+use FS::Record qw( dbh qsearch qsearchs dbh );
use FS::cust_bill;
use FS::cust_bill_pay;
use FS::cust_main;
@ISA = qw( FS::Record );
+#ask FS::UID to run this stuff for us later
+$FS::UID::callback{'FS::cust_pay'} = sub {
+
+ $conf = new FS::Conf;
+ $unsuspendauto = $conf->exists('unsuspendauto');
+
+};
+
=head1 NAME
FS::cust_pay - Object methods for cust_pay objects
@@ -90,6 +99,9 @@ sub insert {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ my $cust_main = qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
+ my $old_balance = $cust_main->balance;
+
my $error = $self->check;
return $error if $error;
@@ -124,6 +136,17 @@ sub insert {
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ #false laziness w/ cust_credit::insert
+ if ( $unsuspendauto && $old_balance && $cust_main->balance <= 0 ) {
+ my @errors = $cust_main->unsuspend;
+ #return
+ # side-fx with nested transactions? upstack rolls back?
+ warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
+ join(' / ', @errors)
+ if @errors;
+ }
+ #eslaf
+
'';
}
@@ -281,7 +304,7 @@ sub unapplied {
=head1 VERSION
-$Id: cust_pay.pm,v 1.7 2001-09-03 22:07:38 ivan Exp $
+$Id: cust_pay.pm,v 1.8 2001-10-09 23:10:16 ivan Exp $
=head1 BUGS