1 <FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
2 % my $yes = emt('yes');
5 <TABLE CLASS="fsinnerbox">
7 % if ( $cust_main->complimentary ) {
9 <TH ALIGN="right"><% mt('Complimentary') |h %></TH>
14 %( my $balance = $cust_main->balance )
15 % =~ s/^(\-?)(.*)$/<FONT SIZE=+1>$1<\/FONT>$money_char$2/;
18 <TH ALIGN="right"><% mt('Balance due') |h %></TH>
19 <TD><B><% $balance %></B></TD>
22 % #54: just an arbitrary number i pulled out of my goober. ideally we'd like
23 % # to consider e.g. a histogram of num_ncancelled_packages for the entire
24 % # customer base, and compare it to a graph of the overhead for generating this
25 % # information. (and optimize it better, we could get it more from SQL)
26 % if ( $cust_main->num_ncancelled_pkgs < 54 ) {
27 % my $sth = dbh->prepare("
28 % SELECT DISTINCT freq FROM cust_pkg LEFT JOIN part_pkg USING (pkgpart)
29 % WHERE freq IS NOT NULL AND freq != '0'
30 % AND ( cancel IS NULL OR cancel = 0 )
32 % ") or die $DBI::errstr;
34 % $sth->execute($cust_main->custnum) or die $sth->errstr;
36 % #not really a numeric sort because freqs can actually be all sorts of things
37 % # but good enough for the 99% cases of ordering monthly quarterly annually
38 % my @freqs = sort { $a <=> $b } map { $_->[0] } @{ $sth->fetchall_arrayref };
40 % foreach my $freq (@freqs) {
41 % my @cust_pkg = qsearch({
42 % 'table' => 'cust_pkg',
43 % 'addl_from' => 'LEFT JOIN part_pkg USING (pkgpart)',
44 % 'hashref' => { 'custnum' => $cust_main->custnum, },
45 % 'extra_sql' => 'AND ( cancel IS NULL OR cancel = 0 )
46 % AND freq = '. dbh->quote($freq),
47 % 'order_by' => 'ORDER BY COALESCE(start_date,0), pkgnum', # to ensure old pkgs come before change_to_pkg
50 % my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty;
54 % foreach my $cust_pkg (@cust_pkg) {
55 % my $part_pkg = $cust_pkg->part_pkg;
56 % next if $cust_pkg->susp
57 % && ! $cust_pkg->option('suspend_bill')
58 % && ( ! $part_pkg->option('suspend_bill')
59 % || $cust_pkg->option('no_suspend_bill')
62 % #pkg change handling
63 % next if $skip_pkg->{$cust_pkg->pkgnum};
64 % if ($cust_pkg->change_to_pkgnum) {
65 % #if change is on or before next bill date, use new pkg
66 % next if $cust_pkg->expire <= $cust_pkg->bill;
67 % #if change is after next bill date, use old (this) pkg
68 % $skip_pkg->{$cust_pkg->change_to_pkgnum} = 1;
73 % #add recurring amounts for this package and its billing add-ons
74 % foreach my $l_part_pkg ( $part_pkg->self_and_bill_linked ) {
75 % $pkg_amount += $l_part_pkg->base_recur($cust_pkg);
78 % #subtract amounts for any active discounts
79 % #(there should only be one at the moment, otherwise this makes no sense)
80 % foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
81 % my $discount = $cust_pkg_discount->discount;
82 % #and only one of these for each
83 % $pkg_amount -= $discount->amount;
84 % $pkg_amount -= $amount * $discount->percent/100;
87 % $pkg_amount *= ( $cust_pkg->quantity || 1 );
89 % $amount += $pkg_amount;
94 <TH ALIGN="right"><% emt( ucfirst($freq_pretty). ' recurring' ) %></TH>
95 <TD><% $money_char. sprintf('%.2f', $amount) %></TD>
102 % if ( $conf->exists('cust_main-select-prorate_day') ) {
104 <TH ALIGN="right"><% mt('Prorate day of month') |h %></TH>
105 <TD><% $cust_main->prorate_day %>
110 % if ( $conf->exists('cust_main-select-billday')
111 % && qsearch({ 'table' => 'cust_payby',
112 % 'hashref' => { 'custnum' => $cust_main->custnum, },
113 % 'extra_sql' => "AND payby IN ( 'CARD', 'CHEK' )",
114 % 'order_by' => 'LIMIT 1',
119 <TH ALIGN="right"><% mt('Payment day of month') |h %></TH>
120 <TD><% $cust_main->billday %>
125 % if ( $cust_main->po_number ) {
127 <TH ALIGN="right"><% mt('Purchase Order #') |h %></TH>
128 <TD><% $cust_main->po_number %></TD>
132 % my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
134 % unless ( $conf->exists('cust_class-tax_exempt')
135 % || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
139 <TH ALIGN="right"><% mt('Tax exempt') |h %><% @exempt_groups ? ' ('.emt('all taxes').')' : '' %></TH>
140 <TD><% $cust_main->tax ? $yes : $no %></TD>
144 % foreach my $exempt_group ( @exempt_groups ) {
145 % my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
147 <TH ALIGN="right"><% mt('Tax exempt') |h %> (<% $exempt_group %> taxes)</TH>
148 <TD><% $cust_main_exemption ? $yes : $no %>
149 <% $cust_main_exemption ? $cust_main_exemption->exempt_number : '' |h %>
154 % if ( $conf->config('tax_data_vendor') eq 'cch' ) {
156 <TH ALIGN="right"><% mt('Tax location') |h %></TH>
157 % my $tax_location = $conf->exists('tax-ship_address')
158 % ? $cust_main->ship_location
159 % : $cust_main->bill_location;
160 <TD><% $tax_location->geocode('cch') %></TD>
164 <TH ALIGN="right"><% mt('Postal mail invoices') |h %></TH>
166 <% ( grep { $_ eq 'POST' } @invoicing_list )
167 ? $yes. ( $cust_main->invoice_attn
168 ? ', attn: '. $cust_main->invoice_attn
176 <TH ALIGN="right"><% mt('Email invoices') |h %></TH>
178 <% $cust_main->invoice_noemail ? $no : $yes %>
181 % unless ( $conf->exists('cust-email-high-visibility')) {
183 <TH ALIGN="right"><% mt('Email address(es)') |h %></TH>
185 <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || $no %>
186 % if ( $cust_main->message_noemail ) {
188 <SPAN STYLE="font-size: small"><% emt('(do not send notices)') %></SPAN>
194 <TH ALIGN="right"><% mt('Invoice terms') |h %></TH>
196 <% $cust_main->invoice_terms
197 || emt('Default').' ('. ( $conf->config('invoice_default_terms', $cust_main->agentnum)
198 || emt('Payable upon receipt')
205 <TH ALIGN="right"><% mt('Credit limit') |h %></TH>
207 % my $default_credit_limit = $conf->config('default_credit_limit');
208 <% length($cust_main->credit_limit)
209 ? $money_char. sprintf("%.2f", $cust_main->credit_limit)
210 : $default_credit_limit
211 ? "Default ($money_char". sprintf("%.2f", $default_credit_limit). ")"
214 % if ( $cust_main->num_cust_main_credit_limit ) {
215 <A HREF="<% $p %>search/cust_main_credit_limit.html?custnum=<% $cust_main->custnum %>">(incidents)</A>
220 % if ( $conf->exists('voip-cust_cdr_spools') ) {
222 <TH ALIGN="right"><% mt('Spool CDRs') |h %></TH>
223 <TD><% $cust_main->spool_cdr ? $yes : $no %></TD>
227 % if ( $conf->exists('voip-cust_cdr_squelch') ) {
229 <TH ALIGN="right"><% mt($conf->exists('voip-cdr_email') ? 'Print CDRs' : 'Show CDRs') |h %></TH>
230 <TD><% $cust_main->squelch_cdr ? $no : $yes %></TD>
234 % if ( $conf->exists('voip-cust_accountcode_cdr') ) {
236 <TH ALIGN="right"><% mt('Breakdown CDRs by accountcode') |h %></TH>
237 <TD><% $cust_main->accountcode_cdr ? $yes : $no %></TD>
241 % if ( $conf->exists('voip-cust_email_csv_cdr') ) {
243 <TH ALIGN="right"><% mt('Email CDRs as CSV') |h %></TH>
244 <TD><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
248 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
250 <TH ALIGN="right"><% mt('CDR termination settlement') |h %></TH>
251 <TD><% $cust_main->cdr_termination_percentage %><% $cust_main->cdr_termination_percentage =~ /\d/ ? '%' : '' %></TD>
255 % if ( $cust_main->currency ) {
257 <TH ALIGN="right"><% mt('Invoicing currency') |h %></TH>
258 <TD><% $cust_main->currency. ': '. code2currency($cust_main->currency) %></TD>
262 % if ( $cust_main->locale ) {
263 % my %locale_info = FS::Locales->locale_info($cust_main->locale);
265 <TH ALIGN="right"><% mt('Invoicing locale') |h %></TH>
266 <TD><% $locale_info{name} . " (" . $locale_info{country} .")" %></TD>
274 my( $cust_main ) = @_;
275 my @invoicing_list = $cust_main->invoicing_list;
276 my $conf = new FS::Conf;
277 my $money_char = $conf->config('money_char') || '$';
279 #false laziness w/edit/cust_main/billing.html
280 my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
281 my $term_sth = dbh->prepare($term_sql) or die dbh->errstr;
282 $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
283 my $show_term = $term_sth->fetchrow_arrayref->[0];