Added missing field for bank charges in bank_trans, rewritten bank transaction views...
[fa-stable.git] / sales / includes / db / payment_db.inc
index 873e8389784a69e55b2a8d9e1f591a592122df87..18ede1c6fa6f7f161d51508077d555f3a2f414cf 100644 (file)
@@ -25,7 +25,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args(); while (count($args) < 12) $args[] = 0;
        $args = (object)array_combine(array('trans_no', 'customer_id', 'branch_id', 'bank_account', 
                'date_', 'ref', 'amount', 'discount', 'memo_','rate','charge', 'bank_amount'), $args);
@@ -34,10 +34,10 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
        $company_record = get_company_prefs();
 
        if ($trans_no != 0) {
-         delete_comments(ST_CUSTPAYMENT, $trans_no);
-         void_bank_trans(ST_CUSTPAYMENT, $trans_no, true);
-         void_gl_trans(ST_CUSTPAYMENT, $trans_no, true);
-         void_cust_allocations(ST_CUSTPAYMENT, $trans_no, $date_);
+               delete_comments(ST_CUSTPAYMENT, $trans_no);
+               void_bank_trans(ST_CUSTPAYMENT, $trans_no, true);
+               void_gl_trans(ST_CUSTPAYMENT, $trans_no, true);
+               void_cust_allocations(ST_CUSTPAYMENT, $trans_no, $date_);
        }
 
        $bank = get_bank_account($bank_account);
@@ -78,19 +78,17 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
        if (($discount + $amount) != 0) {
        /* Now Credit Debtors account with receipts + discounts */
        $total += add_gl_trans_customer(ST_CUSTPAYMENT, $payment_no, $date_,
-               $debtors_account, 0, 0, -($discount + $amount), $customer_id,
-               "Cannot insert a GL transaction for the debtors account credit");
+               $debtors_account, 0, 0, -($discount + $amount), $customer_id);
        }
        if ($discount != 0)     {
                /* Now Debit discount account with discounts allowed*/
                $total += add_gl_trans_customer(ST_CUSTPAYMENT, $payment_no, $date_,
-                       $discount_account, 0, 0, $discount, $customer_id,
-                       "Cannot insert a GL transaction for the payment discount debit");
+                       $discount_account, 0, 0, $discount, $customer_id);
        }
 
        if ($charge != 0)       {
                /* Now Debit bank charge account with charges */
-               $charge_act = get_company_pref('bank_charge_act');
+               $charge_act = get_bank_charge_account($bank_account);
                $total += add_gl_trans(ST_CUSTPAYMENT, $payment_no, $date_,     $charge_act, 0, 0, '', 
                        $charge, $bank['bank_curr_code'], PT_CUSTOMER,  $customer_id);
        }
@@ -106,7 +104,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
        /*now enter the bank_trans entry */
        add_bank_trans(ST_CUSTPAYMENT, $payment_no, $bank_account, $ref,
-               $date_, $bank_amount - $charge, PT_CUSTOMER, $customer_id);
+               $date_, $bank_amount, -$charge, PT_CUSTOMER, $customer_id);
 
        add_comments(ST_CUSTPAYMENT, $payment_no, $date_, $memo_);
 
@@ -123,7 +121,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
 function void_customer_payment($type, $type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        hook_db_prevoid($type, $type_no);
        void_bank_trans($type, $type_no, true);
@@ -134,5 +132,3 @@ function void_customer_payment($type, $type_no)
        commit_transaction();
 }
 
-
-?>
\ No newline at end of file