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);
16 // do the source account postings
17 add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
20 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
21 $date_, $payment_type, -$amount,
22 payment_person_types::misc(), "", $currency,
23 "Cannot insert a source bank transaction");
25 // do the destination account postings
26 add_gl_trans($trans_type, $trans_no, $date_, $to_account, 0, 0, "",
29 add_bank_trans($trans_type, $trans_no, $to_account, $ref,
30 $date_, $payment_type, $amount,
31 payment_person_types::misc(), "",
33 "Cannot insert a destination bank transaction");
35 add_comments($trans_type, $trans_no, $date_, $memo_);
37 references::save_last($ref, $trans_type);
44 //----------------------------------------------------------------------------------
46 // $amount is in $from_account's currency
48 // returns an array of (inserted trans type, trans no)
50 function add_bank_transaction($trans_type, $from_account, $items, $date_,
51 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
53 // we can only handle type 1 (payment)and type 2 (deposit)
54 if ($trans_type != systypes::bank_payment() && $trans_type != systypes::bank_deposit())
55 display_db_error("Invalid type ($trans_type) sent to add_bank_transaction");
59 $currency = get_bank_account_currency($from_account);
61 // the gl items are already inversed/negated for type 2 (deposit)
62 $total_amount = $items->gl_items_total();
64 if ($person_type_id == payment_person_types::customer())
66 // we need to add a customer transaction record
68 // convert to customer currency
69 $cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_);
70 // we need to negate it too
71 $cust_amount = -$cust_amount;
73 $trans_no = write_customer_trans($trans_type, 0, $person_id, $person_detail_id, $date_,
77 elseif ($person_type_id == payment_person_types::supplier())
79 // we need to add a supplier transaction record
80 // convert to supp currency
81 $supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
83 // we need to negate it too
84 $supp_amount = -$supp_amount;
86 $trans_no = add_supp_trans($trans_type, $person_id, $date_, '',
87 $ref, "", $supp_amount, 0, 0);
92 $trans_no = get_next_trans_no($trans_type);
95 // do the source account postings
96 add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
97 -$total_amount, $currency, $person_type_id, $person_id);
99 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
100 $date_, $type, -$total_amount,
101 $person_type_id, $person_id,
103 "Cannot insert a source bank transaction");
105 foreach ($items->gl_items as $gl_item)
107 $is_bank_to = is_bank_account($gl_item->code_id);
109 if ($trans_type == 1 AND $is_bank_to)
111 // we don't allow payments to go to a bank account. use transfer for this !
112 display_db_error("invalid payment entered. Cannot pay to another bank account", "");
115 // do the destination account postings
116 add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
117 $gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
118 $gl_item->amount, $currency, $person_type_id, $person_id);
122 add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
123 $date_, $type, $gl_item->amount,
124 $person_type_id, $person_id, $currency,
125 "Cannot insert a destination bank transaction");
129 add_comments($trans_type, $trans_no, $date_, $memo_);
131 references::save_last($ref, $trans_type);
133 commit_transaction();
135 return array($trans_type, $trans_no);
138 //----------------------------------------------------------------------------------------
140 function add_bank_payment($from_account, $items, $date_,
141 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
143 return add_bank_transaction(systypes::bank_payment(), $from_account, $items, $date_,
144 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_);
147 //---------------------------------------------------------------------------------------------
149 function add_bank_deposit($from_account, $items, $date_,
150 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
152 return add_bank_transaction(systypes::bank_deposit(), $from_account, $items, $date_,
153 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_);
156 //---------------------------------------------------------------------------------------------