[freeside-commits] freeside/httemplate/search report_tax.cgi, 1.44, 1.45

Ivan,,, ivan at wavetail.420.am
Sun Nov 2 11:26:52 PST 2008


Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory wavetail.420.am:/tmp/cvs-serv14747

Modified Files:
	report_tax.cgi 
Log Message:
fix overreporting of tax invoiced when using & reporting with taxclasses, RT#4131

Index: report_tax.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/report_tax.cgi,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- report_tax.cgi	16 Sep 2008 15:58:33 -0000	1.44
+++ report_tax.cgi	2 Nov 2008 19:26:49 -0000	1.45
@@ -292,7 +292,11 @@
 my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 );
 my $out = 'Out of taxable region(s)';
 my %regions = ();
-foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) {
+foreach my $r ( qsearch({ 'table'     => 'cust_main_county',
+                          'extra_sql' => $gotcust,
+                       })
+              )
+{
   #warn $r->county. ' '. $r->state. ' '. $r->country. "\n";
 
   my $label = getlabel($r);
@@ -423,37 +427,31 @@
 
 }
 
-my $taxwhere = "$from_join_cust $where AND payby != 'COMP' ";
-my @taxparam = @base_param;
-my %base_regions = ();
-#foreach my $label ( keys %regions ) {
-foreach my $r (
-  qsearch( 'cust_main_county',
-           {},
-           "DISTINCT
-              country,
-              state,
-              county,
-              CASE WHEN taxname IS NULL THEN '' ELSE taxname END AS taxname,".
-
-	      #a little bit unsure of this part... test?
-	      #ah, it looks like it winds up being irrelevant as ->{'tax'} 
-	      # from $regions is not displayed when show_taxclasses is on
-	      ( $cgi->param('show_taxclasses')
-                  ? " CASE WHEN taxclass IS NULL THEN '' ELSE taxclass END "
-                  : " '' "
-       	      )." AS taxclass"
-           ,
-           $gotcust
-         )
-) {
+my $distinct = "country, state, county,
+                CASE WHEN taxname IS NULL THEN '' ELSE taxname END AS taxname";
+my $taxclass_distinct = 
+  #a little bit unsure of this part... test?
+  #ah, it looks like it winds up being irrelevant as ->{'tax'} 
+  # from $regions is not displayed when show_taxclasses is on
+  ( $cgi->param('show_taxclasses')
+      ? " CASE WHEN taxclass IS NULL THEN '' ELSE taxclass END "
+      : " '' "
+  )." AS taxclass";
 
-  #warn join('-', map { $r->$_() } qw( country state county taxname ) )."\n";
+my %qsearch = (
+  'select'    => "DISTINCT $distinct, $taxclass_distinct",
+  'table'     => 'cust_main_county',
+  'hashref'   => {},
+  'extra_sql' => $gotcust,
+);
 
-  my $label = getlabel($r);
+my $taxwhere = "$from_join_cust $where AND payby != 'COMP' ";
+my @taxparam = @base_param;
 
-  #my $fromwhere = $join_pkg. $where. " AND payby != 'COMP' ";
-  #my @param = @base_param; 
+#should i be a cust_main_county method or something
+#need to pass in $taxwhere & @taxparam???
+my $_taxamount_sub = sub {
+  my $r = shift;
 
   #match itemdesc if necessary!
   my $named_tax =
@@ -464,11 +462,34 @@
   my $sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) ".
             " $taxwhere AND pkgnum = 0 $named_tax";
 
-  my $x = scalar_sql($r, \@taxparam, $sql );
+  scalar_sql($r, \@taxparam, $sql );
+};
+
+#foreach my $label ( keys %regions ) {
+foreach my $r ( qsearch(\%qsearch) ) {
+
+  #warn join('-', map { $r->$_() } qw( country state county taxname ) )."\n";
+
+  my $label = getlabel($r);
+
+  #my $fromwhere = $join_pkg. $where. " AND payby != 'COMP' ";
+  #my @param = @base_param; 
+
+  my $x = &{$_taxamount_sub}($r);
+
   $tax += $x;
   $regions{$label}->{'tax'} += $x;
 
-  if ( $cgi->param('show_taxclasses') ) {
+}
+
+my %base_regions = ();
+if ( $cgi->param('show_taxclasses') ) {
+
+  $qsearch{'select'} = "DISTINCT $distinct";
+  foreach my $r ( qsearch(\%qsearch) ) {
+
+    my $x = &{$_taxamount_sub}($r);
+
     my $base_label = getlabel($r, 'no_taxclass'=>1 );
     $base_regions{$base_label}->{'label'} = $base_label;
     $base_regions{$base_label}->{'url_param'} =
@@ -478,6 +499,7 @@
 
 }
 
+
 #ordering
 my @regions =
   map $regions{$_},



More information about the freeside-commits mailing list