Allowed multiply bank accounts on same gl account, removed bank trans type.
[fa-stable.git] / purchasing / includes / db / supp_payment_db.inc
1 <?php
2
3 function add_supp_payment($supplier_id, $date_, $bank_account,
4         $amount, $discount, $ref, $memo_)
5 {
6         begin_transaction();
7
8         $supplier_currency = get_supplier_currency($supplier_id);
9     $bank_account_currency = get_bank_account_currency($bank_account);
10         $bank_gl_account = get_bank_gl_account($bank_account);
11
12         $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
13         $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
14
15         // it's a supplier payment
16         $trans_type = 22;
17
18         /* Create a supp_trans entry for the supplier payment */
19         $payment_id = add_supp_trans($trans_type, $supplier_id, $date_, $date_,
20                 $ref, "", -$supp_amount, 0, -$supp_discount);
21
22         // Now debit creditors account with payment + discount
23
24     $supplier_accounts = get_supplier_accounts($supplier_id);
25
26         add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
27                 $supp_amount + $supp_discount, $supplier_id);
28
29         // Now credit discount received account with discounts
30         if ($supp_discount != 0)
31         {
32                 add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
33                         -$supp_discount, $supplier_id);
34         }
35
36         if ($supp_amount != 0)
37         {
38                 add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
39                         -$supp_amount, $supplier_id);
40         }
41
42    /*now enter the bank_trans entry */
43         add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
44                 $date_, -($amount), payment_person_types::supplier(),
45                 $supplier_id, $bank_account_currency,
46                 "Could not add the supplier payment bank transaction");
47
48         add_comments($trans_type, $payment_id, $date_, $memo_);
49
50         references::save_last($ref, $trans_type);
51
52         commit_transaction();
53
54         return $payment_id;
55 }
56
57 //------------------------------------------------------------------------------------------------
58
59 function void_supp_payment($type, $type_no)
60 {
61         begin_transaction();
62
63         void_bank_trans($type, $type_no, true);
64         void_gl_trans($type, $type_no, true);
65         void_supp_allocations($type, $type_no);
66         void_supp_trans($type, $type_no);
67
68         commit_transaction();
69 }
70
71
72 ?>