Supplier Inquiry/Customer Inquiry: removed inconsistency in unsettled/overdue transac...
[fa-stable.git] / purchasing / includes / db / suppliers_db.inc
index e0a1515042ac1f8cf6262cb93715428e953fa137..c031cede6d186e36703592b81dce2819e7f8ef9b 100644 (file)
@@ -92,9 +92,9 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
        $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
     else       
        $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT."
-       OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0),
-               (trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc),
-               (trans.ov_amount + trans.ov_gst + trans.ov_discount + trans.alloc))";
+       OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0), 1, -1)*
+               ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc)";
+
        $due = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_SUPPCREDIT.",trans.due_date,trans.tran_date)";
     $sql = "SELECT supp.supp_name, supp.curr_code, ".TB_PREF."payment_terms.terms,