$channelData = $forecast[$storeId][$channel] ?? [];
$titleData = [];
+ // Always use share-based value if it exists
if (isset($channelData['share']) && is_numeric($channelData['share'])) {
- $titleData = [round($quantity * $channelData['share'], 2)];
+ $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];
- $total = array_sum($details);
- $titleData = [
- isset($titleData[0]) ? $titleData[0] : round($quantity * $total, 2),
- 'details' => array_map(fn($val) => round($val, 2), $details),
- ];
+ $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 ?: [];
}
+
}
}