2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 //-----------------------------------------------------------------------------------------
14 // Returns next transaction number.
15 // Used only for transactions stored in tables without autoincremented key.
18 function get_next_trans_no ($trans_type){
20 $st = get_systype_db_info($trans_type);
22 if (!($st && $st[0] && $st[2])) {
23 // this is in fact internal error condition.
24 display_error('Internal error: invalid type passed to get_next_trans_no()');
27 $sql1 = "SELECT MAX(`$st[2]`) as last_no FROM $st[0]";
29 $sql1 .= " WHERE `$st[1]`=".db_escape($trans_type);
31 // check also in voided transactions (some transactions like location transfer are removed completely)
32 $sql2 = "SELECT MAX(`id`) as last_no FROM ".TB_PREF."voided WHERE `type`=".db_escape($trans_type);
34 $sql = "SELECT max(last_no) last_no FROM ($sql1 UNION $sql2) a";
35 $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
36 $myrow = db_fetch_row($result);
41 //-----------------------------------------------------------------------------
43 function get_systype_db_info($type)
47 case ST_JOURNAL : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
48 case ST_BANKPAYMENT : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
49 case ST_BANKDEPOSIT : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
51 case ST_BANKTRANSFER : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
52 case ST_SALESINVOICE : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
53 case ST_CUSTCREDIT : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
54 case ST_CUSTPAYMENT : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
55 case ST_CUSTDELIVERY : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
56 case ST_LOCTRANSFER : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
57 case ST_INVADJUST : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
58 case ST_PURCHORDER : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "ord_date");
59 case ST_SUPPINVOICE : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
60 case ST_SUPPCREDIT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
61 case ST_SUPPAYMENT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
62 case ST_SUPPRECEIVE : return array("".TB_PREF."grn_batch", null, "id", "reference", "delivery_date");
63 case ST_WORKORDER : return array("".TB_PREF."workorders", null, "id", "wo_ref", "released_date");
64 case ST_MANUISSUE : return array("".TB_PREF."wo_issues", null, "issue_no", "reference", "issue_date");
65 case ST_MANURECEIVE : return array("".TB_PREF."wo_manufacture", null, "id", "reference", "date_");
66 case ST_SALESORDER : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
67 case 31 : return array("".TB_PREF."service_orders", null, "order_no", "cust_ref", "date");
68 case ST_SALESQUOTE : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
69 case ST_DIMENSION : return array("".TB_PREF."dimensions", null, "id", "reference", "date_");
70 case ST_COSTUPDATE : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
73 display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);
76 function get_systypes()
78 $sql = "SELECT * FROM ".TB_PREF."sys_types";
79 $result = db_query($sql, "could not query systypes table");