summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2005-12-25 00:52:27 +0000
committerivan <ivan>2005-12-25 00:52:27 +0000
commit3213e7c1e281dbdba8baa980028482df3b9c1873 (patch)
tree7096d01bf15dafbdfdc707d28ee6d2d88761acad
parent9cc2ba7cbf26eefbd1d01a2f98b47a24a8766428 (diff)
add invoice event to suspend only when greater than N amount
-rw-r--r--FS/FS/cust_bill.pm20
-rw-r--r--FS/FS/cust_main.pm13
-rw-r--r--FS/FS/part_bill_event.pm2
-rwxr-xr-xhttemplate/edit/part_bill_event.cgi9
4 files changed, 39 insertions, 5 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 44b50ae..6e3b2b2 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -236,6 +236,25 @@ sub cust_main {
qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
}
+=item cust_suspend_if_balance_over AMOUNT
+
+Suspends the customer associated with this invoice if the total amount owed on
+this invoice and all older invoices is greater than the specified amount.
+
+Returns a list: an empty list on success or a list of errors.
+
+=cut
+
+sub cust_suspend_if_balance_over {
+ my( $self, $amount ) = ( shift, shift );
+ my $cust_main = $self->cust_main;
+ if ( $cust_main->total_owed_date($self->_date) < $amount ) {
+ return ();
+ } else {
+ $cust_main->suspend;
+ }
+}
+
=item cust_credit
Depreciated. See the cust_credited method.
@@ -2389,6 +2408,7 @@ sub _items_payments {
}
+
=back
=head1 SUBROUTINES
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 7866369..a265e41 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -1460,7 +1460,8 @@ sub unsuspend {
=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.
+
+Returns a list: an empty list on success or a list of errors.
=cut
@@ -1472,8 +1473,9 @@ sub suspend {
=item suspend_if_pkgpart PKGPART [ , PKGPART ... ]
Suspends all unsuspended packages (see L<FS::cust_pkg>) matching the listed
-PKGPARTs (see L<FS::part_pkg>). Always returns a list: an empty list on
-success or a list of errors.
+PKGPARTs (see L<FS::part_pkg>).
+
+Returns a list: an empty list on success or a list of errors.
=cut
@@ -1488,8 +1490,9 @@ sub suspend_if_pkgpart {
=item suspend_unless_pkgpart PKGPART [ , PKGPART ... ]
Suspends all unsuspended packages (see L<FS::cust_pkg>) unless they match the
-listed PKGPARTs (see L<FS::part_pkg>). Always returns a list: an empty list
-on success or a list of errors.
+listed PKGPARTs (see L<FS::part_pkg>).
+
+Returns a list: an empty list on success or a list of errors.
=cut
diff --git a/FS/FS/part_bill_event.pm b/FS/FS/part_bill_event.pm
index 573b21b..8143e34 100644
--- a/FS/FS/part_bill_event.pm
+++ b/FS/FS/part_bill_event.pm
@@ -134,6 +134,8 @@ sub check {
or $c =~ /^\s*\$cust_main\->suspend_(if|unless)_pkgpart\([\d\,\s]*\);\s*$/
+ or $c =~ /^\s*\$cust_bill\->cust_suspend_if_balance_over\([\d\.\s]*\);\s*$/
+
or do {
#log
return "illegal eventcode: $c";
diff --git a/httemplate/edit/part_bill_event.cgi b/httemplate/edit/part_bill_event.cgi
index 64a8249..cc6bb47 100755
--- a/httemplate/edit/part_bill_event.cgi
+++ b/httemplate/edit/part_bill_event.cgi
@@ -94,6 +94,9 @@ sub select_agentnum {
'</SELECT>';
}
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char');
+
#this is pretty kludgy right here.
tie my %events, 'Tie::IxHash',
@@ -110,6 +113,12 @@ tie my %events, 'Tie::IxHash',
'code' => '$cust_main->suspend();',
'weight' => 10,
},
+ 'suspend' => {
+ 'name' => 'Suspend if balance (this invoice and previous) over',
+ 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
+ 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
+ 'weight' => 10,
+ },
'suspend-if-pkgpart' => {
'name' => 'Suspend packages',
'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',