From: Janusz Dobrowolski Date: Thu, 27 Jun 2013 19:06:50 +0000 (+0200) Subject: Fixed bug in get_next_trans_no() resulting in invisibility of new stock movements... X-Git-Tag: 2.3-final~229 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=74b56e0a9ff4aff5cf84e397682ee8e27db080b5;p=fa-stable.git Fixed bug in get_next_trans_no() resulting in invisibility of new stock movements entered after some transaction is voided (applies to location transfer and inventory adjustment). --- diff --git a/includes/systypes.inc b/includes/systypes.inc index 974adfdb..c1c17a4a 100644 --- a/includes/systypes.inc +++ b/includes/systypes.inc @@ -14,6 +14,7 @@ // Returns next transaction number. // Used only for transactions stored in tables without autoincremented key. // + function get_next_trans_no ($trans_type){ $st = get_systype_db_info($trans_type); @@ -23,11 +24,14 @@ function get_next_trans_no ($trans_type){ display_error('Internal error: invalid type passed to get_next_trans_no()'); return 0; } - $sql = "SELECT MAX(`$st[2]`) FROM $st[0]"; - + $sql1 = "SELECT MAX(`$st[2]`) as last_no FROM $st[0]"; if ($st[1] != null) - $sql .= " WHERE `$st[1]`=".db_escape($trans_type); + $sql1 .= " WHERE `$st[1]`=".db_escape($trans_type); + + // check also in voided transactions (some transactions like location transfer are removed completely) + $sql2 = "SELECT MAX(`id`) as last_no FROM ".TB_PREF."voided WHERE `type`=".db_escape($trans_type); + $sql = "SELECT max(last_no) last_no FROM ($sql1 UNION $sql2) a"; $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved"); $myrow = db_fetch_row($result);