From f3c4bc88460be7576d81b9ca234b421950f48c01 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 5 Apr 2007 02:04:21 +0000 Subject: [PATCH] per-customer invoice terms override --- FS/FS/Schema.pm | 1 + FS/FS/cust_bill.pm | 48 +++++++++++++++++++++++++--------- FS/FS/cust_main.pm | 11 ++------ httemplate/edit/cust_main.cgi | 2 ++ httemplate/edit/cust_main/billing.html | 17 ++++++++++-- httemplate/view/cust_main/billing.html | 24 ++++++++++------- 6 files changed, 69 insertions(+), 34 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 85ad94531..2c26ba271 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -454,6 +454,7 @@ sub tables_hashref { 'referral_custnum', 'int', 'NULL', '', '', '', 'comments', 'text', 'NULL', '', '', '', 'spool_cdr','char', 'NULL', 1, '', '', + 'invoice_terms', 'varchar', 'NULL', $char_d, '', '', ], 'primary_key' => 'custnum', 'unique' => [ [ 'agentnum', 'agent_custid' ] ], diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 82b5e0c1e..d39e6ddc1 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -1193,11 +1193,7 @@ sub print_csv { my $taxtotal = 0; $taxtotal += $_->{'amount'} foreach $self->_items_tax; - my $duedate = ''; - if ( $conf->exists('invoice_default_terms') - && $conf->config('invoice_default_terms')=~ /^\s*Net\s*(\d+)\s*$/ ) { - $duedate = time2str("%m/%d/%Y", $self->_date + ($1*86400) ); - } + my $duedate = $self->due_date2str('%m/%d/%Y'); #date_format? my( $previous_balance, @unused ) = $self->previous; #previous balance @@ -1908,7 +1904,7 @@ sub print_latex { 'smallfooter' => join("\n", $conf->config_orbase('invoice_latexsmallfooter', $template) ), 'returnaddress' => $returnaddress, 'quantity' => 1, - 'terms' => $conf->config('invoice_default_terms') || 'Payable upon receipt', + 'terms' => $self->terms, #'notes' => join("\n", $conf->config('invoice_latexnotes') ), # better hang on to conf_dir for a while 'conf_dir' => "$FS::UID::conf_dir/conf.$FS::UID::datasrc", @@ -2324,8 +2320,7 @@ sub print_html { 'city' => encode_entities($cust_main->city), 'state' => encode_entities($cust_main->state), 'zip' => encode_entities($cust_main->zip), - 'terms' => $conf->config('invoice_default_terms') - || 'Payable upon receipt', + 'terms' => $self->terms, 'cid' => $cid, 'template' => $template, # 'conf_dir' => "$FS::UID::conf_dir/conf.$FS::UID::datasrc", @@ -2501,14 +2496,41 @@ sub _latex_escape { #utility methods for print_* +sub terms { + my $self = shift; + + #check for an invoice- specific override (eventually) + + #check for a customer- specific override + return $self->cust_main->invoice_terms + if $self->cust_main->invoice_terms; + + #use configured default or default default + $conf->config('invoice_default_terms') || 'Payable upon receipt'; +} + +sub due_date { + my $self = shift; + my $duedate = ''; + if ( $self->terms =~ /^\s*Net\s*(\d+)\s*$/ ) { + $duedate = $self->_date() + ( $1 * 86400 ); + } + $duedate; +} + +sub due_date2str { + my $self = shift; + $self->due_date ? time2str(shift, $self->due_date) : ''; +} + sub balance_due_msg { my $self = shift; my $msg = 'Balance Due'; - return $msg unless $conf->exists('invoice_default_terms'); - if ( $conf->config('invoice_default_terms') =~ /^\s*Net\s*(\d+)\s*$/ ) { - $msg .= ' - Please pay by '. time2str("%x", $self->_date + ($1*86400) ); - } elsif ( $conf->config('invoice_default_terms') ) { - $msg .= ' - '. $conf->config('invoice_default_terms'); + return $msg unless $self->terms; + if ( $self->due_date ) { + $msg .= ' - Please pay by '. $self->due_date2str('%x'); + } elsif ( $self->terms ) { + $msg .= ' - '. $self->terms; } $msg; } diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 80111da0e..f6867224a 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1221,6 +1221,7 @@ sub check { || $self->ut_numbern('referral_custnum') || $self->ut_textn('stateid') || $self->ut_textn('stateid_state') + || $self->ut_textn('invoice_terms') ; #barf. need message catalogs. i18n. etc. $error .= "Please select an advertising source." @@ -2773,15 +2774,7 @@ sub realtime_bop { unless ( $transaction->error_message ) { my $t_response; - #this should be normalized :/ - # - # bad, ad-hoc B:OP:PayflowPro "transaction_response" BS - if ( $transaction->can('param') - && $transaction->param('transaction_response') ) { - $t_response = $transaction->param('transaction_response') - - # slightly better, ad-hoc B:OP:TransactionCentral without "param" - } elsif ( $transaction->can('response_page') ) { + if ( $transaction->can('response_page') ) { $t_response = { 'page' => ( $transaction->can('response_page') ? $transaction->response_page diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index a843772d2..2c3123ccb 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -313,6 +313,7 @@ function bottomfixup(what) { var billing_bottomvars = new Array( 'tax', 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX', + 'invoice_terms', 'spool_cdr' ); @@ -392,6 +393,7 @@ function copyelement(from, to) { % % 'tax', % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX', +% 'invoice_terms', % 'spool_cdr' % ) { % diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index ba10929ed..65b4400a4 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -408,8 +408,22 @@ Email invoice -% if ( $conf->exists('voip-cust_cdr_spools') ) { + + Invoice terms + + + + + +% if ( $conf->exists('voip-cust_cdr_spools') ) { spool_cdr eq "Y" ? 'CHECKED' : '' %>> Spool CDRs @@ -418,7 +432,6 @@ % } - diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html index 1f80dc5bc..b73270c6c 100644 --- a/httemplate/view/cust_main/billing.html +++ b/httemplate/view/cust_main/billing.html @@ -1,11 +1,3 @@ -% -% my( $cust_main ) = @_; -% my @invoicing_list = $cust_main->invoicing_list; -% my $conf = new FS::Conf; -% my $money_char = $conf->config('money_char') || '$'; -% - - Billing information % # If we can't see the unencrypted card, then bill now is an exercise in frustration %if ( ! $cust_main->is_encrypted($cust_main->payinfo) ) { @@ -179,14 +171,26 @@ Billing information <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || 'no' %> -% if ( $conf->exists('voip-cust_cdr_spools') ) { + + Invoice terms + + <% $cust_main->invoice_terms || 'Default ('. ( $conf->config('invoice_default_terms') || 'Payable upon receipt' ). ')' %> + + +% if ( $conf->exists('voip-cust_cdr_spools') ) { Spool CDRs <% $cust_main->spool_cdr ? 'yes' : 'no' %> % } - +<%init> + +my( $cust_main ) = @_; +my @invoicing_list = $cust_main->invoicing_list; +my $conf = new FS::Conf; +my $money_char = $conf->config('money_char') || '$'; + -- 2.11.0