]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Разделение продаж на типы
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 26 Jun 2025 14:38:35 +0000 (17:38 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 26 Jun 2025 14:38:35 +0000 (17:38 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/controllers/CategoryPlanController.php
erp24/services/AutoPlannogrammaService.php
erp24/views/auto-plannogramma/1.php

index 2c9904b286bd0560b4f381226e9ab5f5c1216111..72787a0d9c7f5e6f95bddf22cc387f7413e7b6bc 100644 (file)
@@ -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([
index ce61ae5b80f63411a5362c3e1e3cbe010d6ac1ab..69b0fe3806120652f570f88164d4e5a9382ac2ec 100644 (file)
@@ -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) {
index 4977154e8d09a3f09c2b18d1634d96e03baa51ca..a83dc2cd5ae62e6c70752c6c8e15d4cfa164e03b 100644 (file)
@@ -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
             ];
         }
 
index cab06204435c902a7e7b7611c3ae6c949f6543c6..9c0fc76ad34f3a4824c608ac2a235474dd9adc7f 100644 (file)
                 'pluginOptions' => ['allowClear' => true],
             ])->label('По дефолту продажи!') ?>
         </div>
+        <div class="col-md">
+            <?= $form->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('Только для типа Продажи!') ?>
+        </div>
         <div class="col-md">
             <?= Html::submitButton('Фильтровать', ['class' => 'btn btn-primary']) ?>
         </div>