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