]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-360 Сборка страницы автопм
authormarina <m.zozirova@gmail.com>
Mon, 16 Jun 2025 13:22:59 +0000 (16:22 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 16 Jun 2025 13:22:59 +0000 (16:22 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/web/js/autoplannogramma/autoplannogramma.js

index d124e04888d728c3331d3ed2b3d74bb7f33222ca..3c52596c349d6a85d9b18d777a9865eeaa92fcd8 100644 (file)
@@ -1750,22 +1750,16 @@ class AutoPlannogrammaController extends BaseController
         ]);
     }
 
-    public function actionWeeklyBouquetProductsForecast()
+    public function actionWeeklyBouquetProductsForecast($storeId, $month, $year, $week)
     {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
 
-        $request = Yii::$app->request;
-        $storeIdRequest = $request->get('storeId');
-        $monthRequest = $request->get('month');
-        $yearRequest = $request->get('year');
-        $weekRequest = $request->get('week');
-
-        if (!$monthRequest || !$yearRequest || $weekRequest === null) {
+        if (!$month || !$year || $week === null) {
             return ['success' => false, 'message' => 'Нет параметров'];
         }
 
         $service = new AutoPlannogrammaService();
-        $result = $service->getWeeklyBouquetProductsForecast($monthRequest, $yearRequest, $storeIdRequest);
+        $result = $service->getWeeklyBouquetProductsForecast($month, $year, $storeId);
 
         if (!is_array($result)) {
             return ['success' => false, 'message' => 'Ошибка структуры данных'];
@@ -1785,8 +1779,8 @@ class AutoPlannogrammaController extends BaseController
         }
 
 
-        if ($weekRequest !== null) {
-            $week = (int)$weekRequest;
+        if ($week !== null) {
+            $week = (int)$week;
             $grouped = isset($grouped[$week]) ? [$week => $grouped[$week]] : [];
         }
 
@@ -1794,8 +1788,6 @@ class AutoPlannogrammaController extends BaseController
             'success' => true,
             'data' => $grouped,
         ];
-
-
     }
 
     public function actionGetSubcategories(string $category, int $year, int $week): array
index e1b77ff2153f0c73c4265293b77183fd12988e4b..f8df96891d6c88e55544e093da2f314f0447a13d 100644 (file)
@@ -99,7 +99,7 @@ $('.subcategory .list-group-item').on('click', function (e) {
                 const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible');
                 if (!isVisible) return;
 
-                const val = valuesMap[storeId] || { quantity: '', id: '' };
+                const val = valuesMap[storeId] || {quantity: '', id: ''};
 
                 const td = $(`
                     <td data-store-id="${storeId}">
@@ -140,7 +140,7 @@ $('.category .list-group-item').on('click', function () {
     const year = $('#year').val();
     const week = $('#week').val();
     $('.loader-overlay').removeClass('d-none');
-    $.get('/auto-plannogramma/get-subcategories', { category, year, week }, function (subcategories) {
+    $.get('/auto-plannogramma/get-subcategories', {category, year, week}, function (subcategories) {
         const subMap = {};
         subcategories.forEach(sub => {
             subMap[sub.name] = sub.hasdata;
@@ -227,6 +227,33 @@ function applyStoreFilter() {
     });
 }
 
+$(document).on('click', '.input', function () {
+    const $el = $(this);
+
+    if ($el.data('tooltip-loaded')) return;
+
+    const storeId = $el.data('store_id');
+    const year = $('#year').val();
+    const week = $('#week').val();
+    const month = getMonthByWeek(week, year, true);
+
+    const data = {
+        storeId: storeId,
+        year: year,
+        week: week,
+        month: month
+    };
+
+    $.get('/auto-plannogramma/weekly-bouquet-products-forecast', data, (response) => {
+        const titleText = typeof response === 'object' ? JSON.stringify(response) : response;
+        $el.attr('title', titleText).data('tooltip-loaded', true);
+
+        if ($el.tooltip) {
+            $el.tooltip('dispose').tooltip();
+        }
+    });
+});
+
 $('.btn-save').on('click', function () {
     const changedValues = [];
     let hasErrors = false;
@@ -313,18 +340,24 @@ $('.btn-apply').on('click', function () {
 });
 $('.btn-reset').on('click', resetStoreFilter);
 
-function getMonthByWeek(week, year) {
-    if (!(week) || !(year)) {
+function getMonthByWeek(week, year, returnNumber = false) {
+    if (!week || !year) {
         return;
     }
+
     const start = new Date(year, 0, 4 + (week - 1) * 7 - (new Date(year, 0, 4).getDay() || 7) + 1);
     const end = new Date(start.getTime() + 6 * 24 * 60 * 60 * 1000);
-    const months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
 
-    const startMonth = months[start.getMonth()];
-    const endMonth = months[end.getMonth()];
-
-    return startMonth === endMonth ? startMonth : `${startMonth} - ${endMonth}`;
+    if (returnNumber) {
+        const startMonthNum = start.getMonth() + 1; // от 1 до 12
+        const endMonthNum = end.getMonth() + 1;
+        return startMonthNum === endMonthNum ? startMonthNum : `${startMonthNum}-${endMonthNum}`;
+    } else {
+        const months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
+        const startMonth = months[start.getMonth()];
+        const endMonth = months[end.getMonth()];
+        return startMonth === endMonth ? startMonth : `${startMonth} - ${endMonth}`;
+    }
 }
 
 function getMonthNumberByWeek(week, year) {