From c7c96355331687b6fd44bfe541b402bd0664481d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Fri, 5 Dec 2014 10:45:26 -0800 Subject: [PATCH] agent-ize invoice_default_terms, RT#32513 --- FS/FS/Conf.pm | 1 + FS/FS/Template_Mixin.pm | 13 ++++++++++--- FS/FS/cust_bill.pm | 7 +++++++ FS/FS/part_event/Condition/cust_bill_past_due.pm | 17 +++++++++-------- httemplate/edit/cust_main/billing.html | 3 ++- httemplate/edit/quick-charge.html | 14 +++++++++----- httemplate/elements/select-terms.html | 8 +++++--- httemplate/search/report_cust_main.html | 7 +++++-- httemplate/view/cust_main/billing.html | 7 ++++++- 9 files changed, 54 insertions(+), 23 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 8fb6220df..97659bc8c 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1539,6 +1539,7 @@ and customer address. Include units.', 'section' => 'invoicing', 'description' => 'Optional default invoice term, used to calculate a due date printed on invoices.', 'type' => 'select', + 'per_agent' => 1, 'select_enum' => [ '', 'Payable upon receipt', 'Net 0', 'Net 3', 'Net 5', 'Net 9', 'Net 10', 'Net 14', 'Net 15', 'Net 18', 'Net 20', 'Net 21', 'Net 25', 'Net 30', 'Net 45', diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 346e78167..f67de76fc 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -1856,8 +1856,15 @@ sub terms { my $cust_main = $self->cust_main; return $cust_main->invoice_terms if $cust_main && $cust_main->invoice_terms; + my $agentnum = ''; + if ( $cust_main ) { + $agentnum = $cust_main->agentnum; + } elsif ( my $prospect_main = $self->prospect_main ) { + $agentnum = $prospect_main->agentnum; + } + #use configured default - $conf->config('invoice_default_terms') || ''; + $conf->config('invoice_default_terms', $agentnum) || ''; } sub due_date { @@ -1891,8 +1898,8 @@ sub balance_due_date { my $self = shift; my $conf = $self->conf; my $duedate = ''; - if ( $conf->exists('invoice_default_terms') - && $conf->config('invoice_default_terms')=~ /^\s*Net\s*(\d+)\s*$/ ) { + my $terms = $self->terms; + if ( $terms =~ /^\s*Net\s*(\d+)\s*$/ ) { $duedate = $self->time2str_local('rdate', $self->_date + ($1*86400) ); } $duedate; diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 5be984e86..0c07e9afa 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -3323,6 +3323,13 @@ Currently only supported on PostgreSQL. =cut sub due_date_sql { + die "don't use: doesn't account for agent-specific invoice_default_terms"; + + #we're passed a $conf but not a specific customer (that's in the query), so + # to make this work we'd need an agentnum-aware "condition_sql_conf" like + # "condition_sql_option" that retreives a conf value with SQL in an agent- + # aware fashion + my $conf = new FS::Conf; 'COALESCE( SUBSTRING( diff --git a/FS/FS/part_event/Condition/cust_bill_past_due.pm b/FS/FS/part_event/Condition/cust_bill_past_due.pm index 47a90cf4a..5e24acfc9 100644 --- a/FS/FS/part_event/Condition/cust_bill_past_due.pm +++ b/FS/FS/part_event/Condition/cust_bill_past_due.pm @@ -35,13 +35,14 @@ sub condition { $as_of >= ($cust_bill->due_date || $cust_bill->_date); } -sub condition_sql { - my( $class, $table, %opt ) = @_; - return 'true' if $opt{'driver_name'} ne 'Pg'; - my $delay = $class->condition_sql_option_integer('delay', 'Pg'); - my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5]; - my $as_of = timelocal(0,0,0,$mday,$mon,$year) . " - ($delay * 86400)"; - "( $as_of ) >= ".FS::cust_bill->due_date_sql; -} +#->due_date_sql can't cope with agent-specific invoice_default_terms +#sub condition_sql { +# my( $class, $table, %opt ) = @_; +# return 'true' if $opt{'driver_name'} ne 'Pg'; +# my $delay = $class->condition_sql_option_integer('delay', 'Pg'); +# my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5]; +# my $as_of = timelocal(0,0,0,$mday,$mon,$year) . " - ($delay * 86400)"; +# "( $as_of ) >= ".FS::cust_bill->due_date_sql; +#} 1; diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index 1f44905f8..fcd8f017c 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -547,7 +547,8 @@ <% mt('Invoice terms') |h %> <& /elements/select-terms.html, - 'curr_value' => $cust_main->invoice_terms, + 'curr_value' => $cust_main->invoice_terms, + 'agentnum' => $cust_main->agentnum, &> diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html index 0db154337..da9ac6e66 100644 --- a/httemplate/edit/quick-charge.html +++ b/httemplate/edit/quick-charge.html @@ -200,8 +200,9 @@ function bill_now_changed (what) { > <% mt('with terms') |h %> <& /elements/select-terms.html, - 'curr_value' => scalar($cgi->param('invoice_terms')), - 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ), + 'curr_value' => scalar($cgi->param('invoice_terms')), + 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ), + 'agentnum' => $cust_main->agentnum, &> @@ -429,9 +430,12 @@ my $default_terms; if ( $cust_main->invoice_terms ) { $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms); } else { - $default_terms = emt("Default ([_1])", - ($conf->config('invoice_default_terms') || emt('Payable upon receipt')) - ); + $default_terms = + emt( "Default ([_1])", + ( $conf->config('invoice_default_terms', $cust_main->agentnum) + || emt('Payable upon receipt') + ) + ); } my @description; diff --git a/httemplate/elements/select-terms.html b/httemplate/elements/select-terms.html index 88396920f..716832f52 100644 --- a/httemplate/elements/select-terms.html +++ b/httemplate/elements/select-terms.html @@ -26,9 +26,11 @@ my $conf = new FS::Conf; my $empty_label = $opt{'empty_label'} - || emt('Default').' ('. - ($conf->config('invoice_default_terms') || emt('Payable upon receipt')). - ')'; + || emt('Default').' ('. + ( $conf->config('invoice_default_terms', $opt{'agentnum'}) + || emt('Payable upon receipt') + ). + ')'; my $empty_value = $opt{'empty_value'} || ''; diff --git a/httemplate/search/report_cust_main.html b/httemplate/search/report_cust_main.html index 994f9503b..2b406729a 100755 --- a/httemplate/search/report_cust_main.html +++ b/httemplate/search/report_cust_main.html @@ -236,9 +236,12 @@ <% mt('Invoice terms') |h %> +% my @agentnums = $FS::CurrentUser::CurrentUser->agentnums; +% my $agentnum = scalar(@agentnums) == 1 ? $agentnums[0] : ''; <& /elements/select-terms.html, - 'pre_options' => [ '' => emt('all') ], - 'empty_value' => 'NULL', + 'pre_options' => [ '' => emt('all') ], + 'empty_value' => 'NULL', + 'agentnum' => $agentnum, &> diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html index 2c4b3fb2d..64ec591a2 100644 --- a/httemplate/view/cust_main/billing.html +++ b/httemplate/view/cust_main/billing.html @@ -260,7 +260,12 @@ <% mt('Invoice terms') |h %> - <% $cust_main->invoice_terms || emt('Default').' ('. ( $conf->config('invoice_default_terms') || emt('Payable upon receipt') ). ')' %> + <% $cust_main->invoice_terms + || emt('Default').' ('. ( $conf->config('invoice_default_terms', $cust_main->agentnum) + || emt('Payable upon receipt') + ). + ')' + %> -- 2.11.0