From 5f54e4dc22f40a0a07714b6bdfde25ab25f7e12b Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 28 May 2025 18:45:26 +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 | 4 +- erp24/services/AutoPlannogrammaService.php | 35 +++++++++-- .../week-sales-species-share.php | 62 ++++++++++++------- 3 files changed, 72 insertions(+), 29 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 49c3ad2e..4f24a998 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -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; diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 2c23b248..34877f1e 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -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; } diff --git a/erp24/views/auto-plannogramma/week-sales-species-share.php b/erp24/views/auto-plannogramma/week-sales-species-share.php index ae4969b7..3968b81c 100644 --- a/erp24/views/auto-plannogramma/week-sales-species-share.php +++ b/erp24/views/auto-plannogramma/week-sales-species-share.php @@ -96,31 +96,47 @@ '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], + ], ]; - -?> - $dataProvider, - 'columns' => $columns, -]); ?> - $columns, +]); + -- 2.39.5