summaryrefslogtreecommitdiff
path: root/FS
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 /FS
parentbe2a6e7068337aa57b04bd7fa88090002d79a64b (diff)
agent-ize invoice_default_terms, RT#32513
Diffstat (limited to 'FS')
-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
4 files changed, 27 insertions, 11 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;