SELECT
	o.id as `Order ID`,
	o.number as `Order Number`,
	COALESCE(m.modname,'None') AS `Payment Gateway`,
	o.client_id AS `Client ID`,
	ca.email AS `Client Email`,
	CONCAT(cd.firstname,' ',cd.lastname) AS `Client`,
	hb_currency(o.total) AS `Order Total`,
	o.order_ip AS `Order IP`,
	hb_date(o.date_created) AS `Order Date`,
	o.status AS `Current Status`,
	COALESCE(cp.code,'None') AS `Promotional Coupon`,
	COALESCE(clog.discount,'0.00') AS `Discount`


FROM
	hb_orders o JOIN
	hb_modules_configuration m ON (m.id=o.payment_module) JOIN
	hb_client_details cd ON (cd.id = o.client_id) JOIN
	hb_client_access ca ON (ca.id=cd.id) LEFT JOIN
	hb_coupons_log clog ON (clog.order_id=o.id) LEFT JOIN
	hb_coupons cp ON (cp.id=clog.coupon_id)
WHERE
	o.date_created > :date_bottom	  AND
	o.date_created < :date_top


ORDER BY
	o.date_created ASC