freeside/httemplate/search report_tax.cgi,1.5.4.16,1.5.4.17

ivan ivan at pouncequick.420.am
Tue Nov 9 03:00:12 PST 2004


Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory pouncequick:/tmp/cvs-serv30340

Modified Files:
      Tag: FREESIDE_1_4_BRANCH
	report_tax.cgi 
Log Message:
add handling for texas tax exemption and warning that report might not make sense for partial months other than the current one

Index: report_tax.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/report_tax.cgi,v
retrieving revision 1.5.4.16
retrieving revision 1.5.4.17
diff -u -d -r1.5.4.16 -r1.5.4.17
--- report_tax.cgi	9 Nov 2004 09:31:10 -0000	1.5.4.16
+++ report_tax.cgi	9 Nov 2004 11:00:09 -0000	1.5.4.17
@@ -42,6 +42,7 @@
             )
 ";
 
+my $monthly_exempt_warning = 0;
 my($total, $exempt, $taxable, $owed, $tax) = ( 0, 0, 0, 0, 0 );
 my $out = 'Out of taxable region(s)';
 my %regions;
@@ -81,16 +82,37 @@
     my $t = scalar_sql($r, \@param, 
       "SELECT SUM($e) $fromwhere AND $nottax AND ( tax != 'Y' OR tax IS NULL )"
     );
-    $taxable += $t;
-    $regions{$label}->{'taxable'} += $t;
-    $owed += $t * ($r->tax/100);
-    $regions{$label}->{'owed'} += $t * ($r->tax/100);
 
     my $x = scalar_sql($r, \@param, 
       "SELECT SUM($e) $fromwhere AND $nottax AND tax = 'Y'"
     );
+
+    my($sday,$smon,$syear) = (localtime($beginning) )[ 3, 4, 5 ];
+    $monthly_exempt_warning=1 if $sday != 1 && $beginning;
+    $smon++; $syear+=1900;
+
+    my($eday,$emon,$eyear) = (localtime($ending) )[ 3, 4, 5 ];
+    $emon++; $eyear+=1900;
+
+    my $monthly_exemption = scalar_sql($r, [ 'taxnum' ],
+      "SELECT SUM(amount) FROM cust_tax_exempt where taxnum = ? ".
+      "  AND ( year > $syear OR ( year = $syear and month >= $smon ) )".
+      "  AND ( year < $eyear OR ( year = $eyear and month <= $emon ) )"
+    );
+    if ( $monthly_exemption ) {
+      $t -= $monthly_exemption;
+      $x += $monthly_exemption;
+    }
+
+    $taxable += $t;
+    $regions{$label}->{'taxable'} += $t;
+
     $exempt += $x;
     $regions{$label}->{'exempt'} += $x;
+
+    $owed += $t * ($r->tax/100);
+    $regions{$label}->{'owed'} += $t * ($r->tax/100);
+
   }
 
   if ( defined($regions{$label}->{'rate'})
@@ -213,6 +235,14 @@
   <% } %>
 
 </TABLE>
+
+<% if ( $monthly_exempt_warning ) { %>
+  <BR>
+  Partial-month tax reports (except for current month) may not be correct due
+  to month-granularity tax exemption (usually "texas tax").  For an accurate
+  report, start on the first of a month and end on the last day of a month (or
+  leave blank for to now).
+<% } %>
 
 </BODY>
 </HTML>




More information about the freeside-commits mailing list