X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fsystypes.inc;h=c1c17a4a6f3e95b15b5e7f2fa3270bdafbb7d21e;hb=a84031edf2c09459a446d896191e27907d8cb188;hp=4589e76bca9f622ab8e6ccd466c2efbe570cfbf5;hpb=b3364aceecbf38109924c6ee1d48a28db78ad725;p=fa-stable.git diff --git a/includes/systypes.inc b/includes/systypes.inc index 4589e76b..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]`=$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); @@ -51,7 +55,7 @@ function get_systype_db_info($type) case ST_CUSTDELIVERY : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date"); case ST_LOCTRANSFER : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date"); case ST_INVADJUST : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date"); - case ST_PURCHORDER : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "tran_date"); + case ST_PURCHORDER : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "ord_date"); case ST_SUPPINVOICE : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date"); case ST_SUPPCREDIT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date"); case ST_SUPPAYMENT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date"); @@ -63,7 +67,7 @@ function get_systype_db_info($type) case 31 : return array("".TB_PREF."service_orders", null, "order_no", "cust_ref", "date"); case ST_SALESQUOTE : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date"); case ST_DIMENSION : return array("".TB_PREF."dimensions", null, "id", "reference", "date_"); - case ST_COSTUPDATE : return null; + case ST_COSTUPDATE : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date"); } display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);