foreach ($result as &$productData) {
foreach ($productData['values'] as &$value) {
- $storeId = $value['store_id'];
- $quantity = $value['quantity'];
+ $storeId = $value['store_id'] ?? null;
+ $quantity = $value['quantity'] ?? 0;
$value['title'] = [];
if (!isset($forecast[$storeId])) {
continue;
}
+ // Безопасно получаем write_offs для всего value
+ $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;
+ }
+ }
+
foreach (['offline', 'marketplace', 'online'] as $channel) {
$channelData = $forecast[$storeId][$channel] ?? [];
$titleData = [];
- $autoplannogramma = isset($value['id']) ? Autoplannogramma::findOne(['id' => $value['id']]) : null;
- $titleData['write_offs'] = $autoplannogramma ? $autoplannogramma->writeoffs_forecast : null;
-
if (isset($channelData['share']) && is_numeric($channelData['share'])) {
$titleData[0] = round($quantity * $channelData['share'], 2);
}
$value['title'][$channel] = $titleData ?: [];
}
-
}
}