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 $page_security = 'SA_VOIDTRANSACTION';
14 include($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/admin/db/transactions_db.inc");
22 include_once($path_to_root . "/admin/db/voiding_db.inc");
25 $js .= get_js_date_picker();
26 if ($use_popup_windows)
27 $js .= get_js_open_window(800, 500);
29 page(_($help_context = "Void a Transaction"), false, false, "", $js);
31 simple_page_mode(true);
32 //----------------------------------------------------------------------------------------
33 function exist_transaction($type, $type_no)
35 $void_entry = get_voided_entry($type, $type_no);
37 if ($void_entry != null)
42 case ST_JOURNAL : // it's a journal entry
43 if (!exists_gl_trans($type, $type_no))
47 case ST_BANKPAYMENT : // it's a payment
48 case ST_BANKDEPOSIT : // it's a deposit
49 case ST_BANKTRANSFER : // it's a transfer
50 if (!exists_bank_trans($type, $type_no))
54 case ST_SALESINVOICE : // it's a customer invoice
55 case ST_CUSTCREDIT : // it's a customer credit note
56 case ST_CUSTPAYMENT : // it's a customer payment
57 case ST_CUSTDELIVERY : // it's a customer dispatch
58 if (!exists_customer_trans($type, $type_no))
62 case ST_LOCTRANSFER : // it's a stock transfer
63 if (get_stock_transfer_items($type_no) == null)
67 case ST_INVADJUST : // it's a stock adjustment
68 if (get_stock_adjustment_items($type_no) == null)
72 case ST_PURCHORDER : // it's a PO
73 case ST_SUPPRECEIVE : // it's a GRN
75 case ST_SUPPINVOICE : // it's a suppler invoice
76 case ST_SUPPCREDIT : // it's a supplier credit note
77 case ST_SUPPAYMENT : // it's a supplier payment
78 if (!exists_supp_trans($type, $type_no))
82 case ST_WORKORDER : // it's a work order
83 if (!get_work_order($type_no, true))
87 case ST_MANUISSUE : // it's a work order issue
88 if (!exists_work_order_issue($type_no))
92 case ST_MANURECEIVE : // it's a work order production
93 if (!exists_work_order_produce($type_no))
97 case ST_SALESORDER: // it's a sales order
98 case ST_SALESQUOTE: // it's a sales quotation
100 case ST_COSTUPDATE : // it's a stock cost update
108 function view_link($trans)
110 if (!isset($trans['type']))
111 $trans['type'] = $_POST['filterType'];
112 return get_trans_view_str($trans["type"], $trans["trans_no"]);
115 function select_link($row)
117 if (!isset($row['type']))
118 $row['type'] = $_POST['filterType'];
119 return button('Edit'.$row["trans_no"], _("Select"), _("Select"), ICON_EDIT);
122 function gl_view($row)
124 if (!isset($row['type']))
125 $row['type'] = $_POST['filterType'];
126 return get_gl_view_str($row["type"], $row["trans_no"]);
129 function date_view($row)
131 return $row['trans_date'];
134 function ref_view($row)
139 function voiding_controls()
143 $not_implemented = array(ST_PURCHORDER, ST_SUPPRECEIVE, ST_SALESORDER,
144 ST_SALESQUOTE, ST_COSTUPDATE);
148 start_table(TABLESTYLE_NOBORDER);
151 systypes_list_cells(_("Transaction Type:"), 'filterType', null, true, $not_implemented);
152 if (list_updated('filterType'))
159 $sql = get_sql_for_view_transactions($_POST['filterType'], null, null, $trans_ref);
164 _("#") => array('insert'=>true, 'fun'=>'view_link'),
165 _("Reference") => array('fun'=>'ref_view'),
166 _("Date") => array('type'=>'date', 'fun'=>'date_view'),
167 _("GL") => array('insert'=>true, 'fun'=>'gl_view'),
168 _("Select") => array('insert'=>true, 'fun'=>'select_link')
171 $table =& new_db_pager('transactions', $sql, $cols);
172 $table->width = "40%";
173 display_db_pager($table);
175 start_table(TABLESTYLE2);
177 if ($selected_id != -1)
179 hidden('trans_no', $selected_id);
180 hidden('selected_id', $selected_id);
184 hidden('trans_no', '');
185 $_POST['memo_'] = '';
187 label_row(_("Transaction #:"), ($selected_id==-1?'':$selected_id));
189 date_row(_("Voiding Date:"), 'date_');
191 textarea_row(_("Memo:"), 'memo_', null, 30, 4);
195 if (!isset($_POST['ProcessVoiding']))
196 submit_center('ProcessVoiding', _("Void Transaction"), true, '', 'default');
199 if (!exist_transaction($_POST['filterType'],$_POST['trans_no']))
201 display_error(_("The entered transaction does not exist or cannot be voided."));
202 unset($_POST['trans_no']);
203 unset($_POST['memo_']);
204 unset($_POST['date_']);
205 submit_center('ProcessVoiding', _("Void Transaction"), true, '', 'default');
209 display_warning(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
211 submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
212 submit_center_last('CancelVoiding', _("Cancel"), '', 'cancel');
219 //----------------------------------------------------------------------------------------
221 function check_valid_entries()
223 if (is_closed_trans($_POST['filterType'],$_POST['trans_no']))
225 display_error(_("The selected transaction was closed for edition and cannot be voided."));
226 set_focus('trans_no');
229 if (!is_date($_POST['date_']))
231 display_error(_("The entered date is invalid."));
235 if (!is_date_in_fiscalyear($_POST['date_']))
237 display_error(_("The entered date is not in fiscal year."));
242 if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
244 display_error(_("The transaction number is expected to be numeric and greater than zero."));
245 set_focus('trans_no');
252 //----------------------------------------------------------------------------------------
254 function handle_void_transaction()
256 if (check_valid_entries()==true)
258 $void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
259 if ($void_entry != null)
261 display_error(_("The selected transaction has already been voided."), true);
262 unset($_POST['trans_no']);
263 unset($_POST['memo_']);
264 unset($_POST['date_']);
265 set_focus('trans_no');
269 $ret = void_transaction($_POST['filterType'], $_POST['trans_no'],
270 $_POST['date_'], $_POST['memo_']);
274 display_notification_centered(_("Selected transaction has been voided."));
275 unset($_POST['trans_no']);
276 unset($_POST['memo_']);
277 unset($_POST['date_']);
280 display_error(_("The entered transaction does not exist or cannot be voided."));
281 set_focus('trans_no');
287 //----------------------------------------------------------------------------------------
289 if (!isset($_POST['date_']))
291 $_POST['date_'] = Today();
292 if (!is_date_in_fiscalyear($_POST['date_']))
293 $_POST['date_'] = end_fiscalyear();
296 if (isset($_POST['ProcessVoiding']))
298 if (!check_valid_entries())
299 unset($_POST['ProcessVoiding']);
300 $Ajax->activate('_page_body');
303 if (isset($_POST['ConfirmVoiding']))
305 handle_void_transaction();
306 $Ajax->activate('_page_body');
309 if (isset($_POST['CancelVoiding']))
312 $Ajax->activate('_page_body');
315 //----------------------------------------------------------------------------------------