return $data;
}
- public function actionMonthGoal($month, $year)
+ public function actionMonthGoal()
{
+ $request = Yii::$app->request;
+
+ $month = $request->post('month') ? (int)$request->post('month') : 5;
+ $year = $request->post('year') ? (int)$request->post('year') : 2025;
$result = StorePlanService::getBouquetSpiecesMonthGoal($month, $year);
- $month = $month ?? 5;
- $year = $year ?? 2025;
$stores = CityStore::find()
->select(['id', 'name'])
->where(['visible' => CityStore::IS_VISIBLE])
->asArray()
->all();
-
$storesMap = ArrayHelper::map($stores, 'id', 'name');
-
return $this->render('month-goal', [
'result' => $result,
'storesMap' => $storesMap,
<?php
+use yii\helpers\Html;
+use yii\helpers\Url;
+
/* @var $result array // Массив с ключами 'detail' и 'final'
@var $storesMap array // Маппинг [store_id => store_name]
@var $month integer
?>
<h1>Цели на месяц: <?= $month ?>/<?= $year ?></h1>
+<!-- Форма для выбора месяца и года -->
+<?= Html::beginForm(Url::to(['bouquet/month-goal']), 'post') ?>
+<label for="month">Месяц:</label>
+<?= Html::input('number', 'month', $month, ['min' => 1, 'max' => 12]) ?>
+
+<label for="year">Год:</label>
+<?= Html::input('number', 'year', $year, ['min' => 2000, 'max' => 2100]) ?>
+
+<?= Html::submitButton('Показать', ['class' => 'btn btn-primary']) ?>
+<?= Html::endForm() ?>
+
+<hr>
+
+<!-- Таблица для итоговых сумм ('final') -->
<h2>Итоговые суммы по магазинам и видам продукции</h2>
<table border="1" cellpadding="5" cellspacing="0">
<thead>
<?php if (!empty($result['final'])): ?>
<?php foreach ($result['final'] as $storeId => $speciesData): ?>
<?php
- // Ð\9eпÑ\80еделÑ\8fем имÑ\8f магазина по mapping'Ñ\83, еÑ\81ли оно оÑ\82Ñ\81Ñ\83Ñ\82Ñ\81Ñ\82вÑ\83еÑ\82 – выводим id
+ // Ð\95Ñ\81ли имÑ\8f магазина оÑ\82Ñ\81Ñ\83Ñ\82Ñ\81Ñ\82вÑ\83еÑ\82 в mapping'е – выводим id
$storeName = isset($storesMap[$storeId]) ? $storesMap[$storeId] : $storeId;
?>
<?php foreach ($speciesData as $species => $sum): ?>
<tr>
- <td><?= htmlspecialchars($storeName) ?></td>
- <td><?= htmlspecialchars($species) ?></td>
+ <td><?= Html::encode($storeName) ?></td>
+ <td><?= Html::encode($species) ?></td>
<td><?= $sum ?></td>
</tr>
<?php endforeach; ?>
</tr>
<?php endif; ?>
</tbody>
+</table>
+
+<!-- Таблица для подробного расчёта ('detail') -->
+<h2>Подробный расчёт по магазинам</h2>
+<table border="1" cellpadding="5" cellspacing="0">
+ <thead>
+ <tr>
+ <th>Магазин</th>
+ <th>Вид продукции</th>
+ <th>Тип продаж</th>
+ <th>Сумма</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php if (!empty($result['detail'])): ?>
+ <?php foreach ($result['detail'] as $storeId => $speciesData): ?>
+ <?php
+ // Определяем имя магазина по mapping'у
+ $storeName = isset($storesMap[$storeId]) ? $storesMap[$storeId] : $storeId;
+ ?>
+ <?php foreach ($speciesData as $species => $saleTypes): ?>
+ <?php foreach ($saleTypes as $saleType => $amount): ?>
+ <tr>
+ <td><?= Html::encode($storeName) ?></td>
+ <td><?= Html::encode($species) ?></td>
+ <td><?= Html::encode($saleType) ?></td>
+ <td><?= $amount ?></td>
+ </tr>
+ <?php endforeach; ?>
+ <?php endforeach; ?>
+ <?php endforeach; ?>
+ <?php else: ?>
+ <tr>
+ <td colspan="4">Нет данных для отображения.</td>
+ </tr>
+ <?php endif; ?>
+ </tbody>
</table>
\ No newline at end of file