3 include_once($path_to_root . "/sales/includes/sales_db.inc");
4 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
5 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
6 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
8 function void_transaction($type, $type_no, $date_, $memo_)
10 $void_entry = get_voided_entry($type, $type_no);
12 if ($void_entry != null)
16 case 0 : // it's a journal entry
17 if (!exists_gl_trans($type, $type_no))
19 void_gl_trans($type, $type_no);
20 if (exists_bank_trans($type, $type_no))
21 void_bank_trans($type, $type_no);
24 case 1 : // it's a payment
25 case 2 : // it's a deposit
26 case 4 : // it's a transfer
27 if (!exists_bank_trans($type, $type_no))
29 void_bank_trans($type, $type_no);
32 case 10 : // it's a customer invoice
33 case 11 : // it's a customer credit note
34 case 12 : // it's a customer payment
35 case 13 : // it's a customer dispatch
36 if (!exists_customer_trans($type, $type_no))
38 if ($type == 13) // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
40 $delivery = get_customer_trans($type_no, $type);
41 if ($delivery['trans_link'] != 0)
43 $inv = get_customer_trans($delivery['trans_link'], 10);
44 if ($inv['ov_amount'] != 0 || $inv['ov_discount'] != 0 || $inv['ov_gst'] != 0 ||
45 $inv['ov_freight'] != 0 || $inv['ov_freight_tax'] != 0 || $inv['alloc'] != 0)
49 post_void_customer_trans($type, $type_no);
52 case systypes::location_transfer() : // it's a stock transfer
53 if (get_stock_transfer_items($type_no) == null)
55 void_stock_transfer($type_no);
58 case systypes::inventory_adjustment() : // it's a stock adjustment
59 if (get_stock_adjustment_items($type_no) == null)
61 void_stock_adjustment($type_no);
64 case 25 : // it's a GRN
66 case 20 : // it's a suppler invoice
67 case 21 : // it's a supplier credit note
68 case 22 : // it's a supplier payment
69 if (!exists_supp_trans($type, $type_no))
71 if (!post_void_supp_trans($type, $type_no))
75 case systypes::work_order() : // it's a work order
76 if (!get_work_order($type_no, true))
78 void_work_order($type_no);
81 case 28 : // it's a work order issue
82 if (!exists_work_order_issue($type_no))
84 void_work_order_issue($type_no);
87 case 29 : // it's a work order production
88 if (!exists_work_order_produce($type_no))
90 void_work_order_produce($type_no);
93 case systypes::cost_update() : // it's a stock cost update
98 // only add an entry if it's actually been voided
99 add_voided_entry($type, $type_no, $date_, $memo_);
104 //--------------------------------------------------------------------------------------------------
106 function get_voided_entry($type, $type_no)
108 $sql = "SELECT * FROM ".TB_PREF."voided WHERE type=$type AND id=$type_no";
110 $result = db_query($sql, "could not query voided transaction table");
112 return db_fetch($result);
115 //--------------------------------------------------------------------------------------------------
117 function add_voided_entry($type, $type_no, $date_, $memo_)
119 $date = date2sql($date_);
120 $sql = "INSERT INTO ".TB_PREF."voided (type, id, date_, memo_)
121 VALUES ($type, $type_no, ".db_escape($date).", ".db_escape($memo_).")";
123 db_query($sql, "could not add voided transaction entry");
126 //--------------------------------------------------------------------------------------------------