add `unsuspendauto' config file: enable the automatic unsuspension of suspended
authorivan <ivan>
Tue, 9 Oct 2001 23:10:17 +0000 (23:10 +0000)
committerivan <ivan>
Tue, 9 Oct 2001 23:10:17 +0000 (23:10 +0000)
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
FS/FS/cust_main.pm
FS/FS/cust_pay.pm
FS/FS/cust_pkg.pm
README.1.4.0pre3-4
bin/fs-setup
httemplate/docs/config.html
httemplate/docs/install.html
httemplate/docs/schema.html
httemplate/docs/upgrade8.html

index 1f792da..54c201a 100644 (file)
@@ -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
 
index 0a7f1f7..d5beca9 100644 (file)
@@ -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
 
index 42ca0b0..daf5b52 100644 (file)
@@ -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
 
index d2d7419..1bcf74f 100644 (file)
@@ -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
 
index 9814a65..102b578 100644 (file)
@@ -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 );
 
index 476b84d..edfc5ff 100755 (executable)
@@ -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' => [ [] ],
index 0cafc82..63f6bab 100644 (file)
@@ -107,6 +107,7 @@ All further configuration files and directories are located in
   <li><a name="soaretry">soaretry</a> - SOA retry for new domains
   <li><a name="statedefault">statedefault</a> - Default state or province (if not supplied, the default is `CA')
   <li><a name="textradiusprepend">textradiusprepend</a> - <b>DEPRECIATED</b>, 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.
+  <li><a name="unsuspendauto">unsuspendauto</a> _ 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.
   <li><a name="usernamemin">usernamemin</a> - Minimum username length (default 2);
   <li><a name="usernamemax">usernamemax</a> - Maximum username length (default is the size of the SQL column, probably specified when fs-setup was run)
   <li><a name="username-letter">username-letter</a> - The existance of this file will turn on the requirement that usernames contain at least one letter.
index 53eb8f8..44644dc 100644 (file)
@@ -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 '<i>set_a_freeside_database_password</i>';</pre>
       <li> with <a href="http://www.postgresql.org/users-lounge/docs/7.1/postgres/user-manag.html#DATABASE-USERS">PostgreSQL</a>
     </ul>
-  <li>Add the freeside database to your database engine.  (with <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#CREATE_DATABASE">MySQL</a>) (with <a href="http://postgresql.readysetnet.com/users-lounge/docs/7.1/postgres/managing-databases.html#MANAGE-AG-CREATEDB">PostgreSQL</a>)
+  <li>Add the freeside database to your database engine.  (with <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#CREATE_DATABASE">MySQL</a>) (with <a href="http://www.postgresql.org/users-lounge/docs/7.1/postgres/managing-databases.html#MANAGE-AG-CREATEDB">PostgreSQL</a>)
   <li>Unpack the tarball: <pre>gunzip -c fs-x.y.z.tar.gz | tar xvf -</pre>
   <li>Build and install the Perl libraries:
     <pre>
index c3cb514..d831c59 100644 (file)
         <li>expire - (future) cancellation date
         <li>cancel - (past) cancellation date
         <li>otaker - order taker
+        <li>manual_flag - If this field is set to 1, disables the automatic unsuspensiond of this package when using the <a href="config.html#unsuspendauto">unsuspendauto</a> config file.
       </ul>
     <li><a name="cust_refund" href="man/FS/cust_refund.html">cust_refund</a> - Refunds.  The transfer of money to a customer; equivalent to a negative <a href="#cust_pay">cust_pay</a> record.
       <ul>
index afb8429..79eb6da 100644 (file)
@@ -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 );