and show the flag in view UI, #38191
[freeside.git] / httemplate / view / cust_main / billing.html
1 <FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
2 % my $yes = emt('yes');
3 % my $no = emt('no');
4 % my $allowed = emt('allowed');
5 % my $refused = emt('refused');
6
7 <TABLE CLASS="fsinnerbox">
8
9 % if ( $cust_main->complimentary ) {
10   <TR>
11     <TH ALIGN="right"><% mt('Complimentary') |h %></TH>
12     <TD><% $yes %></TD>
13   </TR>
14 % }
15
16 %( my $balance = $cust_main->balance )
17 %  =~ s/^(\-?)(.*)$/<FONT SIZE=+1>$1<\/FONT>$money_char$2/;
18
19 <TR>
20   <TH ALIGN="right"><% mt('Balance due') |h %></TH>
21   <TD><B><% $balance %></B></TD>
22 </TR>
23
24 <TR ID="recurring_row">
25   <TH ID="recurring_label" ALIGN="right"><% emt( 'Recurring' ) %></TH>
26   <TD ID="recurring_value"><IMG SRC="<% $fsurl %>images/wait-orange.gif"></TD>
27 </TR>
28
29 <& '/elements/xmlhttp.html',
30      'url'  => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
31      'subs' => [ 'get_display_recurring'] &>
32
33 <SCRIPT>
34 function set_display_recurring (xmlresult) {
35   var recurring = JSON.parse(xmlresult);
36   var rlabel = document.getElementById('recurring_label');
37   var rvalue = document.getElementById('recurring_value');
38   var rrow   = document.getElementById('recurring_row');
39   if (recurring['error']) {
40     rvalue.innerHTML = '<SPAN STYLE="color: red">Error</SPAN>';
41     console.log('display_recurring error: ' + recurring['error']);
42   } else if (recurring['display_recurring'].length) {
43     for (var ri = 0; ri < recurring['display_recurring'].length; ri++) {
44       var robj = recurring['display_recurring'][ri];
45       var freq_pretty = robj['freq_pretty'].charAt(0).toUpperCase()+robj['freq_pretty'].slice(1)+' recurring';
46       var amount = '<% $money_char %>'+parseFloat(robj['amount']).toFixed(2);
47       if (ri + 1 < recurring['display_recurring'].length) {
48         var rr = document.createElement('TR');
49         var rl = document.createElement('TH');
50         rl.style.textAlign = 'right';
51         rl.innerHTML = freq_pretty;
52         rr.appendChild(rl);
53         var rv = document.createElement('TD');
54         rv.innerHTML = amount;
55         rr.appendChild(rv);
56         rrow.parentNode.insertBefore(rr,rrow);
57       } else {
58         rlabel.innerHTML = freq_pretty;
59         rvalue.innerHTML = amount;
60       }
61     }
62   } else {
63     rrow.parentNode.removeChild(rrow);
64   }
65 }
66 </SCRIPT>
67
68 % # 10 is an arbitrary number, use ajax for customers with many packages
69 % if ( $cust_main->num_billing_pkgs > 10 ) {
70 <& '/elements/xmlhttp.html',
71      'url'  => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
72      'subs' => [ 'get_display_recurring'] &>
73 <SCRIPT>
74 get_display_recurring('custnum',<% $cust_main->custnum %>,set_display_recurring);
75 </SCRIPT>
76 % } else {
77 <SCRIPT>
78 set_display_recurring(<% encode_json({'display_recurring' => [ $cust_main->display_recurring ]}) |js_string %>);
79 </SCRIPT>
80 % }
81
82 % if ( $conf->exists('cust_main-select-prorate_day') ) {
83 <TR>
84   <TH ALIGN="right"><% mt('Prorate day of month') |h %></TH>
85   <TD><% $cust_main->prorate_day %>
86   <% $cust_main->force_prorate_day && ('<i>'.emt('(applies to all packages)').'</i>') %>
87   </TD>
88 </TR>
89 % }
90
91 % if ( $conf->exists('cust_main-select-billday') 
92 %        && qsearch({ 'table'     => 'cust_payby',
93 %                     'hashref'   => { 'custnum' => $cust_main->custnum, },
94 %                     'extra_sql' => "AND payby IN ( 'CARD', 'CHEK' )",
95 %                     'order_by'  => 'LIMIT 1',
96 %                  })
97 %    )
98 % {
99     <TR>
100       <TH ALIGN="right"><% mt('Payment day of month') |h %></TH>
101       <TD><% $cust_main->billday %>
102       </TD>
103     </TR>
104 % }
105
106 % if ( $cust_main->po_number ) { 
107     <TR>
108       <TH ALIGN="right"><% mt('Purchase Order #') |h %></TH>
109       <TD><% $cust_main->po_number %></TD>
110     </TR>
111 % } 
112
113 % my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
114
115 % unless (    $conf->exists('cust_class-tax_exempt')
116 %          || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
117 %        )
118 % {
119     <TR>
120       <TH ALIGN="right"><% mt('Tax exempt') |h %><% @exempt_groups ? ' ('.emt('all taxes').')' : '' %></TH>
121       <TD><% $cust_main->tax ? $yes : $no %></TD>
122     </TR>
123 % }
124
125 % foreach my $exempt_group ( @exempt_groups ) {
126 %   my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
127     <TR>
128       <TH ALIGN="right"><% mt('Tax exempt') |h %> (<% $exempt_group %> taxes)</TH>
129       <TD><% $cust_main_exemption ? $yes : $no %>
130         <% $cust_main_exemption ? $cust_main_exemption->exempt_number : '' |h %>
131       </TD>
132     </TR>
133 % }
134
135 % if ( $conf->config('tax_data_vendor') eq 'cch' ) {
136 <TR>
137   <TH ALIGN="right"><% mt('Tax location') |h %></TH>
138 % my $tax_location = $conf->exists('tax-ship_address')
139 %                    ? $cust_main->ship_location
140 %                    : $cust_main->bill_location;
141   <TD><% $tax_location->geocode('cch') %></TD>
142 </TR>
143 % }
144 <TR>
145   <TH ALIGN="right"><% mt('Postal mail invoices') |h %></TH>
146 % if ( $cust_main->postal_invoice ) {
147   <TD><% $yes .  ( $cust_main->invoice_attn
148                      ? ', attn: '. $cust_main->invoice_attn
149                      : ''
150                  ) %>
151   </TD>
152 % } elsif ( $cust_main->invoice_noemail
153 %           or scalar(@invoicing_list) == 0 ) {
154 %   # alert the user that this customer has no way to receive an invoice
155   <TD CLASS="error"><% $no %></TD>
156 % } else {
157   <TD><% $no %></TD>
158 % }
159   </TD>
160 </TR>
161 <TR>
162   <TH ALIGN="right"><% mt('Email invoices') |h %></TH>
163 % if ( $cust_main->invoice_noemail and ! $cust_main->postal_invoice ) {
164 %   # as above, warn if the customer refuses both email and postal invoices
165   <TD CLASS="error"><% $refused %></TD>
166 % } else {
167   <TD><% $cust_main->invoice_noemail ? $refused : $allowed %></TD>
168 % }
169 </TR>
170 <TR>
171   <TH ALIGN="right"><% mt('Other email notices') |h %></TH>
172   <TD>
173     <% $cust_main->message_noemail ? $refused : $allowed %>
174   </TD>
175 </TR>
176 <TR>
177   <TH ALIGN="right"><% mt('Invoice terms') |h %></TH>
178   <TD>
179     <% $cust_main->invoice_terms
180          || emt('Default').' ('. ( $conf->config('invoice_default_terms', $cust_main->agentnum)
181                                      || emt('Payable upon receipt')
182                                  ).
183                            ')'
184     %>
185   </TD>
186 </TR>
187 <TR>
188   <TH ALIGN="right"><% mt('Credit limit') |h %></TH>
189   <TD>
190 %   my $default_credit_limit = $conf->config('default_credit_limit');
191     <% length($cust_main->credit_limit)
192          ? $money_char. sprintf("%.2f", $cust_main->credit_limit)
193          : $default_credit_limit
194            ? "Default ($money_char". sprintf("%.2f", $default_credit_limit). ")"
195            : emt('Unlimited')
196     %>
197 %   if ( $cust_main->num_cust_main_credit_limit ) {
198       <A HREF="<% $p %>search/cust_main_credit_limit.html?custnum=<% $cust_main->custnum %>">(incidents)</A>
199 %   }
200   </TD>
201 </TR>
202
203 % if ( $conf->exists('voip-cust_cdr_spools') ) { 
204   <TR>
205     <TH ALIGN="right"><% mt('Spool CDRs') |h %></TH>
206     <TD><% $cust_main->spool_cdr ? $yes : $no %></TD>
207   </TR>
208 % } 
209
210 % if ( $conf->exists('voip-cust_cdr_squelch') ) { 
211   <TR>
212     <TH ALIGN="right"><% mt($conf->exists('voip-cdr_email') ? 'Print CDRs' : 'Show CDRs') |h %></TH>
213     <TD><% $cust_main->squelch_cdr ? $no : $yes %></TD>
214   </TR>
215 % } 
216
217 % if ( $conf->exists('voip-cust_accountcode_cdr') ) { 
218    <TR>
219      <TH ALIGN="right"><% mt('Breakdown CDRs by accountcode') |h %></TH>
220      <TD><% $cust_main->accountcode_cdr ? $yes : $no %></TD>
221    </TR>
222 % }
223
224 % if ( my $attach = $conf->config('voip-cdr_email_attach') ) { 
225   <TR>
226     <TH ALIGN="right"><% mt('Email CDRs as '.uc($attach)) |h %></TH>
227     <TD><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
228   </TR>
229 % } 
230
231 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
232   <TR>
233     <TH ALIGN="right"><% mt('CDR termination settlement') |h %></TH>
234     <TD><% $cust_main->cdr_termination_percentage %><% $cust_main->cdr_termination_percentage =~ /\d/ ? '%' : '' %></TD>
235   </TR>
236 % }
237
238 % if ( $cust_main->currency ) {
239   <TR>
240     <TH ALIGN="right"><% mt('Invoicing currency') |h %></TH>
241     <TD><% $cust_main->currency. ': '. code2currency($cust_main->currency) %></TD>
242   </TR>
243 % }
244
245 % if ( $cust_main->locale ) {
246 % my %locale_info = FS::Locales->locale_info($cust_main->locale);
247   <TR>
248     <TH ALIGN="right"><% mt('Invoicing locale') |h %></TH>
249     <TD><% $locale_info{name} . " (" . $locale_info{country} .")" %></TD>
250   </TR>
251 % }
252
253
254 </TABLE>
255 <%init>
256
257 my( $cust_main ) = @_;
258 my @invoicing_list = $cust_main->invoicing_list_emailonly;
259 my $conf = new FS::Conf;
260 my $money_char = $conf->config('money_char') || '$';
261
262 #false laziness w/edit/cust_main/billing.html
263 my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
264 my $term_sth = dbh->prepare($term_sql)  or die dbh->errstr;
265 $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
266 my $show_term = $term_sth->fetchrow_arrayref->[0];
267
268 </%init>