Fixed focus issues
[fa-stable.git] / gl / gl_deposit.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/ui/items_cart.inc");
6 include_once($path_to_root . "/includes/session.inc");
7
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/data_checks.inc");
10
11 include_once($path_to_root . "/gl/includes/ui/gl_deposit_ui.inc");
12 include_once($path_to_root . "/gl/includes/gl_db.inc");
13 include_once($path_to_root . "/gl/includes/gl_ui.inc");
14
15 $js = '';
16 if ($use_popup_windows)
17         $js .= get_js_open_window(800, 500);
18 if ($use_date_picker)
19         $js .= get_js_date_picker();
20
21 page(_("Bank Account Deposit Entry"), false, false, '', $js);
22
23 //-----------------------------------------------------------------------------------------------
24
25 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
26
27 check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
28
29 //-----------------------------------------------------------------------------------------------
30
31 if (isset($_GET['AddedID']))
32 {
33         $trans_no = $_GET['AddedID'];
34         $trans_type = systypes::bank_deposit();
35
36         display_notification_centered(_("Deposit has been entered"));
37
38         display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Deposit")));
39
40         hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Deposit"));
41
42         display_footer_exit();
43 }
44
45 //--------------------------------------------------------------------------------------------------
46
47 function copy_to_py()
48 {
49         $_SESSION['deposit_items']->from_loc = $_POST['bank_account'];
50         $_SESSION['deposit_items']->tran_date = $_POST['date_'];
51         $_SESSION['deposit_items']->transfer_type = $_POST['type'];
52         $_SESSION['deposit_items']->increase = $_POST['PayType'];
53         if (!isset($_POST['person_id']))
54                 $_POST['person_id'] = "";
55         $_SESSION['deposit_items']->person_id = $_POST['person_id'];
56         if (!isset($_POST['PersonDetailID']))
57                 $_POST['PersonDetailID'] = "";
58         $_SESSION['deposit_items']->branch_id = $_POST['PersonDetailID'];
59         $_SESSION['deposit_items']->memo_ = $_POST['memo_'];
60 }
61
62 //--------------------------------------------------------------------------------------------------
63
64 function copy_from_py()
65 {
66         $_POST['bank_account'] = $_SESSION['deposit_items']->from_loc;
67         $_POST['date_'] = $_SESSION['deposit_items']->tran_date;
68         $_POST['type'] = $_SESSION['deposit_items']->transfer_type;
69         $_POST['PayType'] = $_SESSION['deposit_items']->increase;
70         $_POST['person_id'] = $_SESSION['deposit_items']->person_id;
71         $_POST['PersonDetailID'] = $_SESSION['deposit_items']->branch_id;
72         $_POST['memo_'] = $_SESSION['deposit_items']->memo_;
73 }
74
75 //-----------------------------------------------------------------------------------------------
76
77 function handle_new_order()
78 {
79         if (isset($_SESSION['deposit_items']))
80         {
81                 $_SESSION['deposit_items']->clear_items();
82                 unset ($_SESSION['deposit_items']);
83         }
84
85         session_register("deposit_items");
86
87         $_SESSION['deposit_items'] = new items_cart;
88         $_POST['date_'] = Today();
89         if (!is_date_in_fiscalyear($_POST['date_']))
90                 $_POST['date_'] = end_fiscalyear();
91         $_SESSION['deposit_items']->tran_date = $_POST['date_'];
92 }
93
94 //-----------------------------------------------------------------------------------------------
95
96 if (isset($_POST['Process']))
97 {
98
99         $input_error = 0;
100
101         if (!references::is_valid($_POST['ref']))
102         {
103                 display_error( _("You must enter a reference."));
104                 set_focus('ref');
105                 $input_error = 1;
106         }
107         elseif (!is_new_reference($_POST['ref'], systypes::bank_deposit()))
108         {
109                 display_error( _("The entered reference is already in use."));
110                 set_focus('ref');
111                 $input_error = 1;
112         }
113
114         if (!is_date($_POST['date_']))
115         {
116                 display_error(_("The entered date for the deposit is invalid."));
117                 set_focus('date_');
118                 $input_error = 1;
119         }
120
121         if (!is_date_in_fiscalyear($_POST['date_']))
122         {
123                 display_error(_("The entered date is not in fiscal year."));
124                 set_focus('date_');
125                 $input_error = 1;
126         }
127
128         if ($input_error == 1)
129                 unset($_POST['Process']);
130 }
131
132 //-----------------------------------------------------------------------------------------------
133
134 if (isset($_POST['Process']))
135 {
136
137         $trans = add_bank_deposit($_POST['bank_account'],
138                 $_SESSION['deposit_items'], $_POST['date_'],
139                 $_POST['PayType'], $_POST['person_id'], $_POST['PersonDetailID'],
140                 $_POST['type'], $_POST['ref'], $_POST['memo_']);
141
142         $trans_type = $trans[0];
143         $trans_no = $trans[1];
144
145         $_SESSION['deposit_items']->clear_items();
146         unset($_SESSION['deposit_items']);
147
148         meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
149
150 } /*end of process credit note */
151
152 //-----------------------------------------------------------------------------------------------
153
154 function check_item_data()
155 {
156         if (!check_num('amount', 0))
157         {
158                 display_error( _("The amount entered is not a valid number or is less than zero."));
159                 set_focus('amount');
160                 return false;
161         }
162
163         if ($_POST['code_id'] == $_POST['bank_account'])
164         {
165                 display_error( _("The source and destination accouts cannot be the same."));
166                 set_focus('code_id');
167                 return false;
168         }
169
170         if (is_bank_account($_POST['code_id']))
171         {
172                 display_error( _("You cannot make a deposit from a bank account. Please use the transfer funds facility for this."));
173                 set_focus('code_id');
174                 return false;
175         }
176
177         return true;
178 }
179
180 //-----------------------------------------------------------------------------------------------
181
182 function handle_update_item()
183 {
184     if($_POST['UpdateItem'] != "" && check_item_data())
185     {
186         $_SESSION['deposit_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
187                   $_POST['dimension2_id'], -input_num('amount'), $_POST['LineMemo']);
188     }
189 }
190
191 //-----------------------------------------------------------------------------------------------
192
193 function handle_delete_item()
194 {
195         $_SESSION['deposit_items']->remove_gl_item($_GET['Delete']);
196 }
197
198 //-----------------------------------------------------------------------------------------------
199
200 function handle_new_item()
201 {
202         if (!check_item_data())
203                 return;
204
205         $_SESSION['deposit_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
206           $_POST['dimension2_id'], -input_num('amount'), $_POST['LineMemo']);
207 }
208
209 //-----------------------------------------------------------------------------------------------
210 if (isset($_GET['Edit'])) {
211         copy_from_py();
212         set_focus('dimension_id');
213 }
214 if (isset($_GET['Delete'])) {
215         copy_from_py();
216         handle_delete_item();
217         set_focus('_code_id_edit');
218 }
219 if (isset($_POST['AddItem'])) {
220         copy_to_py();
221         handle_new_item();
222         set_focus('_code_id_edit');
223 }
224 if (isset($_POST['UpdateItem'])) {
225         copy_to_py();
226         handle_update_item();
227         set_focus('_code_id_edit');
228 }
229 if (isset($_POST['CancelItemChanges']))
230         set_focus('_code_id_edit');
231
232 if (isset($_POST['EditItem']))
233         set_focus('dimension_id');
234
235 //-----------------------------------------------------------------------------------------------
236
237 if (isset($_GET['NewDeposit']) || !isset($_SESSION['deposit_items']))
238 {
239         handle_new_order();
240 }
241
242 //-----------------------------------------------------------------------------------------------
243
244 start_form(false, true);
245
246 display_order_header($_SESSION['deposit_items']);
247
248 start_table("$table_style width=90%", 10);
249 start_row();
250 echo "<td>";
251 display_gl_items(_("Deposit Items"), $_SESSION['deposit_items']);
252 gl_options_controls();
253 echo "</td>";
254 end_row();
255 end_table(1);
256
257 if (!isset($_POST['Process']))
258 {
259         if ($_SESSION['deposit_items']->count_gl_items() >= 1)
260         {
261         submit_center_first('Update', _("Update"));
262             submit_center_last('Process', _("Process Deposit"));
263         }
264         else
265         submit_center('Update', _("Update"));
266 }
267
268 end_form();
269
270 //------------------------------------------------------------------------------------------------
271
272 end_page();
273
274 ?>