Inserted Copyright Notice and fixed graphic items
[fa-stable.git] / admin / void_transaction.php
1 <?php
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 ***********************************************************************/
12 $path_to_root="..";
13 $page_security = 14;
14 include_once($path_to_root . "/includes/session.inc");
15
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");
19
20 include_once($path_to_root . "/admin/db/voiding_db.inc");
21 $js = "";
22 if ($use_date_picker)
23         $js .= get_js_date_picker();
24 page(_("Void a Transaction"), false, false, "", $js);
25
26 //----------------------------------------------------------------------------------------
27
28 function voiding_controls()
29 {
30         global $table_style2;
31         
32         start_form(false, true);
33
34         start_table($table_style2);
35
36         systypes_list_row(_("Transaction Type:"), "filterType", null, true);
37
38     text_row(_("Transaction #:"), 'trans_no', null, 12, 12);
39
40     date_row(_("Voiding Date:"), 'date_');
41
42     textarea_row(_("Memo:"), 'memo_', null, 30, 4);
43
44         end_table(1);
45
46     if (!isset($_POST['ProcessVoiding']))
47         submit_center('ProcessVoiding', _("Void Transaction"), true, '', true);
48     else 
49     {
50         
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);
54     }
55
56         end_form();
57 }
58
59 //----------------------------------------------------------------------------------------
60
61 function check_valid_entries()
62 {
63         if (!is_date($_POST['date_']))
64         {
65                 display_error(_("The entered date is invalid."));
66                 set_focus('date_');
67                 return false;
68         }
69         if (!is_date_in_fiscalyear($_POST['date_']))
70         {
71                 display_error(_("The entered date is not in fiscal year."));
72                 set_focus('date_');
73                 return false;
74         }
75
76         if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
77         {
78                 display_error(_("The transaction number is expected to be numeric and greater than zero."));
79                 set_focus('trans_no');
80                 return false;
81         }
82
83         return true;
84 }
85
86 //----------------------------------------------------------------------------------------
87
88 function handle_void_transaction()
89 {
90         if (check_valid_entries()==true) 
91         {
92
93                 $void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
94                 if ($void_entry != null) 
95                 {
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');
101                         return;
102                 }
103
104                 $ret = void_transaction($_POST['filterType'], $_POST['trans_no'],
105                         $_POST['date_'], $_POST['memo_']);
106
107                 if ($ret) 
108                 {
109                         display_notification_centered(_("Selected transaction has been voided."));
110                         unset($_POST['trans_no']);
111                         unset($_POST['memo_']);
112                         unset($_POST['date_']);
113                 }
114                 else {
115                         display_error(_("The entered transaction does not exist or cannot be voided."));
116                         set_focus('trans_no');
117
118                 }
119         }
120 }
121
122 //----------------------------------------------------------------------------------------
123
124 if (!isset($_POST['date_']))
125 {
126         $_POST['date_'] = Today();
127         if (!is_date_in_fiscalyear($_POST['date_']))
128                 $_POST['date_'] = end_fiscalyear();
129 }               
130         
131 if (isset($_POST['ProcessVoiding']))
132 {
133         if (!check_valid_entries())
134                 unset($_POST['ProcessVoiding']);
135         $Ajax->activate('_page_body');
136 }
137
138 if (isset($_POST['ConfirmVoiding']))
139 {
140         handle_void_transaction();
141         $Ajax->activate('_page_body');
142 }
143
144 if (isset($_POST['CancelVoiding']))
145 {
146         $Ajax->activate('_page_body');
147 }
148
149 //----------------------------------------------------------------------------------------
150
151 voiding_controls();
152
153 end_page();
154
155 ?>