diff options
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/cust_credit.pm | 56 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 66 | ||||
-rw-r--r-- | FS/FS/cust_pay.pm | 29 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 10 |
4 files changed, 153 insertions, 8 deletions
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 1f792da..54c201a 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -1,8 +1,8 @@ package FS::cust_credit; use strict; -use vars qw( @ISA ); -use FS::UID qw( getotaker ); +use vars qw( @ISA $conf $unsuspendauto ); +use FS::UID qw( dbh getotaker ); use FS::Record qw( qsearch qsearchs ); use FS::cust_main; use FS::cust_refund; @@ -10,6 +10,14 @@ use FS::cust_credit_bill; @ISA = qw( FS::Record ); +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::cust_credit'} = sub { + + $conf = new FS::Conf; + $unsuspendauto = $conf->exists('unsuspendauto'); + +}; + =head1 NAME FS::cust_credit - Object methods for cust_credit records @@ -69,6 +77,48 @@ sub table { 'cust_credit'; } Adds this credit to the database ("Posts" the credit). If there is an error, returns the error, otherwise returns false. +=cut + +sub insert { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + 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->SUPER::insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error inserting $self: $error"; + } + + $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 + + ''; + +} + =item delete Currently unimplemented. @@ -185,7 +235,7 @@ sub credited { =head1 VERSION -$Id: cust_credit.pm,v 1.11 2001-09-02 07:49:52 ivan Exp $ +$Id: cust_credit.pm,v 1.12 2001-10-09 23:10:16 ivan Exp $ =head1 BUGS diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 0a7f1f7..d5beca9 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -98,6 +98,8 @@ FS::cust_main - Object methods for cust_main records @cust_pkg = $record->ncancelled_pkgs; + @cust_pkg = $record->suspended_pkgs; + $error = $record->bill; $error = $record->bill %options; $error = $record->bill 'time' => $time; @@ -708,6 +710,68 @@ sub ncancelled_pkgs { ] }; } +=item suspended_pkgs + +Returns all suspended packages (see L<FS::cust_pkg>) for this customer. + +=cut + +sub suspended_pkgs { + my $self = shift; + grep { $_->susp } $self->ncancelled_pkgs; +} + +=item unflagged_suspended_pkgs + +Returns all unflagged suspended packages (see L<FS::cust_pkg>) for this +customer (thouse packages without the `manual_flag' set). + +=cut + +sub unflagged_suspended_pkgs { + my $self = shift; + return $self->suspended_pkgs + unless dbdef->table('cust_pkg')->column('manual_flag'); + grep { ! $_->manual_flag } $self->suspended_pkgs; +} + +=item unsuspended_pkgs + +Returns all unsuspended (and uncancelled) packages (see L<FS::cust_pkg>) for +this customer. + +=cut + +sub unsuspended_pkgs { + my $self = shift; + grep { ! $_->susp } $self->ncancelled_pkgs; +} + +=item unsuspend + +Unsuspends all unflagged suspended packages (see L</unflagged_suspended_pkgs> +and L<FS::cust_pkg>) for this customer. Always returns a list: an empty list +on success or a list of errors. + +=cut + +sub unsuspend { + my $self = shift; + grep { $_->unsuspend } $self->suspended_pkgs; +} + +=item suspend + +Suspends all unsuspended packages (see L<FS::cust_pkg>) for this customer. +Always returns a list: an empty list on success or a list of errors. + +=cut + +sub suspend { + my $self = shift; + grep { $_->suspend } $self->unsuspended_pkgs; +} + =item bill OPTIONS Generates invoices (see L<FS::cust_bill>) for this customer. Usually used in @@ -1724,7 +1788,7 @@ sub append_fuzzyfiles { =head1 VERSION -$Id: cust_main.pm,v 1.38 2001-09-26 09:17:06 ivan Exp $ +$Id: cust_main.pm,v 1.39 2001-10-09 23:10:16 ivan Exp $ =head1 BUGS 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 diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index d2d7419..1bcf74f 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -77,6 +77,9 @@ inherits from FS::Record. The following fields are currently supported: =item otaker - order taker (assigned automatically if null, see L<FS::UID>) +=item manual_flag - If this field is set to 1, disables the automatic +unsuspensiond of this package when using the B<unsuspendauto> config file. + =back Note: setup, bill, susp, expire and cancel are specified as UNIX timestamps; @@ -197,6 +200,11 @@ sub check { $self->otaker =~ /^(\w{0,16})$/ or return "Illegal otaker"; $self->otaker($1); + if ( $self->dbdef_table->column('manual_flag') ) { + $self->manual_flag =~ /^([01]?)$/ or return "Illegal manual_flag"; + $self->manual_flag($1); + } + ''; #no error } @@ -568,7 +576,7 @@ sub order { =head1 VERSION -$Id: cust_pkg.pm,v 1.8 2001-10-09 03:11:50 ivan Exp $ +$Id: cust_pkg.pm,v 1.9 2001-10-09 23:10:16 ivan Exp $ =head1 BUGS |