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