From: marina Date: Mon, 12 May 2025 15:20:48 +0000 (+0300) Subject: ERP-413 Обработка ОС Планограмма (месяц) X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e55bc82bee5c3f7225ccbdb8e75abf4c33de545a;p=erp24_rep%2Fyii-erp24%2F.git ERP-413 Обработка ОС Планограмма (месяц) --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 05489a84..bc6a3c3d 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -213,7 +213,8 @@ class AutoPlannogrammaController extends BaseController $filters = [ 'category' => $request->get('category'), 'store_id' => $request->get('store_id'), - 'plan_date' => $request->get('plan_date'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), 'type' => $request->get('type'), ]; @@ -221,12 +222,10 @@ class AutoPlannogrammaController extends BaseController 'allModels' => [], 'pagination' => ['pageSize' => 100], ]); - if (!empty($filters['plan_date'])) { - $planDateParts = explode('-', $filters['plan_date']); - if (count($planDateParts) === 2) { - [$month, $year] = $planDateParts; - $filters['plan_date'] = "$year-$month-01"; - } + + // Обработка даты на год и месяц + 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(); $data = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); @@ -274,7 +273,8 @@ class AutoPlannogrammaController extends BaseController $filters = [ 'category' => $request->get('category'), 'store_id' => $request->get('store_id'), - 'plan_date' => $request->get('plan_date'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), 'type' => $request->get('type'), ]; @@ -283,19 +283,15 @@ class AutoPlannogrammaController extends BaseController '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'; - if (!empty($filters['plan_date'])) { - $planDateParts = explode('-', $filters['plan_date']); - if (count($planDateParts) === 2) { - [$month, $year] = $planDateParts; - $filters['plan_date'] = "$year-$month-01"; - } $service = new AutoPlannogrammaService(); $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters); $data = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date'], $filters); - $flatData = array_filter($data, function ($row) use ($filters) { foreach ($filters as $key => $value) { if (empty($value)) continue; @@ -308,12 +304,12 @@ class AutoPlannogrammaController extends BaseController return true; }); - $dataProvider = new ArrayDataProvider([ 'allModels' => $flatData, 'pagination' => ['pageSize' => 100], ]); } + return $this->render('2', [ 'dataProvider' => $dataProvider, 'filters' => $filters, @@ -328,7 +324,8 @@ class AutoPlannogrammaController extends BaseController 'category' => $request->get('category'), 'subcategory' => $request->get('subcategory'), 'store_id' => $request->get('store_id'), - 'plan_date' => $request->get('plan_date'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), 'type' => $request->get('type'), ]; @@ -338,12 +335,9 @@ class AutoPlannogrammaController extends BaseController ]); - if (!empty($filters['plan_date'])) { - $planDateParts = explode('-', $filters['plan_date']); - if (count($planDateParts) === 2) { - [$month, $year] = $planDateParts; - $filters['plan_date'] = "$year-$month-01"; - } + // Обработка даты на год и месяц + 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(); $data = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); @@ -379,7 +373,8 @@ class AutoPlannogrammaController extends BaseController 'category' => $request->get('category'), 'subcategory' => $request->get('subcategory'), 'store_id' => $request->get('store_id'), - 'plan_date' => $request->get('plan_date'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), 'type' => $request->get('type'), ]; @@ -389,7 +384,9 @@ class AutoPlannogrammaController extends BaseController ]); - if (!empty($filters['plan_date'])) { + // Обработка даты на год и месяц + if (!empty($filters['year']) && !empty($filters['month'])) { + $filters['plan_date'] = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01'; $planDateParts = explode('-', $filters['plan_date']); if (count($planDateParts) === 2) { [$month, $year] = $planDateParts; @@ -442,7 +439,8 @@ class AutoPlannogrammaController extends BaseController 'subcategory' => $request->get('subcategory'), 'species' => $request->get('species'), 'store_id' => $request->get('store_id'), - 'plan_date' => $request->get('plan_date'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), 'type' => $request->get('type'), ]; @@ -451,13 +449,9 @@ class AutoPlannogrammaController extends BaseController 'pagination' => ['pageSize' => 100], ]); - - if (!empty($filters['plan_date'])) { $planDateParts = explode('-', $filters['plan_date']); - if (count($planDateParts) === 2) { - [$month, $year] = $planDateParts; - $filters['plan_date'] = "$year-$month-01"; - } - + // Обработка даты на год и месяц + 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(); $data = $service->getMonthSpeciesShareOrWriteOff( @@ -500,7 +494,8 @@ class AutoPlannogrammaController extends BaseController 'subcategory' => $request->get('subcategory'), 'species' => $request->get('species'), 'store_id' => $request->get('store_id'), - 'plan_date' => $request->get('plan_date'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), 'type' => $request->get('type'), ]; @@ -510,13 +505,9 @@ class AutoPlannogrammaController extends BaseController ]); - if (!empty($filters['plan_date'])) { - $planDateParts = explode('-', $filters['plan_date']); - if (count($planDateParts) === 2) { - [$month, $year] = $planDateParts; - $filters['plan_date'] = "$year-$month-01"; - } - + // Обработка даты на год и месяц + 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(); $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff( diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 70f6a2cc..b4a07680 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -86,10 +86,6 @@ class AutoPlannogrammaService return []; } - if (!in_array($type, [self::TYPE_SALES, self::TYPE_WRITE_OFFS], true)) { - throw new \InvalidArgumentException("Недопустимый тип операции: $type"); - } - $query = $this->buildBaseTotalsQuery($type); $query = $this->applyJoins($query, $type); @@ -119,11 +115,6 @@ class AutoPlannogrammaService */ public function getMonthCategoryShareOrWriteOff(string $dateFrom, ?array $filters = null, string $type = self::TYPE_SALES): array { - // Проверка типа операции - if (!in_array($type, [self::TYPE_SALES, self::TYPE_WRITE_OFFS], true)) { - throw new \InvalidArgumentException("Недопустимый тип операции: $type"); - } - // Получение ID видимых магазинов $storeIds = array_map(fn($store) => $store->id, $this->getVisibleStores()); @@ -250,10 +241,6 @@ class AutoPlannogrammaService */ public function getMonthSubcategoryShareOrWriteOff(string $dateFrom, ?array $filters = null, string $type = self::TYPE_SALES): array { - if (!in_array($type, [self::TYPE_SALES, self::TYPE_WRITE_OFFS], true)) { - throw new \InvalidArgumentException("Недопустимый тип операции: $type"); - } - $storeIds = array_map(fn($store) => $store->id, $this->getVisibleStores()); if (!empty($filters['store_id'])) { $storeIds = array_intersect($storeIds, [(int)$filters['store_id']]); @@ -266,6 +253,12 @@ class AutoPlannogrammaService $productTableJoin = $type === self::TYPE_WRITE_OFFS ? ['wp' => 'write_offs_products'] : ['sp' => 'sales_products']; $productTableJoinCondition = $type === self::TYPE_WRITE_OFFS ? 'wp.write_offs_id = w.id' : 'sp.check_id = s.id'; + $date = new \DateTime($dateFrom); + $months = [ + ['between', 'date', $date->modify('-1 year')->format('Y-m-01'), $date->format('Y-m-t')], + ['between', 'date', $date->modify('-1 year')->format('Y-m-01'), $date->format('Y-m-t')], + ]; + $query = (new Query()) ->select([ 'store_id' => 'main.ex_entity_id', @@ -287,9 +280,9 @@ class AutoPlannogrammaService ->leftJoin($productTableJoin, $productTableJoinCondition) ->leftJoin('products_1c_nomenclature p1c', "p1c.id = $productJoinCondition") ->leftJoin('export_import_table ex', $storeJoinCondition) - ->where(['>=', 'date', $dateFrom]) ->andWhere(['ex.entity_id' => $storeIds]) ->andWhere(['<>', 'p1c.subcategory', '']) + ->andWhere(['or', ...$months]) ->groupBy(['ex.entity_id', 'p1c.category', 'p1c.subcategory']), ]) ->innerJoin( @@ -302,9 +295,9 @@ class AutoPlannogrammaService ->leftJoin($productTableJoin, $productTableJoinCondition) ->leftJoin('products_1c_nomenclature p1c', "p1c.id = $productJoinCondition") ->leftJoin('export_import_table ex', $storeJoinCondition) - ->where(['>=', 'date', $dateFrom]) ->andWhere(['ex.entity_id' => $storeIds]) ->andWhere(['<>', 'p1c.subcategory', '']) + ->andWhere(['or', ...$months]) ->groupBy(['ex.entity_id'])], 'main.ex_entity_id = totals.store_id' ); @@ -312,7 +305,7 @@ class AutoPlannogrammaService $rows = $query->all(); $result = []; - foreach ($rows as $row) { + foreach ($rows as $row) { $result[] = [ 'store_id' => $row['store_id'], 'category' => $row['category'], @@ -334,6 +327,10 @@ class AutoPlannogrammaService */ public function getMonthSubcategoryGoal(array $subcategoryShare, array $categoryGoals): array { + echo '
';
+        var_dump($subcategoryShare);
+        echo '
'; + die(); $indexedGoals = []; foreach ($categoryGoals as $goal) { $indexedGoals[$goal['store_id']][$goal['category']] = $goal['goal']; @@ -365,10 +362,6 @@ class AutoPlannogrammaService */ public function getMonthSpeciesShareOrWriteOff(string $dateFrom, ?array $filters = null, string $type = self::TYPE_SALES): array { - if (!in_array($type, [self::TYPE_SALES, self::TYPE_WRITE_OFFS], true)) { - throw new \InvalidArgumentException("Недопустимый тип операции: $type"); - } - $storeIds = array_map(fn($store) => $store->id, $this->getVisibleStores()); if (!empty($filters['store_id'])) { $storeIds = array_intersect($storeIds, [(int)$filters['store_id']]); @@ -381,6 +374,12 @@ class AutoPlannogrammaService $productTableJoin = $type === self::TYPE_WRITE_OFFS ? ['wp' => 'write_offs_products'] : ['sp' => 'sales_products']; $productTableJoinCondition = $type === self::TYPE_WRITE_OFFS ? 'wp.write_offs_id = w.id' : 'sp.check_id = s.id'; + $date = new \DateTime($dateFrom); + $months = [ + ['between', 'date', $date->modify('-1 year')->format('Y-m-01'), $date->format('Y-m-t')], + ['between', 'date', $date->modify('-1 year')->format('Y-m-01'), $date->format('Y-m-t')], + ]; + $query = (new Query()) ->select([ 'store_id' => 'main.ex_entity_id', @@ -418,7 +417,7 @@ class AutoPlannogrammaService ->leftJoin($productTableJoin, $productTableJoinCondition) ->leftJoin('products_1c_nomenclature p1c', "p1c.id = $productJoinCondition") ->leftJoin('export_import_table ex', $storeJoinCondition) - ->where(['>=', key($fromTable) . '.date', $dateFrom]) + ->andWhere(['or', ...$months]) ->andWhere(['ex.entity_id' => $storeIds]) ->andWhere(['<>', 'p1c.species', '']) ->groupBy(['ex.entity_id'])], @@ -482,16 +481,15 @@ class AutoPlannogrammaService { $datePlan = $filters['plan_date']; $dateFromForCategory = (new \DateTime($datePlan))->modify('-' . (self::CATEGORY_LOOKBACK_MONTHS + self::LOOKBACK_MONTHS) . ' months')->format(self::DATE_FORMAT); - $dateToForCategory = (new \DateTime($datePlan))->modify('-' . (self::CATEGORY_LOOKBACK_MONTHS + self::LOOKBACK_MONTHS) . ' months')->format(self::DATE_FORMAT); $dateFrom = (new \DateTime($datePlan))->modify('-' . (self::SUBCATEGORY_LOOKBACK_MONTHS + self::LOOKBACK_MONTHS). ' months')->format(self::DATE_FORMAT); $monthCategoryShare = $this->getMonthCategoryShareOrWriteOff($dateFromForCategory, $filters); $monthCategoryGoal = $this->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters); - $monthSubcategoryShare = $this->getMonthSubcategoryShareOrWriteOff($dateFrom, $filters); + $monthSubcategoryShare = $this->getMonthSubcategoryShareOrWriteOff($datePlan, $filters); $monthSubcategoryGoal = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); - $monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOff($dateFrom, $filters); + $monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOff($datePlan, $filters); $monthSpeciesGoal = $this->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); $filtered = array_filter($monthSpeciesGoal, function ($row) use ($filters) { diff --git a/erp24/views/auto-plannogramma/1.php b/erp24/views/auto-plannogramma/1.php index 265601f9..68f18ce9 100644 --- a/erp24/views/auto-plannogramma/1.php +++ b/erp24/views/auto-plannogramma/1.php @@ -7,7 +7,7 @@ use yii\widgets\ActiveForm; use yii_app\records\CityStore; use yii_app\records\Products1cNomenclature;?> -

+

'get']); ?>
@@ -33,17 +33,17 @@ ])->label('Магазин') ?>
- field(new \yii\base\DynamicModel(['plan_date' => $filters['plan_date'] ?? '']), 'plan_date')->widget(DatePicker::class, [ - 'pluginOptions' => [ - 'autoclose' => true, - 'format' => 'mm-yyyy', - ], - 'options' => [ - 'class' => 'form-control', - 'placeholder' => 'Плановая дата', - 'name' => 'plan_date', - ], - ])->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, [ @@ -77,3 +77,4 @@ ['attribute' => 'percent', 'label' => 'Доля', 'format' => ['percent', 2]], ], ]); ?> + diff --git a/erp24/views/auto-plannogramma/2.php b/erp24/views/auto-plannogramma/2.php index 960cd920..d6c71186 100644 --- a/erp24/views/auto-plannogramma/2.php +++ b/erp24/views/auto-plannogramma/2.php @@ -36,17 +36,17 @@ ])->label('Магазин') ?>
- field(new \yii\base\DynamicModel(['plan_date' => $filters['plan_date'] ?? '']), 'plan_date')->widget(DatePicker::class, [ - 'pluginOptions' => [ - 'autoclose' => true, - 'format' => 'mm-yyyy', - ], - 'options' => [ - 'class' => 'form-control', - 'placeholder' => 'Плановая дата', - 'name' => 'plan_date', - ], - ])->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, [ diff --git a/erp24/views/auto-plannogramma/3.php b/erp24/views/auto-plannogramma/3.php index 5caf65b6..22586e78 100644 --- a/erp24/views/auto-plannogramma/3.php +++ b/erp24/views/auto-plannogramma/3.php @@ -46,17 +46,17 @@ ])->label('Магазин') ?>
- field(new \yii\base\DynamicModel(['plan_date' => $filters['plan_date'] ?? '']), 'plan_date')->widget(DatePicker::class, [ - 'pluginOptions' => [ - 'autoclose' => true, - 'format' => 'mm-yyyy', - ], - 'options' => [ - 'class' => 'form-control', - 'placeholder' => 'Плановая дата', - 'name' => 'plan_date', - ], - ])->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, [ diff --git a/erp24/views/auto-plannogramma/4.php b/erp24/views/auto-plannogramma/4.php index 94a02682..4ab49e21 100644 --- a/erp24/views/auto-plannogramma/4.php +++ b/erp24/views/auto-plannogramma/4.php @@ -48,17 +48,17 @@ ])->label('Магазин') ?>
- field(new \yii\base\DynamicModel(['plan_date' => $filters['plan_date'] ?? '']), 'plan_date')->widget(DatePicker::class, [ - 'pluginOptions' => [ - 'autoclose' => true, - 'format' => 'mm-yyyy', - ], - 'options' => [ - 'class' => 'form-control', - 'placeholder' => 'Плановая дата', - 'name' => 'plan_date', - ], - ])->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, [ diff --git a/erp24/views/auto-plannogramma/5.php b/erp24/views/auto-plannogramma/5.php index 000bdaa4..fc707197 100644 --- a/erp24/views/auto-plannogramma/5.php +++ b/erp24/views/auto-plannogramma/5.php @@ -59,17 +59,17 @@ ])->label('Магазин') ?>
- field(new \yii\base\DynamicModel(['plan_date' => $filters['plan_date'] ?? '']), 'plan_date')->widget(DatePicker::class, [ - 'pluginOptions' => [ - 'autoclose' => true, - 'format' => 'mm-yyyy', - ], - 'options' => [ - 'class' => 'form-control', - 'placeholder' => 'Плановая дата', - 'name' => 'plan_date', - ], - ])->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, [ diff --git a/erp24/views/auto-plannogramma/6.php b/erp24/views/auto-plannogramma/6.php index db1e5ea9..c49498d1 100644 --- a/erp24/views/auto-plannogramma/6.php +++ b/erp24/views/auto-plannogramma/6.php @@ -59,17 +59,17 @@ ])->label('Магазин') ?>
- field(new \yii\base\DynamicModel(['plan_date' => $filters['plan_date'] ?? '']), 'plan_date')->widget(DatePicker::class, [ - 'pluginOptions' => [ - 'autoclose' => true, - 'format' => 'mm-yyyy', - ], - 'options' => [ - 'class' => 'form-control', - 'placeholder' => 'Плановая дата', - 'name' => 'plan_date', - ], - ])->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, [