public function calculateWeeklyProductForecastPieces(
array $productForecastSpecies,
- array $weeklySales
+ array $weeklySales,
+ array $filters
): array
{
-
+ $date = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01';
+ $df = (new \DateTime($date))
+ ->setTime(0, 0, 0)->format('Y-m-d H:i:s');
+ $dt = (new \DateTime($date))
+ ->modify('last day of this month')->setTime(23, 59, 59)
+ ->format('Y-m-d H:i:s');
+ $actualProducts = Products1cNomenclatureActuality::find()
+ ->select(['guid'])
+ ->where(['<=', 'date_from', $df])
+ ->andWhere(['>=', 'date_to', $dt])
+ ->asArray()
+ ->column();
$forecastMap = [];
foreach ($productForecastSpecies as $item) {
$sid = $item['store_id'];
foreach ($productsInSpec as $pid => $piecesMon) {
$forecastWeekPieces = round($piecesMon * $wShare, 2);
-
+ if (!in_array($pid, $actualProducts)) {
+ continue;
+ }
$result[] = [
'week' => $week,
'store_id' => $sid,
$weeklySales = $this->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters);
- $weeklySalesForecast = $this->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales);
+ $weeklySalesForecast = $this->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales, $filters);
return $weeklySalesForecast;
}
$baseGroup = $groupsArr[0];
$storeItem = (int)$item['store_id'];
$guid = (string)$item['product_guid'];
- $group = $baseGroup;
if (!in_array($guid, $actualProducts)) {
- continue;
+ continue;
}
- $group = (string)$item['matrix_group'];
+ $group = $baseGroup;
$type = (string)$item['type'];
$forecastValue = (float)$item['week_forecast'];
if (isset($salesShares[$storeItem]) && isset($salesShares[$storeItem][$type])) {