From 8129aabb3fb5dd02cb59d601d26b57b139999af6 Mon Sep 17 00:00:00 2001 From: fomichev Date: Fri, 30 May 2025 13:11:25 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?utf8?q?=D0=BE=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2?= =?utf8?q?=D1=83=20-=20=D1=80=D0=B0=D1=81=D1=87=D0=B5=D1=82=20=D1=81=20?= =?utf8?q?=D1=80=D0=B0=D1=81=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=D0=BC=20?= =?utf8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 37 +---- erp24/services/AutoPlannogrammaService.php | 143 +++++++++--------- erp24/views/auto-plannogramma/9.php | 30 +++- 3 files changed, 101 insertions(+), 109 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index b42da27c..0fabb8d1 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -522,23 +522,9 @@ class AutoPlannogrammaController extends BaseController $service = new AutoPlannogrammaService(); $data = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); - $flatData = []; - //var_dump($data);die(); - foreach ($data as $storeId => $categories) { - foreach ($categories as $row) { - $flatData[] = [ - 'store_id' => (string)$storeId, - 'category' => $row['category'] ?? null, - 'subcategory' => $row['subcategory'] ?? null, - 'base_total_store' => $row['base_total_store'] ?? null, - 'new_total_store' => $row['new_total_store'] ?? null, - 'total_sum' => $row['total_sum'] ?? null, - 'percent' => $row['percent'] ?? null, - ]; - } - } - $flatData = array_filter($flatData, function ($row) use ($filters) { + + $flatData = array_filter($data, function ($row) use ($filters) { foreach ($filters as $key => $value) { if (empty($value)) continue; if (!isset($row[$key])) continue; @@ -646,24 +632,7 @@ class AutoPlannogrammaController extends BaseController $data = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); - $flatData = []; - - foreach ($data as $storeId => $categories) { - foreach ($categories as $row) { - $flatData[] = [ - 'store_id' => (string)$storeId, - 'category' => $row['category'] ?? null, - 'subcategory' => $row['subcategory'] ?? null, - 'species' => $row['species'] ?? null, - 'base_total_store' => $row['base_total_store'] ?? null, - 'new_total_store' => $row['new_total_store'] ?? null, - 'total_sum' => $row['total_sum'] ?? null, - 'percent' => $row['percent'] ?? null, - ]; - } - } - - $flatData = array_filter($flatData, function ($row) use ($filters) { + $flatData = array_filter($data, function ($row) use ($filters) { foreach ($filters as $key => $value) { if (empty($value)) continue; if (!isset($row[$key])) continue; diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 0038b6fc..c334df19 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -424,7 +424,8 @@ class AutoPlannogrammaService ? round($newSubTotal / $newCatTotal, 4) : 0.0; - $result[$sid][] = [ + $result[] = [ + 'store_id' => $sid, 'category' => $cat, 'subcategory' => $subcat, 'total_sum' => $newSubTotal, @@ -678,7 +679,8 @@ class AutoPlannogrammaService ? round($newSpecTotal / $newSubcatTotal, 4) : 0.0; - $finalResult[$sid][] = [ + $finalResult[] = [ + 'store_id' => $sid, 'category' => $cat, 'subcategory' => $subcat, 'species' => $spec , @@ -919,20 +921,17 @@ class AutoPlannogrammaService * component_guid, component_name, component_category, * quantity, price, cost */ - public function getProductsComponentsInCategory(int $storeId, string $month, string $year, string $type = 'sales'): array + public function getProductsComponentsInCategory(int $storeId, string $month, string $year, string $type = self::TYPE_SALES): array { $region = CityStoreParams::find() ->where(['store_id' => $storeId]) ->one()->address_region; if (!$region) { - // определяем регион по городу $cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar(); - if ($cityId == 1) { - $region = BouquetComposition::REGION_MSK; - } else { - $region = BouquetComposition::REGION_NN; - } + $region = $cityId == 1 + ? BouquetComposition::REGION_MSK + : BouquetComposition::REGION_NN; } $monthStart = sprintf('%04d-%02d-01 00:00:00', $year, $month); @@ -943,7 +942,16 @@ class AutoPlannogrammaService if ($type == self::TYPE_SALES) { $salesProducts = Sales::find() ->alias('s') - ->select(['s.id', 's.date', 's.operation', 'sp.product_id', 'p1c.type', 'p1c.components' , 'p1c.name']) + ->select([ + 's.id', + 's.date', + 's.operation', + 'sp.product_id', + 'p1c.type', + 'p1c.components', + 'p1c.name', + 'sp.quantity AS quantity_product' + ]) ->innerJoin( ['sp' => SalesProducts::tableName()], 's.id = sp.check_id' @@ -960,22 +968,21 @@ class AutoPlannogrammaService ->andWhere(['not', ['s.operation' => ['Удален', 'Удаление']]]) ->andWhere(['between', 's.date', $monthStart, $monthEnd]) ->andWhere(['not', ['p1c.components' => '']]) - //->andWhere(['not in', 'nom.category', ['', 'букет', 'сборка', 'сервис']]) ->asArray() ->all(); - $componentProducts = $salesProducts; + $componentProducts = $salesProducts; } else { - $writeOffsProducts = WriteOffs::find() ->alias('w') ->select([ - 'write_off_id' => 'w.id', - 'write_off_date' => 'w.date', - 'product_id' => 'wp.product_id', - 'type' => 'p1c.type', - 'components' => 'p1c.components', - 'product_name' => 'p1c.name', - 'store_id' => 'ex.entity_id', + 'w.id AS write_off_id', + 'w.date AS write_off_date', + 'wp.product_id', + 'p1c.type', + 'p1c.components', + 'p1c.name AS product_name', + 'ex.entity_id AS store_id', + 'wp.quantity AS quantity_product' ]) ->innerJoin( ['wp' => WriteOffsProducts::tableName()], @@ -995,19 +1002,16 @@ class AutoPlannogrammaService ) ->andWhere(['between', 'w.date', $monthStart, $monthEnd]) ->andWhere(['ex.entity_id' => $storeId]) - //->andWhere(['not in', 'nom.category', ['', 'букет', 'сборка', 'сервис']]) - ->andWhere(['<>', 'p1c.components', '']) + ->andWhere(['not', ['p1c.components' => '']]) ->asArray() ->all(); $componentProducts = $writeOffsProducts; } - $components = []; $rows = []; foreach ($componentProducts as $cp) { - - $js = trim($cp['components']); + $js = trim($cp['components']); if ($js === '' || $js[0] !== '{') { continue; } @@ -1020,18 +1024,17 @@ class AutoPlannogrammaService if ($qty <= 0) { continue; } - $components[$guid] = true; - $rows[] = [ - 'sale_id' => $cp['id'], - 'sale_date' => $cp['date'], - 'product_id' => $cp['product_id'], - 'product_name'=> $cp['name'], - 'component_guid' => $guid, - 'quantity' => $qty, - 'type' => $type, - 'operation' => $cp['operation'] ?? '', + 'record_id' => $cp['id'] ?? $cp['write_off_id'], + 'sale_date' => $cp['date'] ?? $cp['write_off_date'], + 'product_id' => $cp['product_id'], + 'product_name' => $cp['name'] ?? $cp['product_name'], + 'quantity_product' => $cp['quantity_product'], + 'component_guid' => $guid, + 'quantity' => $qty, + 'type' => $type, + 'operation' => $cp['operation'] ?? '', ]; } } @@ -1039,8 +1042,8 @@ class AutoPlannogrammaService if (empty($rows)) { return []; } - $guids = array_keys($components); + $guids = array_keys($components); $nomenclatures = Products1cNomenclature::find() ->andWhere(['id' => $guids]) ->andWhere(['not in', 'category', ['', 'букет', 'сборка', 'сервис']]) @@ -1049,51 +1052,54 @@ class AutoPlannogrammaService $priceDynamics = PricesDynamic::find() ->andWhere(['region_id' => $region]) - ->andWhere(['product_id' => array_values( ArrayHelper::getColumn($nomenclatures, 'id') )]) + ->andWhere(['product_id' => array_values(ArrayHelper::getColumn($nomenclatures, 'id'))]) ->orderBy(['date_from' => SORT_DESC]) ->all(); $pricesByProduct = []; foreach ($priceDynamics as $pd) { - /** @var PricesDynamic $pd */ - $pid = $pd->product_id; - $pricesByProduct[$pid][] = $pd; + $pricesByProduct[$pd->product_id][] = $pd; } $result = []; foreach ($rows as $r) { - $guid = $r['component_guid']; - $n = $nomenclatures[$guid] ?? null; - $pid = $n?->id; + $guid = $r['component_guid']; + $n = $nomenclatures[$guid] ?? null; + $pid = $n?->id; $price = 0; - if ($pid && isset($pricesByProduct[$pid])) { - foreach ($pricesByProduct[$pid] as $pd) { - if ($pd->date_from <= $r['sale_date'] && $pd->date_to >= $r['sale_date']) { + foreach ($pricesByProduct[$pid] ?? [] as $pd) { + if ($pd->date_from <= $r['sale_date'] && $pd->date_to >= $r['sale_date']) { + if ($pid == '2b72702a-792f-11e8-9edd-1c6f659fb563') { + $price = 8.66; + } else { $price = $pd->price; - break; } + + + break; } } - $cost = $r['quantity'] * $price; + $cost = $r['quantity'] * $price * $r['quantity_product']; + $costComponent = $r['quantity'] * $price; $result[] = [ - 'store_id' => $storeId, - 'sale_id' => $r['sale_id'], - 'sale_date' => $r['sale_date'], - 'product_id' => $r['product_id'], - 'product_name' => $r['product_name'], - 'component_guid' => $guid, - 'component_name' => $n?->name, - 'component_category' => $n?->category, - 'component_subcategory' => $n?->subcategory, - 'component_species' => $n?->species, - 'quantity' => $r['quantity'], - 'price' => $price, - 'cost' => $cost, - 'month' => $month, - 'year' => $year, - 'type' => $r['type'], - 'operation' => $r['operation'] ?? '', + 'store_id' => $storeId, + 'record_id' => $r['record_id'], + 'sale_date' => $r['sale_date'], + 'product_id' => $r['product_id'], + 'product_name' => $r['product_name'], + 'quantity_product' => $r['quantity_product'], + 'component_guid' => $guid, + 'component_name' => $n?->name, + 'component_category' => $n?->category, + 'component_subcategory'=> $n?->subcategory, + 'component_species' => $n?->species, + 'quantity' => $r['quantity'], + 'price' => $price, + 'cost' => $cost, + 'component_cost' => $costComponent, + 'type' => $type, + 'operation' => $r['operation'], ]; } @@ -1101,6 +1107,7 @@ class AutoPlannogrammaService } + public function sumProductsComponentsByGroup(array $items, string $type, string $group = 'category'): array { $aggregated = []; @@ -1110,8 +1117,6 @@ class AutoPlannogrammaService $category = $row['component_category']; $subcategory = $row['component_subcategory']; $species = $row['component_species']; - $month = $row['month']; - $year = $row['year']; $operation = $row['operation'] ?? null; $cost = (float)$row['cost']; @@ -1134,8 +1139,6 @@ class AutoPlannogrammaService $keyParts[] = $species; } - $keyParts[] = $year; - $keyParts[] = $month; $key = implode('|', $keyParts); @@ -1145,8 +1148,6 @@ class AutoPlannogrammaService 'store_id' => $storeId, 'category' => $category, 'sum' => 0.0, - 'month' => $month, - 'year' => $year, 'type' => $type, ]; diff --git a/erp24/views/auto-plannogramma/9.php b/erp24/views/auto-plannogramma/9.php index 5ae0593e..ff28eca6 100644 --- a/erp24/views/auto-plannogramma/9.php +++ b/erp24/views/auto-plannogramma/9.php @@ -95,6 +95,7 @@ 'store_id', 'label' => 'Магазин', 'value' => function ($data) { return CityStore::findOne($data['store_id'])->name ?? null; @@ -102,16 +103,37 @@ $columns = [ ['attribute' => 'category', 'label' => 'Категория'], ['attribute' => 'subcategory', 'label' => 'Подкатегория'], ['attribute' => 'species', 'label' => 'Тип'], - ['attribute' => 'dirtyGoal', 'label' => 'Неочищенная цель', 'format' => ['decimal', 2]], - ['attribute' => 'bouquetGoal', 'label' => 'Цель букета', 'format' => ['decimal', 2]], - ['attribute' => 'noHistoryGoal', 'label' => 'Товары без истории', 'format' => ['decimal', 2]], - ['attribute' => 'goal', 'label' => 'Очищенная цель', 'format' => ['decimal', 2]], + [ + 'attribute'=>'dirtyGoal', + 'label'=>'Неочищенная цель', + 'format'=>['decimal',2], + 'pageSummary' => true, + ], + [ + 'attribute'=>'bouquetGoal', + 'label'=>'Цель букета', + 'format'=>['decimal',2], + 'pageSummary' => true, + ], + [ + 'attribute'=>'noHistoryGoal', + 'label'=>'Товары без истории', + 'format'=>['decimal',2], + 'pageSummary' => true, + ], + [ + 'attribute'=>'goal', + 'label'=>'Очищенная цель', + 'format'=>['decimal',2], + 'pageSummary' => true, + ], ]; ?> $dataProvider, + 'showPageSummary' => true, 'columns' => $columns, ]); ?>