$channelData = $forecast[$storeId][$channel] ?? [];
$titleData = [];
- // Always use share-based value if it exists
if (isset($channelData['share']) && is_numeric($channelData['share'])) {
$titleData[0] = round($quantity * $channelData['share'], 2);
}
- // Add product-specific details if available
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);
if (!titleObj || typeof titleObj !== 'object') return '';
const typeTitles = {
- offline: '📦 Оффлайн',
- online: '🌐 Онлайн',
- marketplace: '🛒 Маркетплейс'
+ offline: 'Оффлайн',
+ online: 'Онлайн',
+ marketplace: 'Маркетплейс'
};
const parts = Object.entries(titleObj)
.map(([typeKey, typeValue]) => {
const title = typeTitles[typeKey] || typeKey;
- // Handle case where typeValue is an array [numeric_value, {details: {...}}]
if (Array.isArray(typeValue) && typeValue.length >= 1) {
const numericValue = parseFloat(typeValue[0]);
const details = typeValue[1]?.details || {};
return `${title}: ${numericValue.toFixed(2)}${lines.length ? '\n' + lines.join('\n') : ''}`;
}
- // Handle case where typeValue is a number (for share-only, if applicable)
if (typeof typeValue === 'number') {
return `${title}: ${typeValue.toFixed(2)}`;
}
- return ''; // Skip invalid or empty values
+ return '';
})
.filter(Boolean);