$ /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
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;
}
//-----------------------------------------------------------------------------