X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fdb%2Fcustalloc_db.inc;h=88e867459cad62b09bdf404c6563012066b0f5fe;hb=65c68ebb3a09aa06418fb7f5e1712ca8012d756f;hp=0a1c78f251123cfdfcb7c0e62d90f0be3dd43d42;hpb=da8311619dd73feae101d246a1957b972e00cbd2;p=fa-stable.git diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index 0a1c78f2..88e86745 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -26,7 +26,8 @@ function delete_cust_allocation($trans_id) function get_DebtorTrans_allocation_balance($trans_type, $trans_no) { - $sql = "SELECT (ov_amount+ov_gst+ov_freight-ov_discount-alloc) AS BalToAllocate + + $sql = "SELECT (ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc) AS BalToAllocate FROM ".TB_PREF."debtor_trans WHERE trans_no=$trans_no AND type=$trans_type"; $result = db_query($sql,"calculate the allocation"); $myrow = db_fetch_row($result); @@ -84,15 +85,14 @@ function get_allocatable_from_cust_transactions($customer_id, $settled) $settled_sql = ""; if (!$settled) { - $settled_sql = " AND round(ABS(ov_amount+ov_gst+ov_freight+ov_discount)-alloc,6) > 0"; + $settled_sql = " AND (round(ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc,6) > 0)"; } - $cust_sql = ""; if ($customer_id != null) - $cust_sql = " AND ".TB_PREF."debtor_trans.debtor_no = $customer_id"; + $cust_sql = " AND ".TB_PREF."debtor_trans.debtor_no = $customer_id"; - return get_customer_transactions("round(ABS(ov_amount+ov_gst+ov_freight+ov_discount)-alloc,6) <= 0 AS settled", - "(type=" . systypes::cust_payment(). " OR type=11 OR type=2) AND (".TB_PREF."debtor_trans.ov_amount < 0) " . $settled_sql . $cust_sql); + return get_customer_transactions("round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) <= 0 AS settled", + "(type=12 OR type=11) AND (".TB_PREF."debtor_trans.ov_amount > 0) " . $settled_sql . $cust_sql); } //------------------------------------------------------------------------------------------------------------- @@ -110,8 +110,9 @@ function get_allocatable_to_cust_transactions($customer_id, $trans_no=null, $typ } else { - return get_customer_transactions(null, "round(ABS(ov_amount+ov_gst+ov_freight+ov_discount)-alloc,6) > 0 + return get_customer_transactions(null, "round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) > 0 AND ".TB_PREF."debtor_trans.type != " . systypes::cust_payment() . " + AND ".TB_PREF."debtor_trans.type != 13 AND ".TB_PREF."debtor_trans.debtor_no=$customer_id"); } }