From 781e26acacaa63165f6976bdbb2195a61335d817 Mon Sep 17 00:00:00 2001 From: marina Date: Thu, 19 Jun 2025 10:12:44 +0300 Subject: [PATCH] =?utf8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 39 ++++++++++++------- .../js/autoplannogramma/autoplannogramma.js | 37 +++++++++++++----- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 70351a11..3b59512c 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -1619,28 +1619,37 @@ class CronController extends Controller if (!empty($writeOffsForecast[$productId][$week]['writeOffs'])) { $writeOffs = $writeOffsForecast[$productId][$week]['writeOffs']; - $details['writeOffs']['groups'] = $writeOffs; + $details['writeOffs']['quantity'] = $writeOffs; $total += is_array($writeOffs) ? array_sum($writeOffs) : (float)$writeOffs; } foreach (['offline', 'online', 'marketplace'] as $type) { - $data = $salesForecast[$productId][$week][$type] ?? null; - if ($data) { - $details[$type]['groups'] = []; - if (isset($data['share'])) { - $share = (float)$data['share']; - $details[$type]['groups']['share'] = $share; - $details[$type]['groups']['quantity'] = round($quantity * $share, 2); - $total += $details[$type]['groups']['quantity']; - unset($data['share']); - } - if (!empty($data)) { - $details[$type]['groups'] = array_merge($details[$type]['groups'], $data); - $total += is_array($data) ? array_sum($data) : (float)$data; - } + if (!isset($salesForecast[$store->id][$productId][$type])) { + $details[$type] = ['share' => 0, 'quantity' => 0, 'groups' => []]; + continue; } + $data = $salesForecast[$store->id][$productId][$type]; + if (!is_array($data)) { + $details[$type] = ['share' => 0, 'quantity' => 0, 'groups' => []]; + continue; + } + $block = []; + $groups = []; + $share = isset($salesForecast[$store->id][$type]['share']) ? (float)$salesForecast[$store->id][$type]['share'] : 0; + $block['share'] = $share; + $block['quantity'] = (float) sprintf('%.2f', round($quantity * $share, 2)); // Нормализует -0 до 0 + $total += $block['quantity']; + foreach ($data as $k => $v) { + $val = (float)$v; + $groups[$k] = $val; + $total += $val; + } + $block['groups'] = !empty($groups) ? $groups : []; + $details[$type] = $block; } + $total = (float) sprintf('%.2f', $total); // Нормализует -0 до 0 для $total + $needsUpdate = !$model->isNewRecord && ( $model->calculate !== $quantity || ceil((float)$model->total) !== ceil($total) || diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index 79415357..e898bb2f 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -410,19 +410,36 @@ const generateTitleString = (titleRaw) => { const parts = Object.entries(titleObj) .map(([typeKey, typeValue]) => { const title = typeTitles[typeKey] || typeKey; - 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}:\n${lines.join('\n')}`; + + if (typeof typeValue !== 'object' || typeValue === null) { + return ''; + } + + const quantity = typeof typeValue.quantity === 'number' + ? parseFloat(typeValue.quantity).toFixed(2) + : '0.00'; + + let result = `${title}: ${quantity}`; + + if (typeKey === 'writeOffs') { + if (typeof typeValue.quantity === 'number') { + result += `\n- Количество: ${parseFloat(typeValue.quantity).toFixed(2)}`; + } } - return ''; + else if (typeof typeValue.groups === 'object' && typeValue.groups !== null) { + const groupEntries = Object.entries(typeValue.groups); + if (groupEntries.length > 0) { + const lines = groupEntries.map( + ([key, val]) => `- ${key.replace(/_/g, ' ')}: ${parseFloat(val).toFixed(2)}` + ); + result += `\n${lines.join('\n')}`; + } + } + + return result; }) .filter(Boolean); return parts.join('\n\n'); -}; +}; \ No newline at end of file -- 2.39.5