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.
*
[$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);
$weeklyData = $this->getWeeklySpeciesDataForMonth(
$mYear, $filters, $productFilter, $type
);
-
+ $yearData[$mYear] = $weeklyData;
foreach ($weeklyData as $row) {
$week = $row['week'];
$sid = $row['store_id'];
($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(
'species' => $spec,
'sumWeek' => $sumWeek,
'percent' => $percent,
+ 'sumMonth' => $sumMonth
];
}
}
}
}
- return ['weeksData' => $rows];
+ return $rows;
}
<?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,
+]);
+