}
$isGoalExists = isset($goalsMap[$storeId][$cat][$sub][$spec]);
$goal = $goalsMap[$storeId][$cat][$sub][$spec] ?? 0;
- if ($goal !== 0) {
+ if ($isGoalExists) {
$forecastSum = $goal * $share;
} else {
$forecastSum = $avgWeightedSumm;
'product_id' => $item['product_id'],
'forecast_pieces' => (float)$item['forecast_pieces'],
'history_status' => 'With history',
+ 'is_goal_exists' => $item['is_goal_exists']
];
}
$pid = $p['product_id'];
$forecastPieces = (float)$p['forecast_pieces'];
$historyStatus = $p['history_status'];
+ $goalExistsFlag = $p['is_goal_exists'] ?? 1;
$summ = $productSumms[$pid] ?? 0.0;
if ($totalSumm > 0) {
'forecast_pieces' => $forecastPieces,
'share' => $share,
'history_status' => $historyStatus,
+ 'is_goal_exists' => $goalExistsFlag,
]);
}
}
]);
$cleanGoal = $goalsMap[$key] ?? 0;
- $productSales = $shareItem['share'] * $cleanGoal;
+ $goalExistsFlag = $shareItem['is_goal_exists'];
+ if ($goalExistsFlag) {
+ $productSales = $shareItem['share'] * $cleanGoal;
+ $productSalesPieces = round($productSales / $price, 2);
+ } else {
+ $productSales = $shareItem['forecast_pieces'] * $price;
+ $productSalesPieces = $shareItem['forecast_pieces'];
+ }
- $productSalesPieces = round($productSales / $price, 2);
$result[] = [
'store_id' => $shareItem['store_id'],
$cleanedSpeciesGoals = $this->subtractSpeciesGoals($goals, [], []);
$salesProductForecastShare = $this->calculateProductForecastShare($noHistoryProductData, $historyProductData);
- var_dump($salesProductForecastShare); die();
- $productForecastSpecies = $this->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
+ $productForecastSpecies = $this->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
+ var_dump($productForecastSpecies); die();
$weeklySales = $this->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters);
$weeklySalesForecast = $this->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales, $filters);