RT#29406: Per customer option to display service address of package on invoice
authorJonathan Prykop <jonathan@freeside.biz>
Sat, 7 Mar 2015 02:08:32 +0000 (20:08 -0600)
committerJonathan Prykop <jonathan@freeside.biz>
Sat, 7 Mar 2015 02:08:32 +0000 (20:08 -0600)
FS/FS/Schema.pm
FS/FS/Template_Mixin.pm
FS/FS/cust_main.pm
httemplate/docs/schema.html
httemplate/edit/cust_main.cgi
httemplate/view/cust_main/contacts.html

index da128d5..e7b3b6f 100644 (file)
@@ -1633,6 +1633,7 @@ sub tables_hashref {
         'complimentary', 'char', 'NULL', 1, '', '',
         'po_number', 'varchar', 'NULL', $char_d, '', '',
         'invoice_attn', 'varchar', 'NULL', $char_d, '', '',
+        'invoice_ship_address', 'char', 'NULL', 1, '', '',
       ],
       'primary_key'  => 'custnum',
       'unique'       => [ [ 'agentnum', 'agent_custid' ] ],
index ed6c8e0..412a5b0 100644 (file)
@@ -569,7 +569,7 @@ sub print_generic {
                                              || $cust_main->contact_firstlast ),
 
     #global config
-    'ship_enable'     => $conf->exists('invoice-ship_address'),
+    'ship_enable'     => $cust_main->invoice_ship_address || $conf->exists('invoice-ship_address'),
     'unitprices'      => $conf->exists('invoice-unitprice'),
     'smallernotes'    => $conf->exists('invoice-smallernotes'),
     'smallerfooter'   => $conf->exists('invoice-smallerfooter'),
index c93a950..427112a 100644 (file)
@@ -279,6 +279,10 @@ Allow self-service editing of ticket subjects, empty or 'Y'
 
 Do not call, empty or 'Y'
 
+=item invoice_ship_address
+
+Display ship_address ("Service address") on invoices for this customer, empty or 'Y'
+
 =back
 
 =head1 METHODS
@@ -460,6 +464,8 @@ sub insert {
     }
   }
 
+  $self->_loc_change();
+
   warn "  inserting $self\n"
     if $DEBUG > 1;
 
@@ -1332,6 +1338,8 @@ sub replace {
     $self->set($l.'num', $new_loc->locationnum);
   } #for $l
 
+  $self->_loc_change($old);
+
   # replace the customer record
   my $error = $self->SUPER::replace($old);
 
@@ -1589,6 +1597,7 @@ sub check {
     || $self->ut_currencyn('currency')
     || $self->ut_alphan('po_number')
     || $self->ut_enum('complimentary', [ '', 'Y' ])
+    || $self->ut_flag('invoice_ship_address')
   ;
 
   foreach (qw(company ship_company)) {
@@ -4773,6 +4782,22 @@ sub process_bill_and_collect {
   $cust_main->bill_and_collect( %$param );
 }
 
+#hook for insert/replace
+#runs after locations have been set
+#but before custnum has been set (for insert)
+sub _loc_change {
+  my $self = shift;
+  my $old = shift;
+  #turn off invoice_ship_address if ship & bill are the same
+  if ($self->bill_locationnum eq $self->ship_locationnum) {
+    $self->invoice_ship_address('');
+  }
+  #preserve old value if global config is set (replace only)
+  elsif ($old && $conf->exists('invoice-ship_address')) {
+    $self->invoice_ship_address($old->invoice_ship_address);
+  }
+}
+
 #starting to take quite a while for big dbs
 #   (JRNL: journaled so it only happens once per database)
 # - seq scan of h_cust_main (yuck), but not going to index paycvv, so
index cd4914a..bb18612 100644 (file)
         <li>otaker - order taker
         <li>referral_custnum
         <li>comments
+        <li>invoice_ship_address - Y or null, does ship address appear on invoice
       </ul>
       (columns in <i>italics</i> are optional)
     <li><a name="cust_main_invoice" href="man/FS/cust_main_invoice.html">cust_main_invoice</a> - Invoice destinations for email invoices.  Note that a customer can have many email destinations for their invoice (either literal or via svcnum), but only one postal destination.
index f99cce2..b6f6b0d 100755 (executable)
           enable_district => 1,
           enable_coords => 1,
       &>
+% unless ($conf->exists('invoice-ship_address')) { #it's always on, so hide per-cust config
+        <TR>
+          <TD>&nbsp;</TD>
+          <TD COLSPAN="7">
+            <% include('/elements/checkbox.html',
+                 'field'      => 'invoice_ship_address',
+                 'value'      => 'Y',
+                 'curr_value' => $cust_main->invoice_ship_address,
+                 'postfix'    => emt('included on invoices'),
+            ) %>
+          </TD>
+        </TR>
+% }
       </TABLE>
     </DIV>
   </TD>
index c9f8005..a5bafea 100644 (file)
  (<% mt('same as billing') %>)
 %   }
 </FONT>
+%   if (
+%     ($this eq 'ship')
+%     && $cust_main->invoice_ship_address 
+%     && !$conf->exists('invoice-ship_address') #it's always on, so hide per-cust config
+%    ) {
+<SPAN STYLE="padding-left: .25em;">(<% emt('included on invoices') %>)</SPAN>
+%   }
 <TABLE CLASS="fsinnerbox">
 
 % if ( $this eq 'bill' ) {