+ $cart = new items_cart($type);
+ $cart->order_id = $trans_no;
+
+ if ($trans_no) {
+
+ $bank_trans = db_fetch(get_bank_trans($type, $trans_no));
+ $_POST['bank_account'] = $bank_trans["bank_act"];
+ $_POST['PayType'] = $bank_trans["person_type_id"];
+ $cart->reference = $bank_trans["ref"];
+
+ if ($bank_trans["person_type_id"] == PT_CUSTOMER)
+ {
+ $trans = get_customer_trans($trans_no, $type);
+ $_POST['person_id'] = $trans["debtor_no"];
+ $_POST['PersonDetailID'] = $trans["branch_code"];
+ }
+ elseif ($bank_trans["person_type_id"] == PT_SUPPLIER)
+ {
+ $trans = get_supp_trans($trans_no, $type);
+ $_POST['person_id'] = $trans["supplier_id"];
+ }
+ elseif ($bank_trans["person_type_id"] == PT_MISC)
+ $_POST['person_id'] = $bank_trans["person_id"];
+ elseif ($bank_trans["person_type_id"] == PT_QUICKENTRY)
+ $_POST['person_id'] = $bank_trans["person_id"];
+ else
+ $_POST['person_id'] = $bank_trans["person_id"];
+
+ $cart->memo_ = get_comments_string($type, $trans_no);
+ $cart->tran_date = sql2date($bank_trans['trans_date']);
+
+ $cart->original_amount = $bank_trans['amount'];
+ $result = get_gl_trans($type, $trans_no);
+ if ($result) {
+ while ($row = db_fetch($result)) {
+ if (is_bank_account($row['account'])) {
+ // date exchange rate is currenly not stored in bank transaction,
+ // so we have to restore it from original gl amounts
+ $ex_rate = $bank_trans['amount']/$row['amount'];
+ } else {
+ $cart->add_gl_item( $row['account'], $row['dimension_id'],
+ $row['dimension2_id'], $row['amount'], $row['memo_']);
+ }
+ }
+ }
+
+ // apply exchange rate
+ foreach($cart->gl_items as $line_no => $line)
+ $cart->gl_items[$line_no]->amount *= $ex_rate;
+
+ } else {
+ $cart->reference = $Refs->get_next($cart->trans_type, null, $cart->tran_date);
+ $cart->tran_date = new_doc_date();
+ if (!is_date_in_fiscalyear($cart->tran_date))
+ $cart->tran_date = end_fiscalyear();
+ }