per-customer invoice terms override
authorivan <ivan>
Thu, 5 Apr 2007 02:04:21 +0000 (02:04 +0000)
committerivan <ivan>
Thu, 5 Apr 2007 02:04:21 +0000 (02:04 +0000)
FS/FS/Schema.pm
FS/FS/cust_bill.pm
FS/FS/cust_main.pm
httemplate/edit/cust_main.cgi
httemplate/edit/cust_main/billing.html
httemplate/view/cust_main/billing.html

index 85ad945..2c26ba2 100644 (file)
@@ -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' ] ],
index 82b5e0c..d39e6dd 100644 (file)
@@ -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;
 }
index 80111da..f686722 100644 (file)
@@ -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
index a843772..2c3123c 100755 (executable)
@@ -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'
 %   ) {
 %
index ba10929..65b4400 100644 (file)
       <TD ALIGN="right" WIDTH="200">Email invoice </TD>
       <TD WIDTH="408"><INPUT TYPE="text" NAME="invoicing_list" VALUE="<% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) %>"></TD>
     </TR>
-% if ( $conf->exists('voip-cust_cdr_spools') ) { 
 
+    <TR>
+      <TD ALIGN="right" WIDTH="200">Invoice terms </TD>
+      <TD WIDTH="408">
+        <SELECT NAME="invoice_terms">
+          <OPTION VALUE="">Default (<% $conf->config('invoice_default_terms') || 'Payable upon receipt' %>)
+%         foreach my $term ( 'Payable upon receipt',
+%                            ( map "Net $_", 0, 10, 15, 30, 45, 60 ),
+%                          ) {
+            <OPTION VALUE="<% $term %>" <% $cust_main->invoice_terms eq $term ? ' SELECTED' : '' %>><% $term %>
+%         }
+        </SELECT>
+      </TD>
+    </TR>
+
+% if ( $conf->exists('voip-cust_cdr_spools') ) { 
       <TR>
        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="spool_cdr" VALUE="Y" <% $cust_main->spool_cdr eq "Y" ? 'CHECKED' : '' %>> Spool CDRs</TD>
       </TR>
       <INPUT TYPE="hidden" NAME="spool_cdr" VALUE="<% $cust_main->spool_cdr %>">
 % } 
 
-
   </TABLE>
 
   </FORM>
index 1f80dc5..b73270c 100644 (file)
@@ -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' %>
   </TD>
 </TR>
-% if ( $conf->exists('voip-cust_cdr_spools') ) { 
+<TR>
+  <TD ALIGN="right">Invoice&nbsp;terms</TD>
+  <TD BGCOLOR="#ffffff">
+    <% $cust_main->invoice_terms || 'Default ('. ( $conf->config('invoice_default_terms') || 'Payable upon receipt' ). ')' %>
+  </TD>
+</TR>
 
+% if ( $conf->exists('voip-cust_cdr_spools') ) { 
   <TR>
     <TD ALIGN="right">Spool&nbsp;CDRs</TD>
     <TD BGCOLOR="#ffffff"><% $cust_main->spool_cdr ? 'yes' : 'no' %></TD>
   </TR>
 % } 
 
-
 </TABLE></TD></TR></TABLE>
+<%init>
+
+my( $cust_main ) = @_;
+my @invoicing_list = $cust_main->invoicing_list;
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
 
+</%init>