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