Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions stats/statsstock.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ public function hookAdminStatsModules()

$sql = 'SELECT p.id_product, p.reference, pl.name, p.cache_is_pack,
IFNULL((
SELECT AVG(product_attribute_shop.wholesale_price)
SELECT SUM(stock2.quantity * IF(product_attribute_shop.wholesale_price != 0, product_attribute_shop.wholesale_price, ps_shop.wholesale_price)) / SUM(stock2.quantity)
FROM ' . _DB_PREFIX_ . 'product_attribute pa
' . Shop::addSqlAssociation('product_attribute', 'pa') . '
WHERE p.id_product = pa.id_product
AND product_attribute_shop.wholesale_price != 0
INNER JOIN ' . _DB_PREFIX_ . 'product ps ON (ps.id_product = pa.id_product)
' . Shop::addSqlAssociation('product', 'ps') . '
LEFT JOIN ' . _DB_PREFIX_ . 'stock_available stock2
ON (stock2.id_product = pa.id_product AND stock2.id_product_attribute = pa.id_product_attribute AND stock2.id_shop = product_attribute_shop.id_shop AND stock2.id_shop_group = product_attribute_shop.id_shop_group)
WHERE p.id_product = pa.id_product AND stock2.quantity IS NOT NULL
), product_shop.wholesale_price) as wholesale_price,
IFNULL(stock.quantity, 0) as quantity
FROM ' . _DB_PREFIX_ . 'product p
Expand Down Expand Up @@ -142,7 +145,7 @@ public function hookAdminStatsModules()
if (!count($products)) {
$this->html .= '<p>' . $this->l('No product matches criteria.') . '</p>';
} else {
$rollup = ['quantity' => 0, 'wholesale_price' => 0, 'stockvalue' => 0];
$rollup = ['quantity' => 0, 'stockvalue' => 0];
$this->html .= '
<table class="table">
<thead>
Expand All @@ -159,7 +162,6 @@ public function hookAdminStatsModules()
foreach ($products as $product) {
if (!$product['cache_is_pack']) {
$rollup['quantity'] += $product['quantity'];
$rollup['wholesale_price'] += $product['wholesale_price'];
$rollup['stockvalue'] += $product['stockvalue'];
}
$this->html .= '<tr>
Expand All @@ -183,14 +185,12 @@ public function hookAdminStatsModules()
<tr>
<td colspan="3"></td>
<td>' . $rollup['quantity'] . '</td>
<td>' . Tools::displayPrice($rollup['wholesale_price'] / max(1, count(array_filter($products, function ($p) {
return !$p['cache_is_pack'];
}))), $currency) . '</td>
<td>' . Tools::displayPrice($rollup['stockvalue'] / max(1, $rollup['quantity']), $currency) . '</td>
<td>' . Tools::displayPrice($rollup['stockvalue'], $currency) . '</td>
</tr>
</tfoot>
</table>
<i class="icon-asterisk"></i> ' . $this->l('This section corresponds to the default wholesale price according to the default supplier for the product. An average price is used when the product has attributes.') . '<br>
<i class="icon-asterisk"></i> ' . $this->l('This section corresponds to the default wholesale price according to the default supplier for the product. A weighted average price is used when the product has attributes.') . '<br>
<i class="icon-exclamation-sign"></i> ' . $this->l('Pack products are marked with "-" and are NOT included in the total quantities or value calculation as they are already accounted for as separate items.') . '
';
}
Expand Down