2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
14 include_once($path_to_root . "/includes/ui/items_cart.inc");
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/gl/includes/ui/gl_bank_ui.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22 include_once($path_to_root . "/gl/includes/gl_ui.inc");
25 if ($use_popup_windows)
26 $js .= get_js_open_window(800, 500);
28 $js .= get_js_date_picker();
30 if (isset($_GET['NewPayment'])) {
31 $_SESSION['page_title'] = _("Bank Account Payment Entry");
32 handle_new_order(systypes::bank_payment());
34 } else if(isset($_GET['NewDeposit'])) {
35 $_SESSION['page_title'] = _("Bank Account Deposit Entry");
36 handle_new_order(systypes::bank_deposit());
38 page($_SESSION['page_title'], false, false, '', $js);
40 //-----------------------------------------------------------------------------------------------
41 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
43 //----------------------------------------------------------------------------------------
44 if ($ret = context_restore()) {
45 if(isset($ret['supplier_id']))
46 $_POST['person_id'] = $ret['supplier_id'];
47 if(isset($ret['customer_id']))
48 $_POST['person_id'] = $ret['customer_id'];
49 set_focus('person_id');
50 if(isset($ret['branch_id'])) {
51 $_POST['PersonDetailID'] = $ret['branch_id'];
52 set_focus('PersonDetailID');
55 if (isset($_POST['_person_id_editor'])) {
56 if ($_POST['PayType']==payment_person_types::supplier())
57 $editor = '/purchasing/manage/suppliers.php?supplier_id=';
59 $editor = '/sales/manage/customers.php?debtor_no=';
61 // $_SESSION['pay_items'] should stay unchanged during call
63 context_call($path_to_root.$editor.$_POST['person_id'],
64 array('bank_account', 'date_', 'PayType', 'person_id',
65 'PersonDetailID', 'ref', 'memo_') );
67 //--------------------------------------------------------------------------------------------------
68 function line_start_focus() {
71 $Ajax->activate('items_table');
72 set_focus('_code_id_edit');
75 //-----------------------------------------------------------------------------------------------
77 if (isset($_GET['AddedID']))
79 $trans_no = $_GET['AddedID'];
80 $trans_type = systypes::bank_payment();
82 display_notification_centered(_("Payment has been entered"));
84 display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Payment")));
86 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), "NewPayment=yes");
88 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Deposit"), "NewDeposit=yes");
90 display_footer_exit();
93 if (isset($_GET['AddedDep']))
95 $trans_no = $_GET['AddedDep'];
96 $trans_type = systypes::bank_deposit();
98 display_notification_centered(_("Deposit has been entered"));
100 display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Deposit")));
102 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Deposit"), "NewDeposit=yes");
104 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A Payment"), "NewPayment=yes");
106 display_footer_exit();
108 if (isset($_POST['_date__changed'])) {
109 $Ajax->activate('_ex_rate');
111 //--------------------------------------------------------------------------------------------------
113 function handle_new_order($type)
115 if (isset($_SESSION['pay_items']))
117 unset ($_SESSION['pay_items']);
120 session_register("pay_items");
122 $_SESSION['pay_items'] = new items_cart($type);
124 $_POST['date_'] = Today();
125 if (!is_date_in_fiscalyear($_POST['date_']))
126 $_POST['date_'] = end_fiscalyear();
127 $_SESSION['pay_items']->tran_date = $_POST['date_'];
130 //-----------------------------------------------------------------------------------------------
132 if (isset($_POST['Process']))
137 if ($_SESSION['pay_items']->count_gl_items() < 1) {
138 display_error(_("You must enter at least one payment line."));
139 set_focus('code_id');
143 if (!references::is_valid($_POST['ref']))
145 display_error( _("You must enter a reference."));
149 elseif (!is_new_reference($_POST['ref'], $_SESSION['pay_items']->trans_type))
151 display_error( _("The entered reference is already in use."));
155 if (!is_date($_POST['date_']))
157 display_error(_("The entered date for the payment is invalid."));
161 elseif (!is_date_in_fiscalyear($_POST['date_']))
163 display_error(_("The entered date is not in fiscal year."));
168 if ($input_error == 1)
169 unset($_POST['Process']);
172 if (isset($_POST['Process']))
175 $trans = add_bank_transaction(
176 $_SESSION['pay_items']->trans_type, $_POST['bank_account'],
177 $_SESSION['pay_items'], $_POST['date_'],
178 $_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'),
179 $_POST['ref'], $_POST['memo_']);
181 $trans_type = $trans[0];
182 $trans_no = $trans[1];
184 $_SESSION['pay_items']->clear_items();
185 unset($_SESSION['pay_items']);
187 meta_forward($_SERVER['PHP_SELF'], $trans_type==systypes::bank_payment() ?
188 "AddedID=$trans_no" : "AddedDep=$trans_no");
190 } /*end of process credit note */
192 //-----------------------------------------------------------------------------------------------
194 function check_item_data()
196 //if (!check_num('amount', 0))
198 // display_error( _("The amount entered is not a valid number or is less than zero."));
199 // set_focus('amount');
203 if ($_POST['code_id'] == $_POST['bank_account'])
205 display_error( _("The source and destination accouts cannot be the same."));
206 set_focus('code_id');
210 //if (is_bank_account($_POST['code_id']))
212 // if ($_SESSION['pay_items']->trans_type == systypes::bank_payment())
213 // display_error( _("You cannot make a payment to a bank account. Please use the transfer funds facility for this."));
215 // display_error( _("You cannot make a deposit from a bank account. Please use the transfer funds facility for this."));
216 // set_focus('code_id');
223 //-----------------------------------------------------------------------------------------------
225 function handle_update_item()
227 $amount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * input_num('amount');
228 if($_POST['UpdateItem'] != "" && check_item_data())
230 $_SESSION['pay_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
231 $_POST['dimension2_id'], $amount , $_POST['LineMemo']);
236 //-----------------------------------------------------------------------------------------------
238 function handle_delete_item($id)
240 $_SESSION['pay_items']->remove_gl_item($id);
244 //-----------------------------------------------------------------------------------------------
246 function handle_new_item()
248 if (!check_item_data())
250 $amount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * input_num('amount');
252 $_SESSION['pay_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
253 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
256 //-----------------------------------------------------------------------------------------------
257 $id = find_submit('Delete');
259 handle_delete_item($id);
261 if (isset($_POST['AddItem']))
264 if (isset($_POST['UpdateItem']))
265 handle_update_item();
267 if (isset($_POST['CancelItemChanges']))
270 if (isset($_POST['go']))
272 display_quick_entries($_SESSION['pay_items'], $_POST['person_id'], input_num('totamount'),
273 $_SESSION['pay_items']->trans_type==systypes::bank_payment() ? QE_PAYMENT : QE_DEPOSIT);
274 $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
277 //-----------------------------------------------------------------------------------------------
279 start_form(false, true);
281 display_bank_header($_SESSION['pay_items']);
283 start_table("$table_style2 width=90%", 10);
286 display_gl_items($_SESSION['pay_items']->trans_type==systypes::bank_payment() ?
287 _("Payment Items"):_("Deposit Items"), $_SESSION['pay_items']);
288 gl_options_controls();
293 submit_center_first('Update', _("Update"), '', null);
294 submit_center_last('Process', $_SESSION['pay_items']->trans_type==systypes::bank_payment() ?
295 _("Process Payment"):_("Process Deposit"), '', true);
299 //------------------------------------------------------------------------------------------------