5 include_once($path_to_root . "/includes/ui/items_cart.inc");
6 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/data_checks.inc");
11 include_once($path_to_root . "/gl/includes/ui/gl_bank_ui.inc");
12 include_once($path_to_root . "/gl/includes/gl_db.inc");
13 include_once($path_to_root . "/gl/includes/gl_ui.inc");
16 if ($use_popup_windows)
17 $js .= get_js_open_window(800, 500);
19 $js .= get_js_date_picker();
21 if (isset($_GET['NewPayment'])) {
22 $_SESSION['page_title'] = _("Bank Account Payment Entry");
23 handle_new_order(systypes::bank_payment());
25 } else if(isset($_GET['NewDeposit'])) {
26 $_SESSION['page_title'] = _("Bank Account Deposit Entry");
27 handle_new_order(systypes::bank_deposit());
29 page($_SESSION['page_title'], false, false, '', $js);
31 //-----------------------------------------------------------------------------------------------
32 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
34 //----------------------------------------------------------------------------------------
35 if ($ret = context_restore()) {
36 if(isset($ret['supplier_id']))
37 $_POST['person_id'] = $ret['supplier_id'];
38 if(isset($ret['customer_id']))
39 $_POST['person_id'] = $ret['customer_id'];
40 set_focus('person_id');
41 if(isset($ret['branch_id'])) {
42 $_POST['PersonDetailID'] = $ret['branch_id'];
43 set_focus('PersonDetailID');
46 if (isset($_POST['_person_id_editor'])) {
47 if ($_POST['PayType']==payment_person_types::supplier())
48 $editor = '/purchasing/manage/suppliers.php?supplier_id=';
50 $editor = '/sales/manage/customers.php?debtor_no=';
52 // $_SESSION['pay_items'] should stay unchanged during call
54 context_call($path_to_root.$editor.$_POST['person_id'],
55 array('bank_account', 'date_', 'PayType', 'person_id',
56 'PersonDetailID', 'ref', 'memo_') );
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 = systypes::bank_payment();
73 display_notification_centered(_("Payment 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['AddedDep']))
86 $trans_no = $_GET['AddedDep'];
87 $trans_type = systypes::bank_deposit();
89 display_notification_centered(_("Deposit has been entered"));
91 display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Deposit")));
93 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Deposit"), "NewDeposit=yes");
95 hyperlink_params($_SERVER['PHP_SELF'], _("Enter A Payment"), "NewPayment=yes");
97 display_footer_exit();
99 if (isset($_POST['_date__changed'])) {
100 $Ajax->activate('_ex_rate');
102 //--------------------------------------------------------------------------------------------------
104 function handle_new_order($type)
106 if (isset($_SESSION['pay_items']))
108 unset ($_SESSION['pay_items']);
111 session_register("pay_items");
113 $_SESSION['pay_items'] = new items_cart($type);
115 $_POST['date_'] = Today();
116 if (!is_date_in_fiscalyear($_POST['date_']))
117 $_POST['date_'] = end_fiscalyear();
118 $_SESSION['pay_items']->tran_date = $_POST['date_'];
121 //-----------------------------------------------------------------------------------------------
123 if (isset($_POST['Process']))
128 if ($_SESSION['pay_items']->count_gl_items() < 1) {
129 display_error(_("You must enter at least one payment line."));
130 set_focus('code_id');
134 if (!references::is_valid($_POST['ref']))
136 display_error( _("You must enter a reference."));
140 elseif (!is_new_reference($_POST['ref'], $_SESSION['pay_items']->trans_type))
142 display_error( _("The entered reference is already in use."));
146 if (!is_date($_POST['date_']))
148 display_error(_("The entered date for the payment is invalid."));
152 elseif (!is_date_in_fiscalyear($_POST['date_']))
154 display_error(_("The entered date is not in fiscal year."));
159 if ($input_error == 1)
160 unset($_POST['Process']);
163 if (isset($_POST['Process']))
166 $trans = add_bank_transaction(
167 $_SESSION['pay_items']->trans_type, $_POST['bank_account'],
168 $_SESSION['pay_items'], $_POST['date_'],
169 $_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'),
170 $_POST['ref'], $_POST['memo_']);
172 $trans_type = $trans[0];
173 $trans_no = $trans[1];
175 $_SESSION['pay_items']->clear_items();
176 unset($_SESSION['pay_items']);
178 meta_forward($_SERVER['PHP_SELF'], $trans_type==systypes::bank_payment() ?
179 "AddedID=$trans_no" : "AddedDep=$trans_no");
181 } /*end of process credit note */
183 //-----------------------------------------------------------------------------------------------
185 function check_item_data()
187 //if (!check_num('amount', 0))
189 // display_error( _("The amount entered is not a valid number or is less than zero."));
190 // set_focus('amount');
194 if ($_POST['code_id'] == $_POST['bank_account'])
196 display_error( _("The source and destination accouts cannot be the same."));
197 set_focus('code_id');
201 //if (is_bank_account($_POST['code_id']))
203 // if ($_SESSION['pay_items']->trans_type == systypes::bank_payment())
204 // display_error( _("You cannot make a payment to a bank account. Please use the transfer funds facility for this."));
206 // display_error( _("You cannot make a deposit from a bank account. Please use the transfer funds facility for this."));
207 // set_focus('code_id');
214 //-----------------------------------------------------------------------------------------------
216 function handle_update_item()
218 $amount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * input_num('amount');
219 if($_POST['UpdateItem'] != "" && check_item_data())
221 $_SESSION['pay_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
222 $_POST['dimension2_id'], $amount , $_POST['LineMemo']);
227 //-----------------------------------------------------------------------------------------------
229 function handle_delete_item($id)
231 $_SESSION['pay_items']->remove_gl_item($id);
235 //-----------------------------------------------------------------------------------------------
237 function handle_new_item()
239 if (!check_item_data())
241 $amount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * input_num('amount');
243 $_SESSION['pay_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
244 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
247 //-----------------------------------------------------------------------------------------------
248 $id = find_submit('Delete');
250 handle_delete_item($id);
252 if (isset($_POST['AddItem']))
255 if (isset($_POST['UpdateItem']))
256 handle_update_item();
258 if (isset($_POST['CancelItemChanges']))
261 if (isset($_POST['go']))
263 display_quick_entries($_SESSION['pay_items'], $_POST['person_id'], input_num('totamount'),
264 $_SESSION['pay_items']->trans_type==systypes::bank_payment() ? QE_PAYMENT : QE_DEPOSIT);
265 $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
268 //-----------------------------------------------------------------------------------------------
270 start_form(false, true);
272 display_bank_header($_SESSION['pay_items']);
274 start_table("$table_style2 width=90%", 10);
277 display_gl_items($_SESSION['pay_items']->trans_type==systypes::bank_payment() ?
278 _("Payment Items"):_("Deposit Items"), $_SESSION['pay_items']);
279 gl_options_controls();
284 submit_center_first('Update', _("Update"), '', null);
285 submit_center_last('Process', $_SESSION['pay_items']->trans_type==systypes::bank_payment() ?
286 _("Process Payment"):_("Process Deposit"), '', true);
290 //------------------------------------------------------------------------------------------------