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

SF.net SVN: ledger-smb:[3318] trunk



Revision: 3318
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3318&view=rev
Author:   einhverfr
Date:     2011-06-24 01:12:45 +0000 (Fri, 24 Jun 2011)

Log Message:
-----------
Tax save problems solved, confirmed working

Modified Paths:
--------------
    trunk/LedgerSMB/AM.pm
    trunk/bin/am.pl
    trunk/sql/modules/Account.sql

Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm	2011-06-23 23:26:49 UTC (rev 3317)
+++ trunk/LedgerSMB/AM.pm	2011-06-24 01:12:45 UTC (rev 3318)
@@ -1904,32 +1904,25 @@
     # connect to database
     my $dbh = $form->{dbh};
 
-    my $query = qq|
-		UPDATE tax 
-		   SET validto = (now())::date 
-		 WHERE chart_id = ?|;
-    my $update_sth = $dbh->prepare($query) || $form->dberror($query);
-
-    $query = qq|
-		INSERT INTO tax (chart_id, rate, taxnumber, validto, 
-			pass, taxmodule_id)
-			VALUES (?, ?, ?, ?, ?, ?)|;
-
-    my $sth = $dbh->prepare($query);
     foreach my $item ( split / /, $form->{taxaccounts} ) {
         my ( $chart_id, $i ) = split /_/, $item;
         my $rate =
           $form->parse_amount( $myconfig, $form->{"taxrate_$i"} ) / 100;
         my $validto = $form->{"validto_$i"};
-        $validto = undef if not $validto;
-        
+        $validto = 'infinity' if not $validto;
+        $form->{"pass_$i"} = 0 if not $form->{"pass_$i"};
+        delete $form->{"old_validto_$i"} if ! $form->{"old_validto_$i"};
+
+        $sth = $dbh->prepare('select account__save_tax(?,?,?,?,?,?,?)');         
         my @queryargs = (
-            $chart_id, $rate, $form->{"taxnumber_$i"}, $validto,
-            $form->{"pass_$i"}, $form->{"taxmodule_id_$i"}
+            $chart_id, $validto, $rate, $form->{"taxnumber_$i"},
+            $form->{"pass_$i"}, $form->{"taxmodule_id_$i"},
+            $form->{"old_validto_$i"}
         );
+       $sth->execute(@queryargs) ||$form->dberror($query);
 
-        $update_sth->execute($chart_id) || $form->dberror($query);
-        $sth->execute(@queryargs) || $form->dberror($query);
+        
+
     }
 
     my $rc = $dbh->commit;

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2011-06-23 23:26:49 UTC (rev 3317)
+++ trunk/bin/am.pl	2011-06-24 01:12:45 UTC (rev 3318)
@@ -1485,6 +1485,7 @@
         for (qw(taxnumber validto pass taxmodulename)) {
             $form->{"${_}_$i"} = $ref->{$_};
         }
+        $form->{"old_validto_$i"} = $ref->{validto};
         $form->{taxaccounts} .= "$ref->{id}_$i ";
     }
     chop $form->{taxaccounts};
@@ -1512,6 +1513,7 @@
           $form->format_amount( \%myconfig, $form->{"taxrate_$i"} );
 
         $hiddens{"taxdescription_$i"} = $form->{"taxdescription_$i"};
+        $hiddens{"old_validto_$i"} = $form->{"old_validto_$i"};
 
         my %select = (name => "taxmodule_id_$i", options => []);
         foreach my $taxmodule ( sort keys %$form ) {
@@ -1563,6 +1565,7 @@
 
     @a = split / /, $form->{taxaccounts};
     $ndx = $#a + 1;
+    AM->taxes( \%myconfig, \%$form );
 
     foreach $item (@a) {
         ( $accno, $i ) = split /_/, $item;

Modified: trunk/sql/modules/Account.sql
===================================================================
--- trunk/sql/modules/Account.sql	2011-06-23 23:26:49 UTC (rev 3317)
+++ trunk/sql/modules/Account.sql	2011-06-24 01:12:45 UTC (rev 3318)
@@ -185,3 +185,30 @@
 $$
     SELECT * FROM account_link_description;
 $$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION account__save_tax
+(in_chart_id int, in_validto date, in_rate numeric, in_taxnumber text, 
+in_pass int, in_taxmodule_id int, in_old_validto date)
+returns bool as
+$$
+BEGIN
+	UPDATE tax SET validto = in_validto,
+               rate = in_rate,
+               taxnumber = in_taxnumber,
+               pass = in_pass,
+               taxmodule_id = in_taxmodule_id
+         WHERE chart_id = in_chart_id and validto = in_old_validto;
+
+         IF FOUND THEN
+             return true;
+         END IF;
+
+         INSERT INTO tax(chart_id, validto, rate, taxnumber, pass, taxmodule_id)
+         VALUES (in_chart_id, in_validto, in_rate, in_taxnumber, in_pass,
+                 in_taxmodule_id);
+
+         RETURN TRUE;
+
+END;
+$$ language plpgsql;
+     


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.