$productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory(
$filters['store_id'],
$filters['month'],
- $filters['category'],
- $filters['subcategory'],
- $filters['species'],
$productSalesShare,
- $goals
+ $goals,
+ $filters['subcategory'],
+ $filters['category'],
+ $filters['species']
);
- $matrixForecast = MatrixBouquetForecast::find()
+/* $matrixForecast = MatrixBouquetForecast::find()
->where(['year' => $filters['year'], 'month' => $filters['month']])
->asArray()
->all();
}
}
- $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);
+ $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/
$salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast);
// $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
- //var_dump($salesProductForecastShare); die();
+ var_dump($productSalesForecast); die();
$productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory(
$filters['store_id'],
$filters['month'],
- $filters['category'],
- $filters['subcategory'],
- $filters['species'],
$productSalesShare,
- $goals
+ $goals,
+ $filters['subcategory'],
+ $filters['category'],
+ $filters['species']
);
$matrixForecast = MatrixBouquetForecast::find()
return $result;
}
- public static function calculateProductForecastInPiecesProductsWithHistory(
+ public function calculateProductForecastInPiecesProductsWithHistory(
int $storeId,
string $month,
- string $category,
- string $subcategory,
- string $species,
array $productSalesShare,
- array $speciesGoals
+ array $speciesGoals,
+ string $subcategory = null,
+ string $category = null,
+ string $species = null
): array {
$result = [];
- $goal = null;
- foreach ($speciesGoals as $item) {
- if (
- $item['store_id'] == $storeId &&
- $item['category'] == $category &&
- $item['subcategory'] == $subcategory &&
- $item['species'] == $species
- ) {
- $goal = $item['goal'];
- break;
- }
- }
-
- if ($goal === null) {
+ if (empty($speciesGoals)) {
return [];
}
+ $goalsMap = $this->mapGoalsBySpecies($speciesGoals);
+
$region = CityStoreParams::find()
->where(['store_id' => $storeId])
- ->select('address_region')
- ->scalar();
+ ->one()->address_region ?? null;
if (!$region) {
$cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar();
if (!$priceRecord || $priceRecord->price <= 0) {
continue;
}
-
+ $goal = $goalsMap[$data['store_id']][$data['category']][$data['subcategory']][$data['species']];
$forecastSum = $goal * $share;
$forecastCount = $forecastSum / $priceRecord->price;
'goal_share' => round($forecastSum, 2),
'price' => $priceRecord->price,
'forecast_pieces' => round($forecastCount),
- 'store_id' => $storeId,
- 'category' => $category,
- 'subcategory' => $subcategory,
- 'species' => $species,
+ 'store_id' => $data['store_id'],
+ 'category' => $data['category'],
+ 'subcategory' => $data['subcategory'],
+ 'species' => $data['species'],
];
}
$productsData = [];
$globalTotal = 0;
-
+ // var_dump($productsWithHistory); die();
foreach ($productsWithHistory as $product) {
$guid = $product['guid'];
$result = self::processProductWithHistory($storeId, $product, $weightedPeriods);
}
return [
+ 'store_id' => $storeId,
+ 'category' => $product['category'],
+ 'subcategory' => $product['subcategory'],
+ 'species' => $product['species'],
'monthlySales' => $monthlySales,
'monthlyWeighted' => $monthlyWeighted,
'weightedSum' => $weightedSum,