]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Экспорт в эксель
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 16 Apr 2025 12:49:32 +0000 (15:49 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 16 Apr 2025 12:49:32 +0000 (15:49 +0300)
erp24/views/bouquet/month-goal.php

index b030367c38ad212f5058392c27120e867bc7a251..3ea81784e5e4caed6bdd95d13c99c762a5d2024d 100644 (file)
@@ -4,7 +4,7 @@ use kartik\grid\GridView;
 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 */
@@ -18,6 +18,7 @@ $saleTypesLabels = [
     2 => 'Интернет магазины',
     3 => 'Маркетплейсы',
 ];
+
 ?>
 <div class="show-goal p-4">
     <h1>Цели букета на месяц: <?= Html::encode($month) ?>/<?= Html::encode($year) ?></h1>
@@ -170,4 +171,121 @@ $saleTypesLabels = [
     <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>