From: Janusz Dobrowolski Date: Tue, 1 Dec 2009 20:24:34 +0000 (+0000) Subject: Next transaction number retrieved from transaction table instead of sys_types X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=57eee7775881536eace77ce101c6c09673ee1219;p=textcart.git Next transaction number retrieved from transaction table instead of sys_types --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d37b923..2ae28b3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/includes/systypes.inc b/includes/systypes.inc index 9f93fd5..4589e76 100644 --- a/includes/systypes.inc +++ b/includes/systypes.inc @@ -9,26 +9,29 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -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; } //-----------------------------------------------------------------------------