2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
14 include_once($path_to_root . "/includes/session.inc");
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/ui.inc");
18 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/admin/db/voiding_db.inc");
23 $js .= get_js_date_picker();
24 page(_("Void a Transaction"), false, false, "", $js);
26 //----------------------------------------------------------------------------------------
28 function voiding_controls()
32 start_form(false, true);
34 start_table($table_style2);
36 systypes_list_row(_("Transaction Type:"), "filterType", null, true);
38 text_row(_("Transaction #:"), 'trans_no', null, 12, 12);
40 date_row(_("Voiding Date:"), 'date_');
42 textarea_row(_("Memo:"), 'memo_', null, 30, 4);
46 if (!isset($_POST['ProcessVoiding']))
47 submit_center('ProcessVoiding', _("Void Transaction"), true, '', true);
51 display_note(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
52 submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
53 submit_center_last('CancelVoiding', _("Cancel"), '', true);
59 //----------------------------------------------------------------------------------------
61 function check_valid_entries()
63 if (!is_date($_POST['date_']))
65 display_error(_("The entered date is invalid."));
69 if (!is_date_in_fiscalyear($_POST['date_']))
71 display_error(_("The entered date is not in fiscal year."));
76 if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
78 display_error(_("The transaction number is expected to be numeric and greater than zero."));
79 set_focus('trans_no');
86 //----------------------------------------------------------------------------------------
88 function handle_void_transaction()
90 if (check_valid_entries()==true)
93 $void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
94 if ($void_entry != null)
96 display_error(_("The selected transaction has already been voided."), true);
97 unset($_POST['trans_no']);
98 unset($_POST['memo_']);
99 unset($_POST['date_']);
100 set_focus('trans_no');
104 $ret = void_transaction($_POST['filterType'], $_POST['trans_no'],
105 $_POST['date_'], $_POST['memo_']);
109 display_notification_centered(_("Selected transaction has been voided."));
110 unset($_POST['trans_no']);
111 unset($_POST['memo_']);
112 unset($_POST['date_']);
115 display_error(_("The entered transaction does not exist or cannot be voided."));
116 set_focus('trans_no');
122 //----------------------------------------------------------------------------------------
124 if (!isset($_POST['date_']))
126 $_POST['date_'] = Today();
127 if (!is_date_in_fiscalyear($_POST['date_']))
128 $_POST['date_'] = end_fiscalyear();
131 if (isset($_POST['ProcessVoiding']))
133 if (!check_valid_entries())
134 unset($_POST['ProcessVoiding']);
135 $Ajax->activate('_page_body');
138 if (isset($_POST['ConfirmVoiding']))
140 handle_void_transaction();
141 $Ajax->activate('_page_body');
144 if (isset($_POST['CancelVoiding']))
146 $Ajax->activate('_page_body');
149 //----------------------------------------------------------------------------------------