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 ***********************************************************************/
12 include_once($path_to_root . "/sales/includes/sales_db.inc");
13 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
14 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
15 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
17 function void_transaction($type, $type_no, $date_, $memo_)
19 $void_entry = get_voided_entry($type, $type_no);
21 if ($void_entry != null)
25 case 0 : // it's a journal entry
26 if (!exists_gl_trans($type, $type_no))
28 void_journal_trans($type, $type_no);
31 case 1 : // it's a payment
32 case 2 : // it's a deposit
33 case 4 : // it's a transfer
34 if (!exists_bank_trans($type, $type_no))
36 void_bank_trans($type, $type_no);
39 case 10 : // it's a customer invoice
40 case 11 : // it's a customer credit note
41 case 12 : // it's a customer payment
42 case 13 : // it's a customer dispatch
43 if (!exists_customer_trans($type, $type_no))
45 if ($type == 13) // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
47 $delivery = get_customer_trans($type_no, $type);
48 if ($delivery['trans_link'] != 0)
50 if (get_voided_entry(10, $delivery['trans_link']) === false)
54 post_void_customer_trans($type, $type_no);
57 case systypes::location_transfer() : // it's a stock transfer
58 if (get_stock_transfer_items($type_no) == null)
60 void_stock_transfer($type_no);
63 case systypes::inventory_adjustment() : // it's a stock adjustment
64 if (get_stock_adjustment_items($type_no) == null)
66 void_stock_adjustment($type_no);
69 case 25 : // it's a GRN
71 case 20 : // it's a suppler invoice
72 case 21 : // it's a supplier credit note
73 case 22 : // it's a supplier payment
74 if (!exists_supp_trans($type, $type_no))
76 if (!post_void_supp_trans($type, $type_no))
80 case systypes::work_order() : // it's a work order
81 if (!get_work_order($type_no, true))
83 void_work_order($type_no);
86 case 28 : // it's a work order issue
87 if (!exists_work_order_issue($type_no))
89 void_work_order_issue($type_no);
92 case 29 : // it's a work order production
93 if (!exists_work_order_produce($type_no))
95 void_work_order_produce($type_no);
98 case systypes::cost_update() : // it's a stock cost update
103 // only add an entry if it's actually been voided
104 add_voided_entry($type, $type_no, $date_, $memo_);
109 //--------------------------------------------------------------------------------------------------
111 function get_voided_entry($type, $type_no)
113 $sql = "SELECT * FROM ".TB_PREF."voided WHERE type=$type AND id=$type_no";
115 $result = db_query($sql, "could not query voided transaction table");
117 return db_fetch($result);
120 //--------------------------------------------------------------------------------------------------
122 function add_voided_entry($type, $type_no, $date_, $memo_)
124 $date = date2sql($date_);
125 $sql = "INSERT INTO ".TB_PREF."voided (type, id, date_, memo_)
126 VALUES ($type, $type_no, ".db_escape($date).", ".db_escape($memo_).")";
128 db_query($sql, "could not add voided transaction entry");
131 //--------------------------------------------------------------------------------------------------