]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Вывод 8 шага
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 20 May 2025 14:51:50 +0000 (17:51 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 20 May 2025 14:51:50 +0000 (17:51 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/services/StorePlanService.php
erp24/views/auto-plannogramma/8.php

index dd5451fafe4a61b19230924d6c6967f9a5be60a9..c96a8fa1fa71ecf5636e3ae32666d36618816388 100644 (file)
@@ -608,9 +608,9 @@ class AutoPlannogrammaController extends BaseController
 
         $filters = [
             'category' => $request->get('category'),
-            'subcategory' => $request->get('subcategory'),
-            'species' => $request->get('species'),
-            'store_id' => $request->get('store_id'),
+            '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'),
@@ -625,17 +625,11 @@ class AutoPlannogrammaController extends BaseController
         // Обработка даты на год и месяц
         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); die();
+            $service = new AutoPlannogrammaService();
+            $data = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters);
 
-            $data = StorePlanService::calculateSpeciesForecastForProductsWithoutHistory(
-                $filters['store_id'],
-                $filters['month'],
-                $filters['year'],
-                $filters['category'],
-                $filters['subcategory'],
-                $filters['species'],
-            );
-
-            var_dump($data); die();
+            //var_dump($data); die();
             $flatData = array_filter($data, function ($row) use ($filters) {
                 foreach ($filters as $key => $value) {
                     if (empty($value)) continue;
index 5bb2ddc15f1c80dcc6c7914fe658be091d43d4af..28709a9ecb34fcd220555bf1011d9730423456d5 100644 (file)
@@ -540,4 +540,86 @@ class AutoPlannogrammaService
 
         return array_values($filtered);
     }
+
+    /**
+     * Общий расчёт плана для заданной категории товаров без истории.
+     *
+     * @param int    $storeId
+     * @param string $yearMonth   строка "YYYY-MM", например "2025-03"
+     * @param string $category
+     * @param string|null $subcategory
+     * @param string|null $species
+     * @return array  [
+     *     [
+     *         'store_id'    => …,
+     *         'category'    => …,
+     *         'subcategory' => …,
+     *         'species'     => …,
+     *         'month'       => …,
+     *         'year'        => …,
+     *         'sum'         => …,
+     *     ],
+     *     …
+     * ]
+     *
+     */
+    public function calculateSpeciesForecastForProductsWithoutHistory($dateFrom, $filters): array
+    {
+        // Получение ID видимых магазинов
+        $storeIds = array_map(fn($store) => $store->id, $this->getVisibleStores());
+
+        $subcategory = !empty($filters['subcategory']) ? $filters['subcategory'] : null;
+        $species = !empty($filters['species']) ? $filters['species'] : null;
+
+        // Применение фильтра по магазину, если указан
+        if (!empty($filters['store_id'])) {
+            $storeIds = array_intersect($storeIds, [(int)$filters['store_id']]);
+        }
+        $date = new \DateTime($dateFrom);
+        $month = $date->format('m');
+        $year = $date->format('Y');
+
+        $result = [];
+        foreach ($storeIds as $storeId) {
+            $histResult = StorePlanService::calculateHistoricalShare(
+                $storeId,
+                $month,
+                $year,
+                $filters['category'],
+                $subcategory,
+                $species
+            );
+
+            $productsWithoutHistory = $histResult['without_history'] ?? [];
+
+            if (empty($productsWithoutHistory)) {
+                continue;
+            }
+
+            $weightedResults = StorePlanService::calculateWeightedSalesForProductsWithoutHistory(
+                $storeId,
+                $month,
+                $year,
+                $productsWithoutHistory
+            );
+
+
+            if (empty($weightedResults)) {
+                continue;
+            }
+
+            $costs = StorePlanService::calculateCostForProductsWithoutHistory(
+                $storeId, $month, $year, $weightedResults
+            );
+
+            if (!empty($costs)) {
+                $result = array_merge($result, $costs);
+            }
+        }
+
+
+        return $result;
+    }
+
+
 }
\ No newline at end of file
index 6068c9db773bd93d0f2428d6bc11dc8175aa7e5f..fad3130d600b1caf26e671251fa1ad90be066b90 100755 (executable)
@@ -332,7 +332,7 @@ class StorePlanService
      *          ...
      *      ]
      */
-    private static function getSalesHistory($storeId, $periods, $category, $subcategory, $species)
+    private static function getSalesHistory($storeId, $periods, $category, $subcategory = null, $species = null)
     {
         $salesHistory = [];
 
@@ -640,71 +640,7 @@ class StorePlanService
     }
 
 
-    /**
-     * Общий расчёт плана для заданной категории товаров без истории.
-     *
-     * @param int    $storeId
-     * @param string $yearMonth   строка "YYYY-MM", например "2025-03"
-     * @param string $category
-     * @param string|null $subcategory
-     * @param string|null $species
-     * @return array  [
-     *     [
-     *         'store_id'    => …,
-     *         'category'    => …,
-     *         'subcategory' => …,
-     *         'species'     => …,
-     *         'month'       => …,
-     *         'year'        => …,
-     *         'sum'         => …,
-     *     ],
-     *     …
-     * ]
-     *
-     */
-    public static function calculateSpeciesForecastForProductsWithoutHistory(
-        int    $storeId,
-        string $month,
-        string $year,
-        string $category,
-        ?string $subcategory,
-        ?string $species
-    ): array {
-
-        $histResult = self::calculateHistoricalShare(
-            $storeId,
-            $month,
-            $year,
-            $category,
-            $subcategory,
-            $species
-        );
-        $productsWithoutHistory = $histResult['without_history'] ?? [];
-
-        if (empty($productsWithoutHistory)) {
-            return [];
-        }
-
-        $weightedResults = self::calculateWeightedSalesForProductsWithoutHistory(
-            $storeId,
-            $month,
-            $year,
-            $productsWithoutHistory
-        );
 
-        if (empty($weightedResults)) {
-            return [];
-        }
-
-        $costs = self::calculateCostForProductsWithoutHistory(
-            $storeId,
-            $month,
-            $year,
-            $weightedResults
-        );
-
-        return $costs;
-    }
 
     /**
      * Получает идентификаторы товаров, похожих на указанный товар,
index 8e2519cecdd6b70df56e31a265f8741edc6f4bf8..aa89abba6d2dc7abd08c47bad7bee4c237fce570 100644 (file)
@@ -10,7 +10,7 @@
         use yii_app\records\CityStore;
         use yii_app\records\Products1cNomenclature;
         ?>
-        <h1 class="ms-3 mb-4"><?= Html::encode("Расчет цели месяца для типов (month_species_goal)") ?></h1>
+        <h1 class="ms-3 mb-4"><?= Html::encode("Расчет доли товара без истории (month_nohistory_sale_frcst)") ?></h1>
         <?php
         $form = ActiveForm::begin(['method' => 'get']); ?>
         <div class="row p-3">
@@ -102,15 +102,10 @@ $columns = [
     ['attribute' => 'category', 'label' => 'Категория'],
     ['attribute' => 'subcategory', 'label' => 'Подкатегория'],
     ['attribute' => 'species', 'label' => 'Тип'],
-    ['attribute' => 'goal', 'label' => 'Сумма План', 'format' => ['decimal', 2]],
+    ['attribute' => 'sum', '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]],
-    ]);
-}
+
 ?>
 <?= GridView::widget([
     'dataProvider' => $dataProvider,