- $sql = "SELECT SUM(IF(".TB_PREF."supp_trans.type = ".ST_SUPPINVOICE.", (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst +
- ".TB_PREF."supp_trans.ov_discount)";
- if ($convert)
- $sql .= " * rate";
- $sql .= ", 0)) AS charges,
- SUM(IF(".TB_PREF."supp_trans.type <> ".ST_SUPPINVOICE.", (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst +
- ".TB_PREF."supp_trans.ov_discount)";
- if ($convert)
- $sql .= "* rate";
- $sql .= ", 0)) AS credits,
- SUM(".TB_PREF."supp_trans.alloc";
- if ($convert)
- $sql .= " * rate";
- $sql .= ") AS Allocated,
- SUM((".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst +
- ".TB_PREF."supp_trans.ov_discount - ".TB_PREF."supp_trans.alloc)";
- if ($convert)
- $sql .= " * rate";
- $sql .= ") AS OutStanding
+ $sql = "SELECT
+ SUM(IF(type IN(".ST_SUPPINVOICE.",".ST_BANKDEPOSIT."), (ov_amount + ov_gst + ov_discount), 0)) AS charges,
+ SUM(IF(type NOT IN(".ST_SUPPINVOICE.",".ST_BANKDEPOSIT."), (ov_amount + ov_gst + ov_discount), 0)) AS credits,
+ SUM(IF(type NOT IN(".ST_SUPPINVOICE.",".ST_BANKDEPOSIT."),alloc * -1, alloc)) AS Allocated,
+ SUM(IF(type IN(".ST_SUPPINVOICE.",".ST_BANKDEPOSIT."), (ov_amount + ov_gst + ov_discount - alloc),
+ (ov_amount + ov_gst + ov_discount + alloc))) AS OutStanding