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