summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormark <mark>2010-09-22 21:22:03 +0000
committermark <mark>2010-09-22 21:22:03 +0000
commitcb0b8c862de7c7ab68b172faa29167f47894627b (patch)
treea690eda6f9b6d6e9274094583618962e7b248227
parent197c503fbe112896332e9ca5f17c9c5a2ea4bb87 (diff)
customer credit limits, RT#8209
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cust_main.pm1
-rw-r--r--FS/FS/part_event/Condition/balance_credit_limit.pm32
-rw-r--r--httemplate/edit/cust_main/billing.html12
-rwxr-xr-xhttemplate/edit/process/cust_main.cgi4
-rw-r--r--httemplate/view/cust_main/billing.html8
6 files changed, 58 insertions, 0 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 57ef18eef..09daef014 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -768,6 +768,7 @@ sub tables_hashref {
'squelch_cdr','char', 'NULL', 1, '', '',
'cdr_termination_percentage', 'decimal', 'NULL', '', '', '',
'invoice_terms', 'varchar', 'NULL', $char_d, '', '',
+ 'credit_limit', @money_typen, '', '',
'archived', 'char', 'NULL', 1, '', '',
'email_csv_cdr', 'char', 'NULL', 1, '', '',
],
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index f9204cad1..b1b2753ea 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -1415,6 +1415,7 @@ sub check {
|| $self->ut_textn('invoice_terms')
|| $self->ut_alphan('geocode')
|| $self->ut_floatn('cdr_termination_percentage')
+ || $self->ut_floatn('credit_limit')
;
#barf. need message catalogs. i18n. etc.
diff --git a/FS/FS/part_event/Condition/balance_credit_limit.pm b/FS/FS/part_event/Condition/balance_credit_limit.pm
new file mode 100644
index 000000000..1bc2aa1b7
--- /dev/null
+++ b/FS/FS/part_event/Condition/balance_credit_limit.pm
@@ -0,0 +1,32 @@
+package FS::part_event::Condition::balance_credit_limit;
+
+use strict;
+use FS::cust_main;
+
+use base qw( FS::part_event::Condition );
+
+sub description { 'Customer is over credit limit'; }
+
+sub condition {
+ my($self, $object) = @_;
+
+ my $cust_main = $self->cust_main($object);
+
+ my $over = $cust_main->credit_limit;
+ return 0 if !length($over); # if credit limit is null, no limit
+
+ $cust_main->balance > $over;
+}
+
+sub condition_sql {
+ my( $class, $table ) = @_;
+
+ my $balance_sql = FS::cust_main->balance_sql;
+
+ "(cust_main.credit_limit IS NULL OR
+ $balance_sql - cust_main.credit_limit > 0 )";
+
+}
+
+1;
+
diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html
index ad83778ca..aeb67b662 100644
--- a/httemplate/edit/cust_main/billing.html
+++ b/httemplate/edit/cust_main/billing.html
@@ -417,6 +417,18 @@
%>
</TD>
</TR>
+ <TR>
+ <TD ALIGN="right" WIDTH="200">Credit limit </TD>
+ <TD WIDTH="408">
+ <SCRIPT TYPE="text/javascript">
+function toggle(obj) {
+ obj.form.credit_limit.disabled = obj.checked;
+}
+ </SCRIPT>
+ <INPUT TYPE="text" NAME="credit_limit" VALUE=<% sprintf('"%.2f"', $cust_main->credit_limit) %><% length($cust_main->credit_limit) ? '' : ' DISABLED' %>>
+ <INPUT TYPE="checkbox" NAME="no_credit_limit" VALUE=1 onclick="toggle(this)"<% length($cust_main->credit_limit) ? '' : ' CHECKED'%>> Unlimited
+ </TD>
+ </TR>
% if ( $conf->exists('voip-cust_cdr_spools') ) {
<TR>
diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi
index 3158d7bbf..e2238bd67 100755
--- a/httemplate/edit/process/cust_main.cgi
+++ b/httemplate/edit/process/cust_main.cgi
@@ -73,6 +73,10 @@ if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
);
}
+if ( $cgi->param('no_credit_limit') ) {
+ $new->setfield('credit_limit', '');
+}
+
$new->tagnum( [ $cgi->param('tagnum') ] );
my %usedatetime = ( 'birthdate' => 1 );
diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html
index 54c180bdd..dd195236a 100644
--- a/httemplate/view/cust_main/billing.html
+++ b/httemplate/view/cust_main/billing.html
@@ -206,6 +206,14 @@ Billing information
<% $cust_main->invoice_terms || 'Default ('. ( $conf->config('invoice_default_terms') || 'Payable upon receipt' ). ')' %>
</TD>
</TR>
+<TR>
+ <TD ALIGN="right">Credit&nbsp;limit</TD>
+ <TD BGCOLOR="#ffffff">
+ <% length($cust_main->credit_limit) ?
+ $money_char.sprintf("%.2f", $cust_main->credit_limit) :
+ 'Unlimited' %>
+ </TD>
+</TR>
% if ( $conf->exists('voip-cust_cdr_spools') ) {
<TR>