From b3a7a85dd03d32a4ebb6eea7e60461d0a59183dd Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 3 Jul 2025 17:59:00 +0300 Subject: [PATCH] =?utf8?q?=D0=93=D1=80=D1=83=D0=BF=D0=BF=D0=B8=D1=80=D0=BE?= =?utf8?q?=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D0=B1=D0=B2=D0=B7=D0=BE?= =?utf8?q?=D0=B2=D1=8B=D0=BC=20=D0=BC=D0=B0=D1=82=D1=80=D0=B8=D1=86=D0=B0?= =?utf8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 4 +++- .../controllers/AutoPlannogrammaController.php | 8 +++++--- erp24/services/AutoPlannogrammaService.php | 17 +++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 3d1b9f41..62731b29 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -1591,7 +1591,7 @@ class CronController extends Controller public function actionAutoplannogrammaCalculate(): void { $date = new DateTime(); - $date->modify('+2 months'); + $date->modify('+0 months'); $planDate = $date->format('Y-m-01'); $month = (int)$date->format('m'); $year = (int)$date->format('Y'); @@ -1646,6 +1646,8 @@ class CronController extends Controller $writeOffs = $writeOffsForecast[$productId][$week]['writeOffs']; $details['writeOffs']['quantity'] = $writeOffs; $total += is_array($writeOffs) ? array_sum($writeOffs) : (float)$writeOffs; + } else { + $details['writeOffs']['quantity'] = 0; } foreach (['offline', 'online', 'marketplace'] as $type) { diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 4a8c90f9..3cb494cc 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -1285,7 +1285,9 @@ class AutoPlannogrammaController extends BaseController $service = new AutoPlannogrammaService(); //$goals = $service->calculateFullGoalChain($filters); //$forecast = $service->calculateFullForecastForWeek($filters); - //var_dump( $forecast); die(); + //$writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($filters['month'], $filters['year'], $forecast, $filters['store_id']); + //$salesForecast = $service->getWeeklyBouquetProductsSalesForecast($filters['month'], $filters['year'], $filters['store_id']); + // var_dump( $salesForecast); die(); $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters); $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']); $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters); @@ -1511,10 +1513,10 @@ class AutoPlannogrammaController extends BaseController } $detailsArray = $data; foreach ($detailsArray as $type => $typeArr) { - if (!isset($typeArr['groups']) ) { + if (!isset($typeArr['groups']) && $type !== AutoPlannogrammaService::TYPE_WRITE_OFFS) { continue; } - $groups = $typeArr['groups']; + $groups = $typeArr['groups'] ?? []; $groups[$type] = $typeArr['quantity']; foreach ($groups as $group => $quantity) { if (in_array($group, array_keys($mappingTypes))) { diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 6d60b524..0ecac3ef 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -1467,8 +1467,8 @@ class AutoPlannogrammaService 'category' => $cat, 'subcategory' => $sub, 'species' => $spec, - 'percent' => $percent, - 'monthly_goal' => $monthlyGoal, + 'percent' => $percent ?? 0, + 'monthly_goal' => $monthlyGoal ?? 0, 'weekly_goal' => $weeklyGoal, ]; } @@ -2143,7 +2143,7 @@ class AutoPlannogrammaService $guid = $componentDataRecord['component_guid']; $nomenclatureData = $nomenclatures[$guid] ?? null; $productId = $nomenclatureData?->id; - $price = 0; + $price = null; $dailyPrices = []; foreach ($pricesByProduct[$productId] ?? [] as $priceRecordForProduct) { if (defined($heliumConstant) && $productId == constant($heliumConstant)) { @@ -2162,7 +2162,8 @@ class AutoPlannogrammaService } if (!empty($dailyPrices)) { $price = min($dailyPrices); - } else { + } + if ($price === null) { $price = 0.0; } $cost = $componentDataRecord['quantity'] * $price * $componentDataRecord['quantity_product']; @@ -3017,16 +3018,19 @@ class AutoPlannogrammaService $salesShares[$storeId]['marketplace'] = round($market / $total, 4); } } + foreach ($weeklyForecasts as $item) { + $groupsArr = explode('_', (string)$item['matrix_group']); + $baseGroup = $groupsArr[0]; $storeItem = (int)$item['store_id']; $guid = (string)$item['product_guid']; - $group = (string)$item['matrix_group']; + $group = $baseGroup; $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; + $grouped[$storeItem][$guid][$type][$group] = ($grouped[$storeItem][$guid][$type][$group] ?? 0) + $forecastValue; } return $grouped; @@ -3051,6 +3055,7 @@ class AutoPlannogrammaService [$monthSpeciesGoal['subcategory']] [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal']; } + $productsWriteoffsShare = $this->calculateWriteOffShareByMonth($weeklySalesForecast, $month, $year); $productsWriteoffsShareMap = []; foreach ($productsWriteoffsShare as $productWriteoffs) { -- 2.39.5