Skip to content

Commit

Permalink
Merge pull request #2381 from dpfaffenbauer/issues/reports
Browse files Browse the repository at this point in the history
[Reports] fix reports to only select actual orders
  • Loading branch information
dpfaffenbauer authored Sep 28, 2023
2 parents a668fec + 2f5ff7a commit a61112f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/CarriersReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Carbon\Carbon;
use CoreShop\Component\Core\Model\StoreInterface;
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use CoreShop\Component\Shipping\Model\CarrierInterface;
Expand Down Expand Up @@ -75,7 +76,8 @@ public function getReportData(ParameterBag $parameterBag): array
ON o.o_id = `order`.oo_id
WHERE store = $storeId AND o_creationDate > $fromTimestamp AND o_creationDate < $toTimestamp
) t
WHERE store = $storeId AND carrier IS NOT NULL AND o_creationDate > $fromTimestamp AND o_creationDate < $toTimestamp GROUP BY carrier";
WHERE store = $storeId AND carrier IS NOT NULL AND o_creationDate > $fromTimestamp AND o_creationDate < $toTimestamp AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY carrier";

$results = $this->db->fetchAllAssociative($sql);
$data = [];
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/CategoriesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Currency\Formatter\MoneyFormatterInterface;
use CoreShop\Component\Locale\Context\LocaleContextInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Doctrine\DBAL\Connection;
Expand Down Expand Up @@ -94,7 +95,7 @@ public function getReportData(ParameterBag $parameterBag): array
INNER JOIN object_query_$orderItemClassId AS orderItems ON orderItems.product__id = catProductDependencies.sourceId
INNER JOIN object_relations_$orderClassId AS orderRelations ON orderRelations.dest_id = orderItems.oo_id AND orderRelations.fieldname = \"items\"
INNER JOIN object_query_$orderClassId AS `orders` ON `orders`.oo_id = orderRelations.src_id
WHERE orders.store = $storeId" . (($orderStateFilter !== null) ? ' AND `orders`.orderState IN (' . rtrim(str_repeat('?,', count($orderStateFilter)), ',') . ')' : '') . " AND orders.orderDate > ? AND orders.orderDate < ? AND orderItems.product__id IS NOT NULL
WHERE orders.store = $storeId" . (($orderStateFilter !== null) ? ' AND `orders`.orderState IN (' . rtrim(str_repeat('?,', count($orderStateFilter)), ',') . ')' : '') . " AND orders.orderDate > ? AND orders.orderDate < ? AND orderItems.product__id IS NOT NULL AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY categories.oo_id
ORDER BY quantityCount DESC
LIMIT $offset,$limit";
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/CustomersReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Currency\Formatter\MoneyFormatterInterface;
use CoreShop\Component\Locale\Context\LocaleContextInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Order\OrderStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use Doctrine\DBAL\Connection;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function getReportData(ParameterBag $parameterBag): array
COUNT(customer.oo_id) as `orderCount`
FROM object_query_$orderClassId AS orders
INNER JOIN object_query_$customerClassId AS customer ON orders.customer__id = customer.oo_id
WHERE orders.orderState = '$orderCompleteState' AND orders.orderDate > ? AND orders.orderDate < ? AND customer.oo_id IS NOT NULL
WHERE orders.orderState = '$orderCompleteState' AND orders.orderDate > ? AND orders.orderDate < ? AND customer.oo_id IS NOT NULL AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY customer.oo_id
ORDER BY COUNT(customer.oo_id) DESC
LIMIT $offset,$limit";
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/ManufacturerReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Currency\Formatter\MoneyFormatterInterface;
use CoreShop\Component\Locale\Context\LocaleContextInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Doctrine\DBAL\Connection;
Expand Down Expand Up @@ -101,7 +102,7 @@ public function getReportData(ParameterBag $parameterBag): array
INNER JOIN object_query_$orderItemClassId AS orderItems ON orderItems.product__id = manProductDependencies.sourceid
INNER JOIN object_relations_$orderClassId AS orderRelations ON orderRelations.dest_id = orderItems.oo_id AND orderRelations.fieldname = \"items\"
INNER JOIN object_query_$orderClassId AS `orders` ON `orders`.oo_id = orderRelations.src_id
WHERE orders.store = $storeId" . (($orderStateFilter !== null) ? ' AND `orders`.orderState IN (' . rtrim(str_repeat('?,', count($orderStateFilter)), ',') . ')' : '') . " AND orders.orderDate > ? AND orders.orderDate < ? AND orderItems.product__id IS NOT NULL
WHERE orders.store = $storeId" . (($orderStateFilter !== null) ? ' AND `orders`.orderState IN (' . rtrim(str_repeat('?,', count($orderStateFilter)), ',') . ')' : '') . " AND orders.orderDate > ? AND orders.orderDate < ? AND orderItems.product__id IS NOT NULL AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY manufacturers.oo_id
ORDER BY quantityCount DESC
LIMIT $offset,$limit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use CoreShop\Component\Core\Model\PaymentProviderInterface;
use CoreShop\Component\Core\Model\StoreInterface;
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Doctrine\DBAL\Connection;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function getReportData(ParameterBag $parameterBag): array
ON o.o_id = `order`.oo_id
WHERE store = $storeId AND o_creationDate > $fromTimestamp AND o_creationDate < $toTimestamp
) t
WHERE store = $storeId AND o_creationDate > $fromTimestamp AND o_creationDate < $toTimestamp
WHERE store = $storeId AND o_creationDate > $fromTimestamp AND o_creationDate < $toTimestamp AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY paymentProvider";

$results = $this->db->fetchAllAssociative($sql);
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/ProductsReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Currency\Formatter\MoneyFormatterInterface;
use CoreShop\Component\Locale\Context\LocaleContextInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Doctrine\DBAL\Connection;
Expand Down Expand Up @@ -104,7 +105,7 @@ public function getReportData(ParameterBag $parameterBag): array
INNER JOIN object_query_$orderItemClassId AS orderItems ON products.o_id = orderItems.mainObjectId
INNER JOIN object_relations_$orderClassId AS orderRelations ON orderRelations.dest_id = orderItems.oo_id AND orderRelations.fieldname = \"items\"
INNER JOIN object_query_$orderClassId AS `order` ON `order`.oo_id = orderRelations.src_id
WHERE products.o_type = 'object' AND `order`.store = $storeId" . (($orderStateFilter !== null) ? ' AND `order`.orderState IN (' . rtrim(str_repeat('?,', count($orderStateFilter)), ',') . ')' : '') . " AND `order`.orderDate > ? AND `order`.orderDate < ?
WHERE products.o_type = 'object' AND `order`.store = $storeId" . (($orderStateFilter !== null) ? ' AND `order`.orderState IN (' . rtrim(str_repeat('?,', count($orderStateFilter)), ',') . ')' : '') . " AND `order`.orderDate > ? AND `order`.orderDate < ? AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY products.o_id
LIMIT $offset,$limit";
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/SalesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Currency\Formatter\MoneyFormatterInterface;
use CoreShop\Component\Locale\Context\LocaleContextInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Order\OrderStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
Expand Down Expand Up @@ -103,7 +104,7 @@ protected function getData(ParameterBag $parameterBag): array
$sqlQuery = "
SELECT DATE(FROM_UNIXTIME(orderDate)) AS dayDate, orderDate, SUM(totalGross) AS total
FROM object_query_$classId as orders
WHERE orders.store = $storeId AND orders.orderState = '$orderCompleteState' AND orders.orderDate > ? AND orders.orderDate < ?
WHERE orders.store = $storeId AND orders.orderState = '$orderCompleteState' AND orders.orderDate > ? AND orders.orderDate < ? AND saleState='" . OrderSaleStates::STATE_ORDER . "'
GROUP BY " . $groupSelector;

$results = $this->db->fetchAllAssociative($sqlQuery, [$from->getTimestamp(), $to->getTimestamp()]);
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/Report/VouchersReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use CoreShop\Component\Core\Report\ReportInterface;
use CoreShop\Component\Currency\Formatter\MoneyFormatterInterface;
use CoreShop\Component\Locale\Context\LocaleContextInterface;
use CoreShop\Component\Order\OrderSaleStates;
use CoreShop\Component\Order\OrderStates;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
Expand Down Expand Up @@ -79,7 +80,7 @@ public function getReportData(ParameterBag $parameterBag): array
FROM object_collection_CoreShopProposalCartPriceRuleItem_$classId as orderVouchers
INNER JOIN object_query_$classId as orders ON orders.oo_id = orderVouchers.o_id
LEFT JOIN coreshop_cart_price_rule AS priceRule ON orderVouchers.cartPriceRule = priceRule.id
WHERE orderVouchers.voucherCode <> '' AND orders.store = $storeId AND orders.orderState = '$orderCompleteState' AND orders.orderDate > ? AND orders.orderDate < ?
WHERE orderVouchers.voucherCode <> '' AND orders.store = $storeId AND orders.orderState = '$orderCompleteState' AND orders.orderDate > ? AND orders.orderDate < ? AND saleState='" . OrderSaleStates::STATE_ORDER . "'
ORDER BY orders.orderDate DESC
LIMIT $offset,$limit";

Expand Down

0 comments on commit a61112f

Please sign in to comment.