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" ROWSPAN=2></TH>
18 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=9>Sales</TH>
19 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
20 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Rate</TH>
21 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
22 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax owed</TH>
23 % unless ( $cgi->param('show_taxclasses') ) {
24 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax invoiced</TH>
25 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
26 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax credited</TH>
27 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2></TH>
28 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax collected</TH>
33 <TH CLASS="grid" BGCOLOR="#cccccc">Total</TH>
34 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
35 <TH CLASS="grid" BGCOLOR="#cccccc">Non-taxable<BR><FONT SIZE=-1>(tax-exempt customer)</FONT></TH>
36 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
37 <TH CLASS="grid" BGCOLOR="#cccccc">Non-taxable<BR><FONT SIZE=-1>(tax-exempt package)</FONT></TH>
38 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
39 <TH CLASS="grid" BGCOLOR="#cccccc">Non-taxable<BR><FONT SIZE=-1>(monthly exemption)</FONT></TH>
40 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
41 <TH CLASS="grid" BGCOLOR="#cccccc">Taxable</TH>
44 % my $bgcolor1 = '#eeeeee';
45 % my $bgcolor2 = '#ffffff';
48 % foreach my $region ( @regions ) {
51 % if ( $region->{'label'} eq $out ) {
54 % $link = ';'. $region->{'url_param'}
55 % if $region->{'url_param'};
58 % if ( $bgcolor eq $bgcolor1 ) {
59 % $bgcolor = $bgcolor2;
61 % $bgcolor = $bgcolor1;
65 % my $hicolor = $bgcolor;
66 % unless ( $cgi->param('show_taxclasses') ) {
67 % my $diff = abs( sprintf( '%.2f', $region->{'owed'} )
68 % - sprintf( '%.2f', $region->{'tax'} )
70 % if ( $diff > 0.02 ) {
71 % # $hicolor = $hicolor eq '#eeeeee' ? '#eeee66' : '#ffff99';
72 % #} elsif ( $diff ) {
73 % $hicolor = $hicolor eq '#eeeeee' ? '#eeee99' : '#ffffcc';
78 % my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
79 % my $tdh = qq(TD CLASS="grid" BGCOLOR="$hicolor");
80 % my $bigmath = '<FONT FACE="sans-serif" SIZE="+1"><B>';
81 % my $bme = '</B></FONT>';
84 <<%$td%>><% $region->{'label'} %></TD>
85 <<%$td%> ALIGN="right">
86 <A HREF="<% $baselink. $link %>;nottax=1"
87 ><% &$money_sprintf( $region->{'total'} ) %></A>
89 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
90 <<%$td%> ALIGN="right">
91 <A HREF="<% $baselink. $link %>;nottax=1;cust_tax=Y"
92 ><% &$money_sprintf( $region->{'exempt_cust'} ) %></A>
94 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
95 <<%$td%> ALIGN="right">
96 <A HREF="<% $baselink. $link %>;nottax=1;pkg_tax=Y"
97 ><% &$money_sprintf( $region->{'exempt_pkg'} ) %></A>
99 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
100 <<%$td%> ALIGN="right">
101 <A HREF="<% $exemptlink. $link %>"
102 ><% &$money_sprintf( $region->{'exempt_monthly'} ) %></A>
104 <<%$td%>><FONT SIZE="+1"><B> = </B></FONT></TD>
105 <<%$td%> ALIGN="right">
106 <A HREF="<% $baselink. $link %>;nottax=1;taxable=1"
107 ><% &$money_sprintf( $region->{'taxable'} ) %></A>
109 <<%$td%>><% $region->{'label'} eq 'Total' ? '' : "$bigmath X $bme" %></TD>
110 <<%$td%> ALIGN="right"><% $region->{'rate'} %></TD>
111 <<%$td%>><% $region->{'label'} eq 'Total' ? '' : "$bigmath = $bme" %></TD>
112 <<%$tdh%> ALIGN="right">
113 <% &$money_sprintf( $region->{'owed'} ) %>
116 % unless ( $cgi->param('show_taxclasses') ) {
117 % my $invlink = $region->{'url_param_inv'}
118 % ? ';'. $region->{'url_param_inv'}
121 <<%$tdh%> ALIGN="right">
122 <A HREF="<% $baselink. $invlink %>;istax=1"
123 ><% &$money_sprintf( $region->{'tax'} ) %></A>
125 <<%$tdh%>><FONT SIZE="+1"><B> - </B></FONT></TD>
126 <<%$tdh%> ALIGN="right">
127 <A HREF="<% $creditlink. $invlink %>;istax=1"
128 ><% &$money_sprintf( $region->{'credit'} ) %></A>
130 <<%$tdh%>><FONT SIZE="+1"><B> = </B></FONT></TD>
131 <<%$tdh%> ALIGN="right">
132 <% &$money_sprintf( $region->{'tax'} - $region->{'credit'} ) %>
141 % if ( $cgi->param('show_taxclasses') ) {
144 <% include('/elements/table-grid.html') %>
146 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
147 <TH CLASS="grid" BGCOLOR="#cccccc">Tax invoiced</TH>
148 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
149 <TH CLASS="grid" BGCOLOR="#cccccc">Tax credited</TH>
150 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
151 <TH CLASS="grid" BGCOLOR="#cccccc">Tax collected</TH>
154 % #some false laziness w/above
155 % $bgcolor1 = '#eeeeee';
156 % $bgcolor2 = '#ffffff';
158 % foreach my $region ( @base_regions ) {
161 % if ( $region->{'label'} eq $out ) {
164 % $link = ';'. $region->{'url_param'}
165 % if $region->{'url_param'};
168 % if ( $bgcolor eq $bgcolor1 ) {
169 % $bgcolor = $bgcolor2;
171 % $bgcolor = $bgcolor1;
173 % my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
174 % my $tdh = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
177 % my $invlink = $region->{'url_param_inv'}
178 % ? ';'. $region->{'url_param_inv'}
182 <<%$td%>><% $region->{'label'} %></TD>
183 <<%$td%> ALIGN="right">
184 <A HREF="<% $baselink. $link %>;istax=1"
185 ><% &$money_sprintf( $region->{'tax'} ) %></A>
187 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
188 <<%$tdh%> ALIGN="right">
189 <A HREF="<% $creditlink. $invlink %>;istax=1"
190 ><% &$money_sprintf( $region->{'credit'} ) %></A>
192 <<%$td%>><FONT SIZE="+1"><B> = </B></FONT></TD>
193 <<%$tdh%> ALIGN="right">
194 <% &$money_sprintf( $region->{'tax'} - $region->{'credit'} ) %>
200 % if ( $bgcolor eq $bgcolor1 ) {
201 % $bgcolor = $bgcolor2;
203 % $bgcolor = $bgcolor1;
205 % my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
209 <<%$td%> ALIGN="right">
210 <A HREF="<% $baselink %>;istax=1"
211 ><% &$money_sprintf( $tot_tax ) %></A>
213 <<%$td%>><FONT SIZE="+1"><B> - </B></FONT></TD>
214 <<%$td%> ALIGN="right">
215 <A HREF="<% $creditlink %>;istax=1"
216 ><% &$money_sprintf( $tot_credit ) %></A>
218 <<%$td%>><FONT SIZE="+1"><B> = </B></FONT></TD>
219 <<%$td%> ALIGN="right">
220 <% &$money_sprintf( $tot_tax - $tot_credit ) %>
228 <% include('/elements/footer.html') %>
233 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
235 my $conf = new FS::Conf;
237 my $user = getotaker;
239 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
241 my $join_cust = ' JOIN cust_bill USING ( invnum )
242 LEFT JOIN cust_main USING ( custnum ) ';
243 my $join_cust_pkg = $join_cust.
244 ' LEFT JOIN cust_pkg USING ( pkgnum )
245 LEFT JOIN part_pkg USING ( pkgpart ) ';
246 $join_cust_pkg .= ' LEFT JOIN cust_location USING ( locationnum )'
247 if $conf->exists('tax-pkg_address');
249 my $from_join_cust_pkg = " FROM cust_bill_pkg $join_cust_pkg ";
251 my $where = "WHERE _date >= $beginning AND _date <= $ending ";
253 my( $location_sql, @base_param ) = FS::cust_pkg->location_sql;
254 $where .= " AND $location_sql ";
257 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
258 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
259 die "agent not found" unless $agent;
260 $agentname = $agent->agent;
261 $where .= ' AND cust_main.agentnum = '. $agent->agentnum;
266 my $prefix = @_ ? shift : '';
268 ( $table.${prefix}city = cust_main_county.city
269 OR cust_main_county.city = ''
270 OR cust_main_county.city IS NULL )
271 AND ( $table.${prefix}county = cust_main_county.county
272 OR cust_main_county.county = ''
273 OR cust_main_county.county IS NULL )
274 AND ( $table.${prefix}state = cust_main_county.state
275 OR cust_main_county.state = ''
276 OR cust_main_county.state IS NULL )
277 AND ( $table.${prefix}country = cust_main_county.country )
282 if ( $conf->exists('tax-ship_address') ) {
285 ( cust_main_county.country = cust_main.country
286 OR cust_main_county.country = cust_main.ship_country
292 ( ( ship_last IS NULL OR ship_last = '' )
293 AND ". gotcust('cust_main'). "
296 ( ship_last IS NOT NULL AND ship_last != ''
297 AND ". gotcust('cust_main', 'ship_'). "
304 $gotcust = gotcust('cust_main');
307 if ( $conf->exists('tax-pkg_address') ) {
309 ( cust_pkg.locationnum IS NULL AND $gotcust)
310 OR ( cust_pkg.locationnum IS NOT NULL AND ". gotcust('cust_location'). " )";
312 "WHERE 0 < ( SELECT COUNT(*) FROM cust_pkg
313 LEFT JOIN cust_main USING ( custnum )
314 LEFT JOIN cust_location USING ( locationnum )
321 "WHERE 0 < ( SELECT COUNT(*) FROM cust_main WHERE $gotcust LIMIT 1 )";
324 my $out = 'Out of taxable region(s)';
327 foreach my $r ( qsearch({ 'table' => 'cust_main_county',
328 'extra_sql' => $gotcust,
332 #warn $r->county. ' '. $r->state. ' '. $r->country. "\n";
334 my $label = getlabel($r);
335 $regions{$label}->{'label'} = $label;
337 $regions{$label}->{$_} = $r->$_() for (qw( county state country )); #taxname?
339 my @url_param = qw( county state country taxname );
340 push @url_param, 'city' if $cgi->param('show_cities') && $r->city();
342 $regions{$label}->{'url_param'} =
343 join(';', map "$_=".uri_escape($r->$_()), @url_param );
345 my @param = @base_param;
346 my $mywhere = $where;
348 if ( $r->taxclass ) {
350 $mywhere .= " AND taxclass = ? ";
351 push @param, 'taxclass';
352 $regions{$label}->{'url_param'} .= ';taxclass='. uri_escape($r->taxclass);
353 #no, always# if $cgi->param('show_taxclasses');
355 $regions{$label}->{'taxclass'} = $r->taxclass;
359 $regions{$label}->{'url_param'} .= ';taxclassNULL=1'
360 if $cgi->param('show_taxclasses');
362 my $same_sql = $r->sql_taxclass_sameregion;
363 $mywhere .= " AND $same_sql" if $same_sql;
367 my $fromwhere = "$from_join_cust_pkg $mywhere"; # AND payby != 'COMP' ";
369 # my $label = getlabel($r);
370 # $regions{$label}->{'label'} = $label;
372 my $nottax = 'pkgnum != 0';
374 ## calculate total for this region
377 "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) $fromwhere AND $nottax";
378 my $t = scalar_sql($r, \@param, $t_sql);
379 $regions{$label}->{'total'} += $t;
381 #if ( $label eq $out ) # && $t ) {
382 # warn "adding $t for ".
383 # join('/', map $r->$_, qw( taxclass county state country ) ). "\n";
384 # #warn $t_sql if $r->state eq 'FL';
387 ## calculate customer-exemption for this region
391 # my($taxable, $x_cust) = (0, 0);
392 # foreach my $e ( grep { $r->get($_.'tax') !~ /^Y/i }
393 # qw( cust_bill_pkg.setup cust_bill_pkg.recur ) ) {
394 # $taxable += scalar_sql($r, \@param,
395 # "SELECT SUM($e) $fromwhere AND $nottax AND ( tax != 'Y' OR tax IS NULL )"
398 # $x_cust += scalar_sql($r, \@param,
399 # "SELECT SUM($e) $fromwhere AND $nottax AND tax = 'Y'"
403 #false laziness -ish w/report_tax.cgi
406 my $q_taxname = dbh->quote($r->taxname);
409 OR EXISTS ( SELECT 1 FROM cust_main_exemption
410 WHERE cust_main_exemption.custnum = cust_main.custnum
411 AND cust_main_exemption.taxname = $q_taxname
416 $cust_exempt = " tax = 'Y' ";
419 my $x_cust = scalar_sql($r, \@param,
420 "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur)
421 $fromwhere AND $nottax AND $cust_exempt "
424 $regions{$label}->{'exempt_cust'} += $x_cust;
426 ## calculate package-exemption for this region
428 my $x_pkg = scalar_sql($r, \@param,
430 ( CASE WHEN part_pkg.setuptax = 'Y'
431 THEN cust_bill_pkg.setup
436 ( CASE WHEN part_pkg.recurtax = 'Y'
437 THEN cust_bill_pkg.recur
445 ( part_pkg.setuptax = 'Y' AND cust_bill_pkg.setup > 0 )
446 OR ( part_pkg.recurtax = 'Y' AND cust_bill_pkg.recur > 0 )
448 AND ( tax != 'Y' OR tax IS NULL )
451 $regions{$label}->{'exempt_pkg'} += $x_pkg;
453 ## calculate monthly exemption (texas tax) for this region
455 # count up all the cust_tax_exempt_pkg records associated with
456 # the actual line items.
458 my $x_monthly = scalar_sql($r, \@param,
460 FROM cust_tax_exempt_pkg
461 JOIN cust_bill_pkg USING ( billpkgnum )
465 $regions{$label}->{'exempt_monthly'} += $x_monthly;
467 my $taxable = $t - $x_cust - $x_pkg - $x_monthly;
468 $regions{$label}->{'taxable'} += $taxable;
470 $regions{$label}->{'owed'} += $taxable * ($r->tax/100);
472 if ( defined($regions{$label}->{'rate'})
473 && $regions{$label}->{'rate'} != $r->tax.'%' ) {
474 $regions{$label}->{'rate'} = 'variable';
476 $regions{$label}->{'rate'} = $r->tax.'%';
481 my $distinct = "country, state, county, city,
482 CASE WHEN taxname IS NULL THEN '' ELSE taxname END AS taxname";
483 my $taxclass_distinct =
484 #a little bit unsure of this part... test?
485 #ah, it looks like it winds up being irrelevant as ->{'tax'}
486 # from $regions is not displayed when show_taxclasses is on
487 ( $cgi->param('show_taxclasses')
488 ? " CASE WHEN taxclass IS NULL THEN '' ELSE taxclass END "
494 'select' => "DISTINCT $distinct, $taxclass_distinct",
495 'table' => 'cust_main_county',
497 'extra_sql' => $gotcust,
500 my $taxfromwhere = " FROM cust_bill_pkg $join_cust ";
501 my $taxwhere = $where;
502 if ( $conf->exists('tax-pkg_address') ) {
504 $taxfromwhere .= 'LEFT JOIN cust_bill_pkg_tax_location USING ( billpkgnum )
505 LEFT JOIN cust_location USING ( locationnum ) ';
508 $taxwhere =~ s/cust_pkg\.locationnum/cust_bill_pkg_tax_location.locationnum/g;
511 my $creditfromwhere = $taxfromwhere.
512 " JOIN cust_credit_bill_pkg USING (billpkgnum";
513 $creditfromwhere .= " ,billpkgtaxlocationnum"
514 if $conf->exists('tax-pkg_address');
515 $creditfromwhere .= ")";
517 $taxfromwhere .= " $taxwhere "; #AND payby != 'COMP' ";
518 $creditfromwhere .= " $taxwhere AND billpkgtaxratelocationnum IS NULL"; #AND payby != 'COMP' ";
520 my @taxparam = @base_param;
523 #should i be a cust_main_county method or something
524 #need to pass in $taxfromwhere & @taxparam???
525 my $_taxamount_sub = sub {
528 #match itemdesc if necessary!
531 ? 'AND itemdesc = '. dbh->quote($r->taxname)
532 : "AND ( itemdesc IS NULL OR itemdesc = '' OR itemdesc = 'Tax' )";
534 my $sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) ".
535 " $taxfromwhere AND cust_bill_pkg.pkgnum = 0 $named_tax";
537 scalar_sql($r, \@taxparam, $sql );
540 my $_creditamount_sub = sub {
543 #match itemdesc if necessary!
546 ? 'AND itemdesc = '. dbh->quote($r->taxname)
547 : "AND ( itemdesc IS NULL OR itemdesc = '' OR itemdesc = 'Tax' )";
549 my $sql = "SELECT SUM(cust_credit_bill_pkg.amount) ".
550 " $creditfromwhere AND cust_bill_pkg.pkgnum = 0 $named_tax";
552 scalar_sql($r, \@taxparam, $sql );
555 #tax-report_groups filtering
556 my($group_op, $group_value) = ( '', '' );
557 if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ ) {
558 ( $group_op, $group_value ) = ( $1, $2 );
560 my $group_test = sub {
562 return 1 unless $group_op; #in case we get called inadvertantly
563 if ( $label eq $out ) { #don't display "out of taxable region" in this case
565 } elsif ( $group_op eq '=' ) {
566 $label =~ /^$group_value/;
567 } elsif ( $group_op eq '!=' ) {
568 $label !~ /^$group_value/;
570 die "guru meditation #00de: group_op $group_op\n";
576 #foreach my $label ( keys %regions ) {
577 foreach my $r ( qsearch(\%qsearch) ) {
579 #warn join('-', map { $r->$_() } qw( country state county taxname ) )."\n";
581 my $label = getlabel($r);
583 next unless &{$group_test}($label);
586 #my $fromwhere = $join_pkg. $where. " AND payby != 'COMP' ";
587 #my @param = @base_param;
589 my $x = &{$_taxamount_sub}($r);
591 $regions{$label}->{'tax'} += $x;
592 $tot_tax += $x unless $cgi->param('show_taxclasses');
594 ## calculate credit for this region
596 $x = &{$_creditamount_sub}($r);
598 $regions{$label}->{'credit'} += $x;
599 $tot_credit += $x unless $cgi->param('show_taxclasses');
603 my %base_regions = ();
604 if ( $cgi->param('show_taxclasses') ) {
606 $qsearch{'select'} = "DISTINCT $distinct";
607 foreach my $r ( qsearch(\%qsearch) ) {
609 my $x = &{$_taxamount_sub}($r);
611 my $base_label = getlabel($r, 'no_taxclass'=>1 );
612 $base_regions{$base_label}->{'label'} = $base_label;
614 $base_regions{$base_label}->{'url_param'} =
615 join(';', map "$_=". uri_escape($r->$_()),
616 qw( county state country taxname )
619 $base_regions{$base_label}->{'tax'} += $x;
622 ## calculate credit for this region
624 $x = &{$_creditamount_sub}($r);
626 $base_regions{$base_label}->{'credit'} += $x;
633 my @regions = keys %regions;
635 #tax-report_groups filtering
636 @regions = grep &{$group_test}($_), @regions
640 my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 );
641 my( $exempt_cust, $exempt_pkg, $exempt_monthly, $tot_credit ) = ( 0, 0, 0, 0 );
647 $total += $regions{$_}->{'total'};
648 $tot_taxable += $regions{$_}->{'taxable'};
649 $tot_owed += $regions{$_}->{'owed'};
650 $exempt_cust += $regions{$_}->{'exempt_cust'};
651 $exempt_pkg += $regions{$_}->{'exempt_pkg'};
652 $exempt_monthly += $regions{$_}->{'exempt_monthly'};
653 $tot_credit += $regions{$_}->{'credit'};
654 $taxclasses{$regions{$_}->{'taxclass'}} = 1
655 if $regions{$_}->{'taxclass'};
656 $county{$regions{$_}->{'county'}} = 1;
657 $state{$regions{$_}->{'state'}} = 1;
658 $country{$regions{$_}->{'country'}} = 1;
661 my $total_url_param = '';
662 my $total_url_param_invoiced = '';
665 my @country = keys %country;
666 warn "WARNING: multiple countries on this grouped report; total links broken"
667 if scalar(@country) > 1;
668 my $country = $country[0];
670 my @state = keys %state;
671 warn "WARNING: multiple countries on this grouped report; total links broken"
672 if scalar(@state) > 1;
673 my $state = $state[0];
675 $total_url_param_invoiced =
677 'report_group='.uri_escape("$group_op $group_value").';'.
678 join(';', map 'taxclass='.uri_escape($_), keys %taxclasses );
679 $total_url_param .= ';'.
680 "country=$country;state=".uri_escape($state).';'.
681 join(';', map 'county='.uri_escape($_), keys %county ) ;
688 sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) }
692 map $base_regions{$_},
693 sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) }
699 'url_param' => $total_url_param,
700 'url_param_inv' => $total_url_param_invoiced,
702 'exempt_cust' => $exempt_cust,
703 'exempt_pkg' => $exempt_pkg,
704 'exempt_monthly' => $exempt_monthly,
705 'taxable' => $tot_taxable,
709 'credit' => $tot_credit,
714 my $money_char = $conf->config('money_char') || '$';
715 my $money_sprintf = sub {
716 $money_char. sprintf('%.2f', shift );
726 && ! scalar( qsearch('cust_main_county', { 'city' => $r->city,
727 'county' => $r->county,
728 'state' => $r->state,
729 'country' => $r->country,
730 'tax' => { op=>'>', value=>0 },
736 #kludge to avoid "will not stay shared" warning
737 my $out = 'Out of taxable region(s)';
739 # } elsif ( $r->taxname && count_taxname($r->taxname) == 1 ) {
740 # $label = $r->taxname;
741 ## $regions{$label}->{'taxname'} = $label;
742 ## push @{$regions{$label}->{$_}}, $r->$_() foreach qw( county state country );
744 $label = $r->country;
745 $label = $r->state.", $label" if $r->state;
746 $label = $r->county." county, $label" if $r->county;
747 $label = $r->city. ", $label" if $r->city && $cgi->param('show_cities');
748 $label = "$label (". $r->taxclass. ")"
750 && $cgi->param('show_taxclasses')
751 && ! $opt{'no_taxclass'};
752 $label = $r->taxname. " ($label)" if $r->taxname;
757 #my %count_taxname = (); #cache
759 # my $taxname = shift;
760 # return $count_taxname{$taxname} if exists $count_taxname{$taxname};
761 # my $sql = 'SELECT COUNT(*) FROM cust_main_county WHERE taxname = ?';
762 # my $sth = dbh->prepare($sql) or die dbh->errstr;
763 # $sth->execute( $taxname )
764 # or die "Unexpected error executing statement $sql: ". $sth->errstr;
765 # $count_taxname{$taxname} = $sth->fetchrow_arrayref->[0];
768 #false laziness w/FS::Report::Table::Monthly (sub should probably be moved up
769 #to FS::Report or FS::Record or who the fuck knows where)
771 my( $r, $param, $sql ) = @_;
773 my $sth = dbh->prepare($sql) or die dbh->errstr;
774 $sth->execute( map $r->$_(), @$param )
775 or die "Unexpected error executing statement $sql: ". $sth->errstr;
776 $sth->fetchrow_arrayref->[0] || 0;
779 my $dateagentlink = "begin=$beginning;end=$ending";
780 $dateagentlink .= ';agentnum='. $cgi->param('agentnum')
781 if length($agentname);
782 my $baselink = $p. "search/cust_bill_pkg.cgi?$dateagentlink";
783 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
784 my $creditlink = $p. "search/cust_credit_bill_pkg.html?$dateagentlink";