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

index bdc52b333971016c5817dd3ee9af8268afbab372..af2924e60569a684a86beba6d7fd6f8fa2316278 100644 (file)
@@ -1660,7 +1660,7 @@ class CronController extends Controller
                             'capacity_type' => 1,
                             'details' => json_encode($details, JSON_UNESCAPED_UNICODE),
                             'calculate' => $quantity,
-                            'modify' => $quantity,
+                            'modify' => round($total, 2),
                             'total' => round($total, 2)
                         ]);
 
index 2970b8124788329175a1b7f1b6248756517f972e..155af6fff6773be8fde5f2ce04a518dc21b17f09 100644 (file)
@@ -124,7 +124,8 @@ class AutoPlannogrammaController extends BaseController
                 'p1n.id AS product_id',
                 'p1n.name AS product_name',
                 'a.store_id',
-                'a.quantity',
+                'a.modify',
+                'a.details',
                 'a.month'
             ])
             ->asArray()
@@ -141,56 +142,18 @@ class AutoPlannogrammaController extends BaseController
                     'product_id' => $productId,
                     'name' => $productName,
                     'values' => [],
+                    'title' => [],
                 ];
             }
 
             $result[$productId]['values'][] = [
                 'id' => $model['plan_id'],
-                'quantity' => (int)$model['quantity'],
+                'quantity' => (int)$model['modify'],
                 'store_id' => (int)$model['store_id'],
+                'title' => !empty($model['details']) ? json_decode($model['details'], true) : null,
             ];
         }
 
-        $forecast = (new AutoPlannogrammaService())->getWeeklyBouquetProductsForecast($filters['month'], $filters['year'], null, $filters['week']);
-
-        foreach ($result as &$productData) {
-            foreach ($productData['values'] as &$value) {
-                $storeId = $value['store_id'] ?? null;
-                $quantity = $value['quantity'] ?? 0;
-                $value['title'] = [];
-
-                if (!isset($forecast[$storeId])) {
-                    continue;
-                }
-
-
-                foreach (['offline', 'marketplace', 'online'] as $channel) {
-                    $channelData = $forecast[$storeId][$channel] ?? [];
-                    $titleData = [];
-
-                    if (isset($channelData['share']) && is_numeric($channelData['share'])) {
-                        $titleData[0] = round($quantity * $channelData['share'], 2);
-                    }
-
-                    if (isset($productData['product_id']) && isset($forecast[$storeId][$productData['product_id']][$channel])) {
-                        $details = $forecast[$storeId][$productData['product_id']][$channel];
-                        $titleData[0] = $titleData[0] ?? round($quantity * array_sum($details), 2);
-                        $titleData[1] = ['details' => array_map(fn($val) => round($val, 2), $details)];
-                    }
-
-                    $value['title'][$channel] = $titleData ?: [];
-                }
-
-                $value['title']['write_offs'] = null;
-                if (isset($value['id']) && is_numeric($value['id'])) {
-                    $autoplannogramma = Autoplannogramma::findOne(['id' => $value['id']]);
-                    if ($autoplannogramma) {
-                        $value['title']['write_offs'] = $autoplannogramma->writeoffs_forecast;
-                    }
-                }
-            }
-        }
-
         return array_values($result);
     }
 
@@ -208,7 +171,7 @@ class AutoPlannogrammaController extends BaseController
             if (isset($item['id'])) {
                 $model = Autoplannogramma::findOne($item['id']);
                 if ($model !== null) {
-                    $model->quantity = $item['value'];
+                    $model->modify = $item['value'];
                     $model->auto_forecast = false;
                 }
             } else {
@@ -218,8 +181,8 @@ class AutoPlannogrammaController extends BaseController
                 $model->year = $item['year'] ?? null;
                 $model->month = $item['month'] ?? null;
                 $model->week = $item['week'] ?? null;
-                $model->quantity = $item['value'];
-                $model->quantity_forecast = 0;
+                $model->modify = $item['value'];
+                $model->calculate = 0;
                 $model->auto_forecast = false;
             }
 
index 7294845e6c39d2785251fcfda2c7ecc581e3aea0..fa0cfa4d215120a7a37175050ee90cfaabf3ed62 100644 (file)
@@ -395,23 +395,20 @@ const generateTitleString = (titleObj) => {
         offline: 'Оффлайн',
         online: 'Онлайн',
         marketplace: 'Маркетплейс',
-        write_offs: 'Списания'
+        writeOffs: 'Списания'
     };
 
     const parts = Object.entries(titleObj)
         .map(([typeKey, typeValue]) => {
             const title = typeTitles[typeKey] || typeKey;
-
-            if (Array.isArray(typeValue) && typeValue.length >= 1) {
-                const numericValue = parseFloat(typeValue[0]);
-                const details = typeValue[1]?.details || {};
-                const lines = Object.entries(details)
+            if (
+                typeof typeValue === 'object' &&
+                typeValue !== null &&
+                typeof typeValue.groups === 'object'
+            ) {
+                const lines = Object.entries(typeValue.groups)
                     .map(([key, val]) => `- ${key.replace(/_/g, ' ')}: ${parseFloat(val).toFixed(2)}`);
-                return `${title}: ${numericValue.toFixed(2)}${lines.length ? '\n' + lines.join('\n') : ''}`;
-            }
-
-            if (typeof typeValue === 'number') {
-                return `${title}: ${typeValue.toFixed(2)}`;
+                return `${title}:\n${lines.join('\n')}`;
             }
 
             return '';
@@ -419,4 +416,4 @@ const generateTitleString = (titleObj) => {
         .filter(Boolean);
 
     return parts.join('\n\n');
-};
\ No newline at end of file
+};