From 357d842afa186bdb2b5f60fb058826e5162aeecf Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Wed, 14 Aug 2024 10:37:12 +0300 Subject: [PATCH] =?utf8?q?[ERP-140]=20Test=20=D1=84=D0=B0=D0=BA=D1=82=20?= =?utf8?q?=D0=BC=D0=BE=D1=82=D0=B8=D0=B2=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/actions/motivation/TestFactAction.php | 62 +++++++++++++++++++++ erp24/controllers/MotivationController.php | 1 + erp24/services/MotivationService.php | 55 +++++++++--------- erp24/views/motivation/test-fact.php | 56 +++++++++++++++++++ 4 files changed, 146 insertions(+), 28 deletions(-) create mode 100644 erp24/actions/motivation/TestFactAction.php create mode 100644 erp24/views/motivation/test-fact.php diff --git a/erp24/actions/motivation/TestFactAction.php b/erp24/actions/motivation/TestFactAction.php new file mode 100644 index 00000000..87f915e4 --- /dev/null +++ b/erp24/actions/motivation/TestFactAction.php @@ -0,0 +1,62 @@ + $currentDate->format('Y'), // Текущий год + 'month' => $currentDate->format('n') // Текущий месяц (1-12) + ], [ + [['year', 'month'], 'safe'] + ]); + + $motivations = Motivation::find()->all(); + $possibleYears = ArrayHelper::getColumn($motivations, 'year'); + $years = array_filter(range(2023, 20100), function ($k) use ($possibleYears) { + return in_array($k, $possibleYears); + }); + $years = array_combine($years, $years); + $possibleMonth = ArrayHelper::getColumn($motivations, 'month'); + $months = array_filter([1 => 'Январь', 2 => 'Февраль', 3 => 'Март', 4 => 'Апрель', 5 => 'Май', 6 => 'Июнь', 7 => 'Июль', 8 => 'Август', 9 => 'Сентябрь', 10 => 'Октябрь', 11 => 'Ноябрь', 12 => 'Декабрь'], function ($k, $v) use ($possibleMonth) { + return in_array($v, $possibleMonth); + }, ARRAY_FILTER_USE_BOTH); + + // Загружаем данные из GET-запроса, если они есть + if (Yii::$app->request->get()) { + $model->load(Yii::$app->request->get()); + + if ($model->year === '') { + $model->year = $currentDate->format('Y'); + } else { + $model->year = intval($model->year); + // Проверяем, что год находится в допустимом диапазоне + if (!in_array($model->year, $years)) { + $model->year = $currentDate->format('Y'); + } + } + + $model->month = intval($model->month); + + MotivationService::calculateMonthSales($model->year, $model->month); + + MotivationService::calculateMonthServices($model->year, $model->month); + + MotivationService::calculateMonthDefect($model->year, $model->month); + } + + return $this->controller->render('test-fact', compact('model', 'years', 'months')); + } +} \ No newline at end of file diff --git a/erp24/controllers/MotivationController.php b/erp24/controllers/MotivationController.php index f81c287b..c6cfd50e 100644 --- a/erp24/controllers/MotivationController.php +++ b/erp24/controllers/MotivationController.php @@ -16,6 +16,7 @@ class MotivationController extends Controller 'create-value' => \yii_app\actions\motivation\CreateValueAction::class, 'update-value' => \yii_app\actions\motivation\UpdateValueAction::class, 'delete-value' => \yii_app\actions\motivation\DeleteValueAction::class, + 'test-fact' => \yii_app\actions\motivation\TestFactAction::class, ]; } diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 66a665ca..5e499e6d 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -533,20 +533,20 @@ class MotivationService $returnSales = Sales::find()->where(['operation' => Sales::OPERATION_RETURN, 'sales_check' => $salesIds])->all(); $returnSalesIds = ArrayHelper::getColumn($returnSales, 'sales_check'); - $salesOffline = Sales::find()->select(['SUM(summ) as total']) + $salesOffline = Sales::find()->select(['SUM(summ) as total', 'store_id']) ->where(['between', 'date', $monthStart, $monthEnd]) ->andWhere(['operation' => Sales::OPERATION_SALE]) ->andWhere(['order_id' => ['', '0']]) - ->andWhere(['NOT IN', 'check_id', $returnSalesIds]) + ->andWhere(['NOT IN', 'id', $returnSalesIds]) ->groupBy(['store_id']) ->indexBy('store_id') ->asArray()->all(); - $salesOnline = Sales::find()->select(['SUM(summ) as total']) + $salesOnline = Sales::find()->select(['SUM(summ) as total', 'store_id']) ->where(['between', 'date', $monthStart, $monthEnd]) ->andWhere(['operation' => Sales::OPERATION_SALE]) ->andWhere(['NOT IN', 'order_id', ['', '0']]) - ->andWhere(['NOT IN', 'check_id', $returnSalesIds]) + ->andWhere(['NOT IN', 'id', $returnSalesIds]) ->groupBy(['store_id']) ->indexBy('store_id') ->asArray()->all(); @@ -642,14 +642,14 @@ class MotivationService // Ищем продукты из категории services $salesProduct = SalesProducts::find()->alias('p') - ->select(['SUM(summ) as total']) + ->select(['SUM(p.summ) as total', 'store_id']) ->leftJoin('sales s', 's.id = p.check_id') ->where(['check_id' => $salesIds]) ->andWhere(['NOT IN', 'check_id', $returnSalesIds]) ->andWhere(['product_id' => array_keys($products1c)]) - ->groupBy(['s.store_id']) - ->indexBy('s.store_id') - ->asArray()->one(); + ->groupBy(['store_id']) + ->indexBy('store_id') + ->asArray()->all(); // Ищем продажи по продуктовым гуидам по каталог-гуидам категории services_delivery $salesDelivery = Sales::find()->alias('s') @@ -666,14 +666,14 @@ class MotivationService // Ищем продукты из категории services_delivery $salesProductDelivery = SalesProducts::find()->alias('p') - ->select(['SUM(summ) as total']) + ->select(['SUM(p.summ) as total', 'store_id']) ->leftJoin('sales s', 's.id = p.check_id') ->where(['check_id' => $salesIdsDelivery]) ->andWhere(['NOT IN', 'check_id', $returnSalesIdsDelivery]) ->andWhere(['product_id' => array_keys($products1cDelivery)]) - ->groupBy(['s.store_id']) - ->indexBy('s.store_id') - ->asArray()->one(); + ->groupBy(['store_id']) + ->indexBy('store_id') + ->asArray()->all(); $motivations = Motivation::find()->where(['year' => $year, 'month' => $month])->indexBy('store_id')->all(); @@ -728,26 +728,25 @@ class MotivationService $motivations = Motivation::find()->where(['year' => $year, 'month' => $month])->indexBy('store_id')->all(); $motivationValueGroup = MotivationValueGroup::find()->where(['alias' => 'fact'])->one(); - $exportImportTables = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', + $exportImportTables = ExportImportTable::find()->select(['export_val', 'entity_id'])->where(['entity' => 'city_store', 'entity_id' => array_keys($motivations), 'export_id' => 1])->indexBy('entity_id')->all(); /** @var $exportImportTables ExportImportTable[] */ foreach ($exportImportTables as $store_id => $store_guid) { - $writeOffs = WriteOffs::find()->select(['sum(summ) as total', 'type']) - ->where(['between', 'date', $monthStart, $monthEnd]) - ->andWhere(['store_id' => $store_guid]) - ->groupBy(['type']) - ->indexBy('type') - ->asArray()->all(); - - foreach ($writeOffs as $key => $data) { - $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key); - if (empty($motivationItemType)) { - continue; - } - $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one(); - /** @var $motivationCostsItem MotivationCostsItem */ - if (isset($motivations[$store_id])) { + if (isset($motivations[$store_id])) { + $writeOffs = WriteOffs::find()->select(['sum(summ) as total', 'type']) + ->where(['between', 'date', $monthStart, $monthEnd]) + ->andWhere(['store_id' => $store_guid]) + ->groupBy(['type']) + ->indexBy('type') + ->asArray()->all(); + foreach ($writeOffs as $key => $data) { + $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key); + if (empty($motivationItemType)) { + continue; + } + $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one(); + /** @var $motivationCostsItem MotivationCostsItem */ $motivationValue = MotivationValue::find()->where(['motivation_id' => $motivations[$store_id]->id, 'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $motivationCostsItem->code])->one(); if (!$motivationValue) { diff --git a/erp24/views/motivation/test-fact.php b/erp24/views/motivation/test-fact.php new file mode 100644 index 00000000..e95249e7 --- /dev/null +++ b/erp24/views/motivation/test-fact.php @@ -0,0 +1,56 @@ + + +
+ + 'GET', 'action' => '/motivation/test-fact']) ?> + +
+
+
+
Год:
+
+ field($model, 'year')->widget(Select2::class, [ + 'data' => $years, + 'language' => 'ru', + 'options' => ['placeholder' => 'Год...'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ])->label(false) ?> +
+
+
Месяц:
+
+ field($model, 'month')->widget(Select2::class, [ + 'data' => $months, + 'language' => 'ru', + 'options' => ['placeholder' => 'Месяц...'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ])->label(false) ?> +
+
+
+
'btn btn-secondary btn-sm']) ?>
+
+
+
+ + + + +
-- 2.39.5