From: fomichev Date: Mon, 26 May 2025 15:12:23 +0000 (+0300) Subject: Прогноз товаров без истории X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=1dd8cf4bc141b70d71f8b7304db82a1e4ed45671;p=erp24_rep%2Fyii-erp24%2F.git Прогноз товаров без истории --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 6a1c9b7d..8b1947e2 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -695,13 +695,14 @@ class AutoPlannogrammaController extends BaseController $filters['subcategory'], $filters['species'] ); - // var_dump($result); die(); + $withoutHistoryResults = StorePlanService::calculateMedianSalesForProductsWithoutHistoryExtended( $filters['store_id'], $filters['month'], $filters['year'], $result['without_history'] ); + var_dump($data); die(); $productSalesShare = StorePlanService::calculateProductSalesShare( $filters['store_id'], $filters['month'], diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index 9d71f8b5..fbc18625 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -677,47 +677,51 @@ class StorePlanService int $selectedMonth, int $selectedYear, array $medianProductsWithoutHistory - ): array - { + ): array { + $accumulator = []; + $prices = []; + $guidToGroup = []; - $accumulator = []; - // var_dump($productsWithoutHistory); die(); - foreach ($medianProductsWithoutHistory as $guid => $info) { - $quantity = (float)$info; - if ($quantity <= 0) { - continue; - } - // цена за два месяца назад + foreach ($medianProductsWithoutHistory as $guid => $qty) { + $q = (float)$qty; + if ($q <= 0) continue; + $price = self::getPriceForProductAtOffsetMonthWeekly( - $guid, - $selectedYear, - $selectedMonth, - $storeId, - 2 + $guid, $selectedYear, $selectedMonth, $storeId, 2 ); + $prices[$guid] = $price; - $cost = $quantity * $price; - - /** @var Products1cNomenclature $nom */ $nom = Products1cNomenclature::findOne($guid); $cat = $nom->category ?? ''; $sub = $nom->subcategory ?? ''; $sp = $nom->species ?? ''; + $groupKey = implode('|', [$cat,$sub,$sp]); + $guidToGroup[$guid] = $groupKey; - $key = implode('|', [$cat, $sub, $sp]); - if (!isset($accumulator[$key])) { - $accumulator[$key] = [ + if (!isset($accumulator[$groupKey])) { + $accumulator[$groupKey] = [ 'store_id' => $storeId, 'category' => $cat, 'subcategory' => $sub, 'species' => $sp, 'month' => $selectedMonth, 'year' => $selectedYear, - 'goal' => 0.0, + 'goal' => 0.0, + 'forecasts' => [], ]; } - $accumulator[$key]['goal'] += $cost; + $accumulator[$groupKey]['goal'] += $q * $price; + } + + foreach ($medianProductsWithoutHistory as $guid => $_) { + $groupKey = $guidToGroup[$guid]; + $goal = $accumulator[$groupKey]['goal']; + $price = $prices[$guid] ?? 0.0; + $accumulator[$groupKey]['forecasts'][$guid] = + $price > 0.0 + ? ($goal / $price) + : 0.0; } return array_values($accumulator);