5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/includes/ui.inc");
9 include_once($path_to_root . "/includes/data_checks.inc");
11 include_once($path_to_root . "/admin/db/voiding_db.inc");
14 $js .= get_js_date_picker();
15 if ($use_popup_windows)
16 $js .= get_js_open_window(800, 500);
18 page(_("Void a Transaction"), false, false, "", $js);
20 //----------------------------------------------------------------------------------------
21 function exist_transaction($type, $type_no)
23 $void_entry = get_voided_entry($type, $type_no);
25 if ($void_entry != null)
30 case 0 : // it's a journal entry
31 if (!exists_gl_trans($type, $type_no))
35 case 1 : // it's a payment
36 case 2 : // it's a deposit
37 case 4 : // it's a transfer
38 if (!exists_bank_trans($type, $type_no))
42 case 10 : // it's a customer invoice
43 case 11 : // it's a customer credit note
44 case 12 : // it's a customer payment
45 case 13 : // it's a customer dispatch
46 if (!exists_customer_trans($type, $type_no))
50 case systypes::location_transfer() : // it's a stock transfer
51 if (get_stock_transfer_items($type_no) == null)
55 case systypes::inventory_adjustment() : // it's a stock adjustment
56 if (get_stock_adjustment_items($type_no) == null)
60 case 25 : // it's a GRN
62 case 20 : // it's a suppler invoice
63 case 21 : // it's a supplier credit note
64 case 22 : // it's a supplier payment
65 if (!exists_supp_trans($type, $type_no))
69 case systypes::work_order() : // it's a work order
70 if (!get_work_order($type_no, true))
74 case 28 : // it's a work order issue
75 if (!exists_work_order_issue($type_no))
79 case 29 : // it's a work order production
80 if (!exists_work_order_produce($type_no))
84 case systypes::cost_update() : // it's a stock cost update
92 function voiding_controls()
96 start_form(false, true);
98 start_table($table_style2);
100 systypes_list_row(_("Transaction Type:"), "filterType", null, true);
102 text_row(_("Transaction #:"), 'trans_no', null, 12, 12);
104 date_row(_("Voiding Date:"), 'date_');
106 textarea_row(_("Memo:"), 'memo_', null, 30, 4);
110 if (!isset($_POST['ProcessVoiding']))
111 submit_center('ProcessVoiding', _("Void Transaction"), true, '', true);
114 if (!exist_transaction($_POST['filterType'],$_POST['trans_no']))
116 display_error(_("The entered transaction does not exist or cannot be voided."));
117 unset($_POST['trans_no']);
118 unset($_POST['memo_']);
119 unset($_POST['date_']);
120 submit_center('ProcessVoiding', _("Void Transaction"), true, '', true);
124 display_notification_centered(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
125 if ($_POST['filterType'] == 0) // GL transaction are not included in get_trans_view_str
126 $view_str = get_gl_view_str($_POST['filterType'],$_POST['trans_no'], _("View Transaction"));
128 $view_str = get_trans_view_str($_POST['filterType'],$_POST['trans_no'], _("View Transaction"));
129 display_note($view_str);
131 submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
132 submit_center_last('CancelVoiding', _("Cancel"), '', true);
139 //----------------------------------------------------------------------------------------
141 function check_valid_entries()
143 if (!is_date($_POST['date_']))
145 display_error(_("The entered date is invalid."));
149 if (!is_date_in_fiscalyear($_POST['date_']))
151 display_error(_("The entered date is not in fiscal year."));
156 if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
158 display_error(_("The transaction number is expected to be numeric and greater than zero."));
159 set_focus('trans_no');
166 //----------------------------------------------------------------------------------------
168 function handle_void_transaction()
170 if (check_valid_entries()==true)
173 $void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
174 if ($void_entry != null)
176 display_error(_("The selected transaction has already been voided."), true);
177 unset($_POST['trans_no']);
178 unset($_POST['memo_']);
179 unset($_POST['date_']);
180 set_focus('trans_no');
184 $ret = void_transaction($_POST['filterType'], $_POST['trans_no'],
185 $_POST['date_'], $_POST['memo_']);
189 display_notification_centered(_("Selected transaction has been voided."));
190 unset($_POST['trans_no']);
191 unset($_POST['memo_']);
192 unset($_POST['date_']);
195 display_error(_("The entered transaction does not exist or cannot be voided."));
196 set_focus('trans_no');
202 //----------------------------------------------------------------------------------------
204 if (!isset($_POST['date_']))
206 $_POST['date_'] = Today();
207 if (!is_date_in_fiscalyear($_POST['date_']))
208 $_POST['date_'] = end_fiscalyear();
211 if (isset($_POST['ProcessVoiding']))
213 if (!check_valid_entries())
214 unset($_POST['ProcessVoiding']);
215 $Ajax->activate('_page_body');
218 if (isset($_POST['ConfirmVoiding']))
220 handle_void_transaction();
221 $Ajax->activate('_page_body');
224 if (isset($_POST['CancelVoiding']))
226 $Ajax->activate('_page_body');
229 //----------------------------------------------------------------------------------------