From bc60fbd27b5ca8d41b9dae134ccc7f493c2742db Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 24 Oct 2016 11:50:07 -0700 Subject: [PATCH] more detailed view of invoice taxes --- httemplate/view/cust_bill.cgi | 25 +++++-- httemplate/view/cust_bill_tax_matrix.html | 119 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 httemplate/view/cust_bill_tax_matrix.html diff --git a/httemplate/view/cust_bill.cgi b/httemplate/view/cust_bill.cgi index 6d5277612..c7238e6a8 100755 --- a/httemplate/view/cust_bill.cgi +++ b/httemplate/view/cust_bill.cgi @@ -132,12 +132,6 @@ function areyousure(href, message) { <% mt('View typeset invoice PDF') |h %> % $br++; -% } - -% if ( $cust_bill->num_cust_event ) { -<% $br ? '|' : '' %> -<% mt('View invoice events') |h %> -% $br++; % } % my @modes = grep {! $_->disabled} @@ -164,6 +158,25 @@ function change_invoice_mode(obj) { obj.form.submit(); } + +% } + +% if ( $cust_bill->num_cust_event ) { +<% $br ? '|' : '' %> +<% mt('View invoice events') |h %> +% $br++; +% } +% if ( $cust_bill->tax > 0 ) { # inefficient +<% $br ? '|' : '' %> +<& /elements/popup_link.html, + 'action' => 'cust_bill_tax_matrix.html?' . $cust_bill->invnum, + 'label' => mt('View tax details'), + 'actionlabel' => mt('Tax details'), + 'width' => 1050, + 'height' => 500, + 'title' => emt('Tax details'), +&> +% $br++; % }

diff --git a/httemplate/view/cust_bill_tax_matrix.html b/httemplate/view/cust_bill_tax_matrix.html new file mode 100644 index 000000000..d581bf2fe --- /dev/null +++ b/httemplate/view/cust_bill_tax_matrix.html @@ -0,0 +1,119 @@ +<%init> +my $curuser = $FS::CurrentUser::CurrentUser; +die "access denied" + unless $curuser->access_right('View invoices'); + +my ($invnum) = $cgi->keywords; +my $agentnums = $curuser->agentnums_href; +my $cust_bill = FS::cust_bill->by_key($invnum) + || FS::cust_bill_void->by_key($invnum); + +if (!$cust_bill or !$agentnums->{ $cust_bill->cust_main->agentnum }) { + die "invalid invnum $invnum"; +} + +my %column_of; # taxname => @tax_amounts column index +my @tax_amounts; # array of arrays +my @sale_amounts; # just an array +my @taxable_descs; # taxable item row headings +my @itemdescs; # column headings +my %taxname_of; # billpkgnum => taxname + +my $lineitem_table = 'cust_bill_pkg'; +if ($cust_bill->isa('FS::cust_bill_void')) { + $lineitem_table .= '_void'; +} + +my (@tax, @nontax); +foreach (qsearch({ + 'table' => $lineitem_table, + 'hashref' => { 'invnum' => $invnum }, + 'order_by' => 'ORDER BY itemdesc, billpkgnum', # save on sorting the columns later +}) ) { + if ( $_->pkgnum or $_->feepart ) { + push @nontax, $_; + } else { + push @tax, $_; + } +} +my $col = 0; +foreach (@tax) { + $taxname_of{$_->billpkgnum} = $_->itemdesc; + push @itemdescs, $_->itemdesc; + $column_of{$_->itemdesc} = $col++; +} + +foreach my $sale (@nontax) { + my $this_row = []; + foreach my $link_table (qw( + cust_bill_pkg_tax_location cust_bill_pkg_tax_rate_location + )) { + $link_table .= '_void' if $cust_bill->isa('FS::cust_pkg_void'); + foreach my $link (qsearch({ + 'table' => $link_table, + 'hashref' => { 'taxable_billpkgnum' => $sale->billpkgnum } + })) { + # find the itemdesc on this tax + my $taxname = $taxname_of{ $link->billpkgnum }; + # and accumulate in the column it belongs in + ($this_row->[ $column_of{ $taxname } ] ||= 0) + += $link->amount; + } + } # foreach $link_table + # create a row if we added any taxes + if ( @$this_row ) { + push @tax_amounts, $this_row; + push @sale_amounts, $sale->setup + $sale->recur; + push @taxable_descs, $sale->desc; + } +} + + +<& /elements/header-popup.html &> + + + + + + +% for (my $col = 0; $col < scalar(@itemdescs); $col++) { + +% } + + + +% for (my $row = 0; $row < scalar(@taxable_descs); $row++) { +% my $this_row = $tax_amounts[$row]; + + + +% for (my $col = 0; $col < scalar(@itemdescs); $col++) { + +% } + +% } + +
<% emt('Charge') %><% emt($itemdescs[$col]) %>
<% emt($taxable_descs[$row]) %><% sprintf('%.2f', $sale_amounts[$row]) %><% $this_row->[$col] ? sprintf('%.2f', $this_row->[$col]) : '' %>
+<& /elements/footer.html &> -- 2.11.0