+if (isset($_GET['customer_id']))
+{
+ $_POST['customer_id'] = $_GET['customer_id'];
+}
+
+if (!isset($_POST['bank_account']))
+{ // first page call
+ $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,0);
+
+ if (isset($_GET['SInvoice'])) {
+ // get date and supplier
+ $inv = get_customer_trans($_GET['SInvoice'], ST_SALESINVOICE);
+ if($inv) {
+ $_POST['customer_id'] = $inv['debtor_no'];
+ $_POST['DateBanked'] = sql2date($inv['tran_date']);
+ foreach($_SESSION['alloc']->allocs as $line => $trans) {
+ if ($trans->type == ST_SALESINVOICE && $trans->type_no == $_GET['SInvoice']) {
+ $_POST['amount'] =
+ $_SESSION['alloc']->amount = price_format($_SESSION['alloc']->allocs[$line]->amount);
+ $_SESSION['alloc']->allocs[$line]->current_allocated =
+ $_SESSION['alloc']->allocs[$line]->amount;
+ break;
+ }
+ }
+ unset($inv);
+ } else
+ display_error(_("Invalid sales invoice number."));
+ }
+}
+
+if (list_updated('BranchID')) {
+ // when branch is selected via external editor also customer can change
+ $br = get_branch(get_post('BranchID'));
+ $_POST['customer_id'] = $br['debtor_no'];
+ $Ajax->activate('customer_id');
+}
+
+if (!isset($_POST['customer_id']))
+ $_POST['customer_id'] = get_global_customer(false);
+if (!isset($_POST['DateBanked'])) {
+ $_POST['DateBanked'] = new_doc_date();
+ if (!is_date_in_fiscalyear($_POST['DateBanked'])) {
+ $_POST['DateBanked'] = end_fiscalyear();
+ }
+}
+