2 my $curuser = $FS::CurrentUser::CurrentUser;
4 unless $curuser->access_right('View invoices');
6 my ($invnum) = $cgi->keywords;
7 my $agentnums = $curuser->agentnums_href;
8 my $cust_bill = FS::cust_bill->by_key($invnum)
9 || FS::cust_bill_void->by_key($invnum);
11 if (!$cust_bill or !$agentnums->{ $cust_bill->cust_main->agentnum }) {
12 die "invalid invnum $invnum";
15 my %column_of; # taxname => @tax_amounts column index
16 my @tax_amounts; # array of arrays
17 my @sale_amounts; # just an array
18 my @taxable_descs; # taxable item row headings
19 my @itemdescs; # column headings
20 my %taxname_of; # billpkgnum => taxname
22 my $lineitem_table = 'cust_bill_pkg';
23 if ($cust_bill->isa('FS::cust_bill_void')) {
24 $lineitem_table .= '_void';
29 'table' => $lineitem_table,
30 'hashref' => { 'invnum' => $invnum },
31 'order_by' => 'ORDER BY itemdesc, billpkgnum', # save on sorting the columns later
33 if ( $_->pkgnum or $_->feepart ) {
41 $taxname_of{$_->billpkgnum} = $_->itemdesc;
42 push @itemdescs, $_->itemdesc;
43 $column_of{$_->itemdesc} = $col++;
46 foreach my $sale (@nontax) {
48 foreach my $link_table (qw(
49 cust_bill_pkg_tax_location cust_bill_pkg_tax_rate_location
51 $link_table .= '_void' if $cust_bill->isa('FS::cust_pkg_void');
52 foreach my $link (qsearch({
53 'table' => $link_table,
54 'hashref' => { 'taxable_billpkgnum' => $sale->billpkgnum }
56 # find the itemdesc on this tax
57 my $taxname = $taxname_of{ $link->billpkgnum };
58 # and accumulate in the column it belongs in
59 ($this_row->[ $column_of{ $taxname } ] ||= 0)
62 } # foreach $link_table
63 # create a row if we added any taxes
65 push @tax_amounts, $this_row;
66 push @sale_amounts, $sale->setup + $sale->recur;
67 push @taxable_descs, $sale->desc;
72 <& /elements/header-popup.html &>
78 background-color: #cccccc;
81 table.grid tbody tr:nth-child(even) {
82 background-color: #eeeeee;
84 table.grid tbody tr:nth-child(odd) {
85 background-color: #ffffff;
100 <th><% emt('Charge') %></th>
101 % for (my $col = 0; $col < scalar(@itemdescs); $col++) {
102 <th><% emt($itemdescs[$col]) %></th>
107 % for (my $row = 0; $row < scalar(@taxable_descs); $row++) {
108 % my $this_row = $tax_amounts[$row];
110 <th><% emt($taxable_descs[$row]) %></th>
111 <td><% sprintf('%.2f', $sale_amounts[$row]) %></td>
112 % for (my $col = 0; $col < scalar(@itemdescs); $col++) {
113 <td><% $this_row->[$col] ? sprintf('%.2f', $this_row->[$col]) : '' %></td>
119 <& /elements/footer.html &>