first commit
This commit is contained in:
17
extension/opencart/admin/model/report/activity.php
Normal file
17
extension/opencart/admin/model/report/activity.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Activity
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class Activity extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getActivities(): array {
|
||||
$query = $this->db->query("SELECT `key`, `data`, `date_added` FROM `" . DB_PREFIX . "customer_activity` ORDER BY `date_added` DESC LIMIT 0,5");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
76
extension/opencart/admin/model/report/coupon.php
Normal file
76
extension/opencart/admin/model/report/coupon.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCoupons(array $data = []): array {
|
||||
$sql = "SELECT ch.`coupon_id`, c.`name`, c.`code`, COUNT(DISTINCT ch.`order_id`) AS orders, SUM(ch.`amount`) AS `total` FROM `" . DB_PREFIX . "coupon_history` ch LEFT JOIN `" . DB_PREFIX . "coupon` c ON (ch.`coupon_id` = c.`coupon_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(ch.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(ch.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY ch.`coupon_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 getTotalCoupons(array $data = []): int {
|
||||
$sql = "SELECT COUNT(DISTINCT `coupon_id`) AS `total` FROM `" . DB_PREFIX . "coupon_history`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
546
extension/opencart/admin/model/report/customer.php
Normal file
546
extension/opencart/admin/model/report/customer.php
Normal file
@ -0,0 +1,546 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class Customer extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalCustomersByDay(): array {
|
||||
$customer_data = [];
|
||||
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
$customer_data[$i] = [
|
||||
'hour' => $i,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total`, HOUR(`date_added`) AS `hour` FROM `" . DB_PREFIX . "customer` WHERE DATE(`date_added`) = DATE(NOW()) GROUP BY HOUR(`date_added`) ORDER BY `date_added` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$customer_data[$result['hour']] = [
|
||||
'hour' => $result['hour'],
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $customer_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalCustomersByWeek(): array {
|
||||
$customer_data = [];
|
||||
|
||||
$date_start = strtotime('-' . date('w') . ' days');
|
||||
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$date = date('Y-m-d', $date_start + ($i * 86400));
|
||||
|
||||
$customer_data[date('w', strtotime($date))] = [
|
||||
'day' => date('D', strtotime($date)),
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total`, `date_added` FROM `" . DB_PREFIX . "customer` WHERE DATE(`date_added`) >= DATE('" . $this->db->escape(date('Y-m-d', $date_start)) . "') GROUP BY DAYNAME(`date_added`)");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$customer_data[date('w', strtotime($result['date_added']))] = [
|
||||
'day' => date('D', strtotime($result['date_added'])),
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $customer_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalCustomersByMonth(): array {
|
||||
$customer_data = [];
|
||||
|
||||
for ($i = 1; $i <= date('t'); $i++) {
|
||||
$date = date('Y') . '-' . date('m') . '-' . $i;
|
||||
|
||||
$customer_data[date('j', strtotime($date))] = [
|
||||
'day' => date('d', strtotime($date)),
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total`, `date_added` FROM `" . DB_PREFIX . "customer` WHERE DATE(`date_added`) >= DATE('" . $this->db->escape(date('Y') . '-' . date('m') . '-1') . "') GROUP BY DATE(`date_added`)");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$customer_data[date('j', strtotime($result['date_added']))] = [
|
||||
'day' => date('d', strtotime($result['date_added'])),
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $customer_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalCustomersByYear(): array {
|
||||
$customer_data = [];
|
||||
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$customer_data[$i] = [
|
||||
'month' => date('M', mktime(0, 0, 0, $i, 1)),
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total`, `date_added` FROM `" . DB_PREFIX . "customer` WHERE YEAR(`date_added`) = YEAR(NOW()) GROUP BY MONTH(`date_added`)");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$customer_data[date('n', strtotime($result['date_added']))] = [
|
||||
'month' => date('M', strtotime($result['date_added'])),
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $customer_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomers(array $data = []): array {
|
||||
$sql = "SELECT MIN(`date_added`) AS `date_start`, MAX(`date_added`) AS `date_end`, COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql .= " GROUP BY YEAR(`date_added`), MONTH(`date_added`), DAY(`date_added`)";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql .= " GROUP BY YEAR(`date_added`), WEEK(`date_added`)";
|
||||
break;
|
||||
case 'month':
|
||||
$sql .= " GROUP BY YEAR(`date_added`), MONTH(`date_added`)";
|
||||
break;
|
||||
case 'year':
|
||||
$sql .= " GROUP BY YEAR(`date_added`)";
|
||||
break;
|
||||
}
|
||||
|
||||
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 getTotalCustomers(array $data = []): int {
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), MONTH(`date_added`), DAY(`date_added`)) AS `total` FROM `" . DB_PREFIX . "customer`";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), WEEK(`date_added`)) AS `total` FROM `" . DB_PREFIX . "customer`";
|
||||
break;
|
||||
case 'month':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), MONTH(`date_added`)) AS `total` FROM `" . DB_PREFIX . "customer`";
|
||||
break;
|
||||
case 'year':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`)) AS `total` FROM `" . DB_PREFIX . "customer`";
|
||||
break;
|
||||
}
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrders(array $data = []): array {
|
||||
$sql = "SELECT c.`customer_id`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `customer`, c.`email`, cgd.`name` AS `customer_group`, c.`status`, o.`order_id`, SUM(op.`quantity`) AS `products`, o.`total` AS `total` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.`order_id` = op.`order_id`) LEFT JOIN `" . DB_PREFIX . "customer` c ON (o.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) WHERE o.`customer_id` > '0' AND cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`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']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND o.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND o.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY o.`order_id`";
|
||||
|
||||
$sql = "SELECT t.`customer_id`, t.`customer`, t.`email`, t.`customer_group`, t.`status`, COUNT(DISTINCT t.`order_id`) AS `orders`, SUM(t.`products`) AS `products`, SUM(t.`total`) AS `total` FROM (" . $sql . ") AS t GROUP BY t.`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 getTotalOrders(array $data = []): int {
|
||||
$sql = "SELECT COUNT(DISTINCT o.`customer_id`) AS `total` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "customer` c ON (o.`customer_id` = c.`customer_id`) WHERE o.`customer_id` > '0'";
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`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']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND o.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND o.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRewardPoints(array $data = []): array {
|
||||
$sql = "SELECT cr.`customer_id`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `customer`, c.`email`, cgd.`name` AS `customer_group`, c.`status`, SUM(cr.`points`) AS `points`, COUNT(o.`order_id`) AS `orders`, SUM(o.`total`) AS `total` FROM `" . DB_PREFIX . "customer_reward` cr LEFT JOIN `" . DB_PREFIX . "customer` c ON (cr.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) LEFT JOIN `" . DB_PREFIX . "order` o ON (cr.`order_id` = o.`order_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(cr.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(cr.`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 cr.`customer_id` ORDER BY `points` 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 getTotalRewardPoints(array $data = []): int {
|
||||
$sql = "SELECT COUNT(DISTINCT cr.`customer_id`) AS `total` FROM `" . DB_PREFIX . "customer_reward` cr LEFT JOIN `" . DB_PREFIX . "customer` c ON (cr.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(cr.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(cr.`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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerActivities(array $data = []): array {
|
||||
$sql = "SELECT ca.`customer_activity_id`, ca.`customer_id`, ca.`key`, ca.`data`, ca.`ip`, ca.`date_added` FROM `" . DB_PREFIX . "customer_activity` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(ca.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(ca.`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 (!empty($data['filter_ip'])) {
|
||||
$implode[] = "ca.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY ca.`date_added` 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 getTotalCustomerActivities(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_activity` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(ca.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(ca.`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 (!empty($data['filter_ip'])) {
|
||||
$implode[] = "ca.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerSearches(array $data = []): array {
|
||||
$sql = "SELECT cs.`customer_id`, cs.`keyword`, cs.`category_id`, cs.`products`, cs.`ip`, cs.`date_added`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `customer` FROM `" . DB_PREFIX . "customer_search` cs LEFT JOIN `" . DB_PREFIX . "customer` c ON (cs.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(cs.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(cs.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "cs.`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "cs.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY cs.`date_added` 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 getTotalCustomerSearches(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_search` cs LEFT JOIN `" . DB_PREFIX . "customer` c ON (cs.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(cs.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(cs.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "cs.`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "cs.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Customer Subscription
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class CustomerSubscription extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(array $data = []): array {
|
||||
$sql = "SELECT `s`.`subscription_id`, `s`.`customer_id`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS customer, c.`email`, cgd.`name` AS customer_group, c.`status`, SUM(st.`amount`) AS `total` FROM `" . DB_PREFIX . "subscription_transaction` st LEFT JOIN `" . DB_PREFIX . "subscription` `s` ON (st.`subscription_id` = `s`.`subscription_id`) LEFT JOIN `" . DB_PREFIX . "customer` c ON (`s`.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(st.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(st.`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 `s`.`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 `s`.`customer_id`) AS `total` FROM `" . DB_PREFIX . "subscription_transaction` st LEFT JOIN `" . DB_PREFIX . "subscription` s ON (st.`subscription_id` = `s`.`subscription_id`) LEFT JOIN `" . DB_PREFIX . "customer` c ON (`s`.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$implode[] = "DATE(st.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$implode[] = "DATE(st.`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'];
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class CustomerTransaction
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class CustomerTransaction extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(array $data = []): array {
|
||||
$sql = "SELECT ct.`customer_id`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS customer, c.`email`, cgd.`name` AS customer_group, c.`status`, SUM(ct.`amount`) AS `total` FROM `" . DB_PREFIX . "customer_transaction` ct LEFT JOIN `" . DB_PREFIX . "customer` c ON (ct.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->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'];
|
||||
}
|
||||
}
|
76
extension/opencart/admin/model/report/marketing.php
Normal file
76
extension/opencart/admin/model/report/marketing.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Marketing
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class Marketing extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMarketing(array $data = []): array {
|
||||
$sql = "SELECT m.`marketing_id`, m.`name` AS campaign, m.`code`, m.`clicks` AS clicks, (SELECT COUNT(DISTINCT `order_id`) FROM `" . DB_PREFIX . "order` o1 WHERE o1.`marketing_id` = m.`marketing_id`";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND o1.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND o1.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o1.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o1.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$sql .= ") AS `orders`, (SELECT SUM(`total`) FROM `" . DB_PREFIX . "order` o2 WHERE o2.`marketing_id` = m.`marketing_id`";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND o2.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND o2.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o2.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o2.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY o2.`marketing_id`) AS `total` FROM `" . DB_PREFIX . "marketing` m ORDER BY m.`date_added` ASC";
|
||||
|
||||
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 getTotalMarketing(array $data = []): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "marketing`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
76
extension/opencart/admin/model/report/product_purchased.php
Normal file
76
extension/opencart/admin/model/report/product_purchased.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class ProductPurchased
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class ProductPurchased extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPurchased(array $data = []): array {
|
||||
$sql = "SELECT op.`name`, op.`model`, SUM(op.`quantity`) AS quantity, SUM((op.`price` + op.`tax`) * op.`quantity`) AS `total` FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.`order_id` = o.`order_id`)";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " WHERE o.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE o.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY op.`product_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 getTotalPurchased(array $data = []): int {
|
||||
$sql = "SELECT COUNT(DISTINCT op.`product_id`) AS `total` FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.`order_id` = o.`order_id`)";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " WHERE o.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE o.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
81
extension/opencart/admin/model/report/product_viewed.php
Normal file
81
extension/opencart/admin/model/report/product_viewed.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class ProductViewed
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class ProductViewed extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "product_viewed` (
|
||||
`product_id` INT(11) NOT NULL,
|
||||
`viewed` INT(11) NOT NULL,
|
||||
PRIMARY KEY (`product_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "product_viewed`");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
* @param int $viewed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReport(int $product_id, int $viewed) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_viewed` SET `product_id` = '" . (int)$product_id . "', `viewed` = '" . (int)$viewed . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewed(int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `product_id`, `viewed` FROM `" . DB_PREFIX . "product_viewed` ORDER BY `viewed` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalViewed(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "product_viewed`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotal(): int {
|
||||
$query = $this->db->query("SELECT SUM(`viewed`) AS `total` FROM `" . DB_PREFIX . "product_viewed`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clear(): void {
|
||||
$this->db->query("TRUNCATE TABLE `" . DB_PREFIX . "product_viewed`");
|
||||
}
|
||||
}
|
116
extension/opencart/admin/model/report/returns.php
Normal file
116
extension/opencart/admin/model/report/returns.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Returns
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class Returns extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturns(array $data = []): array {
|
||||
$sql = "SELECT MIN(r.`date_added`) AS date_start, MAX(r.`date_added`) AS date_end, COUNT(r.`return_id`) AS returns FROM `" . DB_PREFIX . "return` r";
|
||||
|
||||
if (!empty($data['filter_return_status_id'])) {
|
||||
$sql .= " WHERE r.`return_status_id` = '" . (int)$data['filter_return_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE r.`return_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(r.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(r.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if (isset($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql .= " GROUP BY YEAR(r.`date_added`), MONTH(r.`date_added`), DAY(r.`date_added`)";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql .= " GROUP BY YEAR(r.`date_added`), WEEK(r.`date_added`)";
|
||||
break;
|
||||
case 'month':
|
||||
$sql .= " GROUP BY YEAR(r.`date_added`), MONTH(r.`date_added`)";
|
||||
break;
|
||||
case 'year':
|
||||
$sql .= " GROUP BY YEAR(r.`date_added`)";
|
||||
break;
|
||||
}
|
||||
|
||||
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 getTotalReturns(array $data = []): int {
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), MONTH(`date_added`), DAY(`date_added`)) AS `total` FROM `" . DB_PREFIX . "return`";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), WEEK(`date_added`)) AS `total` FROM `" . DB_PREFIX . "return`";
|
||||
break;
|
||||
case 'month':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), MONTH(`date_added`)) AS `total` FROM `" . DB_PREFIX . "return`";
|
||||
break;
|
||||
case 'year':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`)) AS `total` FROM `" . DB_PREFIX . "return`";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($data['filter_return_status_id'])) {
|
||||
$sql .= " WHERE `return_status_id` = '" . (int)$data['filter_return_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE `return_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
494
extension/opencart/admin/model/report/sale.php
Normal file
494
extension/opencart/admin/model/report/sale.php
Normal file
@ -0,0 +1,494 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Extension\Opencart\Report;
|
||||
/**
|
||||
* Class Sale
|
||||
*
|
||||
* @package Opencart\Admin\Model\Extension\Opencart\Report
|
||||
*/
|
||||
class Sale extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTotalSales(array $data = []): float {
|
||||
$sql = "SELECT SUM(`total`) AS `total` FROM `" . DB_PREFIX . "order` WHERE `order_status_id` > '0'";
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(`date_added`) = DATE('" . $this->db->escape((string)$data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (float)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalOrdersByCountry(): array {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total, SUM(o.`total`) AS amount, c.`iso_code_2` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "country` c ON (o.`payment_country_id` = c.`country_id`) WHERE o.`order_status_id` > '0' GROUP BY o.`payment_country_id`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalOrdersByDay(): array {
|
||||
$implode = [];
|
||||
|
||||
foreach ($this->config->get('config_complete_status') as $order_status_id) {
|
||||
$implode[] = "'" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$order_data = [];
|
||||
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
$order_data[$i] = [
|
||||
'hour' => $i,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total, HOUR(`date_added`) AS hour FROM `" . DB_PREFIX . "order` WHERE `order_status_id` IN(" . implode(",", $implode) . ") AND DATE(`date_added`) = DATE(NOW()) GROUP BY HOUR(`date_added`) ORDER BY `date_added` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$order_data[$result['hour']] = [
|
||||
'hour' => $result['hour'],
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalOrdersByWeek(): array {
|
||||
$implode = [];
|
||||
|
||||
foreach ($this->config->get('config_complete_status') as $order_status_id) {
|
||||
$implode[] = "'" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$order_data = [];
|
||||
|
||||
$date_start = strtotime('-' . date('w') . ' days');
|
||||
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$date = date('Y-m-d', $date_start + ($i * 86400));
|
||||
|
||||
$order_data[date('w', strtotime($date))] = [
|
||||
'day' => date('D', strtotime($date)),
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total, `date_added` FROM `" . DB_PREFIX . "order` WHERE `order_status_id` IN(" . implode(",", $implode) . ") AND DATE(`date_added`) >= DATE('" . $this->db->escape(date('Y-m-d', $date_start)) . "') GROUP BY DAYNAME(`date_added`)");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$order_data[date('w', strtotime($result['date_added']))] = [
|
||||
'day' => date('D', strtotime($result['date_added'])),
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalOrdersByMonth(): array {
|
||||
$implode = [];
|
||||
|
||||
foreach ($this->config->get('config_complete_status') as $order_status_id) {
|
||||
$implode[] = "'" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$order_data = [];
|
||||
|
||||
for ($i = 1; $i <= date('t'); $i++) {
|
||||
$date = date('Y') . '-' . date('m') . '-' . $i;
|
||||
|
||||
$order_data[date('j', strtotime($date))] = [
|
||||
'day' => date('d', strtotime($date)),
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total, `date_added` FROM `" . DB_PREFIX . "order` WHERE `order_status_id` IN(" . implode(",", $implode) . ") AND DATE(`date_added`) >= DATE('" . $this->db->escape(date('Y') . '-' . date('m') . '-1') . "') GROUP BY DATE(`date_added`)");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$order_data[date('j', strtotime($result['date_added']))] = [
|
||||
'day' => date('d', strtotime($result['date_added'])),
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalOrdersByYear(): array {
|
||||
$implode = [];
|
||||
|
||||
foreach ($this->config->get('config_complete_status') as $order_status_id) {
|
||||
$implode[] = "'" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$order_data = [];
|
||||
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$order_data[$i] = [
|
||||
'month' => date('M', mktime(0, 0, 0, $i, 1)),
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total, `date_added` FROM `" . DB_PREFIX . "order` WHERE `order_status_id` IN(" . implode(",", $implode) . ") AND YEAR(`date_added`) = YEAR(NOW()) GROUP BY MONTH(`date_added`)");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$order_data[date('n', strtotime($result['date_added']))] = [
|
||||
'month' => date('M', strtotime($result['date_added'])),
|
||||
'total' => $result['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrders(array $data = []): array {
|
||||
$sql = "SELECT MIN(o.`date_added`) AS date_start, MAX(o.`date_added`) AS date_end, COUNT(*) AS orders, SUM((SELECT SUM(op.`quantity`) FROM `" . DB_PREFIX . "order_product` `op` WHERE `op`.`order_id` = `o`.`order_id` GROUP BY `op`.`order_id`)) AS products, SUM((SELECT SUM(`ot`.`value`) FROM `" . DB_PREFIX . "order_total` ot WHERE ot.`order_id` = o.`order_id` AND ot.`code` = 'tax' GROUP BY ot.`order_id`)) AS tax, SUM(o.`total`) AS `total` FROM `" . DB_PREFIX . "order` o";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " WHERE o.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE o.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql .= " GROUP BY YEAR(o.`date_added`), MONTH(o.`date_added`), DAY(o.`date_added`)";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql .= " GROUP BY YEAR(o.`date_added`), WEEK(o.`date_added`)";
|
||||
break;
|
||||
case 'month':
|
||||
$sql .= " GROUP BY YEAR(o.`date_added`), MONTH(o.`date_added`)";
|
||||
break;
|
||||
case 'year':
|
||||
$sql .= " GROUP BY YEAR(o.`date_added`)";
|
||||
break;
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY o.`date_added` 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 getTotalOrders(array $data = []): int {
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), MONTH(`date_added`), DAY(`date_added`)) AS `total` FROM `" . DB_PREFIX . "order`";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), WEEK(`date_added`)) AS `total` FROM `" . DB_PREFIX . "order`";
|
||||
break;
|
||||
case 'month':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`), MONTH(`date_added`)) AS `total` FROM `" . DB_PREFIX . "order`";
|
||||
break;
|
||||
case 'year':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`date_added`)) AS `total` FROM `" . DB_PREFIX . "order`";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " WHERE `order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE `order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxes(array $data = []): array {
|
||||
$sql = "SELECT MIN(o.`date_added`) AS date_start, MAX(o.`date_added`) AS date_end, ot.`title`, SUM(ot.`value`) AS total, COUNT(o.`order_id`) AS `orders` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_total` ot ON (ot.`order_id` = o.`order_id`) WHERE ot.`code` = 'tax'";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND `o`.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `o`.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), MONTH(`o`.`date_added`), DAY(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), WEEK(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
case 'month':
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), MONTH(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
case 'year':
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), ot.`title`";
|
||||
break;
|
||||
}
|
||||
|
||||
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 getTotalTaxes(array $data = []): int {
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(o.`date_added`), MONTH(`o`.`date_added`), DAY(`o`.`date_added`), `ot`.`title`) AS `total` FROM `" . DB_PREFIX . "order` `o`";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`o`.`date_added`), WEEK(`o`.`date_added`), `ot`.`title`) AS `total` FROM `" . DB_PREFIX . "order` `o`";
|
||||
break;
|
||||
case 'month':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`o`.`date_added`), MONTH(`o`.`date_added`), `ot`.`title`) AS `total` FROM `" . DB_PREFIX . "order` `o`";
|
||||
break;
|
||||
case 'year':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(`o`.`date_added`), `ot`.`title`) AS `total` FROM `" . DB_PREFIX . "order` `o`";
|
||||
break;
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "order_total` `ot` ON (`o`.`order_id` = `ot`.`order_id`) WHERE `ot`.`code` = 'tax'";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND `o`.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `o`.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(`o`.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(`o`.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getShipping(array $data = []): array {
|
||||
$sql = "SELECT MIN(o.`date_added`) AS date_start, MAX(o.`date_added`) AS date_end, ot.`title`, SUM(ot.`value`) AS total, COUNT(o.`order_id`) AS orders FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_total` ot ON (o.`order_id` = ot.`order_id`) WHERE ot.`code` = 'shipping'";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND `o`.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `o`.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(`o`.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(`o`.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), MONTH(`o`.`date_added`), DAY(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), WEEK(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
case 'month':
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), MONTH(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
case 'year':
|
||||
$sql .= " GROUP BY YEAR(`o`.`date_added`), `ot`.`title`";
|
||||
break;
|
||||
}
|
||||
|
||||
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 getTotalShipping(array $data = []): int {
|
||||
if (!empty($data['filter_group'])) {
|
||||
$group = $data['filter_group'];
|
||||
} else {
|
||||
$group = 'week';
|
||||
}
|
||||
|
||||
switch ($group) {
|
||||
case 'day';
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(o.`date_added`), MONTH(o.`date_added`), DAY(o.`date_added`), ot.`title`) AS `total` FROM `" . DB_PREFIX . "order` o";
|
||||
break;
|
||||
default:
|
||||
case 'week':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(o.`date_added`), WEEK(o.`date_added`), ot.`title`) AS `total` FROM `" . DB_PREFIX . "order` o";
|
||||
break;
|
||||
case 'month':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(o.`date_added`), MONTH(o.`date_added`), ot.`title`) AS `total` FROM `" . DB_PREFIX . "order` o";
|
||||
break;
|
||||
case 'year':
|
||||
$sql = "SELECT COUNT(DISTINCT YEAR(o.`date_added`), ot.`title`) AS `total` FROM `" . DB_PREFIX . "order` o";
|
||||
break;
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "order_total` ot ON (o.`order_id` = ot.`order_id`) WHERE ot.`code` = 'shipping'";
|
||||
|
||||
if (!empty($data['filter_order_status_id'])) {
|
||||
$sql .= " AND `order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_start'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_end'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user