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_);
71 $trans_no = add_customer_trans($trans_type, $person_id, $person_detail_id, $date_,
75 elseif ($person_type_id == payment_person_types::supplier())
77 // we need to add a supplier transaction record
78 // convert to supp currency
79 $supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
81 // we need to negate it too
82 $supp_amount = -$supp_amount;
84 $trans_no = add_supp_trans($trans_type, $person_id, $date_, '',
85 $ref, "", $supp_amount, 0, 0);
90 $trans_no = get_next_trans_no($trans_type);
93 // do the source account postings
94 add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
95 -$total_amount, $currency, $person_type_id, $person_id);
97 add_bank_trans($trans_type, $trans_no, $from_account, $ref,
98 $date_, $type, -$total_amount,
99 $person_type_id, $person_id,
101 "Cannot insert a source bank transaction");
103 foreach ($items->gl_items as $gl_item)
105 $is_bank_to = is_bank_account($gl_item->code_id);
107 if ($trans_type == 1 AND $is_bank_to)
109 // we don't allow payments to go to a bank account. use transfer for this !
110 display_db_error("invalid payment entered. Cannot pay to another bank account", "");
113 // do the destination account postings
114 add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
115 $gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
116 $gl_item->amount, $currency, $person_type_id, $person_id);
120 add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
121 $date_, $type, $gl_item->amount,
122 $person_type_id, $person_id, $currency,
123 "Cannot insert a destination bank transaction");
127 add_comments($trans_type, $trans_no, $date_, $memo_);
129 references::save_last($ref, $trans_type);
131 commit_transaction();
133 return array($trans_type, $trans_no);
136 //----------------------------------------------------------------------------------------
138 function add_bank_payment($from_account, $items, $date_,
139 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
141 return add_bank_transaction(systypes::bank_payment(), $from_account, $items, $date_,
142 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_);
145 //---------------------------------------------------------------------------------------------
147 function add_bank_deposit($from_account, $items, $date_,
148 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
150 return add_bank_transaction(systypes::bank_deposit(), $from_account, $items, $date_,
151 $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_);
154 //---------------------------------------------------------------------------------------------