Icons removed form form buttons for now.
[fa-stable.git] / sales / includes / db / payment_db.inc
1 <?php
2 /*
3   Write/update customer payment.
4 */
5 function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_account,
6         $date_, $ref, $amount, $discount, $memo_, $rate=0)
7 {
8         begin_transaction();
9
10         $company_record = get_company_prefs();
11
12         $payment_no = write_customer_trans(12, $trans_no, $customer_id, $branch_id, 
13                 $date_, $ref, $amount, $discount, 0, 0, 0, 0, 0, 0, 0, "", 0, $rate);
14
15         $bank_gl_account = get_bank_gl_account($bank_account);
16
17         if ($trans_no != 0) {
18           delete_comments(12, $trans_no);
19           void_bank_trans(12, $trans_no, true);
20           void_gl_trans(12, $trans_no, true);
21           void_cust_allocations(12, $trans_no, $date_);
22         }
23         $total = 0;
24         /* Bank account entry first */
25         $total += add_gl_trans_customer(12, $payment_no, $date_,
26                 $bank_gl_account, 0, 0, $amount,  $customer_id,
27                 "Cannot insert a GL transaction for the bank account debit", $rate);
28
29         if ($branch_id != reserved_words::get_any_numeric()) {
30
31                 $branch_data = get_branch_accounts($branch_id);
32
33                 $debtors_account = $branch_data["receivables_account"];
34                 $discount_account = $branch_data["payment_discount_account"];
35
36         } else {
37                 $debtors_account = $company_record["debtors_act"];
38                 $discount_account = $company_record["default_prompt_payment_act"];
39         }
40
41         if (($discount + $amount) != 0) {
42                 /* Now Credit Debtors account with receipts + discounts */
43                 $total += add_gl_trans_customer(12, $payment_no, $date_,
44                         $debtors_account, 0, 0, -($discount + $amount), $customer_id,
45                         "Cannot insert a GL transaction for the debtors account credit", $rate);
46         }
47         if ($discount != 0)     {
48                 /* Now Debit discount account with discounts allowed*/
49                 $total += add_gl_trans_customer(12, $payment_no, $date_,
50                         $discount_account, 0, 0, $discount, $customer_id,
51                         "Cannot insert a GL transaction for the payment discount debit", $rate);
52         }
53
54         /*Post a balance post if $total != 0 */
55         add_gl_balance(12, $payment_no, $date_, -$total, payment_person_types::customer(), $customer_id);       
56
57         /*now enter the bank_trans entry */
58         add_bank_trans(12, $payment_no, $bank_account, $ref,
59                 $date_, $amount, payment_person_types::customer(), $customer_id,
60                 get_customer_currency($customer_id));
61
62         add_comments(12, $payment_no, $date_, $memo_);
63
64         references::save_last($ref, 12);
65
66         commit_transaction();
67
68         return $payment_no;
69 }
70
71 //-------------------------------------------------------------------------------------------------
72
73 function void_customer_payment($type, $type_no)
74 {
75         begin_transaction();
76
77         void_bank_trans($type, $type_no, true);
78         void_gl_trans($type, $type_no, true);
79         void_cust_allocations($type, $type_no);
80         void_customer_trans($type, $type_no);
81
82         commit_transaction();
83 }
84
85
86 ?>