+ if($to)
+ $to = date2sql($to);
+
+ $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
+ FROM ".TB_PREF."debtor_trans t
+ WHERE t.debtor_no = ".db_escape($debtorno)
+ ." AND t.type <> ".ST_CUSTDELIVERY;
+ if ($to)
+ $sql .= " AND t.tran_date < '$to'";
+ $sql .= " GROUP BY debtor_no";
+
+ $result = db_query($sql,"No transactions were returned");
+ return db_fetch($result);
+}
+
+function get_transactions($debtorno, $from, $to)
+{
+ $from = date2sql($from);
+ $to = date2sql($to);