Skip to content

Commit

Permalink
Revert "Add paid order to stats dashboard even when there's no relate…
Browse files Browse the repository at this point in the history
…d invoice generated"
  • Loading branch information
eternoendless committed Sep 14, 2017
1 parent ab075e6 commit a4bc257
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions controllers/admin/AdminStatsController.php
Expand Up @@ -200,25 +200,25 @@ public static function getTotalSales($date_from, $date_to, $granularity = false)
if ($granularity == 'day') {
$sales = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT LEFT(`date_upd`, 10) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales
SELECT LEFT(`invoice_date`, 10) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o').'
GROUP BY LEFT(`date_upd`, 10)');
GROUP BY LEFT(`invoice_date`, 10)');
foreach ($result as $row) {
$sales[strtotime($row['date'])] = $row['sales'];
}
return $sales;
} elseif ($granularity == 'month') {
$sales = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT LEFT(`date_upd`, 7) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales
SELECT LEFT(`invoice_date`, 7) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o').'
GROUP BY LEFT(`date_upd`, 7)');
GROUP BY LEFT(`invoice_date`, 7)');
foreach ($result as $row) {
$sales[strtotime($row['date'].'-01')] = $row['sales'];
}
Expand All @@ -228,7 +228,7 @@ public static function getTotalSales($date_from, $date_to, $granularity = false)
SELECT SUM(total_paid_tax_excl / o.conversion_rate)
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o'));
}
}
Expand All @@ -252,25 +252,25 @@ public static function getOrders($date_from, $date_to, $granularity = false)
if ($granularity == 'day') {
$orders = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT LEFT(`date_upd`, 10) as date, COUNT(*) as orders
SELECT LEFT(`invoice_date`, 10) as date, COUNT(*) as orders
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o').'
GROUP BY LEFT(`date_upd`, 10)');
GROUP BY LEFT(`invoice_date`, 10)');
foreach ($result as $row) {
$orders[strtotime($row['date'])] = $row['orders'];
}
return $orders;
} elseif ($granularity == 'month') {
$orders = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT LEFT(`date_upd`, 7) as date, COUNT(*) as orders
SELECT LEFT(`invoice_date`, 7) as date, COUNT(*) as orders
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o').'
GROUP BY LEFT(`date_upd`, 7)');
GROUP BY LEFT(`invoice_date`, 7)');
foreach ($result as $row) {
$orders[strtotime($row['date'].'-01')] = $row['orders'];
}
Expand All @@ -280,7 +280,7 @@ public static function getOrders($date_from, $date_to, $granularity = false)
SELECT COUNT(*) as orders
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o'));
}

Expand Down Expand Up @@ -429,7 +429,7 @@ public static function getPurchases($date_from, $date_to, $granularity = false)
$purchases = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
LEFT(`date_upd`, 10) as date,
LEFT(`invoice_date`, 10) as date,
SUM(od.`product_quantity` * IF(
od.`purchase_supplier_price` > 0,
od.`purchase_supplier_price` / `conversion_rate`,
Expand All @@ -438,9 +438,9 @@ public static function getPurchases($date_from, $date_to, $granularity = false)
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o').'
GROUP BY LEFT(`date_upd`, 10)');
GROUP BY LEFT(`invoice_date`, 10)');
foreach ($result as $row) {
$purchases[strtotime($row['date'])] = $row['total_purchase_price'];
}
Expand All @@ -455,7 +455,7 @@ public static function getPurchases($date_from, $date_to, $granularity = false)
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `date_upd` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o'));
}
}
Expand All @@ -466,7 +466,7 @@ public static function getExpenses($date_from, $date_to, $granularity = false)

$orders = Db::getInstance()->ExecuteS('
SELECT
LEFT(o.date_upd, 10) as date,
LEFT(`invoice_date`, 10) as date,
total_paid_tax_incl / o.conversion_rate as total_paid_tax_incl,
total_shipping_tax_excl / o.conversion_rate as total_shipping_tax_excl,
o.module,
Expand All @@ -477,7 +477,7 @@ public static function getExpenses($date_from, $date_to, $granularity = false)
LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_delivery = a.id_address
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON o.id_carrier = c.id_carrier
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE o.date_upd BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 AND os.paid = 1
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1
'.Shop::addSqlRestriction(false, 'o'));
foreach ($orders as $order) {
// Add flat fees for this order
Expand Down

0 comments on commit a4bc257

Please sign in to comment.