- $sql .= " AND round(IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0
- AND trans.type NOT IN (".implode(',',array(ST_CUSTPAYMENT,ST_BANKDEPOSIT,ST_CUSTCREDIT,ST_CUSTDELIVERY)).")";
+ $sql .= "
+ AND (
+ trans.type='".ST_SALESINVOICE."'
+ AND round(IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0
+ OR
+ trans.type='". ST_CUSTCREDIT."'
+ AND round(-IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0
+ OR
+ trans.type = '". ST_JOURNAL."'
+ AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0
+ OR
+ trans.type = '". ST_BANKPAYMENT."'
+ AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0
+ )";