3 //----------------------------------------------------------------------------------
5 function add_bank_transfer($from_account, $to_account, $date_,
6 $amount, $payment_type, $ref, $memo_)
10 $trans_type = systypes::bank_transfer();
12 $currency = get_bank_account_currency($from_account);
14 $trans_no = get_next_trans_no($trans_type);
17 // do the source account postings
18 $total += add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
21 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
22 $date_, $payment_type, -$amount,
23 payment_person_types::misc(), "", $currency,
24 "Cannot insert a source bank transaction");
26 // do the destination account postings
27 $total += add_gl_trans($trans_type, $trans_no, $date_, $to_account, 0, 0, "",
29 /*Post a balance post if $total != 0 */
30 add_gl_balance($trans_type, $trans_no, $date_, -$total);
32 add_bank_trans($trans_type, $trans_no, $to_account, $ref,
33 $date_, $payment_type, $amount,
34 payment_person_types::misc(), "",
36 "Cannot insert a destination bank transaction");
38 add_comments($trans_type, $trans_no, $date_, $memo_);
40 references::save_last($ref, $trans_type);
47 //----------------------------------------------------------------------------------
49 // $amount is in $from_account's currency
51 // returns an array of (inserted trans type, trans no)
53 function add_bank_transaction($trans_type, $from_account, $items, $date_,
54 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
56 // we can only handle type 1 (payment)and type 2 (deposit)
57 if ($trans_type != systypes::bank_payment() && $trans_type != systypes::bank_deposit())
58 display_db_error("Invalid type ($trans_type) sent to add_bank_transaction");
62 $currency = get_bank_account_currency($from_account);
64 // the gl items are already inversed/negated for type 2 (deposit)
65 $total_amount = $items->gl_items_total();
67 if ($person_type_id == payment_person_types::customer())
69 // we need to add a customer transaction record
71 // convert to customer currency
72 $cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_);
73 // we need to negate it too
74 $cust_amount = -$cust_amount;
76 $trans_no = write_customer_trans($trans_type, 0, $person_id, $person_detail_id, $date_,
80 elseif ($person_type_id == payment_person_types::supplier())
82 // we need to add a supplier transaction record
83 // convert to supp currency
84 $supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
86 // we need to negate it too
87 $supp_amount = -$supp_amount;
89 $trans_no = add_supp_trans($trans_type, $person_id, $date_, '',
90 $ref, "", $supp_amount, 0, 0);
95 $trans_no = get_next_trans_no($trans_type);
98 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
99 $date_, $type, -$total_amount,
100 $person_type_id, $person_id,
102 "Cannot insert a source bank transaction");
104 foreach ($items->gl_items as $gl_item)
106 $is_bank_to = is_bank_account($gl_item->code_id);
108 if ($trans_type == 1 AND $is_bank_to)
110 // we don't allow payments to go to a bank account. use transfer for this !
111 display_db_error("invalid payment entered. Cannot pay to another bank account", "");
114 // do the destination account postings
115 $total += add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
116 $gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
117 $gl_item->amount, $currency, $person_type_id, $person_id);
121 add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
122 $date_, $type, $gl_item->amount,
123 $person_type_id, $person_id, $currency,
124 "Cannot insert a destination bank transaction");
128 // do the source account postings
129 add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
130 -$total, null, $person_type_id, $person_id);
132 add_comments($trans_type, $trans_no, $date_, $memo_);
134 references::save_last($ref, $trans_type);
136 commit_transaction();
138 return array($trans_type, $trans_no);
141 //----------------------------------------------------------------------------------------