summaryrefslogtreecommitdiff
path: root/FS
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 /FS
parent197c503fbe112896332e9ca5f17c9c5a2ea4bb87 (diff)
customer credit limits, RT#8209
Diffstat (limited to 'FS')
-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
3 files changed, 34 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;
+