From 3213e7c1e281dbdba8baa980028482df3b9c1873 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Dec 2005 00:52:27 +0000 Subject: [PATCH] add invoice event to suspend only when greater than N amount --- FS/FS/cust_bill.pm | 20 ++++++++++++++++++++ FS/FS/cust_main.pm | 13 ++++++++----- FS/FS/part_bill_event.pm | 2 ++ httemplate/edit/part_bill_event.cgi | 9 +++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 44b50ae74..6e3b2b2f8 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 7866369d7..a265e4177 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) 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) matching the listed -PKGPARTs (see L). Always returns a list: an empty list on -success or a list of errors. +PKGPARTs (see L). + +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) unless they match the -listed PKGPARTs (see L). Always returns a list: an empty list -on success or a list of errors. +listed PKGPARTs (see L). + +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 573b21b59..8143e3473 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 64a82493a..cc6bb47d2 100755 --- a/httemplate/edit/part_bill_event.cgi +++ b/httemplate/edit/part_bill_event.cgi @@ -94,6 +94,9 @@ sub select_agentnum { ''; } +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 ". '', + 'weight' => 10, + }, 'suspend-if-pkgpart' => { 'name' => 'Suspend packages', 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);', -- 2.11.0