From 2f5ff7af814f204af2f7cdeb6d0aa20c9731d82b Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Thu, 28 Sep 2023 08:50:36 +0200 Subject: [PATCH] [Reports] fix reports to only select actual orders --- src/CoreShop/Bundle/CoreBundle/Report/CarriersReport.php | 4 +++- src/CoreShop/Bundle/CoreBundle/Report/CategoriesReport.php | 3 ++- src/CoreShop/Bundle/CoreBundle/Report/CustomersReport.php | 3 ++- src/CoreShop/Bundle/CoreBundle/Report/ManufacturerReport.php | 3 ++- .../Bundle/CoreBundle/Report/PaymentProvidersReport.php | 3 ++- src/CoreShop/Bundle/CoreBundle/Report/ProductsReport.php | 3 ++- src/CoreShop/Bundle/CoreBundle/Report/SalesReport.php | 3 ++- src/CoreShop/Bundle/CoreBundle/Report/VouchersReport.php | 3 ++- 8 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/CoreShop/Bundle/CoreBundle/Report/CarriersReport.php b/src/CoreShop/Bundle/CoreBundle/Report/CarriersReport.php index 86ce151cde..58402c4fbc 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/CarriersReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/CarriersReport.php @@ -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; @@ -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 = []; diff --git a/src/CoreShop/Bundle/CoreBundle/Report/CategoriesReport.php b/src/CoreShop/Bundle/CoreBundle/Report/CategoriesReport.php index d677fc5de9..f54aa7fb2d 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/CategoriesReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/CategoriesReport.php @@ -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; @@ -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"; diff --git a/src/CoreShop/Bundle/CoreBundle/Report/CustomersReport.php b/src/CoreShop/Bundle/CoreBundle/Report/CustomersReport.php index a6ec7c79ea..0c960d5bb1 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/CustomersReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/CustomersReport.php @@ -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; @@ -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"; diff --git a/src/CoreShop/Bundle/CoreBundle/Report/ManufacturerReport.php b/src/CoreShop/Bundle/CoreBundle/Report/ManufacturerReport.php index 9711797321..c8e8b04254 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/ManufacturerReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/ManufacturerReport.php @@ -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; @@ -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"; diff --git a/src/CoreShop/Bundle/CoreBundle/Report/PaymentProvidersReport.php b/src/CoreShop/Bundle/CoreBundle/Report/PaymentProvidersReport.php index c2dd2f24b3..8f3c830b64 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/PaymentProvidersReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/PaymentProvidersReport.php @@ -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; @@ -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); diff --git a/src/CoreShop/Bundle/CoreBundle/Report/ProductsReport.php b/src/CoreShop/Bundle/CoreBundle/Report/ProductsReport.php index df67f230a9..957362de6c 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/ProductsReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/ProductsReport.php @@ -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; @@ -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 { diff --git a/src/CoreShop/Bundle/CoreBundle/Report/SalesReport.php b/src/CoreShop/Bundle/CoreBundle/Report/SalesReport.php index 88bc0bd5a8..a1dce594a1 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/SalesReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/SalesReport.php @@ -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; @@ -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()]); diff --git a/src/CoreShop/Bundle/CoreBundle/Report/VouchersReport.php b/src/CoreShop/Bundle/CoreBundle/Report/VouchersReport.php index 4431e40e2d..5ae35bf004 100644 --- a/src/CoreShop/Bundle/CoreBundle/Report/VouchersReport.php +++ b/src/CoreShop/Bundle/CoreBundle/Report/VouchersReport.php @@ -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; @@ -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";