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