enable CardFortress in test database, #71513
[freeside.git] / httemplate / view / cust_bill_tax_matrix.html
1 <%init>
2 my $curuser = $FS::CurrentUser::CurrentUser;
3 die "access denied"
4   unless $curuser->access_right('View invoices');
5
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);
10
11 if (!$cust_bill or !$agentnums->{ $cust_bill->cust_main->agentnum }) {
12   die "invalid invnum $invnum";
13 }
14
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
21
22 my $lineitem_table = 'cust_bill_pkg';
23 if ($cust_bill->isa('FS::cust_bill_void')) {
24   $lineitem_table .= '_void';
25 }
26
27 my (@tax, @nontax);
28 foreach (qsearch({
29   'table' => $lineitem_table,
30   'hashref' => { 'invnum' => $invnum },
31   'order_by' => 'ORDER BY itemdesc, billpkgnum', # save on sorting the columns later
32 }) ) {
33   if ( $_->pkgnum or $_->feepart ) {
34     push @nontax, $_;
35   } else {
36     push @tax, $_;
37   }
38 }
39 my $col = 0;
40 foreach (@tax) {
41   $taxname_of{$_->billpkgnum} = $_->itemdesc;
42   push @itemdescs, $_->itemdesc;
43   $column_of{$_->itemdesc} = $col++;
44 }
45
46 foreach my $sale (@nontax) {
47   my $this_row = [];
48   foreach my $link_table (qw(
49     cust_bill_pkg_tax_location cust_bill_pkg_tax_rate_location
50   )) {
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 }
55     })) {
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)
60         += $link->amount;
61     }
62   } # foreach $link_table
63   # create a row if we added any taxes
64   if ( @$this_row ) {
65     push @tax_amounts, $this_row;
66     push @sale_amounts, $sale->setup + $sale->recur;
67     push @taxable_descs, $sale->desc;
68   }
69 }
70
71 </%init>
72 <& /elements/header-popup.html &>
73 <style>
74   table.grid {
75     border-spacing: 0px;
76   }
77   table.grid thead {
78     background-color: #cccccc;
79     font-size: 12px;
80   }
81   table.grid tbody tr:nth-child(even) {
82     background-color: #eeeeee;
83   }
84   table.grid tbody tr:nth-child(odd) {
85     background-color: #ffffff;
86   }
87   table.grid tbody th {
88     text-align: left;
89     font-size: 12px;
90   }
91   table.grid tbody td {
92     padding-right: 1em;
93     text-align: right;
94   }
95 </style>
96 <table class="grid">
97   <thead>
98     <tr>
99       <th></th>
100       <th><% emt('Charge') %></th>
101 % for (my $col = 0; $col < scalar(@itemdescs); $col++) {
102       <th><% emt($itemdescs[$col]) %></th>
103 % }
104     </tr>
105   </thead>
106   <tbody>
107 % for (my $row = 0; $row < scalar(@taxable_descs); $row++) {
108 %   my $this_row = $tax_amounts[$row];
109     <tr>
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>
114 %   }
115     </tr>
116 % }
117   </tbody>
118 </table>
119 <& /elements/footer.html &>