From c4b85ce11e69d5ba7d6637fc7f72c92eba84188c Mon Sep 17 00:00:00 2001 From: vladfo Date: Mon, 14 Oct 2024 13:01:52 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?utf8?q?=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B=20=D0=BF=D0=BE=20?= =?utf8?q?=D1=81=D1=83=D0=BC=D0=BC=D0=B0=D0=BC=20=D0=B8=20=D0=B2=D0=BE?= =?utf8?q?=D0=B7=D0=B2=D1=80=D0=B0=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../actions/motivation/TestSelfCostAction.php | 10 +++++ erp24/services/MotivationService.php | 38 +++++++++++++++- erp24/views/motivation/test-self-cost.php | 44 +++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/erp24/actions/motivation/TestSelfCostAction.php b/erp24/actions/motivation/TestSelfCostAction.php index 09cd8c1d..e610eb6a 100644 --- a/erp24/actions/motivation/TestSelfCostAction.php +++ b/erp24/actions/motivation/TestSelfCostAction.php @@ -44,6 +44,11 @@ class TestSelfCostAction extends Action $uniqueProductsData = []; if ($startDate && $endDate && $storeId) { + + // Получаем продажи и возвраты + $salesAndReturns = MotivationService::getSalesAndReturns($startDate, $endDate, $storeId); + $salesRecords = $salesAndReturns['salesRecords']; + $returnedSales = $salesAndReturns['returnedSales']; $totalSum = MotivationService::getSelfCostSumByStore($startDate, $endDate, $storeId); // Получаем данные о продуктах и себестоимости @@ -66,6 +71,9 @@ class TestSelfCostAction extends Action 'price' => $item['price'], 'm_price' => $item['m_price'], 'quantity' => $item['quantity'], + 'summ' => $item['summ'], + 'discount' => $item['discount'], + ]; } else { $groupedProducts[$productId]['quantity'] += $item['quantity']; @@ -91,6 +99,8 @@ class TestSelfCostAction extends Action 'uniqueProductsData' => $uniqueProductsData, 'totalSum' => $totalSum, 'totalProductsSum' => $totalProductsSum, + 'salesRecords' => $salesRecords ?? [], + 'returnedSales' => $returnedSales ?? [], ]); } } \ No newline at end of file diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index f6d48702..6680b398 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -1870,6 +1870,7 @@ class MotivationService $salesProducts = SalesProducts::find() ->select(['check_id', 'product_id', 'quantity']) ->where(['check_id' => $salesIds]) + ->andWhere(['type_id' => 1]) ->asArray() ->all(); @@ -1960,7 +1961,7 @@ class MotivationService // Находим товары, проданные в выбранных продажах $salesProducts = SalesProducts::find() - ->select(['check_id', 'product_id', 'quantity', 'price']) + ->select(['check_id', 'product_id', 'quantity', 'price', 'summ', 'discount']) ->where(['check_id' => $salesIds]) ->andWhere(['type_id' => 1]) // ->andWhere(['>', 'price', '0' ]) @@ -2007,6 +2008,8 @@ class MotivationService 'quantity' => $quantity, 'check_id' => $product['check_id'], 'm_price' => $product['price'], + 'summ' => $product['summ'], + 'discount' => $product['discount'], ]; } @@ -2014,6 +2017,39 @@ class MotivationService } + public static function getSalesAndReturns($startDate, $endDate, $storeId) + { + $storeId = (int)$storeId; + $startDate = date('Y-m-d', strtotime($startDate)); + $endDate = date('Y-m-d 23:59:59', strtotime($endDate)); + + // Находим все продажи за указанный период + $salesRecords = Sales::find() + // ->select(['id', 'date']) + ->where(['store_id' => $storeId, 'operation' => Sales::OPERATION_SALE]) + ->andWhere(['>=', 'date', $startDate]) + ->andWhere(['<=', 'date', $endDate]) + ->asArray() + ->all(); + + $endDatePlusThreeWeeks = date('Y-m-d 23:59:59', strtotime($endDate . ' +3 weeks')); + + // Находим возвраты за указанный период + 3 недели + $returnedSales = Sales::find() + // ->select(['id', 'date', 'sales_check']) + ->where(['store_id' => $storeId, 'operation' => Sales::OPERATION_RETURN]) + ->andWhere(['>=', 'date', $startDate]) + ->andWhere(['<=', 'date', $endDatePlusThreeWeeks]) + ->andWhere(['is not', 'sales_check', null]) + ->asArray() + ->all(); + + return [ + 'salesRecords' => $salesRecords, + 'returnedSales' => $returnedSales, + ]; + } + public static function getCostConsumablesSalesSupportByStore($startDate, $endDate, $storeId) { $exportImportTable = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $storeId, 'export_id' => 1])->one(); diff --git a/erp24/views/motivation/test-self-cost.php b/erp24/views/motivation/test-self-cost.php index bc17c5da..200dc186 100644 --- a/erp24/views/motivation/test-self-cost.php +++ b/erp24/views/motivation/test-self-cost.php @@ -11,6 +11,8 @@ use yii\grid\GridView; /* @var $uniqueProductsData array */ /* @var $totalSum float */ /* @var $totalProductsSum float */ +/* @var $salesRecords array */ +/* @var $returnedSales array */ $this->title = 'Себестоимость товаров по магазинам'; ?> @@ -53,6 +55,8 @@ $this->title = 'Себестоимость товаров по магазина ['attribute' => 'check_id', 'label' => 'ID чека'], ['attribute' => 'product_name', 'label' => 'Название'], ['attribute' => 'm_price', 'label' => 'Цена'], + ['attribute' => 'summ', 'label' => 'Сумма', 'footer' => array_sum(array_column($data, 'summ')),], + ['attribute' => 'discount', 'label' => 'Скидка', 'footer' => array_sum(array_column($data, 'discount')),], ['attribute' => 'price', 'label' => 'Себестоимость ед'], [ 'attribute' => 'quantity', @@ -113,4 +117,44 @@ $this->title = 'Себестоимость товаров по магазина ], ]); ?> + + +

Продажи за период

+ new \yii\data\ArrayDataProvider([ + 'allModels' => $salesRecords, + 'pagination' => false, + ]), + 'showFooter' => true, // Показываем подвал таблицы + 'columns' => [ + ['attribute' => 'id', 'label' => 'ID продажи'], + ['attribute' => 'operation', 'label' => 'Операция'], + ['attribute' => 'status', 'label' => 'Статус'], + [ + 'attribute' => 'summ', + 'label' => 'Сумма', + 'footer' => array_sum(array_column($salesRecords, 'summ')), // Сумма всех значений столбца "Сумма" + ], + ['attribute' => 'sales_check', 'label' => 'Чек возврата'], + ['attribute' => 'date', 'label' => 'Дата'], + ], + ]); ?> + + + +

Возвраты за период

+ new \yii\data\ArrayDataProvider([ + 'allModels' => $returnedSales, + 'pagination' => false, + ]), + 'columns' => [ + ['attribute' => 'id', 'label' => 'ID возврата'], + ['attribute' => 'date', 'label' => 'Дата'], + ['attribute' => 'sales_check', 'label' => 'ID продажи'], + ], + ]); ?> + + + \ No newline at end of file -- 2.39.5