From a4e3a674e5cdd88b1502bc9f9c1f629e026c983c Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 28 May 2025 16:27:57 +0300 Subject: [PATCH] =?utf8?q?=D0=A1=D0=B1=D0=BE=D1=80=20=D0=BD=D0=B5=D0=B4?= =?utf8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BF=D1=80=D0=BE=D0=B4?= =?utf8?q?=D0=B0=D0=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 60 +++++++++ erp24/services/AutoPlannogrammaService.php | 2 +- .../week-sales-species-share.php | 126 ++++++++++++++++++ 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 erp24/views/auto-plannogramma/week-sales-species-share.php diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index f9aebf2d..1cf387a6 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -1014,4 +1014,64 @@ class AutoPlannogrammaController extends BaseController 'filters' => $filters, ]); } + + + public function actionWeekSalesSpeciesShare() + { + $request = Yii::$app->request; + + $filters = [ + 'category' => $request->get('category'), + 'subcategory' => $request->get('subcategory') ?? null, + 'species' => $request->get('species') ?? null, + 'store_id' => $request->get('store_id') ?? [], + 'year' => $request->get('year'), + 'month' => $request->get('month'), + 'type' => $request->get('type'), + ]; + + $dataProvider = new ArrayDataProvider([ + 'allModels' => [], + 'pagination' => ['pageSize' => 100], + ]); + + $bouquetSpeciesForecast = []; + // Обработка даты на год и месяц + if (!empty($filters['year']) && !empty($filters['month'])) { + $filters['plan_date'] = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01'; + // var_dump( $filters['plan_date']); die(); + $service = new AutoPlannogrammaService(); + + $weeklySales = $service->getWeeklySpeciesDataForMonth($filters['plan_date'], $filters); + + + + var_dump($weeklySales); die(); + + + + $flatData = array_filter($weeklySales, function ($row) use ($filters) { + foreach ($filters as $key => $value) { + if (empty($value)) continue; + if (!isset($row[$key])) continue; + + if (stripos((string)$row[$key], (string)$value) === false) { + return false; + } + } + return true; + }); + + $dataProvider = new ArrayDataProvider([ + 'allModels' => $flatData, + 'pagination' => ['pageSize' => 100], + ]); + } + return $this->render('week-sales-species-share', [ + 'dataProvider' => $dataProvider, + 'filters' => $filters, + ]); + } + + } diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 3c3c0d98..78694566 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -571,7 +571,7 @@ class AutoPlannogrammaService ?array $productFilter = null, string $type = 'sales' ): array { - [$monthStr, $yearStr] = explode('-', $monthYear); + [$yearStr, $monthStr, $_ ] = explode('-', $monthYear); $month = (int)$monthStr; $year = (int)$yearStr; diff --git a/erp24/views/auto-plannogramma/week-sales-species-share.php b/erp24/views/auto-plannogramma/week-sales-species-share.php new file mode 100644 index 00000000..ae4969b7 --- /dev/null +++ b/erp24/views/auto-plannogramma/week-sales-species-share.php @@ -0,0 +1,126 @@ + +
+ +

+ 'get']); ?> +
+
+ field(new \yii\base\DynamicModel(['category' => $filters['category'] ?? '']), 'category')->widget(Select2::class, [ + 'data' => ArrayHelper::map( + Products1cNomenclature::find()->select('category')->distinct()->asArray()->all(), + 'category', + 'category' + ), + 'options' => ['placeholder' => 'Категория', 'name' => 'category'], + 'pluginOptions' => ['allowClear' => true], + ])->label('Категория') ?> +
+
+ field(new \yii\base\DynamicModel(['subcategory' => $filters['subcategory'] ?? '']), 'subcategory')->widget(Select2::class, [ + 'data' => ArrayHelper::map( + Products1cNomenclature::find()->select('subcategory')->distinct()->asArray()->all(), + 'subcategory', + 'subcategory' + ), + 'options' => ['placeholder' => 'Подкатегория', 'name' => 'subcategory'], + 'pluginOptions' => ['allowClear' => true], + ])->label('Подкатегория') ?> +
+
+ field(new \yii\base\DynamicModel(['species' => $filters['species'] ?? '']), 'species')->widget(Select2::class, [ + 'data' => ArrayHelper::map( + Products1cNomenclature::find()->select('species')->distinct()->asArray()->all(), + 'species', + 'species' + ), + 'options' => ['placeholder' => 'Тип товара', 'name' => 'species'], + 'pluginOptions' => ['allowClear' => true], + ])->label('Товар') ?> +
+
+ field(new \yii\base\DynamicModel(['store_id' => $filters['store_id'] ?? '']), 'store_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map( + CityStore::findAll(['visible' => CityStore::IS_VISIBLE]), + 'id', + 'name' + ), + 'options' => ['placeholder' => 'Магазин', 'name' => 'store_id'], + 'pluginOptions' => ['allowClear' => true], + ])->label('Магазин') ?> +
+
+ field(new \yii\base\DynamicModel(['month' => $filters['month'] ?? '']), 'month')->dropDownList(\yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, [ + 'prompt' => 'Месяц', + 'name' => 'month', + ])->label('Плановый месяц') ?> +
+ +
+ field(new \yii\base\DynamicModel(['year' => $filters['year'] ?? '']), 'year')->dropDownList(['2025' => 2025, '2026' => 2026], [ + 'prompt' => 'Год', + 'name' => 'year', + ])->label('Плановый год') ?> +
+
+ field(new \yii\base\DynamicModel(['type' => $filters['type'] ?? '']), 'type')->widget(Select2::class, [ + 'data' => [ + 'writeOffs' => 'Списания', + 'sales' => 'Продажи' + ], + 'options' => ['placeholder' => 'Тип', 'name' => 'type'], + 'pluginOptions' => ['allowClear' => true], + ])->label('По дефолту продажи!') ?> +
+
+ 'btn btn-primary']) ?> +
+
+ 'btn btn-default']) ?> +
+
+ + +
+ + + + 'store_id', 'label' => 'Магазин', 'value' => function ($data) { + return CityStore::findOne($data['store_id'])->name ?? null; + }], + ['attribute' => 'category', 'label' => 'Категория'], + ['attribute' => 'subcategory', 'label' => 'Подкатегория'], + ['attribute' => 'species', 'label' => 'Тип'], + ['attribute' => 'product_id', 'label' => 'GUID Товара', ], + ['attribute' => 'product_id', 'label' => 'Имя Товара', + 'value' => function ($data) { + return \yii_app\records\Products1c::findOne($data['product_id'])->name ?? null; + }, + ], + ['attribute' => 'forecast_pieces', 'label' => 'Прогноз в шт', 'format' => ['decimal', 2]], + ['attribute' => 'share', 'label' => 'Доля', + + 'format' => ['percent', 2]], + ['attribute' => 'cleanGoal', 'label' => 'Цель вида очищенная', 'format' => ['decimal', 2]], + ['attribute' => 'product_sales', 'label' => 'Прогноз в стоимости внутри вида', 'format' => ['decimal', 2]], + ['attribute' => 'history_status', 'label' => 'Статус товара', ], +]; + + +?> + $dataProvider, + 'columns' => $columns, +]); ?> +