So far, using Opencart 2.0.1.1, I have found the following bugs in Reports:
1. Reports - Sales - Orders:
Gives a bad product quantity when you have multiple orders in the same date. For example I have 2 orders on same date, the column No. of Orders will show 2, but the No. of Products will show only the Quantity for one order. I tried changing the SQL query to no extent - I am not the best with SQL

. The query is located in the file admin/model/report/sale.php, and this part is the function thats handling the calculation, I bolded the part handling the quantity of Products, although I am not sure if thats the only part that is not good, maybe its something else in this function.
Code: Select all
public function getOrders($data = array()) {
$sql = "SELECT MIN(o.date_added) AS date_start, MAX(o.date_added) AS date_end, COUNT(*) AS `orders`, [b](SELECT SUM(op.quantity) FROM `" . DB_PREFIX . "order_product` op WHERE op.order_id = o.order_id GROUP BY op.order_id) AS products[/b], (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) >= '" . $this->db->escape($data['filter_date_start']) . "'";
}
if (!empty($data['filter_date_end'])) {
$sql .= " AND DATE(o.date_added) <= '" . $this->db->escape($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;
}
2. Next we have Reports - Product - Viewed and Purchased. Both had errors in either SQL or PHP and gave wrong results. I can't even remember what exactly I did there is help via Google for these I think.
3. Next is Reports - Customers - Orders
This one shows wrong data in columns No. of orders and Total. The figures are completely wrong. The file handling this part is admin/model/report/customer.php. The function handling the calculation is below, I bolded the query which is responsible for the figures. Again, as I previously said, the part of the query I put in bold is probably not the only one causing the issue, it could be the entire query is wrong.
Code: Select all
public function getOrders($data = array()) {
$sql = "SELECT c.customer_id, CONCAT(c.firstname, ' ', c.lastname) AS customer, c.email, cgd.name AS customer_group, c.status, [b]COUNT(o.order_id) AS orders[/b], SUM(op.quantity) AS products, [b]SUM(o.total) AS `total`[/b] 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_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) >= '" . $this->db->escape($data['filter_date_start']) . "'";
}
if (!empty($data['filter_date_end'])) {
$sql .= " AND DATE(o.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'";
}
$sql .= " GROUP BY o.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;
}
I hope that someone else found a solution to these problems because the queries produce wrong data and it is difficult to use the reports for any viable calculation. Please help!