summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-12-05 10:45:26 -0800
committerIvan Kohler <ivan@freeside.biz>2014-12-05 10:45:26 -0800
commitc7c96355331687b6fd44bfe541b402bd0664481d (patch)
treee39453120b474fc911b8bcc356a0e6059f924e6f
parentbe2a6e7068337aa57b04bd7fa88090002d79a64b (diff)
agent-ize invoice_default_terms, RT#32513
-rw-r--r--FS/FS/Conf.pm1
-rw-r--r--FS/FS/Template_Mixin.pm13
-rw-r--r--FS/FS/cust_bill.pm7
-rw-r--r--FS/FS/part_event/Condition/cust_bill_past_due.pm17
-rw-r--r--httemplate/edit/cust_main/billing.html3
-rw-r--r--httemplate/edit/quick-charge.html14
-rw-r--r--httemplate/elements/select-terms.html8
-rwxr-xr-xhttemplate/search/report_cust_main.html7
-rw-r--r--httemplate/view/cust_main/billing.html7
9 files changed, 54 insertions, 23 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 8fb6220..97659bc 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 346e781..f67de76 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 5be984e..0c07e9a 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 47a90cf..5e24acf 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 1f44905..fcd8f01 100644
--- a/httemplate/edit/cust_main/billing.html
+++ b/httemplate/edit/cust_main/billing.html
@@ -547,7 +547,8 @@
<TD ALIGN="right" WIDTH="200"><% mt('Invoice terms') |h %> </TD>
<TD WIDTH="408">
<& /elements/select-terms.html,
- 'curr_value' => $cust_main->invoice_terms,
+ 'curr_value' => $cust_main->invoice_terms,
+ 'agentnum' => $cust_main->agentnum,
&>
</TD>
</TR>
diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html
index 0db1543..da9ac6e 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,
&>
</TD>
</TR>
@@ -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 8839692..716832f 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 994f950..2b40672 100755
--- a/httemplate/search/report_cust_main.html
+++ b/httemplate/search/report_cust_main.html
@@ -236,9 +236,12 @@
<TR>
<TD ALIGN="right"><% mt('Invoice terms') |h %></TD>
<TD>
+% 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,
&>
</TD>
</TR>
diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html
index 2c4b3fb..64ec591 100644
--- a/httemplate/view/cust_main/billing.html
+++ b/httemplate/view/cust_main/billing.html
@@ -260,7 +260,12 @@
<TR>
<TD ALIGN="right"><% mt('Invoice terms') |h %></TD>
<TD BGCOLOR="#ffffff">
- <% $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')
+ ).
+ ')'
+ %>
</TD>
</TR>
<TR>