}
$grouped = [];
+ $grouped = [];
+ $salesShares = [];
+
+ $plans = SalesWriteOffsPlan::find()
+ ->where(['month' => $month, 'year' => $year])
+ ->indexBy('store_id')
+ ->asArray()
+ ->all();
+ if ($plans) {
+ foreach ($plans as $storeId => $plan) {
+ $total = $plan['total_sales_plan'];
+ $offline = $plan['offline_sales_plan'];
+ $online = $plan['online_sales_shop_plan'];
+ $market = $plan['online_sales_marketplace_plan'];
+ $salesShares[$storeId]['offline'] = round($offline / $total, 4);
+ $salesShares[$storeId]['online'] = round($online / $total, 4);
+ $salesShares[$storeId]['marketplace'] = round($market / $total, 4);
+ }
+ }
+
foreach ($weeklyForecasts as $item) {
$storeItem = (int)$item['store_id'];
$guid = (string)$item['product_guid'];
$group = (string)$item['matrix_group'];
$type = (string)$item['type'];
$forecastValue = (float)$item['week_forecast'];
-
+ if (isset($salesShares[$storeItem]) && isset($salesShares[$storeItem][$type])) {
+ $grouped[$storeItem][$type]['share'] = $salesShares[$storeItem][$type];
+ }
$grouped[$storeItem][$guid][$type][$group] = $forecastValue;
}
return $grouped;
}
+
public function getWeeklyProductsWriteoffsForecast($month, $year, $storeId = null, $weekNumber = null)
{
$weeksProductForecast = [];