]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Сбор недельных продаж
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 28 May 2025 15:45:26 +0000 (18:45 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 28 May 2025 15:45:26 +0000 (18:45 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/views/auto-plannogramma/week-sales-species-share.php

index 49c3ad2e41a452570871c7ce87d10833f33ef49e..4f24a998ab5e8662e32d8b70cec0d16ccfc78e3c 100644 (file)
@@ -1047,11 +1047,11 @@ class AutoPlannogrammaController extends BaseController
            // $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult['weeksData'], $monthSpeciesGoals) ;
 
 
-            var_dump($weeksShareResult); die();
+            //var_dump($weeksShareResult); die();
 
 
 
-            $flatData = array_filter($weeklySales, function ($row) use ($filters) {
+            $flatData = array_filter($weeksShareResult, function ($row) use ($filters) {
                 foreach ($filters as $key => $value) {
                     if (empty($value)) continue;
                     if (!isset($row[$key])) continue;
index 2c23b248ec748feee43d91f052f37ee5085a3e2c..34877f1e862e476d1921dd4dfcbfbc314dd70068 100644 (file)
@@ -670,6 +670,32 @@ class AutoPlannogrammaService
         return $result;
     }
 
+    protected function getWeekRangesForMonth(int $year, int $month): array
+    {
+        $dateFrom = strtotime(sprintf('%04d-%02d-01 00:00:00', $year, $month));
+        $dateTo   = strtotime('+1 month -1 second', $dateFrom);
+        $dayOfWeek   = (int)date('N', $dateFrom);
+        $firstMonday = $dayOfWeek === 1
+            ? $dateFrom
+            : strtotime('next monday', $dateFrom);
+
+        $ranges = [];
+        for ($wkStart = $firstMonday; $wkStart <= $dateTo; $wkStart += 7*86400) {
+            $wkEnd = min($dateTo, $wkStart + 6*86400);
+            $daysInMonth = floor(($wkEnd - max($wkStart, $dateFrom)) / 86400) + 1;
+            if ($daysInMonth < 4) {
+                continue;
+            }
+            $ranges[] = [
+                'index' => (int)date('W', $wkStart),
+                'start' => date('Y-m-d H:i:s', $wkStart),
+                'end'   => date('Y-m-d 23:59:59', $wkEnd),
+            ];
+        }
+
+        return $ranges;
+    }
+
     /**
      * Исторический недельный отчёт и доли по видам с учётом store_id.
      *
@@ -693,7 +719,7 @@ class AutoPlannogrammaService
         [$yearStr, $monthStr, $_ ] = explode('-', $monthYear);
         $month = (int)$monthStr;
         $year  = (int)$yearStr;
-
+        $yearData = [];
         $historical = [];
         for ($yr = $year - 2; $yr < $year; $yr++) {
             $mYear = sprintf('%04d-%02d',$yr, $month);
@@ -701,7 +727,7 @@ class AutoPlannogrammaService
             $weeklyData = $this->getWeeklySpeciesDataForMonth(
                 $mYear, $filters, $productFilter, $type
             );
-
+            $yearData[$mYear] = $weeklyData;
             foreach ($weeklyData as $row) {
                 $week     = $row['week'];
                 $sid      = $row['store_id'];
@@ -718,7 +744,7 @@ class AutoPlannogrammaService
                     ($historical[$week][$sid][$cat][$sub][$spec] ?? 0) + $sumWeek;
             }
         }
-
+var_dump($yearData); die();
         $dateFrom = sprintf('%04d-%02d-01 00:00:00', $year, $month);
         $dateTo   = date('Y-m-d H:i:s', strtotime("$dateFrom +1 month -1 second"));
         $monthWeighted = $this->getMonthSpeciesShareOrWriteOff(
@@ -779,6 +805,7 @@ class AutoPlannogrammaService
                     'species'     => $spec,
                     'sumWeek'    => $sumWeek,
                     'percent'     => $percent,
+                    'sumMonth' => $sumMonth
                 ];
             }
         }
@@ -803,7 +830,7 @@ class AutoPlannogrammaService
             }
         }
 
-        return ['weeksData' => $rows];
+        return  $rows;
     }
 
 
index ae4969b7eac08ae4fc71c40be7c841d2bb6c35d2..3968b81cd8e86d8f22dc760e78af1e1997b89307 100644 (file)
 
 <?php
 $columns = [
-    ['attribute' => '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' => 'Имя Товара',
+    [
+        'attribute' => 'week',
+        'label' => 'Неделя',
+    ],
+    [
+        'attribute' => 'store_id',
+        'label' => 'Магазин',
         'value' => function ($data) {
-            return \yii_app\records\Products1c::findOne($data['product_id'])->name ?? null;
+            return CityStore::findOne($data['store_id'])->name ?? $data['store_id'];
         },
-        ],
-    ['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' => 'Статус товара', ],
+    ],
+    [
+        'attribute' => 'category',
+        'label' => 'Категория',
+    ],
+    [
+        'attribute' => 'subcategory',
+        'label' => 'Подкатегория',
+    ],
+    [
+        'attribute' => 'species',
+        'label' => 'Тип',
+    ],[
+        'attribute' => 'sumMonth',
+        'label' => 'Сумма за месяц',
+        'format' => ['decimal', 0],
+    ],
+    [
+        'attribute' => 'sumWeek',
+        'label' => 'Сумма за неделю',
+        'format' => ['decimal', 0],
+    ],
+    [
+        'attribute' => 'percent',
+        'label' => 'Доля',
+        'format' => ['percent', 2],
+    ],
 ];
 
-
-?>
-<?= GridView::widget([
+echo GridView::widget([
     'dataProvider' => $dataProvider,
-    'columns' => $columns,
-]); ?>
-<?php
+    'columns'      => $columns,
+]);
+