use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
-
+use kartik\export\ExportMenu;
use yii\data\ArrayDataProvider;
/* @var $model yii\base\DynamicModel */
2 => 'Интернет магазины',
3 => 'Маркетплейсы',
];
+
?>
<div class="show-goal p-4">
<h1>Цели букета на месяц: <?= Html::encode($month) ?>/<?= Html::encode($year) ?></h1>
<p>Нет данных.</p>
<?php endif; ?>
+
+ <h2>Детальный разбор по всем магазинам</h2>
+ <?php
+
+ $flattenedDebug = [];
+ if (!empty($result['debug'])) {
+ foreach ($result['debug'] as $storeId => $speciesData) {
+ foreach ($speciesData as $species => $saleTypes) {
+ foreach ($saleTypes as $saleType => $entries) {
+ foreach ($entries as $entry) {
+ $entry['month'] = $month;
+ $entry['year'] = $year;
+ $entry['store_id'] = $storeId;
+ $entry['store_name'] = isset($storesMap[$storeId]) ? $storesMap[$storeId] : $storeId;
+ $entry['species'] = $species;
+ $entry['sale_type'] = $saleType;
+ $entry['sale_type_label']= isset($saleTypesLabels[$saleType]) ? $saleTypesLabels[$saleType] : $saleType;
+ $flattenedDebug[] = $entry;
+ }
+ }
+ }
+ }
+ }
+ $debugProvider = new ArrayDataProvider([
+ 'allModels' => $flattenedDebug,
+ 'pagination' => false,
+ ]);
+ $gridColumns = [
+ ['attribute' => 'month', 'label' => 'Месяц'],
+ ['attribute' => 'year', 'label' => 'Год'],
+ ['attribute' => 'store_name', 'label' => 'Магазин'],
+ ['attribute' => 'species', 'label' => 'Вид продукции'],
+ ['attribute' => 'sale_type_label', 'label' => 'Тип продаж'],
+ [
+ 'attribute' => 'product_guid',
+ 'label' => 'Product GUID',
+ 'value' => function ($model, $key, $index, $widget) {
+ $product = \yii_app\records\Products1c::find()->where(['id' => $model['product_guid']])->one();
+ return $product ? $product->name . " (" . $model['product_guid'] . ")" : $model['product_guid'];
+ }
+ ],
+ [
+ 'attribute' => 'bouquet_id',
+ 'label' => 'Букет',
+ 'value' => function ($model, $key, $index, $widget) {
+ $bouquet = \yii_app\records\BouquetComposition::find()->where(['id' => $model['bouquet_id']])->one();
+ return $bouquet ? $bouquet->name : $model['bouquet_id'];
+ }
+ ],
+ ['attribute' => 'price', 'label' => 'Цена'],
+ ['attribute' => 'count', 'label' => 'Кол-во'],
+ ['attribute' => 'forecast', 'label' => 'Прогноз'],
+ ['attribute' => 'raw_calculation', 'label' => 'Базовый расчёт'],
+ ['attribute' => 'rounded', 'label' => 'С наценкой за сборку'],
+ ];
+ $exportMenu = ExportMenu::widget([
+ 'dataProvider' => $debugProvider,
+ 'columns' => $gridColumns,
+ 'exportConfig' => [
+ ExportMenu::FORMAT_EXCEL => [
+ 'label' => 'Excel',
+ 'options' => ['title' => 'Сохранить в Excel'],
+ ],
+ ExportMenu::FORMAT_TEXT => false,
+ ExportMenu::FORMAT_HTML => false,
+ ExportMenu::FORMAT_CSV => false,
+ ExportMenu::FORMAT_PDF => false,
+
+ ],
+ 'filename' => 'export_' . date('Y-m-d'),
+ 'showColumnSelector' => false,
+ 'showConfirmAlert' => false,
+ 'target' => ExportMenu::TARGET_SELF,
+ 'dropdownOptions' => [
+ 'label' => 'Экспорт данных',
+ ],
+ ]);
+ echo $exportMenu;
+ echo GridView::widget([
+ 'dataProvider' => $debugProvider,
+ 'columns' => $gridColumns,
+// 'exportConfig' => [
+// GridView::CSV => [
+// 'label' => 'CSV',
+// 'icon' => 'glyphicon glyphicon-download',
+// 'iconOptions' => ['class' => 'text-primary'],
+// 'showHeader' => true,
+// 'showPageSummary' => false,
+// 'showFooter' => false,
+// 'filename' => 'debug-export-' . date('Y-m-d_H-i-s'),
+// 'alertMsg' => 'CSV файл будет загружен в ближайшее время.',
+// 'options' => ['title' => 'CSV'],
+// 'mime' => 'application/csv',
+// 'config' => [
+// 'colDelimiter' => ",",
+// 'rowDelimiter' => "\r\n",
+// ],
+// ],
+// // Другие типы экспорта можно отключить, если не нужны:
+// GridView::HTML => false,
+// GridView::TEXT => false,
+// GridView::EXCEL => false,
+// GridView::PDF => false,
+// GridView::JSON => false,
+// ],
+// 'toolbar' => [
+// '{export}',
+// '{toggleData}',
+// ],
+// 'panel' => [
+// 'heading' => 'Детальный разбор (Debug) по всем магазинам',
+// 'type' => GridView::TYPE_PRIMARY,
+// ],
+ ]);
+
+ ?>
+
</div>