3 //----------------------------------------------------------------------------------
4 // Add bank tranfer to database.
6 // $from_account - source bank account id
7 // $to_account - target bank account id
9 function add_bank_transfer($from_account, $to_account, $date_,
10 $amount, $ref, $memo_)
14 $trans_type = systypes::bank_transfer();
16 $currency = get_bank_account_currency($from_account);
18 $trans_no = get_next_trans_no($trans_type);
20 $from_gl_account = get_bank_gl_account($from_account);
21 $to_gl_account = get_bank_gl_account($to_account);
23 // do the source account postings
24 add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
27 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
29 payment_person_types::misc(), "", $currency,
30 "Cannot insert a source bank transaction");
32 // do the destination account postings
33 add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
36 add_bank_trans($trans_type, $trans_no, $to_account, $ref,
37 $date_, $amount, payment_person_types::misc(), "",
38 $currency, "Cannot insert a destination bank transaction");
40 add_comments($trans_type, $trans_no, $date_, $memo_);
42 references::save_last($ref, $trans_type);
49 //----------------------------------------------------------------------------------
50 // Add bank payment or deposit to database.
52 // $from_account - bank account id
53 // $item - transaction cart (line item's amounts in bank account's currency)
54 // $person_type_id - defines type of $person_id identifiers
55 // $person_id - supplier/customer/other id
56 // $person_detail_id - customer branch id or not used
58 // returns an array of (inserted trans type, trans no)
60 function add_bank_transaction($trans_type, $from_account, $items, $date_,
61 $person_type_id, $person_id, $person_detail_id, $ref, $memo_)
63 // we can only handle type 1 (payment)and type 2 (deposit)
64 if ($trans_type != systypes::bank_payment() && $trans_type != systypes::bank_deposit())
65 display_db_error("Invalid type ($trans_type) sent to add_bank_transaction");
69 $currency = get_bank_account_currency($from_account);
70 $bank_gl_account = get_bank_gl_account($from_account);
72 // the gl items are already inversed/negated for type 2 (deposit)
73 $total_amount = $items->gl_items_total();
75 if ($person_type_id == payment_person_types::customer())
77 // we need to add a customer transaction record
79 // convert to customer currency
80 $cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_);
81 // we need to negate it too
82 $cust_amount = -$cust_amount;
84 $trans_no = write_customer_trans($trans_type, 0, $person_id, $person_detail_id, $date_,
88 elseif ($person_type_id == payment_person_types::supplier())
90 // we need to add a supplier transaction record
91 // convert to supp currency
92 $supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
94 // we need to negate it too
95 $supp_amount = -$supp_amount;
97 $trans_no = add_supp_trans($trans_type, $person_id, $date_, '',
98 $ref, "", $supp_amount, 0, 0);
103 $trans_no = get_next_trans_no($trans_type);
106 // do the source account postings
107 add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, 0, 0, "",
108 -$total_amount, $currency, $person_type_id, $person_id);
110 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
111 $date_, -$total_amount, $person_type_id, $person_id,
112 $currency, "Cannot insert a source bank transaction");
114 foreach ($items->gl_items as $gl_item)
116 $is_bank_to = is_bank_account($gl_item->code_id);
118 if ($trans_type == 1 AND $is_bank_to)
120 // we don't allow payments to go to a bank account. use transfer for this !
121 display_db_error("invalid payment entered. Cannot pay to another bank account", "");
124 // do the destination account postings
125 add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
126 $gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
127 $gl_item->amount, $currency, $person_type_id, $person_id);
131 add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
132 $date_, $gl_item->amount, $person_type_id, $person_id,
133 $currency, "Cannot insert a destination bank transaction");
137 add_comments($trans_type, $trans_no, $date_, $memo_);
139 references::save_last($ref, $trans_type);
141 commit_transaction();
143 return array($trans_type, $trans_no);
146 //----------------------------------------------------------------------------------------