From: mark Date: Wed, 22 Sep 2010 21:22:03 +0000 (+0000) Subject: customer credit limits, RT#8209 X-Git-Tag: TORRUS_1_0_9~280 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=cb0b8c862de7c7ab68b172faa29167f47894627b customer credit limits, RT#8209 --- 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 @@ %> + + Credit limit + + + credit_limit) %><% length($cust_main->credit_limit) ? '' : ' DISABLED' %>> + credit_limit) ? '' : ' CHECKED'%>> Unlimited + + % if ( $conf->exists('voip-cust_cdr_spools') ) { 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' ). ')' %> + + Credit limit + + <% length($cust_main->credit_limit) ? + $money_char.sprintf("%.2f", $cust_main->credit_limit) : + 'Unlimited' %> + + % if ( $conf->exists('voip-cust_cdr_spools') ) {