add invoice event to suspend only when greater than N amount
authorivan <ivan>
Sun, 25 Dec 2005 00:52:27 +0000 (00:52 +0000)
committerivan <ivan>
Sun, 25 Dec 2005 00:52:27 +0000 (00:52 +0000)
FS/FS/cust_bill.pm
FS/FS/cust_main.pm
FS/FS/part_bill_event.pm
httemplate/edit/part_bill_event.cgi

index 44b50ae..6e3b2b2 100644 (file)
@@ -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
index 7866369..a265e41 100644 (file)
@@ -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
 
index 573b21b..8143e34 100644 (file)
@@ -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";
index 64a8249..cc6bb47 100755 (executable)
@@ -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%%%);',