Customer Payment, Supplier Payment: early discount support.
[fa-stable.git] / sales / includes / sales_db.inc
index 6cad00f183dfdf7fcb5d1e87d44b90a042674f6c..348d69fd1bb0022cb1451c0374c56000ab35708e 100644 (file)
@@ -388,10 +388,15 @@ function write_sales_trans($cart, $policy = 0)
 }
 
 function save_cust_payment($cart, $customer_id, $branch_id,
-               $bank_account, $trans_date, $ref, $amount, $discount, $memo, $charge, $bank_amount)
+               $bank_account, $trans_date, $ref, $amount, $memo, $charge, $bank_amount)
 {
        begin_transaction(__FUNCTION__, func_get_args());
 
+       $discount = 0;
+       foreach($cart->allocs as $alloc)
+               if ($alloc->discount_confirmed)
+                       $discount += $alloc->early_discount*$alloc->amount;
+
        $payment_no = write_customer_payment($cart->trans_no, $customer_id, $branch_id,
                $bank_account, $trans_date, $ref, $amount, $discount, $memo, 0, $charge, $bank_amount);