3 function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
4 $amount, $discount, $ref, $memo_, $rate=0)
8 $supplier_currency = get_supplier_currency($supplier_id);
9 $bank_account_currency = get_bank_account_currency($bank_account);
13 $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
14 $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
18 $supp_amount = round($amount / $rate, user_price_dec());
19 $supp_discount = round($discount / $rate, user_price_dec());
23 // it's a supplier payment
26 /* Create a supp_trans entry for the supplier payment */
27 $payment_id = add_supp_trans($trans_type, $supplier_id, $date_, $date_,
28 $ref, "", -$supp_amount, 0, -$supp_discount, "", $rate);
30 // Now debit creditors account with payment + discount
33 $supplier_accounts = get_supplier_accounts($supplier_id);
35 // Now credit discount received account with discounts
36 if ($supp_discount != 0)
38 $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
39 -$supp_discount, $supplier_id, "", $rate);
42 if ($supp_amount != 0)
44 $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
45 -$supp_amount, $supplier_id, "", $rate);
48 $total += add_gl_trans($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0, "",
49 -$total, null, payment_person_types::supplier(), $supplier_id,
50 "The general ledger transaction for the control total could not be added");
52 /*Post a balance post if $total != 0 */
53 add_gl_balance($trans_type, $payment_id, $date_, -$total, payment_person_types::supplier(), $supplier_id);
55 /*now enter the bank_trans entry */
56 add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
57 $date_, $payment_type, -($amount), payment_person_types::supplier(),
58 $supplier_id, $bank_account_currency,
59 "Could not add the supplier payment bank transaction");
61 add_comments($trans_type, $payment_id, $date_, $memo_);
63 references::save_last($ref, $trans_type);
70 //------------------------------------------------------------------------------------------------
72 function void_supp_payment($type, $type_no)
76 void_bank_trans($type, $type_no, true);
77 void_gl_trans($type, $type_no, true);
78 void_supp_allocations($type, $type_no);
79 void_supp_trans($type, $type_no);