1 <% include("/elements/header.html", "$agentname Tax Report - ".
3 ? time2str('%h %o %Y ', $beginning )
7 ( $ending == 4294967295
9 : time2str('%h %o %Y', $ending )
14 <% include('/elements/table-grid.html') %>
17 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
18 <TH CLASS="grid" BGCOLOR="#cccccc">Tax collected</TH>
20 % my $bgcolor1 = '#eeeeee';
21 % my $bgcolor2 = '#ffffff';
24 % foreach my $tax ( @taxes ) {
26 % if ( $bgcolor eq $bgcolor1 ) {
27 % $bgcolor = $bgcolor2;
29 % $bgcolor = $bgcolor1;
33 % if ( $tax->{'label'} ne 'Total' ) {
34 % $link = ';'. $tax->{'url_param'};
39 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $tax->{'label'} %></TD>
40 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="right">
41 <A HREF="<% $baselink. $link %>;istax=1"><% $money_char %><% sprintf('%.2f', $tax->{'tax'} ) %></A>
53 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
55 my $conf = new FS::Conf;
56 my $money_char = $conf->config('money_char') || '$';
58 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
61 JOIN cust_bill USING ( invnum )
62 LEFT JOIN cust_main USING ( custnum )
64 my $from_join_cust = "
69 my $where = "WHERE _date >= $beginning AND _date <= $ending ";
72 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
73 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
74 die "agent not found" unless $agent;
75 $agentname = $agent->agent;
76 $where .= ' AND cust_main.agentnum = '. $agent->agentnum;
81 foreach my $t (qsearch({ table => 'cust_bill_pkg',
82 hashref => { pkgpart => 0 },
83 addl_from => $join_cust,
88 #warn $t->itemdesc. "\n";
90 my $label = $t->itemdesc;
92 $taxes{$label}->{'label'} = $label;
93 $taxes{$label}->{'url_param'} = "itemdesc=$label";
95 # calculate total for this tax
96 # calculate customer-exemption for this tax
97 # calculate package-exemption for this tax
98 # calculate monthly exemption (texas tax) for this tax
99 # count up all the cust_tax_exempt_pkg records associated with
100 # the actual line items.
104 foreach my $t (qsearch({ table => 'cust_bill_pkg',
105 select => 'DISTINCT itemdesc',
106 hashref => { pkgpart => 0 },
107 addl_from => $join_cust,
113 my $label = $t->itemdesc;
115 my @taxparam = ( 'itemdesc' );
116 my $taxwhere = "$from_join_cust $where AND payby != 'COMP' ".
119 my $sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) ".
120 " $taxwhere AND pkgnum = 0";
122 my $x = scalar_sql($t, \@taxparam, $sql );
124 $taxes{$label}->{'tax'} += $x;
142 #false laziness w/FS::Report::Table::Monthly (sub should probably be moved up
143 #to FS::Report or FS::Record or who the fuck knows where)
145 my( $r, $param, $sql ) = @_;
147 my $sth = dbh->prepare($sql) or die dbh->errstr;
148 $sth->execute( map $r->$_(), @$param )
149 or die "Unexpected error executing statement $sql: ". $sth->errstr;
150 $sth->fetchrow_arrayref->[0] || 0;
153 my $dateagentlink = "begin=$beginning;end=$ending";
154 $dateagentlink .= ';agentnum='. $cgi->param('agentnum')
155 if length($agentname);
156 my $baselink = $p. "search/cust_bill_pkg.cgi?$dateagentlink";