and show the flag in view UI, #38191
[freeside.git] / httemplate / view / cust_main / billing.html
index a16e8a5..8d3925a 100644 (file)
@@ -1,6 +1,8 @@
 <FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
 % my $yes = emt('yes');
 % my $no = emt('no');
+% my $allowed = emt('allowed');
+% my $refused = emt('refused');
 
 <TABLE CLASS="fsinnerbox">
 
   <TD><B><% $balance %></B></TD>
 </TR>
 
+<TR ID="recurring_row">
+  <TH ID="recurring_label" ALIGN="right"><% emt( 'Recurring' ) %></TH>
+  <TD ID="recurring_value"><IMG SRC="<% $fsurl %>images/wait-orange.gif"></TD>
+</TR>
+
+<& '/elements/xmlhttp.html',
+     'url'  => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
+     'subs' => [ 'get_display_recurring'] &>
+
+<SCRIPT>
+function set_display_recurring (xmlresult) {
+  var recurring = JSON.parse(xmlresult);
+  var rlabel = document.getElementById('recurring_label');
+  var rvalue = document.getElementById('recurring_value');
+  var rrow   = document.getElementById('recurring_row');
+  if (recurring['error']) {
+    rvalue.innerHTML = '<SPAN STYLE="color: red">Error</SPAN>';
+    console.log('display_recurring error: ' + recurring['error']);
+  } else if (recurring['display_recurring'].length) {
+    for (var ri = 0; ri < recurring['display_recurring'].length; ri++) {
+      var robj = recurring['display_recurring'][ri];
+      var freq_pretty = robj['freq_pretty'].charAt(0).toUpperCase()+robj['freq_pretty'].slice(1)+' recurring';
+      var amount = '<% $money_char %>'+parseFloat(robj['amount']).toFixed(2);
+      if (ri + 1 < recurring['display_recurring'].length) {
+        var rr = document.createElement('TR');
+        var rl = document.createElement('TH');
+        rl.style.textAlign = 'right';
+        rl.innerHTML = freq_pretty;
+        rr.appendChild(rl);
+        var rv = document.createElement('TD');
+        rv.innerHTML = amount;
+        rr.appendChild(rv);
+        rrow.parentNode.insertBefore(rr,rrow);
+      } else {
+        rlabel.innerHTML = freq_pretty;
+        rvalue.innerHTML = amount;
+      }
+    }
+  } else {
+    rrow.parentNode.removeChild(rrow);
+  }
+}
+</SCRIPT>
+
+% # 10 is an arbitrary number, use ajax for customers with many packages
+% if ( $cust_main->num_billing_pkgs > 10 ) {
+<& '/elements/xmlhttp.html',
+     'url'  => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
+     'subs' => [ 'get_display_recurring'] &>
+<SCRIPT>
+get_display_recurring('custnum',<% $cust_main->custnum %>,set_display_recurring);
+</SCRIPT>
+% } else {
+<SCRIPT>
+set_display_recurring(<% encode_json({'display_recurring' => [ $cust_main->display_recurring ]}) |js_string %>);
+</SCRIPT>
+% }
+
 % if ( $conf->exists('cust_main-select-prorate_day') ) {
 <TR>
   <TH ALIGN="right"><% mt('Prorate day of month') |h %></TH>
   <TD><% $cust_main->prorate_day %>
+  <% $cust_main->force_prorate_day && ('<i>'.emt('(applies to all packages)').'</i>') %>
   </TD>
 </TR>
 % }
     </TR>
 % }
 
-% if ( $conf->exists('enable_taxproducts') ) {
+% if ( $conf->config('tax_data_vendor') eq 'cch' ) {
 <TR>
   <TH ALIGN="right"><% mt('Tax location') |h %></TH>
 % my $tax_location = $conf->exists('tax-ship_address')
 % }
 <TR>
   <TH ALIGN="right"><% mt('Postal mail invoices') |h %></TH>
-  <TD>
-    <% ( grep { $_ eq 'POST' } @invoicing_list )
-         ? $yes. ( $cust_main->invoice_attn
+% if ( $cust_main->postal_invoice ) {
+  <TD><% $yes .  ( $cust_main->invoice_attn
                      ? ', attn: '. $cust_main->invoice_attn
                      : ''
-                 )
-         : $no
-    %>
+                 ) %>
+  </TD>
+% } elsif ( $cust_main->invoice_noemail
+%           or scalar(@invoicing_list) == 0 ) {
+%   # alert the user that this customer has no way to receive an invoice
+  <TD CLASS="error"><% $no %></TD>
+% } else {
+  <TD><% $no %></TD>
+% }
   </TD>
 </TR>
 <TR>
   <TH ALIGN="right"><% mt('Email invoices') |h %></TH>
-  <TD>
-    <% $cust_main->invoice_noemail ? $no : $yes %>
-  </TD>
+% if ( $cust_main->invoice_noemail and ! $cust_main->postal_invoice ) {
+%   # as above, warn if the customer refuses both email and postal invoices
+  <TD CLASS="error"><% $refused %></TD>
+% } else {
+  <TD><% $cust_main->invoice_noemail ? $refused : $allowed %></TD>
+% }
 </TR>
-% unless ( $conf->exists('cust-email-high-visibility')) {
 <TR>
-  <TH ALIGN="right"><% mt('Email address(es)') |h %></TH>
+  <TH ALIGN="right"><% mt('Other email notices') |h %></TH>
   <TD>
-    <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || $no %>
-%   if ( $cust_main->message_noemail ) {
-    <BR>
-    <SPAN STYLE="font-size: small"><% emt('(do not send notices)') %></SPAN>
-%   }
+    <% $cust_main->message_noemail ? $refused : $allowed %>
   </TD>
 </TR>
-% }
 <TR>
   <TH ALIGN="right"><% mt('Invoice terms') |h %></TH>
   <TD>
    </TR>
 % }
 
-% if ( $conf->exists('voip-cust_email_csv_cdr') ) { 
+% if ( my $attach = $conf->config('voip-cdr_email_attach') ) { 
   <TR>
-    <TH ALIGN="right"><% mt('Email CDRs as CSV') |h %></TH>
+    <TH ALIGN="right"><% mt('Email CDRs as '.uc($attach)) |h %></TH>
     <TD><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
   </TR>
 % } 
 <%init>
 
 my( $cust_main ) = @_;
-my @invoicing_list = $cust_main->invoicing_list;
+my @invoicing_list = $cust_main->invoicing_list_emailonly;
 my $conf = new FS::Conf;
 my $money_char = $conf->config('money_char') || '$';