From: fomichev Date: Thu, 26 Jun 2025 14:38:35 +0000 (+0300) Subject: Разделение продаж на типы X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=cd9f1aac8230c7c80092703474a7d15db920cbf8;p=erp24_rep%2Fyii-erp24%2F.git Разделение продаж на типы --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 2c9904b2..72787a0d 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -244,6 +244,7 @@ class AutoPlannogrammaController extends BaseController 'year' => $request->get('year'), 'month' => $request->get('month'), 'type' => $request->get('type'), + 'sales_type' => $request->get('sales_type'), ]; $dataProvider = new ArrayDataProvider([ diff --git a/erp24/controllers/CategoryPlanController.php b/erp24/controllers/CategoryPlanController.php index ce61ae5b..69b0fe38 100644 --- a/erp24/controllers/CategoryPlanController.php +++ b/erp24/controllers/CategoryPlanController.php @@ -163,7 +163,6 @@ class CategoryPlanController extends Controller { $compoundSalesYear = $dateToStart->format('Y'); $compoundSalesMonth = $dateToStart->format('m'); $compoundSales = $service->getProductsComponentsInCategory($model->store_id, $compoundSalesMonth, $compoundSalesYear); - //var_dump($compoundSales); die(); $offline = []; $online = []; foreach ($compoundSales as $compoundSale) { diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 4977154e..a83dc2cd 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -66,11 +66,21 @@ class AutoPlannogrammaService { // Получение ID видимых магазинов $storeIds = array_map(fn($store) => $store->id, $this->getVisibleStores()); - + $mode = null; // Применение фильтра по магазину, если указан if (!empty($filters['store_id'])) { $storeIds = array_intersect($storeIds, [(int)$filters['store_id']]); } + if (!empty($filters['sales_type'])) { + $mode = $filters['sales_type']; + } + $orderCondition = []; + if ($mode === 'offline') { + $orderCondition = ['order_id' => ['', '0']]; + } elseif ($mode === 'online') { + $orderCondition = ['not in', 'order_id', ['', '0']]; + } + // Формирование компонентов запроса $fromTable = $type === self::TYPE_WRITE_OFFS ? ['w' => 'write_offs'] : ['s' => 'sales']; @@ -141,10 +151,11 @@ class AutoPlannogrammaService ->leftJoin('export_import_table ex', $storeJoinCondition) ->leftJoin('products_1c p1', "p1.id = $productJoinCondition") ->andWhere(['ex.entity_id' => $storeIds]) + ->andFilterWhere($orderCondition) ->andWhere(['p1.components' => '']) ->andWhere(['not in', 'p1c.category', ['', 'букет', 'сборка', 'сервис']]) - ->andWhere(['>=', "$alias.date", (new \DateTime($month1 . '-01'))->format('Y-m-d')]) - ->andWhere(['<=', "$alias.date", (new \DateTime($month3 . '-01'))->modify('last day of this month')->format('Y-m-d')]) + ->andWhere(['>=', "$alias.date", (new \DateTime($month1 . '-01'))->format('Y-m-d 00:00:00')]) + ->andWhere(['<=', "$alias.date", (new \DateTime($month3 . '-01'))->modify('last day of this month')->format('Y-m-d 23:59:59')]) ->groupBy(['ex.entity_id', 'p1c.category']), ]) ->innerJoin([ @@ -159,10 +170,11 @@ class AutoPlannogrammaService ->leftJoin('export_import_table ex', $storeJoinCondition) ->leftJoin('products_1c p1', "p1.id = $productJoinCondition") ->andWhere(['ex.entity_id' => $storeIds]) + ->andFilterWhere($orderCondition) ->andWhere(['p1.components' => '']) ->andWhere(['not in', 'p1c.category', ['', 'букет', 'сборка', 'сервис']]) - ->andWhere(['>=', "$alias.date", (new \DateTime($month1 . '-01'))->format('Y-m-d')]) - ->andWhere(['<=', "$alias.date", (new \DateTime($month3 . '-01'))->modify('last day of this month')->format('Y-m-d')]) + ->andWhere(['>=', "$alias.date", (new \DateTime($month1 . '-01'))->format('Y-m-d 00:00:00')]) + ->andWhere(['<=', "$alias.date", (new \DateTime($month3 . '-01'))->modify('last day of this month')->format('Y-m-d 23:59:59')]) ->groupBy(['ex.entity_id']), ], 'main.ex_entity_id = totals.store_id') ->orderBy('category'); @@ -191,10 +203,20 @@ class AutoPlannogrammaService if (!$items) { continue; } - foreach ($items as $it) { - $allComponentsProductIds[$storeId][] = $it['product_id']; - } - $sums = $this->sumProductsComponentsByGroup($items, $type, 'category'); + + $filtered = match ($mode) { + 'offline' => array_filter($items, fn($it) => in_array($it['order_id'], ['', '0'], true)), + 'online' => array_filter($items, fn($it) => !in_array($it['order_id'], ['', '0'], true)), + default => $items, // для writeOffs — всё + }; + + + $allComponentsProductIds[$storeId] = array_merge( + $allComponentsProductIds[$storeId] ?? [], + array_column($filtered, 'product_id') + ); + + $sums = $this->sumProductsComponentsByGroup($filtered, $type, 'category'); $allComponentsProductIds[$storeId] = array_values(array_unique($allComponentsProductIds[$storeId])); foreach ($sums as $sumRow) { @@ -210,6 +232,7 @@ class AutoPlannogrammaService $result = []; + foreach ($rows as $r) { $sid = $r['store_id']; $baseTotal = (float)$r['totals_total']; @@ -232,6 +255,7 @@ class AutoPlannogrammaService 'base_total_store' => $baseTotal, 'products_list' => $r['products_list'], 'products_components_list' => implode(',', $allComponentsProductIds[$sid] ?? []), + 'mode' => $mode ]; } diff --git a/erp24/views/auto-plannogramma/1.php b/erp24/views/auto-plannogramma/1.php index cab06204..9c0fc76a 100644 --- a/erp24/views/auto-plannogramma/1.php +++ b/erp24/views/auto-plannogramma/1.php @@ -55,6 +55,16 @@ 'pluginOptions' => ['allowClear' => true], ])->label('По дефолту продажи!') ?> +
+ field(new \yii\base\DynamicModel(['sales_type' => $filters['sales_type'] ?? '']), 'sales_type')->widget(Select2::class, [ + 'data' => [ + 'offline' => 'оффлайн', + 'online' => 'онлайн' + ], + 'options' => ['placeholder' => 'Тип продаж', 'name' => 'sales_type'], + 'pluginOptions' => ['allowClear' => true], + ])->label('Только для типа Продажи!') ?> +
'btn btn-primary']) ?>