Release 1.0.1 established on SourceForge, fixing the bugs and including a Date Picker...
[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"));
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"));
44         submit_center_last('CancelVoiding', _("Cancel"));
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                 return false;
58         }
59         if (!is_date_in_fiscalyear($_POST['date_']))
60         {
61                 display_error(_("The entered date is not in fiscal year."));
62                 return false;
63         }
64
65         if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
66         {
67                 display_error(_("The transaction number is expected to be numeric and greater than zero."));
68                 return false;
69         }
70
71         return true;
72 }
73
74 //----------------------------------------------------------------------------------------
75
76 function handle_void_transaction()
77 {
78         if (check_valid_entries()==true) 
79         {
80
81                 $void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
82                 if ($void_entry != null) 
83                 {
84                         display_error(_("The selected transaction has already been voided."), true);
85                         unset($_POST['trans_no']);
86                         unset($_POST['memo_']);
87                         unset($_POST['date_']);
88                         return;
89                 }
90
91                 $ret = void_transaction($_POST['filterType'], $_POST['trans_no'],
92                         $_POST['date_'], $_POST['memo_']);
93
94                 if ($ret) 
95                 {
96                         display_notification_centered(_("Selected transaction has been voided."));
97                         unset($_POST['trans_no']);
98                         unset($_POST['memo_']);
99                         unset($_POST['date_']);
100                 }
101                 else
102                         display_error(_("The entered transaction does not exist or cannot be voided."));
103         }
104 }
105
106 //----------------------------------------------------------------------------------------
107
108 if (!isset($_POST['date_']))
109 {
110         $_POST['date_'] = Today();
111         if (!is_date_in_fiscalyear($_POST['date_']))
112                 $_POST['date_'] = end_fiscalyear();
113 }               
114         
115 if (isset($_POST['ProcessVoiding']))
116 {
117         if (!check_valid_entries())
118                 unset($_POST['ProcessVoiding']);
119 }
120
121 if (isset($_POST['ConfirmVoiding']))
122 {
123         handle_void_transaction();
124 }
125
126 //----------------------------------------------------------------------------------------
127
128 voiding_controls();
129
130 end_page();
131
132 ?>