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;
@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
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.
=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
@cust_pkg = $record->ncancelled_pkgs;
+ @cust_pkg = $record->suspended_pkgs;
+
$error = $record->bill;
$error = $record->bill %options;
$error = $record->bill 'time' => $time;
] };
}
+=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
=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
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
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;
$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
+
'';
}
=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
=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;
$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
}
=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
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 );
#!/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; }
'susp', @date_type,
'cancel', @date_type,
'expire', @date_type,
+ 'manual_flag', 'char', 'NULL', 1,
],
'primary_key' => 'pkgnum',
'unique' => [ [] ],
<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.
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>
<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>
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 );