2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 include_once($path_to_root . "/includes/ui/items_cart.inc");
14 include_once($path_to_root . "/includes/session.inc");
15 $page_security = isset($_GET['NewPayment']) ||
16 @($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT)
17 ? 'SA_PAYMENT' : 'SA_DEPOSIT';
19 include_once($path_to_root . "/includes/date_functions.inc");
20 include_once($path_to_root . "/includes/data_checks.inc");
22 include_once($path_to_root . "/gl/includes/ui/gl_bank_ui.inc");
23 include_once($path_to_root . "/gl/includes/gl_db.inc");
24 include_once($path_to_root . "/gl/includes/gl_ui.inc");
27 if ($use_popup_windows)
28 $js .= get_js_open_window(800, 500);
30 $js .= get_js_date_picker();
32 if (isset($_GET['NewPayment'])) {
33 $_SESSION['page_title'] = _($help_context = "Bank Account Payment Entry");
34 handle_new_order(ST_BANKPAYMENT);
36 } else if(isset($_GET['NewDeposit'])) {
37 $_SESSION['page_title'] = _($help_context = "Bank Account Deposit Entry");
38 handle_new_order(ST_BANKDEPOSIT);
39 } else if(isset($_GET['ModifyPayment'])) {
40 $_SESSION['page_title'] = _($help_context = "Modify Bank Account Entry")." #".$_GET['trans_no'];
41 create_cart(ST_BANKPAYMENT, $_GET['trans_no']);
42 } else if(isset($_GET['ModifyDeposit'])) {
43 $_SESSION['page_title'] = _($help_context = "Modify Bank Deposit Entry")." #".$_GET['trans_no'];
44 create_cart(ST_BANKDEPOSIT, $_GET['trans_no']);
46 page($_SESSION['page_title'], false, false, '', $js);
48 //-----------------------------------------------------------------------------------------------
49 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
51 //----------------------------------------------------------------------------------------
52 if (list_updated('PersonDetailID')) {
53 $br = get_branch(get_post('PersonDetailID'));
54 $_POST['person_id'] = $br['debtor_no'];
55 $Ajax->activate('person_id');
58 //--------------------------------------------------------------------------------------------------
59 function line_start_focus() {
62 $Ajax->activate('items_table');
63 set_focus('_code_id_edit');
66 //-----------------------------------------------------------------------------------------------
68 if (isset($_GET['AddedID']))
70 $trans_no = $_GET['AddedID'];
71 $trans_type = ST_BANKPAYMENT;
73 display_notification_centered(_("Payment $trans_no has been entered"));
75 display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Payment")));
77 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), "NewPayment=yes");
79 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Deposit"), "NewDeposit=yes");
81 display_footer_exit();
84 if (isset($_GET['UpdatedID']))
86 $trans_no = $_GET['UpdatedID'];
87 $trans_type = ST_BANKPAYMENT;
89 display_notification_centered(_("Payment $trans_no has been modified"));
91 display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Payment")));
93 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), "NewPayment=yes");
95 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Deposit"), "NewDeposit=yes");
97 display_footer_exit();
100 if (isset($_GET['AddedDep']))
102 $trans_no = $_GET['AddedDep'];
103 $trans_type = ST_BANKDEPOSIT;
105 display_notification_centered(_("Deposit $trans_no has been entered"));
107 display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Deposit")));
109 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Deposit"), "NewDeposit=yes");
111 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A Payment"), "NewPayment=yes");
113 display_footer_exit();
115 if (isset($_GET['UpdatedDep']))
117 $trans_no = $_GET['UpdatedDep'];
118 $trans_type = ST_BANKDEPOSIT;
120 display_notification_centered(_("Deposit $trans_no has been modified"));
122 display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Deposit")));
124 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Deposit"), "NewDeposit=yes");
126 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Payment"), "NewPayment=yes");
128 display_footer_exit();
131 if (isset($_POST['_date__changed'])) {
132 $Ajax->activate('_ex_rate');
134 //--------------------------------------------------------------------------------------------------
136 function handle_new_order($type)
138 if (isset($_SESSION['pay_items']))
140 unset ($_SESSION['pay_items']);
143 //session_register("pay_items");
145 $_SESSION['pay_items'] = new items_cart($type);
147 $_POST['date_'] = new_doc_date();
148 if (!is_date_in_fiscalyear($_POST['date_']))
149 $_POST['date_'] = end_fiscalyear();
150 $_SESSION['pay_items']->tran_date = $_POST['date_'];
153 function create_cart($type, $trans_no)
157 if (isset($_SESSION['pay_items']))
159 unset ($_SESSION['pay_items']);
162 $_SESSION['pay_items'] = new items_cart($type);
163 $_SESSION['pay_items']->order_id = $trans_no;
166 $result = get_gl_trans($type, $trans_no);
169 while ($row = db_fetch($result)) {
170 if ($row['amount'] == 0) continue;
171 if (is_bank_account($row['account'])) continue;
172 $date = $row['tran_date'];
173 $_SESSION['pay_items']->add_gl_item($row['account'], $row['dimension_id'],
174 $row['dimension2_id'], $row['amount'], $row['memo_']);
177 $_SESSION['pay_items']->memo_ = get_comments_string($type, $trans_no);
178 $_SESSION['pay_items']->tran_date = sql2date($date);
179 $_SESSION['pay_items']->reference = $Refs->get($type, $trans_no);
180 ////////////////////////////////////////////
181 // Check Ref Original ?????
182 $_POST['ref_original'] = $_SESSION['pay_items']->reference; // Store for comparison when updating
184 $bank_trans = db_fetch(get_bank_trans($type, $trans_no));
185 $_POST['bank_account'] = $bank_trans["bank_act"];
186 $_POST['PayType'] = $bank_trans["person_type_id"];
188 if ($bank_trans["person_type_id"] == PT_CUSTOMER) //2
190 $trans = get_customer_trans($trans_no, $type);
191 $_POST['person_id'] = $trans["debtor_no"];
192 $_POST['PersonDetailID'] = $trans["branch_code"];
194 elseif ($bank_trans["person_type_id"] == PT_SUPPLIER) //3
196 $trans = get_supp_trans($trans_no, $type);
197 $_POST['person_id'] = $trans["supplier_id"];
199 elseif ($bank_trans["person_type_id"] == PT_MISC) //0
200 $_POST['person_id'] = $bank_trans["person_id"];
201 elseif ($bank_trans["person_type_id"] == PT_QUICKENTRY) //4
202 $_POST['person_id'] = $bank_trans["person_id"];
204 $_POST['person_id'] = $bank_trans["person_id"];
207 $_SESSION['pay_items']->reference = $Refs->get_next(0);
208 $_SESSION['pay_items']->tran_date = new_doc_date();
209 if (!is_date_in_fiscalyear($_SESSION['pay_items']->tran_date))
210 $_SESSION['pay_items']->tran_date = end_fiscalyear();
211 $_POST['ref_original'] = -1;
214 $_POST['memo_'] = $_SESSION['pay_items']->memo_;
215 $_POST['ref'] = $_SESSION['pay_items']->reference;
216 $_POST['date_'] = $_SESSION['pay_items']->tran_date;
218 //$_SESSION['pay_items'] = &$_SESSION['pay_items'];
220 //-----------------------------------------------------------------------------------------------
222 if (isset($_POST['Process']))
227 if ($_SESSION['pay_items']->count_gl_items() < 1) {
228 display_error(_("You must enter at least one payment line."));
229 set_focus('code_id');
233 if ($_SESSION['pay_items']->gl_items_total() == 0.0) {
234 display_error(_("The total bank amount cannot be 0."));
235 set_focus('code_id');
239 if (!$Refs->is_valid($_POST['ref']))
241 display_error( _("You must enter a reference."));
245 elseif ($_POST['ref'] != $_SESSION['pay_items']->reference && !is_new_reference($_POST['ref'], $_SESSION['pay_items']->trans_type))
247 display_error( _("The entered reference is already in use."));
251 if (!is_date($_POST['date_']))
253 display_error(_("The entered date for the payment is invalid."));
257 elseif (!is_date_in_fiscalyear($_POST['date_']))
259 display_error(_("The entered date is not in fiscal year."));
264 if ($input_error == 1)
265 unset($_POST['Process']);
268 if (isset($_POST['Process']))
272 $_SESSION['pay_items'] = &$_SESSION['pay_items'];
273 $new = $_SESSION['pay_items']->order_id == 0;
277 clear_bank_trans($_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id, true);
278 $trans = reinsert_bank_transaction(
279 $_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id, $_POST['bank_account'],
280 $_SESSION['pay_items'], $_POST['date_'],
281 $_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'),
282 $_POST['ref'], $_POST['memo_'], false);
285 $trans = add_bank_transaction(
286 $_SESSION['pay_items']->trans_type, $_POST['bank_account'],
287 $_SESSION['pay_items'], $_POST['date_'],
288 $_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'),
289 $_POST['ref'], $_POST['memo_'], false);
291 $trans_type = $trans[0];
292 $trans_no = $trans[1];
293 new_doc_date($_POST['date_']);
295 $_SESSION['pay_items']->clear_items();
296 unset($_SESSION['pay_items']);
298 commit_transaction();
301 meta_forward($_SERVER['PHP_SELF'], $trans_type==ST_BANKPAYMENT ?
302 "AddedID=$trans_no" : "AddedDep=$trans_no");
304 meta_forward($_SERVER['PHP_SELF'], $trans_type==ST_BANKPAYMENT ?
305 "UpdatedID=$trans_no" : "UpdatedDep=$trans_no");
307 } /*end of process credit note */
309 //-----------------------------------------------------------------------------------------------
311 function check_item_data()
313 //if (!check_num('amount', 0))
315 // display_error( _("The amount entered is not a valid number or is less than zero."));
316 // set_focus('amount');
320 if ($_POST['code_id'] == $_POST['bank_account'])
322 display_error( _("The source and destination accouts cannot be the same."));
323 set_focus('code_id');
327 //if (is_bank_account($_POST['code_id']))
329 // if ($_SESSION['pay_items']->trans_type == ST_BANKPAYMENT)
330 // display_error( _("You cannot make a payment to a bank account. Please use the transfer funds facility for this."));
332 // display_error( _("You cannot make a deposit from a bank account. Please use the transfer funds facility for this."));
333 // set_focus('code_id');
340 //-----------------------------------------------------------------------------------------------
342 function handle_update_item()
344 $amount = ($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? 1:-1) * input_num('amount');
345 if($_POST['UpdateItem'] != "" && check_item_data())
347 $_SESSION['pay_items']->update_gl_item($_POST['Index'], $_POST['code_id'],
348 $_POST['dimension_id'], $_POST['dimension2_id'], $amount , $_POST['LineMemo']);
353 //-----------------------------------------------------------------------------------------------
355 function handle_delete_item($id)
357 $_SESSION['pay_items']->remove_gl_item($id);
361 //-----------------------------------------------------------------------------------------------
363 function handle_new_item()
365 if (!check_item_data())
367 $amount = ($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? 1:-1) * input_num('amount');
369 $_SESSION['pay_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
370 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
373 //-----------------------------------------------------------------------------------------------
374 $id = find_submit('Delete');
376 handle_delete_item($id);
378 if (isset($_POST['AddItem']))
381 if (isset($_POST['UpdateItem']))
382 handle_update_item();
384 if (isset($_POST['CancelItemChanges']))
387 if (isset($_POST['go']))
389 display_quick_entries($_SESSION['pay_items'], $_POST['person_id'], input_num('totamount'),
390 $_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? QE_PAYMENT : QE_DEPOSIT);
391 $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
394 //-----------------------------------------------------------------------------------------------
398 display_bank_header($_SESSION['pay_items']);
400 start_table(TABLESTYLE2, "width=90%", 10);
403 display_gl_items($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ?
404 _("Payment Items"):_("Deposit Items"), $_SESSION['pay_items']);
405 gl_options_controls();
410 submit_center_first('Update', _("Update"), '', null);
411 submit_center_last('Process', $_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ?
412 _("Process Payment"):_("Process Deposit"), '', 'default');
416 //------------------------------------------------------------------------------------------------