From 4bbf90e800406ff75a5fed09ba5cd71293cda542 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 9 Oct 2001 23:10:17 +0000 Subject: [PATCH] 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) --- FS/FS/cust_credit.pm | 56 ++++++++++++++++++++++++++++++++++-- FS/FS/cust_main.pm | 66 ++++++++++++++++++++++++++++++++++++++++++- FS/FS/cust_pay.pm | 29 +++++++++++++++++-- FS/FS/cust_pkg.pm | 10 ++++++- README.1.4.0pre3-4 | 2 +- bin/fs-setup | 3 +- httemplate/docs/config.html | 1 + httemplate/docs/install.html | 2 +- httemplate/docs/schema.html | 1 + httemplate/docs/upgrade8.html | 1 + 10 files changed, 160 insertions(+), 11 deletions(-) diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 1f792daa6..54c201ad4 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 0a7f1f7cb..d5beca92a 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) 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) 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) for +this customer. + +=cut + +sub unsuspended_pkgs { + my $self = shift; + grep { ! $_->susp } $self->ncancelled_pkgs; +} + +=item unsuspend + +Unsuspends all unflagged suspended packages (see L +and L) 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) 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) 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 42ca0b0a5..daf5b5263 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 d2d74190d..1bcf74f78 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) +=item manual_flag - If this field is set to 1, disables the automatic +unsuspensiond of this package when using the B 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 diff --git a/README.1.4.0pre3-4 b/README.1.4.0pre3-4 index 9814a658a..102b57872 100644 --- a/README.1.4.0pre3-4 +++ b/README.1.4.0pre3-4 @@ -11,7 +11,7 @@ CREATE TABLE part_pop_local ( nxx char(3) not null ); CREATE INDEX part_pop_local1 ON part_pop_local ( npa, nxx ); - +ALTER TABLE cust_pkg ADD manual_flag char(1) NULL; ALTER TABLE cust_pay_batch ADD paybatchnum integer; CREATE UNIQUE INDEX cust_pay_batch_pkey ON cust_pay_batch ( paybatchnum ); diff --git a/bin/fs-setup b/bin/fs-setup index 476b84d87..edfc5ff1c 100755 --- a/bin/fs-setup +++ b/bin/fs-setup @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw # -# $Id: fs-setup,v 1.60 2001-10-02 16:00:30 jeff Exp $ +# $Id: fs-setup,v 1.61 2001-10-09 23:10:17 ivan Exp $ #to delay loading dbdef until we're ready BEGIN { $FS::Record::setup_hack = 1; } @@ -481,6 +481,7 @@ sub tables_hash_hack { 'susp', @date_type, 'cancel', @date_type, 'expire', @date_type, + 'manual_flag', 'char', 'NULL', 1, ], 'primary_key' => 'pkgnum', 'unique' => [ [] ], diff --git a/httemplate/docs/config.html b/httemplate/docs/config.html index 0cafc8280..63f6baba9 100644 --- a/httemplate/docs/config.html +++ b/httemplate/docs/config.html @@ -107,6 +107,7 @@ All further configuration files and directories are located in
  • soaretry - SOA retry for new domains
  • statedefault - Default state or province (if not supplied, the default is `CA')
  • textradiusprepend - DEPRECIATED, use RADIUS check attributes instead. This option will be removed soon. The contents of this file will be prepended to the first line of a user's RADIUS entry in text exports. +
  • unsuspendauto _ The existance of this file will 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.
  • usernamemin - Minimum username length (default 2);
  • usernamemax - Maximum username length (default is the size of the SQL column, probably specified when fs-setup was run)
  • username-letter - The existance of this file will turn on the requirement that usernames contain at least one letter. diff --git a/httemplate/docs/install.html b/httemplate/docs/install.html index 53eb8f856..44644dc91 100644 --- a/httemplate/docs/install.html +++ b/httemplate/docs/install.html @@ -51,7 +51,7 @@ $ mysql -u root -p mysql> GRANT SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE,DROP on freeside.* TO freeside@localhost IDENTIFIED BY 'set_a_freeside_database_password';
  • with PostgreSQL -
  • Add the freeside database to your database engine. (with MySQL) (with PostgreSQL) +
  • Add the freeside database to your database engine. (with MySQL) (with PostgreSQL)
  • Unpack the tarball:
    gunzip -c fs-x.y.z.tar.gz | tar xvf -
  • Build and install the Perl libraries:
    diff --git a/httemplate/docs/schema.html b/httemplate/docs/schema.html
    index c3cb51425..d831c59f4 100644
    --- a/httemplate/docs/schema.html
    +++ b/httemplate/docs/schema.html
    @@ -154,6 +154,7 @@
             
  • expire - (future) cancellation date
  • cancel - (past) cancellation date
  • otaker - order taker +
  • manual_flag - If this field is set to 1, disables the automatic unsuspensiond of this package when using the unsuspendauto config file.
  • cust_refund - Refunds. The transfer of money to a customer; equivalent to a negative cust_pay record.
      diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index afb84296e..79eb6da3f 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -134,6 +134,7 @@ ALTER TABLE cust_main ADD referral_custnum integer NULL; ALTER TABLE cust_pay ADD custnum integer; ALTER TABLE cust_pay_batch ADD paybatchnum integer; ALTER TABLE cust_refund ADD custnum integer; +ALTER TABLE cust_pkg ADD manual_flag char(1) NULL; CREATE INDEX cust_main3 ON cust_main ( referral_custnum ); CREATE INDEX cust_credit_bill1 ON cust_credit_bill ( crednum ); CREATE INDEX cust_credit_bill2 ON cust_credit_bill ( invnum ); -- 2.11.0