config->get('config_language_id') . "'"; if (!empty($data['filter_date_start'])) { $sql .= " AND DATE(ct.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')"; } if (!empty($data['filter_date_end'])) { $sql .= " AND DATE(ct.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')"; } if (!empty($data['filter_customer'])) { $sql .= " AND CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'"; } $sql .= " GROUP BY ct.`customer_id` ORDER BY total DESC"; if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; } $query = $this->db->query($sql); return $query->rows; } /** * @param array $data * * @return int */ public function getTotalTransactions(array $data = []): int { $sql = "SELECT COUNT(DISTINCT ct.`customer_id`) AS `total` FROM `" . DB_PREFIX . "customer_transaction` ct LEFT JOIN `" . DB_PREFIX . "customer` c ON (ct.`customer_id` = c.`customer_id`)"; $implode = []; if (!empty($data['filter_date_start'])) { $implode[] = "DATE(ct.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')"; } if (!empty($data['filter_date_end'])) { $implode[] = "DATE(ct.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')"; } if (!empty($data['filter_customer'])) { $implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'"; } if ($implode) { $sql .= " WHERE " . implode(" AND ", $implode); } $query = $this->db->query($sql); return (int)$query->row['total']; } }