1 <% include("/elements/header.html", "$agentname Tax Report - ".
3 ? time2str('%h %o %Y ', $beginning )
7 ( $ending == 4294967295
9 : time2str('%h %o %Y', $ending )
14 Download full results<BR>
15 as <A HREF="<% $p.'search/report_tax-xls.cgi?'.$cgi->query_string%>">Excel spreadsheet</A>
18 <% include('/elements/table-grid.html') %>
21 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3></TH>
22 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=9>Sales</TH>
23 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3></TH>
24 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3>Rate</TH>
25 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3></TH>
26 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3>Tax owed</TH>
27 % unless ( $cgi->param('show_taxclasses') ) {
28 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3>Tax invoiced</TH>
29 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3></TH>
30 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3>Tax credited</TH>
31 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3></TH>
32 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=3>Tax collected</TH>
37 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Total</TH>
38 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
39 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=1>Non-taxable</TH>
40 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
41 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=1>Non-taxable</TH>
42 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
43 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=1>Non-taxable</TH>
44 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
45 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Taxable</TH>
49 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>(tax-exempt customer)</FONT></TH>
50 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>(tax-exempt package)</FONT></TH>
51 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>(monthly exemption)</FONT></TH>
54 % my $bgcolor1 = '#eeeeee';
55 % my $bgcolor2 = '#ffffff';
58 % foreach my $region ( @regions ) {
61 % if ( $region->{'label'} eq $out ) {
64 % $link = ';'. $region->{'url_param'}
65 % if $region->{'url_param'};
68 % if ( $bgcolor eq $bgcolor1 ) {
69 % $bgcolor = $bgcolor2;
71 % $bgcolor = $bgcolor1;
75 % my $hicolor = $bgcolor;
76 % unless ( $cgi->param('show_taxclasses') ) {
77 % my $diff = abs( sprintf( '%.2f', $region->{'owed'} )
78 % - sprintf( '%.2f', $region->{'tax'} )
80 % if ( $diff > 0.02 ) {
81 % # $hicolor = $hicolor eq '#eeeeee' ? '#eeee66' : '#ffff99';
82 % #} elsif ( $diff ) {
83 % $hicolor = $hicolor eq '#eeeeee' ? '#eeee99' : '#ffffcc';
88 % my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
89 % my $tdh = qq(TD CLASS="grid" BGCOLOR="$hicolor");
90 % my $bigmath = '<FONT FACE="sans-serif" SIZE="+1"><B>';
91 % my $bme = '</B></FONT>';
94 <<%$td%>><% $region->{'label'} %></TD>
95 <<%$td%> ALIGN="right">
96 <A HREF="<% $baselink. $link %>;nottax=1"
97 ><% &$money_sprintf( $region->{'total'} ) %></A>
99 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
100 <<%$td%> ALIGN="right">
101 <A HREF="<% $baselink. $link %>;nottax=1;cust_tax=Y"
102 ><% &$money_sprintf( $region->{'exempt_cust'} ) %></A>
104 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
105 <<%$td%> ALIGN="right">
106 <A HREF="<% $baselink. $link %>;nottax=1;pkg_tax=Y"
107 ><% &$money_sprintf( $region->{'exempt_pkg'} ) %></A>
109 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
110 <<%$td%> ALIGN="right">
111 <A HREF="<% $exemptlink. $link %>"
112 ><% &$money_sprintf( $region->{'exempt_monthly'} ) %></A>
114 <<%$td%>><FONT SIZE="+1"><B> = </B></FONT></TD>
115 <<%$td%> ALIGN="right">
116 <A HREF="<% $baselink. $link %>;nottax=1;taxable=1"
117 ><% &$money_sprintf( $region->{'taxable'} ) %></A>
119 <<%$td%>><% $region->{'label'} eq 'Total' ? '' : "$bigmath X $bme" %></TD>
120 <<%$td%> ALIGN="right"><% $region->{'rate'} %></TD>
121 <<%$td%>><% $region->{'label'} eq 'Total' ? '' : "$bigmath = $bme" %></TD>
122 <<%$tdh%> ALIGN="right">
123 <% &$money_sprintf( $region->{'owed'} ) %>
126 % unless ( $cgi->param('show_taxclasses') ) {
127 % my $invlink = $region->{'url_param_inv'}
128 % ? ';'. $region->{'url_param_inv'}
131 <<%$tdh%> ALIGN="right">
132 <A HREF="<% $baselink. $invlink %>;istax=1"
133 ><% &$money_sprintf( $region->{'tax'} ) %></A>
135 <<%$tdh%>><FONT SIZE="+1"><B> - </B></FONT></TD>
136 <<%$tdh%> ALIGN="right">
137 <A HREF="<% $creditlink. $invlink %>;istax=1"
138 ><% &$money_sprintf( $region->{'credit'} ) %></A>
140 <<%$tdh%>><FONT SIZE="+1"><B> = </B></FONT></TD>
141 <<%$tdh%> ALIGN="right">
142 <% &$money_sprintf( $region->{'tax'} - $region->{'credit'} ) %>
151 % if ( $cgi->param('show_taxclasses') ) {
154 <% include('/elements/table-grid.html') %>
156 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
157 <TH CLASS="grid" BGCOLOR="#cccccc">Tax invoiced</TH>
158 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
159 <TH CLASS="grid" BGCOLOR="#cccccc">Tax credited</TH>
160 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
161 <TH CLASS="grid" BGCOLOR="#cccccc">Tax collected</TH>
164 % #some false laziness w/above
165 % $bgcolor1 = '#eeeeee';
166 % $bgcolor2 = '#ffffff';
168 % foreach my $region ( @base_regions ) {
171 % if ( $region->{'label'} eq $out ) {
174 % $link = ';'. $region->{'url_param'}
175 % if $region->{'url_param'};
178 % if ( $bgcolor eq $bgcolor1 ) {
179 % $bgcolor = $bgcolor2;
181 % $bgcolor = $bgcolor1;
183 % my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
184 % my $tdh = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
187 % my $invlink = $region->{'url_param_inv'}
188 % ? ';'. $region->{'url_param_inv'}
192 <<%$td%>><% $region->{'label'} %></TD>
193 <<%$td%> ALIGN="right">
194 <A HREF="<% $baselink. $link %>;istax=1"
195 ><% &$money_sprintf( $region->{'tax'} ) %></A>
197 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
198 <<%$tdh%> ALIGN="right">
199 <A HREF="<% $creditlink. $invlink %>;istax=1"
200 ><% &$money_sprintf( $region->{'credit'} ) %></A>
202 <<%$td%>><FONT SIZE="+1"><B> = </B></FONT></TD>
203 <<%$tdh%> ALIGN="right">
204 <% &$money_sprintf( $region->{'tax'} - $region->{'credit'} ) %>
210 % if ( $bgcolor eq $bgcolor1 ) {
211 % $bgcolor = $bgcolor2;
213 % $bgcolor = $bgcolor1;
215 % my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
219 <<%$td%> ALIGN="right">
220 <A HREF="<% $baselink %>;istax=1"
221 ><% &$money_sprintf( $tot_tax ) %></A>
223 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
224 <<%$td%> ALIGN="right">
225 <A HREF="<% $creditlink %>;istax=1"
226 ><% &$money_sprintf( $tot_credit ) %></A>
228 <<%$td%>><FONT SIZE="+1"><B> = </B></FONT></TD>
229 <<%$td%> ALIGN="right">
230 <% &$money_sprintf( $tot_tax - $tot_credit ) %>
238 <% include('/elements/footer.html') %>
243 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
245 my $conf = new FS::Conf;
247 my $user = getotaker;
249 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
251 my $join_cust = ' JOIN cust_bill USING ( invnum )
252 LEFT JOIN cust_main USING ( custnum ) ';
253 my $join_cust_pkg = $join_cust.
254 ' LEFT JOIN cust_pkg USING ( pkgnum )
255 LEFT JOIN part_pkg USING ( pkgpart ) ';
256 $join_cust_pkg .= ' LEFT JOIN cust_location USING ( locationnum )'
257 if $conf->exists('tax-pkg_address');
259 my $from_join_cust_pkg = " FROM cust_bill_pkg $join_cust_pkg ";
261 my $where = "WHERE _date >= $beginning AND _date <= $ending ";
263 my( $location_sql, @base_param ) = FS::cust_pkg->location_sql;
264 $where .= " AND $location_sql ";
267 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
268 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
269 die "agent not found" unless $agent;
270 $agentname = $agent->agent;
271 $where .= ' AND cust_main.agentnum = '. $agent->agentnum;
276 my $prefix = @_ ? shift : '';
278 ( $table.${prefix}city = cust_main_county.city
279 OR cust_main_county.city = ''
280 OR cust_main_county.city IS NULL )
281 AND ( $table.${prefix}county = cust_main_county.county
282 OR cust_main_county.county = ''
283 OR cust_main_county.county IS NULL )
284 AND ( $table.${prefix}state = cust_main_county.state
285 OR cust_main_county.state = ''
286 OR cust_main_county.state IS NULL )
287 AND ( $table.${prefix}country = cust_main_county.country )
292 if ( $conf->exists('tax-ship_address') ) {
295 ( cust_main_county.country = cust_main.country
296 OR cust_main_county.country = cust_main.ship_country
302 ( ( ship_last IS NULL OR ship_last = '' )
303 AND ". gotcust('cust_main'). "
306 ( ship_last IS NOT NULL AND ship_last != ''
307 AND ". gotcust('cust_main', 'ship_'). "
314 $gotcust = gotcust('cust_main');
317 if ( $conf->exists('tax-pkg_address') ) {
319 ( cust_pkg.locationnum IS NULL AND $gotcust)
320 OR ( cust_pkg.locationnum IS NOT NULL AND ". gotcust('cust_location'). " )";
322 "WHERE 0 < ( SELECT COUNT(*) FROM cust_pkg
323 LEFT JOIN cust_main USING ( custnum )
324 LEFT JOIN cust_location USING ( locationnum )
331 "WHERE 0 < ( SELECT COUNT(*) FROM cust_main WHERE $gotcust LIMIT 1 )";
334 my $out = 'Out of taxable region(s)';
337 foreach my $r ( qsearch({ 'table' => 'cust_main_county',
338 'extra_sql' => $gotcust,
342 #warn $r->county. ' '. $r->state. ' '. $r->country. "\n";
344 my $label = getlabel($r);
345 $regions{$label}->{'label'} = $label;
347 $regions{$label}->{$_} = $r->$_() for (qw( county state country )); #taxname?
349 my @url_param = qw( county state country taxname );
350 push @url_param, 'city' if $cgi->param('show_cities') && $r->city();
352 $regions{$label}->{'url_param'} =
353 join(';', map "$_=".uri_escape($r->$_()), @url_param );
355 my @param = @base_param;
356 my $mywhere = $where;
358 if ( $r->taxclass ) {
360 $mywhere .= " AND taxclass = ? ";
361 push @param, 'taxclass';
362 $regions{$label}->{'url_param'} .= ';taxclass='. uri_escape($r->taxclass);
363 #no, always# if $cgi->param('show_taxclasses');
365 $regions{$label}->{'taxclass'} = $r->taxclass;
369 $regions{$label}->{'url_param'} .= ';taxclassNULL=1'
370 if $cgi->param('show_taxclasses');
372 my $same_sql = $r->sql_taxclass_sameregion;
373 $mywhere .= " AND $same_sql" if $same_sql;
377 my $fromwhere = "$from_join_cust_pkg $mywhere"; # AND payby != 'COMP' ";
379 # my $label = getlabel($r);
380 # $regions{$label}->{'label'} = $label;
382 my $nottax = 'pkgnum != 0';
384 ## calculate total for this region
387 "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) $fromwhere AND $nottax";
388 my $t = scalar_sql($r, \@param, $t_sql);
389 $regions{$label}->{'total'} += $t;
391 #if ( $label eq $out ) # && $t ) {
392 # warn "adding $t for ".
393 # join('/', map $r->$_, qw( taxclass county state country ) ). "\n";
394 # #warn $t_sql if $r->state eq 'FL';
397 ## calculate customer-exemption for this region
401 # my($taxable, $x_cust) = (0, 0);
402 # foreach my $e ( grep { $r->get($_.'tax') !~ /^Y/i }
403 # qw( cust_bill_pkg.setup cust_bill_pkg.recur ) ) {
404 # $taxable += scalar_sql($r, \@param,
405 # "SELECT SUM($e) $fromwhere AND $nottax AND ( tax != 'Y' OR tax IS NULL )"
408 # $x_cust += scalar_sql($r, \@param,
409 # "SELECT SUM($e) $fromwhere AND $nottax AND tax = 'Y'"
413 #false laziness -ish w/report_tax.cgi
416 my $q_taxname = dbh->quote($r->taxname);
419 OR EXISTS ( SELECT 1 FROM cust_main_exemption
420 WHERE cust_main_exemption.custnum = cust_main.custnum
421 AND cust_main_exemption.taxname = $q_taxname
426 $cust_exempt = " tax = 'Y' ";
429 my $x_cust = scalar_sql($r, \@param,
430 "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur)
431 $fromwhere AND $nottax AND $cust_exempt "
434 $regions{$label}->{'exempt_cust'} += $x_cust;
436 ## calculate package-exemption for this region
438 my $x_pkg = scalar_sql($r, \@param,
440 ( CASE WHEN part_pkg.setuptax = 'Y'
441 THEN cust_bill_pkg.setup
446 ( CASE WHEN part_pkg.recurtax = 'Y'
447 THEN cust_bill_pkg.recur
455 ( part_pkg.setuptax = 'Y' AND cust_bill_pkg.setup > 0 )
456 OR ( part_pkg.recurtax = 'Y' AND cust_bill_pkg.recur > 0 )
458 AND ( tax != 'Y' OR tax IS NULL )
461 $regions{$label}->{'exempt_pkg'} += $x_pkg;
463 ## calculate monthly exemption (texas tax) for this region
465 # count up all the cust_tax_exempt_pkg records associated with
466 # the actual line items.
468 my $x_monthly = scalar_sql($r, \@param,
470 FROM cust_tax_exempt_pkg
471 JOIN cust_bill_pkg USING ( billpkgnum )
475 $regions{$label}->{'exempt_monthly'} += $x_monthly;
477 my $taxable = $t - $x_cust - $x_pkg - $x_monthly;
478 $regions{$label}->{'taxable'} += $taxable;
480 $regions{$label}->{'owed'} += $taxable * ($r->tax/100);
482 if ( defined($regions{$label}->{'rate'})
483 && $regions{$label}->{'rate'} != $r->tax.'%' ) {
484 $regions{$label}->{'rate'} = 'variable';
486 $regions{$label}->{'rate'} = $r->tax.'%';
491 my $distinct = "country, state, county, city,
492 CASE WHEN taxname IS NULL THEN '' ELSE taxname END AS taxname";
493 my $taxclass_distinct =
494 #a little bit unsure of this part... test?
495 #ah, it looks like it winds up being irrelevant as ->{'tax'}
496 # from $regions is not displayed when show_taxclasses is on
497 ( $cgi->param('show_taxclasses')
498 ? " CASE WHEN taxclass IS NULL THEN '' ELSE taxclass END "
504 'select' => "DISTINCT $distinct, $taxclass_distinct",
505 'table' => 'cust_main_county',
507 'extra_sql' => $gotcust,
510 my $taxfromwhere = " FROM cust_bill_pkg $join_cust ";
511 my $taxwhere = $where;
512 if ( $conf->exists('tax-pkg_address') ) {
514 $taxfromwhere .= 'LEFT JOIN cust_bill_pkg_tax_location USING ( billpkgnum )
515 LEFT JOIN cust_location USING ( locationnum ) ';
518 $taxwhere =~ s/cust_pkg\.locationnum/cust_bill_pkg_tax_location.locationnum/g;
521 my $creditfromwhere = $taxfromwhere.
522 " JOIN cust_credit_bill_pkg USING (billpkgnum";
523 $creditfromwhere .= " ,billpkgtaxlocationnum"
524 if $conf->exists('tax-pkg_address');
525 $creditfromwhere .= ")";
527 $taxfromwhere .= " $taxwhere "; #AND payby != 'COMP' ";
528 $creditfromwhere .= " $taxwhere AND billpkgtaxratelocationnum IS NULL"; #AND payby != 'COMP' ";
530 my @taxparam = @base_param;
533 #should i be a cust_main_county method or something
534 #need to pass in $taxfromwhere & @taxparam???
535 my $_taxamount_sub = sub {
538 #match itemdesc if necessary!
541 ? 'AND itemdesc = '. dbh->quote($r->taxname)
542 : "AND ( itemdesc IS NULL OR itemdesc = '' OR itemdesc = 'Tax' )";
544 my $sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) ".
545 " $taxfromwhere AND cust_bill_pkg.pkgnum = 0 $named_tax";
547 scalar_sql($r, \@taxparam, $sql );
550 my $_creditamount_sub = sub {
553 #match itemdesc if necessary!
556 ? 'AND itemdesc = '. dbh->quote($r->taxname)
557 : "AND ( itemdesc IS NULL OR itemdesc = '' OR itemdesc = 'Tax' )";
559 my $sql = "SELECT SUM(cust_credit_bill_pkg.amount) ".
560 " $creditfromwhere AND cust_bill_pkg.pkgnum = 0 $named_tax";
562 scalar_sql($r, \@taxparam, $sql );
565 #tax-report_groups filtering
566 my($group_op, $group_value) = ( '', '' );
567 if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ ) {
568 ( $group_op, $group_value ) = ( $1, $2 );
570 my $group_test = sub {
572 return 1 unless $group_op; #in case we get called inadvertantly
573 if ( $label eq $out ) { #don't display "out of taxable region" in this case
575 } elsif ( $group_op eq '=' ) {
576 $label =~ /^$group_value/;
577 } elsif ( $group_op eq '!=' ) {
578 $label !~ /^$group_value/;
580 die "guru meditation #00de: group_op $group_op\n";
586 #foreach my $label ( keys %regions ) {
587 foreach my $r ( qsearch(\%qsearch) ) {
589 #warn join('-', map { $r->$_() } qw( country state county taxname ) )."\n";
591 my $label = getlabel($r);
593 next unless &{$group_test}($label);
596 #my $fromwhere = $join_pkg. $where. " AND payby != 'COMP' ";
597 #my @param = @base_param;
599 my $x = &{$_taxamount_sub}($r);
601 $regions{$label}->{'tax'} += $x;
602 $tot_tax += $x unless $cgi->param('show_taxclasses');
604 ## calculate credit for this region
606 $x = &{$_creditamount_sub}($r);
608 $regions{$label}->{'credit'} += $x;
609 $tot_credit += $x unless $cgi->param('show_taxclasses');
613 my %base_regions = ();
614 if ( $cgi->param('show_taxclasses') ) {
616 $qsearch{'select'} = "DISTINCT $distinct";
617 foreach my $r ( qsearch(\%qsearch) ) {
619 my $x = &{$_taxamount_sub}($r);
621 my $base_label = getlabel($r, 'no_taxclass'=>1 );
622 $base_regions{$base_label}->{'label'} = $base_label;
624 $base_regions{$base_label}->{'url_param'} =
625 join(';', map "$_=". uri_escape($r->$_()),
626 qw( county state country taxname )
629 $base_regions{$base_label}->{'tax'} += $x;
632 ## calculate credit for this region
634 $x = &{$_creditamount_sub}($r);
636 $base_regions{$base_label}->{'credit'} += $x;
643 my @regions = keys %regions;
645 #tax-report_groups filtering
646 @regions = grep &{$group_test}($_), @regions
650 my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 );
651 my( $exempt_cust, $exempt_pkg, $exempt_monthly, $tot_credit ) = ( 0, 0, 0, 0 );
657 $total += $regions{$_}->{'total'};
658 $tot_taxable += $regions{$_}->{'taxable'};
659 $tot_owed += $regions{$_}->{'owed'};
660 $exempt_cust += $regions{$_}->{'exempt_cust'};
661 $exempt_pkg += $regions{$_}->{'exempt_pkg'};
662 $exempt_monthly += $regions{$_}->{'exempt_monthly'};
663 $tot_credit += $regions{$_}->{'credit'};
664 $taxclasses{$regions{$_}->{'taxclass'}} = 1
665 if $regions{$_}->{'taxclass'};
666 $county{$regions{$_}->{'county'}} = 1;
667 $state{$regions{$_}->{'state'}} = 1;
668 $country{$regions{$_}->{'country'}} = 1;
671 my $total_url_param = '';
672 my $total_url_param_invoiced = '';
675 my @country = keys %country;
676 warn "WARNING: multiple countries on this grouped report; total links broken"
677 if scalar(@country) > 1;
678 my $country = $country[0];
680 my @state = keys %state;
681 warn "WARNING: multiple countries on this grouped report; total links broken"
682 if scalar(@state) > 1;
683 my $state = $state[0];
685 $total_url_param_invoiced =
687 'report_group='.uri_escape("$group_op $group_value").';'.
688 join(';', map 'taxclass='.uri_escape($_), keys %taxclasses );
689 $total_url_param .= ';'.
690 "country=$country;state=".uri_escape($state).';'.
691 join(';', map 'county='.uri_escape($_), keys %county ) ;
698 sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) }
702 map $base_regions{$_},
703 sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) }
709 'url_param' => $total_url_param,
710 'url_param_inv' => $total_url_param_invoiced,
712 'exempt_cust' => $exempt_cust,
713 'exempt_pkg' => $exempt_pkg,
714 'exempt_monthly' => $exempt_monthly,
715 'taxable' => $tot_taxable,
719 'credit' => $tot_credit,
724 my $money_char = $conf->config('money_char') || '$';
725 my $money_sprintf = sub {
726 $money_char. sprintf('%.2f', shift );
736 && ! scalar( qsearch('cust_main_county', { 'city' => $r->city,
737 'county' => $r->county,
738 'state' => $r->state,
739 'country' => $r->country,
740 'tax' => { op=>'>', value=>0 },
746 #kludge to avoid "will not stay shared" warning
747 my $out = 'Out of taxable region(s)';
749 # } elsif ( $r->taxname && count_taxname($r->taxname) == 1 ) {
750 # $label = $r->taxname;
751 ## $regions{$label}->{'taxname'} = $label;
752 ## push @{$regions{$label}->{$_}}, $r->$_() foreach qw( county state country );
754 $label = $r->country;
755 $label = $r->state.", $label" if $r->state;
756 $label = $r->county." county, $label" if $r->county;
757 $label = $r->city. ", $label" if $r->city && $cgi->param('show_cities');
758 $label = "$label (". $r->taxclass. ")"
760 && $cgi->param('show_taxclasses')
761 && ! $opt{'no_taxclass'};
762 $label = $r->taxname. " ($label)" if $r->taxname;
767 #my %count_taxname = (); #cache
769 # my $taxname = shift;
770 # return $count_taxname{$taxname} if exists $count_taxname{$taxname};
771 # my $sql = 'SELECT COUNT(*) FROM cust_main_county WHERE taxname = ?';
772 # my $sth = dbh->prepare($sql) or die dbh->errstr;
773 # $sth->execute( $taxname )
774 # or die "Unexpected error executing statement $sql: ". $sth->errstr;
775 # $count_taxname{$taxname} = $sth->fetchrow_arrayref->[0];
778 #false laziness w/FS::Report::Table::Monthly (sub should probably be moved up
779 #to FS::Report or FS::Record or who the fuck knows where)
781 my( $r, $param, $sql ) = @_;
783 my $sth = dbh->prepare($sql) or die dbh->errstr;
784 $sth->execute( map $r->$_(), @$param )
785 or die "Unexpected error executing statement $sql: ". $sth->errstr;
786 $sth->fetchrow_arrayref->[0] || 0;
789 my $dateagentlink = "begin=$beginning;end=$ending";
790 $dateagentlink .= ';agentnum='. $cgi->param('agentnum')
791 if length($agentname);
792 my $baselink = $p. "search/cust_bill_pkg.cgi?$dateagentlink";
793 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
794 my $creditlink = $p. "search/cust_credit_bill_pkg.html?$dateagentlink";