From: Vladimir Fomichev Date: Tue, 20 May 2025 10:28:27 +0000 (+0300) Subject: 8 шаг X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=995a761234f92765f9b21a2f1a9040dc6d5492ef;p=erp24_rep%2Fyii-erp24%2F.git 8 шаг --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 38f87910..8a98c8de 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -8,7 +8,9 @@ use yii\db\Expression; use yii\db\Query; use yii\helpers\ArrayHelper; use yii_app\records\CityStore; +use yii_app\records\MatrixBouquetForecast; use yii_app\services\AutoPlannogrammaService; +use yii_app\services\StorePlanService; class AutoPlannogrammaController extends BaseController { @@ -536,4 +538,132 @@ class AutoPlannogrammaController extends BaseController 'filters' => $filters, ]); } + + public function action7() + { + $request = Yii::$app->request; + + $filters = [ + 'category' => $request->get('category'), + 'subcategory' => $request->get('subcategory'), + 'species' => $request->get('species'), + '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], + ]); + + $data = []; + // Обработка даты на год и месяц + if (!empty($filters['year']) && !empty($filters['month'])) { + $filters['plan_date'] = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01'; + //$service = new AutoPlannogrammaService(); + $matrixGroups = array_unique( + ArrayHelper::getColumn( MatrixBouquetForecast::find() + ->where(['month' => $filters['month'], 'year' => $filters['year']]) + ->asArray() + ->all(), + 'group') + ); + $forecasts = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups); + $forecastsResult = $forecasts['final']; + foreach ($forecastsResult as $storeId => $speciesGoal) { + foreach ($speciesGoal as $species => $goal) { + $data[] = [ + 'month' => $filters['month'], + 'year' => $filters['year'], + 'store_id' => $storeId, + 'species' => $species, + 'goal' => $goal, + ]; + + } + } + + $flatData = array_filter($data, 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('7', [ + 'dataProvider' => $dataProvider, + 'filters' => $filters, + ]); + } + + + public function action8() + { + $request = Yii::$app->request; + + $filters = [ + 'category' => $request->get('category'), + 'subcategory' => $request->get('subcategory'), + 'species' => $request->get('species'), + '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], + ]); + + + // Обработка даты на год и месяц + if (!empty($filters['year']) && !empty($filters['month'])) { + $filters['plan_date'] = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01'; + // $service = new AutoPlannogrammaService(); + $histShare = StorePlanService::calculateHistoricalShare( + $filters['store_id'], + $filters['month'], + $filters['year'], + $filters['category'], + $filters['subcategory'], + $filters['species'], + ); + + $data = StorePlanService::calculateWeightedSalesForProductsWithoutHistory($filters['store_id'], $filters['month'], $filters['year'], $histShare); +var_dump($histShare); die(); + $flatData = array_filter($data, 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('8', [ + 'dataProvider' => $dataProvider, + 'filters' => $filters, + ]); + } } diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index 366491f7..0ebf1cee 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -276,9 +276,11 @@ class StorePlanService */ private static function getPeriods($baseDate, $count, $withWeeks = false, $withWeights = false) { + $date = new \DateTime($baseDate); + $dateFrom = $date->modify('-3 month')->format('Y-m'); $periods = []; for ($i = 1; $i <= $count; $i++) { - $timestamp = strtotime("-{$i} month", $baseDate); + $timestamp = strtotime("-{$i} month", $dateFrom); $year = date('Y', $timestamp); $month = date('m', $timestamp); diff --git a/erp24/views/auto-plannogramma/8.php b/erp24/views/auto-plannogramma/8.php new file mode 100644 index 00000000..8e2519ce --- /dev/null +++ b/erp24/views/auto-plannogramma/8.php @@ -0,0 +1,119 @@ + +
+ +

+ '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' => 'goal', 'label' => 'Сумма План', 'format' => ['decimal', 2]], +]; + +if ($filters['type'] == 'writeOffs') { + $columns = array_merge($columns, [ + ['attribute' => 'old_value', 'label' => 'Сумма до сверки', 'format' => ['decimal', 2]], + ['attribute' => 'sales_goal', 'label' => 'Сумма продаж', 'format' => ['decimal', 2]], + ]); +} +?> + $dataProvider, + 'columns' => $columns, +]); ?> +