Next transaction number retrieved from transaction table instead of sys_types
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 1 Dec 2009 20:24:34 +0000 (20:24 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 1 Dec 2009 20:24:34 +0000 (20:24 +0000)
CHANGELOG.txt
includes/systypes.inc

index d37b92344a8b0d6752aa384ec0c62466447f9f4e..2ae28b34fb8707ee23617b784725e2a3c64cda02 100644 (file)
@@ -31,6 +31,9 @@ $ config.default.php
 $ /install/save.php
 ! Display sql in case of duplicate data error when go_debug=1.
 $ /includes/errors.inc
+! Next transaction numbers retrieved from transaction table instead of sys_types
+$ /includes/systypes.inc
+
 
 29-Nov-2009 Janusz Dobrowolski
 # Fixed change of language in display preferences. Removed sparse $_SESSION['languages'] variable
index 9f93fd541aeb4afbc38c05c0a0f782a6cb2ac452..4589e76bca9f622ab8e6ccd466c2efbe570cfbf5 100644 (file)
@@ -9,26 +9,29 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-Function get_next_trans_no ($trans_type){
 
-    // sql to get the next display transaction number
-       //these are maintained in the table sys_types
-    // Also updates the transaction number
+//-----------------------------------------------------------------------------------------
+//     Returns next transaction number.
+//     Used only for transactions stored in tables without autoincremented key.
+//
+function get_next_trans_no ($trans_type){
 
-    $sql = "SELECT type_no FROM ".TB_PREF."sys_types WHERE type_id = " . $trans_type;
+       $st = get_systype_db_info($trans_type);
 
-    $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
-
-    $myrow = db_fetch_row($result);
-
-    $next_number = $myrow[0] + 1;
+       if (!($st && $st[0] && $st[2])) {
+               // this is in fact internal error condition.
+               display_error('Internal error: invalid type passed to get_next_trans_no()');
+               return 0;
+       }
+       $sql = "SELECT MAX(`$st[2]`) FROM $st[0]";
 
-    $sql = "UPDATE ".TB_PREF."sys_types SET type_no = $next_number WHERE type_id = $trans_type
-       AND type_no = ". $myrow[0]; //concurrency paranoic protection
+       if ($st[1] != null)
+                $sql .= " WHERE `$st[1]`=$trans_type";
 
-    db_query($sql,"The next transaction number for $trans_type could not be updated");
+    $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
+    $myrow = db_fetch_row($result);
 
-    return $next_number;
+    return $myrow[0] + 1;
 }
 
 //-----------------------------------------------------------------------------