[freeside-commits] branch FREESIDE_3_BRANCH updated. a83f6bb859327c0ff55d6aa30e39e8a0f657be75

Jeremy Davis jeremyd at 420.am
Wed Dec 10 08:24:08 PST 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  a83f6bb859327c0ff55d6aa30e39e8a0f657be75 (commit)
      from  36a9d4661fffb85b8d9ec099ee2dc0ced8991e99 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a83f6bb859327c0ff55d6aa30e39e8a0f657be75
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Dec 5 10:45:26 2014 -0800

    agent-ize invoice_default_terms, RT#32513

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index c7a3dcb..4b6b4b2 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 6ab5558..ebc977a 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 0efe6d1..dda5d81 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -3371,6 +3371,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 f1daebe..7508627 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 e141e7d..06669fa 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 debc7a9..78d51d0 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>

-----------------------------------------------------------------------

Summary of changes:
 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(-)




More information about the freeside-commits mailing list