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

SF.net SVN: ledger-smb:[4243] branches/1.3/LedgerSMB/AM.pm



Revision: 4243
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4243&view=rev
Author:   einhverfr
Date:     2011-12-27 13:11:30 +0000 (Tue, 27 Dec 2011)
Log Message:
-----------
Fixing forex account setting (fxgain_accno_id, fxloss_accno_id) not saving on defaults screen

Modified Paths:
--------------
    branches/1.3/LedgerSMB/AM.pm

Modified: branches/1.3/LedgerSMB/AM.pm
===================================================================
--- branches/1.3/LedgerSMB/AM.pm	2011-12-26 16:05:27 UTC (rev 4242)
+++ branches/1.3/LedgerSMB/AM.pm	2011-12-27 13:11:30 UTC (rev 4243)
@@ -1678,7 +1678,7 @@
     # save defaults
 #    $sth_plain = $dbh->prepare( "
 #		UPDATE defaults SET value = ? WHERE setting_key = ?" );
-    $sth_accno = $dbh->prepare(
+    my $sth_accno = $dbh->prepare(
         qq|
 		UPDATE defaults
                    SET value = (SELECT id
@@ -1686,6 +1686,14 @@
                                               WHERE accno = ?)
 		 WHERE setting_key = ?|
     );
+    my $sth_insert_accno = $dbh->prepare(
+       " INSERT INTO defaults (setting_key, value)
+         SELECT ?, id
+           FROM account 
+          WHERE accno = ? AND 1 NOT IN (SELECT 1 FROM defaults
+                                           WHERE setting_key = ?)"
+    );
+             
     if (..hidden..){
        $defaults = qw(inventory_accno_id income_accno_id expense_accno_id
                       fxgain_accno_id fxloss_accno_id glnumber sinumber vinumber
@@ -1703,21 +1711,19 @@
         if ( $_ =~ /accno/ ) {
             $sth_accno->execute( $val, $_ )
               || $form->dberror("Saving $_");
+            $sth_insert_accno->execute($_, $val, $_);
         }
         else {
-				    my $found=0;
-				    my $sth_defcheck=$dbh->prepare("select count(*) from defaults where setting_key='$_';") || $form->dberror("Select defaults $_");
-				    $sth_defcheck->execute() || $form->dberror("execute defaults $_");
-			            while(my $found1=$sth_defcheck->fetchrow()){$found=$found1;}
-				    
-				  if($found)
-				  {
-					$dbh->do("update defaults set value=" . $dbh->quote($val) . " where setting_key='$_';");
-				  }
-				  else
-				  {
-					$dbh->do("insert into defaults(value,setting_key) values( " . $dbh->quote($val) . ",'$_');"); 
-				  }
+	    my $found=0;
+	    my $sth_defcheck=$dbh->prepare("select count(*) from defaults where setting_key='$_';") || $form->dberror("Select defaults $_");
+	    $sth_defcheck->execute() || $form->dberror("execute defaults $_");
+            while(my $found1=$sth_defcheck->fetchrow()){$found=$found1;}
+		    
+  	      if($found) {
+		  $dbh->do("update defaults set value=" . $dbh->quote($val) . " where setting_key='$_';");
+	       } else {
+	          $dbh->do("insert into defaults(value,setting_key) values( " . $dbh->quote($val) . ",'$_');"); 
+	       }
 
         }
 

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