[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Crappy work-around for tax accounts with expiration



If you have tax accounts that expired at a specific date, only the first one 
(often the expired one) will be used when calculating out an invoice, or 
similar... For example, if you had a tax table like this:

10019	0.07	862865185	2006-06-30	0	1
10019	0.06	862865185	\N	0	1

The 7 percent rate will always be used.  (Now I realize that in theory this 
kind of tax table would never work with 1.2.x because a primary key is 
required for this table, but you may have disabled this, for legacy reasons.  
So here is a patch that works for me, but the code is really hacky and I am 
sure there must be a better way to handle this.  Patch is against 1.2.4:

I still haven't figured out what is going on where the tax account is not 
actually updated upon invoice post when using something other than the 
default chart of accounts tax item that has been discussed somewhat in 
previous posts.  Maybe I'll figure that out...

Leah
-- 
Leah Kubik : d416-585-9971x692 : d416-703-5977 : m416-559-6511
Frauerpower! Co. : www.frauerpower.com : Toronto, ON Canada
MSN: ..hidden.. | AIM: frauerpower | Yahoo: h3inous
F9B6 FEFE 080B 8299 D7EA  1270 005C EC73 47C9 B7A6
--- /usr/local/src/ledgersmb/LedgerSMB/Tax.pm   2007-04-22 04:36:42.000000000 -0400
+++ Tax.pm      2007-05-27 19:36:12.000000000 -0400
@@ -28,9 +28,11 @@
 package Tax;

 use Math::BigFloat;
+use Data::Dumper;

 sub init_taxes {
     my ( $form, $taxaccounts, $taxaccounts2 ) = @_;
+
     my $dbh = $form->{dbh};
     @taxes = ();
     my @accounts = split / /, $taxaccounts;
@@ -45,18 +47,29 @@

     }
     my $query = qq|SELECT t.taxnumber, c.description,
-                       t.rate, t.chart_id, t.pass, m.taxmodulename
+                       t.rate, t.chart_id, t.pass, t.validto, m.taxmodulename
                        FROM tax t INNER JOIN chart c ON (t.chart_id = c.id)
                        INNER JOIN taxmodule m ON (t.taxmodule_id = m.taxmodule_id)
-                       WHERE c.accno = ?|;
+                       WHERE c.accno = ? AND t.validto > ?|;
     my $sth = $dbh->prepare($query);
     foreach $taxaccount (@accounts) {
         next if ( !defined $taxaccount );
         if ( defined $taxaccounts2 ) {
             next if $taxaccount !~ /$taxaccounts2/;
         }
-        $sth->execute($taxaccount) || $form->dberror($query);
+
+        $sth->execute($taxaccount,$form->{transdate}) || $form->dberror($query);
         my $ref = $sth->fetchrow_hashref;
+        if (! $ref) {
+            $query2 = qq|SELECT t.taxnumber, c.description,
+                        t.rate, t.chart_id, t.pass, t.validto, m.taxmodulename
+                        FROM tax t INNER JOIN chart c ON (t.chart_id = c.id)
+                        INNER JOIN taxmodule m ON (t.taxmodule_id = m.taxmodule_id)
+                        WHERE c.accno = ? AND t.validto IS NULL|;
+            $sth2 = $dbh->prepare($query2);
+            $sth2->execute($taxaccount) || $form->dberror($query2);
+            $ref = $sth2->fetchrow_hashref;
+        }

         my $module = $ref->{'taxmodulename'};
         require "LedgerSMB/Taxes/${module}.pm";