Customer Payment, Supplier Payment: early discount support.
[fa-stable.git] / purchasing / includes / purchasing_db.inc
index f7fe7a5d5115d83bd9b1666779ea23f8c4610ca5..fa8b3a497c392a2374938c4181708d9ab4a88b9e 100644 (file)
@@ -262,3 +262,24 @@ function write_supp_allocation($cart)
        return $result;
 }
 
+function save_supp_payment($cart, $supplier_id, $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_supp_payment($cart->trans_no, $supplier_id, $bank_account, $trans_date, $ref, $amount,
+               $discount, $memo, $charge, $bank_amount);
+
+       $cart->trans_no = $payment_no;
+       $cart->date_ = $trans_date;
+       $cart->write();
+
+       commit_transaction();
+
+       return $payment_no;
+}
+