- $sql = "SELECT SUM(IF(t.type = ".ST_SALESINVOICE.",
- (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount)";
- if ($convert)
- $sql .= " * rate";
- $sql .= ", 0)) AS charges,
- SUM(IF(t.type <> ".ST_SALESINVOICE.",
- (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount)";
- if ($convert)
- $sql .= " * rate";
- $sql .= " * -1, 0)) AS credits,
- SUM(t.alloc";
- if ($convert)
- $sql .= " * rate";
- $sql .= ") AS Allocated,
- SUM(IF(t.type = ".ST_SALESINVOICE.",
- (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount - t.alloc)";
- if ($convert)
- $sql .= " * rate";
- $sql .= ",
- ((t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount) * -1 + t.alloc)";
- if ($convert)
- $sql .= " * rate";
- $sql .= ")) AS OutStanding
+ $sql = "SELECT SUM(IF(t.type = ".ST_SALESINVOICE." OR t.type = ".ST_BANKPAYMENT.",
+ (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount), 0)) AS charges,
+ SUM(IF(t.type <> ".ST_SALESINVOICE." AND t.type <> ".ST_BANKPAYMENT.",
+ (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount) * -1, 0)) AS credits,
+ SUM(IF(t.type <> ".ST_SALESINVOICE." AND t.type <> ".ST_BANKPAYMENT.",t.alloc * -1, t.alloc)) AS Allocated,
+ SUM(IF(t.type = ".ST_SALESINVOICE." OR t.type = ".ST_BANKPAYMENT.",
+ (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount - t.alloc),
+ ((t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount) * -1 + t.alloc))) AS OutStanding