]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Скачивание по кнопке Auto
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 3 Jul 2025 10:57:33 +0000 (13:57 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 3 Jul 2025 10:57:33 +0000 (13:57 +0300)
erp24/commands/CronController.php
erp24/controllers/AutoPlannogrammaController.php
erp24/views/auto-plannogramma/index.php
erp24/web/js/autoplannogramma/autoplannogramma.js

index 480b37897896d9d4dc7902fe3b4fa8cbb5f4220c..3d1b9f41a7ce7dfae99c4e31873282dddcdc2fc4 100644 (file)
@@ -1692,7 +1692,7 @@ class CronController extends Controller
                             'store_id' => $store->id,
                             'is_archive' => false,
                             'capacity_type' => 1,
-                            'details' => json_encode($details, JSON_UNESCAPED_UNICODE),
+                            'details' => json_encode($details, JSON_UNESCAPED_UNICODE), // TODO двойное кодирование
                             'calculate' => $quantity,
                             'modify' => ceil($total),
                             'total' => ceil($total)
index 5e9eb96718a6b47b4516f977b2eca4c81a8fdf68..4a8c90f917ee67e2ed84815c31c261cc672cb5fd 100644 (file)
@@ -1424,17 +1424,34 @@ class AutoPlannogrammaController extends BaseController
         $this->layout = false;
         Yii::$app->response->format = Response::FORMAT_RAW;
 
+        $mappingTypes = [
+          'offline' => 'Офлайн',
+          'online' => 'Онлайн',
+          'write_offs' => 'Списания',
+          'marketplace' => 'Маркетплейс'
+        ];
 
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
 
-        $filters = $request->get();
+        $filters = [];
+            $request->get();
+        $filters['year'] = (int)$request->get('year');
+        $filters['week'] = (int)$request->get('week');
+        $filters['city'] = $request->get('city', null);
+        $filters['region'] = $request->get('region', null);
+        $filters['district'] = $request->get('district', null);
+        $filters['capacity_type'] = is_numeric($request->get('capacity_type')) ? (int)$request->get('capacity_type') : null;
+        $filters['store_type'] = is_numeric($request->get('store_type')) ? (int)$request->get('store_type') : null;
+        $filters['territorial_manager'] = is_numeric($request->get('territorial_manager')) ? (int)$request->get('territorial_manager') : null;
+        $filters['bush_chef_florist'] = is_numeric($request->get('bush_chef_florist')) ? (int)$request->get('bush_chef_florist') : null;
 
         $query = Autoplannogramma::find()
             ->alias('a')
             ->leftJoin('products_1c_nomenclature p1n', 'p1n.id = a.product_id')
             ->leftJoin('city_store_params cp', 'cp.store_id = a.store_id')
+            ->leftJoin('city_store c', 'c.id = a.store_id')
            // ->where(['p1n.category' => $category])
            // ->andWhere(['p1n.subcategory' => $subcategory])
             ->andFilterWhere(['=', 'a.year', $filters['year']])
@@ -1461,37 +1478,68 @@ class AutoPlannogrammaController extends BaseController
             $query->andWhere(['in', 'a.store_id', $bushChefFloristStoreIds ?: [-1]]);
         }
 
-        $models = $query
+        $autoplannogrammData = $query
             ->select([
                 'a.id AS plan_id',
                 'p1n.id AS product_id',
+                'a.product_id',
                 'p1n.name AS product_name',
+                'p1n.category AS category',
+                'p1n.subcategory AS subcategory',
+                'p1n.species AS species',
                 'a.store_id',
+                'c.name AS store_name',
                 'a.modify',
+                'a.capacity_type',
                 'a.details',
-                'a.month'
+                'a.month',
+                'a.year',
+                'a.week'
             ])
             ->asArray()
             ->all();
 
+            $detailsData = [];
+            foreach ($autoplannogrammData as $product) {
+                $data = $product['details'];
+                while (is_string($data)) {
+                    $decoded = json_decode($data, true);
+                    if (json_last_error() !== JSON_ERROR_NONE) {
+                        break;
+                    }
+                    $data = $decoded;
+                }
+                $detailsArray = $data;
+                foreach ($detailsArray as $type => $typeArr) {
+                    if (!isset($typeArr['groups']) ) {
+                        continue;
+                    }
+                    $groups = $typeArr['groups'];
+                    $groups[$type] = $typeArr['quantity'];
+                    foreach ($groups as $group => $quantity) {
+                        if (in_array($group, array_keys($mappingTypes))) {
+                            $groupName = $mappingTypes[$group];
+                        } else {
+                            $groupName = $group;
+                        }
+                        $detailsData[] = [
+                            'product_name' => $product['product_name'],
+                            'category' => $product['category'],
+                            'subcategory' => $product['subcategory'],
+                            'species' => $product['species'],
+                            'month' => $product['month'],
+                            'year' => $product['year'],
+                            'week' => $product['week'] . '/' . $product['year'] . '/' . $product['month'],
+                            'type_pm' => $product['capacity_type'] == 1 ? 'max' : 'min',
+                            'shop' => $product['store_id'] . ' ' . $product['store_name'],
+                            'group_name' => $groupName,
+                            'quantity' => $quantity,
+                            'value_type' => $type,
+                        ];
+                    }
 
-            foreach ($weeklySalesForecast as $fc ) {
-                $rows[] = [
-                    'week' => $fc['week'],
-                    'type_pm' => 'max',
-                    'shop' => $fc['store_id'],
-                    'category' => $fc['category'],
-                    'subcategory' => $fc['subcategory'],
-                    'species' => $fc['species'],
-                    'product_name' => $fc['product_id'],
-                    'quantity'  => $fc['forecast_week_pieces'],
-                    'value_type' => 'offline',
-                    'group_name' => 'Оффлайн',
-                ];
+                }
             }
-
-
-
             $spreadsheet = new Spreadsheet();
         $sheet = $spreadsheet->getActiveSheet();
         $sheet->setTitle('Отчёт');
@@ -1509,7 +1557,7 @@ class AutoPlannogrammaController extends BaseController
 
         $rowNum = 2;
 
-        foreach ($rows as $row) {
+        foreach ($detailsData as $row) {
             $sheet->setCellValue('A' . $rowNum, $row['week']);
             $sheet->setCellValue('B' . $rowNum, $row['type_pm']);
             $sheet->setCellValue('C' . $rowNum, $row['shop']);
index 9ee91af0c7f654a0e334ea6715693ff3227c3a55..950f0727f1e03db3f376f562faff2d2c27b19ce5 100644 (file)
@@ -187,7 +187,11 @@ $this->registerJsFile('/js/autoplannogramma/autoplannogramma.js', ['position' =>
                     <?= Html::label("КШФ:", null, ['class' => 'label-kshf']) ?><br>
 
                     <div class="buttons d-flex justify-content-end">
-                        <?= Html::a('Auto', Url::to(['auto-plannogramma/week-sales-species-excel']), ['class' => 'btn btn-success ms-1 btn-auto', 'target' => '_blank']) ?>
+                        <?= Html::a('Auto', '#', [
+                            'class' => 'btn btn-success ms-1 btn-auto',
+                            'id' => 'export-excel-btn',
+                            'target' => '_blank'
+                        ]) ?>
                         <?= Html::a('Corrected', '#', ['class' => 'btn btn-success ms-1 btn-corrected']) ?>
                     </div>
                 </th>
index e337b58d11f19f8bd79241df591c8fea976a5055..553d40f4857e3774b77f251c5d13e379d719773f 100644 (file)
@@ -5,6 +5,31 @@ document.addEventListener("DOMContentLoaded", () => {
             row.style.display = "none";
         }
     });
+    $('#export-excel-btn').on('click', function (e) {
+        e.preventDefault();
+
+        const baseUrl = '/auto-plannogramma/export-excel';
+        const params = {
+            year: $('#year').val(),
+            week: $('#week').val(),
+            city: $('#city').val(),
+            region: $('#region').val(),
+            store_type: $('#store-type').val(),
+            capacity_type: $('#capacity-type').val() || null,
+            bush_chef_florist: $('#bush_chef_florist').val(),
+            territorial_manager: $('#territorial-manager').val(),
+            polnogramma_type: $('#polnogramma-type').val()
+        };
+
+        const query = Object.entries(params)
+            .filter(([_, v]) => v !== null && v !== '')
+            .map(([k, v]) => k + '=' + encodeURIComponent(v))
+            .join('&');
+
+        const url = baseUrl + (query ? '?' + query : '');
+
+        window.open(url, '_blank');
+    });
 
     document.querySelectorAll(".category").forEach(category => {
         category.addEventListener("click", function () {