debtor.name,
branch.br_name,
debtor.curr_code,
- IF(prep_amount, prep_amount, trans.ov_amount + trans.ov_gst + trans.ov_freight
+ IF(prep_amount, prep_amount, abs(trans.ov_amount) + trans.ov_gst + trans.ov_freight
+ trans.ov_freight_tax + trans.ov_discount) AS TotalAmount,"
// if ($filter != ALL_TEXT)
// $sql .= "@bal := @bal+IF(prep_amount, prep_amount, trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount), ";
trans.due_date,
debtor.address,
trans.version,
- round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) <= 0 AS settled,
+ round(abs(ov_amount)+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) <= 0 AS settled,
trans.debtor_no
FROM "
." WHERE trans.debtor_no=debtor.debtor_no
AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount > 0))
OR (type=".ST_CUSTCREDIT. " AND (ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)>0)
- OR (type=".ST_JOURNAL. " AND (trans.ov_amount > 0)))";
+ OR (type=".ST_JOURNAL. " AND (trans.ov_amount < 0)))";
if (!$settled)
- $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) > 0)";
+ $sql .= " AND round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc, 6) > 0";
if ($customer_id != null)
$sql .= " AND trans.debtor_no = ".db_escape($customer_id);
}
else
{
- $sql .= " AND round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) > 0
+ $sql .= " AND round(abs(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 .= " GROUP BY type, trans_no";
}
function fmt_amount($row)
{
$value =
- $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ?
+ $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT || $row['type']==ST_JOURNAL ?
-$row["TotalAmount"] : $row["TotalAmount"];
return price_format($value);
}