]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Рефакторинг
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 22 Aug 2025 09:48:26 +0000 (12:48 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 22 Aug 2025 09:48:26 +0000 (12:48 +0300)
erp24/controllers/Products1cNomenclatureActualityController.php

index 3003c2b7e595e625302ab83596c4d4fc1a6cd8f5..4de295f449bb863e793f8546b2daf139ace1b766 100644 (file)
@@ -133,18 +133,18 @@ class Products1cNomenclatureActualityController extends Controller
             }
 
             if ($filter->date_from || $filter->date_to) {
-                $hasDf = !empty($filter->date_from);
-                $hasDt = !empty($filter->date_to);
+                $hasDateFrom = !empty($filter->date_from);
+                $hasDateTo = !empty($filter->date_to);
 
-                $df = null;
-                $dt = null;
+                $dateFrom = null;
+                $dateTo = null;
 
-                if ($hasDf) {
-                    $df = (new \DateTime("{$filter->date_from}-01"))
+                if ($hasDateFrom) {
+                    $dateFrom = (new \DateTime("{$filter->date_from}-01"))
                         ->setTime(0, 0, 0)->format('Y-m-d H:i:s');
                 }
-                if ($hasDt) {
-                    $dt = (new \DateTime("{$filter->date_to}-01"))
+                if ($hasDateTo) {
+                    $dateTo = (new \DateTime("{$filter->date_to}-01"))
                         ->modify('last day of this month')->setTime(23, 59, 59)
                         ->format('Y-m-d H:i:s');
                 }
@@ -153,16 +153,16 @@ class Products1cNomenclatureActualityController extends Controller
                     ->alias('a')
                     ->where('a.guid = n.id');
 
-                if ($hasDf && !$hasDt) {
-                    $dateExists//->andWhere(['a.date_from' => $df])
-                        ->andWhere(['>=', 'a.date_to', $df]);;
-                } elseif (!$hasDf && $hasDt) {
-                    $dateExists//->andWhere(['a.date_to' => $dt])
-                        ->andWhere(['<=', 'a.date_from', $dt]);
+                if ($hasDateFrom && !$hasDateTo) {
+                    $dateExists//->andWhere(['a.date_from' => $dateFrom])
+                        ->andWhere(['>=', 'a.date_to', $dateFrom]);;
+                } elseif (!$hasDateFrom && $hasDateTo) {
+                    $dateExists//->andWhere(['a.date_to' => $dateTo])
+                        ->andWhere(['<=', 'a.date_from', $dateTo]);
                 } else {
                     $dateExists
-                        ->andWhere(['>=', 'a.date_to',   $df])
-                        ->andWhere(['<=', 'a.date_from', $dt]);
+                        ->andWhere(['>=', 'a.date_to',   $dateFrom])
+                        ->andWhere(['<=', 'a.date_from', $dateTo]);
                 }
 
                 if (!empty($filter->onlyInactive)) {
@@ -171,18 +171,18 @@ class Products1cNomenclatureActualityController extends Controller
                     $query->andWhere(['exists', $dateExists->select(new \yii\db\Expression('1'))]);
                 }
 
-                $query->with(['actualities' => function ($q) use ($hasDf, $hasDt, $df, $dt) {
-                    if ($hasDf && !$hasDt) {
-                        $q//->andWhere(['date_from' => $df])
-                            ->andWhere(['>=', 'date_to', $df]);
-                    } elseif (!$hasDf && $hasDt) {
-                        $q//->andWhere(['date_to' => $dt])
-                            ->andWhere(['<=', 'date_from', $dt]);
+                $query->with(['actualities' => function ($subQuery) use ($hasDateFrom, $hasDateTo, $dateFrom, $dateTo) {
+                    if ($hasDateFrom && !$hasDateTo) {
+                        $subQuery//->andWhere(['date_from' => $dateFrom])
+                            ->andWhere(['>=', 'date_to', $dateFrom]);
+                    } elseif (!$hasDateFrom && $hasDateTo) {
+                        $subQuery//->andWhere(['date_to' => $dateTo])
+                            ->andWhere(['<=', 'date_from', $dateTo]);
                     } else {
-                        $q->andWhere(['>=', 'date_to',   $df])
-                            ->andWhere(['<=', 'date_from', $dt]);
+                        $subQuery->andWhere(['>=', 'date_to',   $dateFrom])
+                            ->andWhere(['<=', 'date_from', $dateTo]);
                     }
-                    $q->orderBy(['date_from' => SORT_ASC]);
+                    $subQuery->orderBy(['date_from' => SORT_ASC]);
                 }]);
             } else {
                 $query->with(['actualities' => function ($q) {
@@ -361,18 +361,18 @@ class Products1cNomenclatureActualityController extends Controller
                 continue;
             }
 
-            $fromDt = \DateTime::createFromFormat('Y-m', $row['from']);
-            $toDt = \DateTime::createFromFormat('Y-m', $row['to']);
-            if (!$fromDt || !$toDt) {
+            $fromDate = \DateTime::createFromFormat('Y-m', $row['from']);
+            $toDate = \DateTime::createFromFormat('Y-m', $row['to']);
+            if (!$fromDate || !$toDate) {
                 continue;
             }
-            $fromDt->setDate((int)$fromDt->format('Y'), (int)$fromDt->format('m'), 1)
+            $fromDate->setDate((int)$fromDate->format('Y'), (int)$fromDate->format('m'), 1)
                 ->setTime(0, 0, 0);
-            $toDt->modify('last day of this month')
+            $toDate->modify('last day of this month')
                 ->setTime(23, 59, 59);
 
-            $from = $fromDt->format('Y-m-d H:i:s');
-            $to = $toDt->format('Y-m-d H:i:s');
+            $from = $fromDate->format('Y-m-d H:i:s');
+            $to = $toDate->format('Y-m-d H:i:s');
 
             if ($from > $to) {
                 Yii::warning("GUID {$row['guid']}: пропускаем — from > to");
@@ -381,8 +381,8 @@ class Products1cNomenclatureActualityController extends Controller
 
             $guid = $row['guid'];
 
-            $fromAdj = (clone $fromDt)->modify('-1 second')->format('Y-m-d H:i:s');
-            $toAdj   = (clone $toDt)->modify('+1 second')->format('Y-m-d H:i:s');
+            $fromAdj = (clone $fromDate)->modify('-1 second')->format('Y-m-d H:i:s');
+            $toAdj   = (clone $toDate)->modify('+1 second')->format('Y-m-d H:i:s');
 
             /** @var Products1cNomenclatureActuality[] $hits */
             $hits = Products1cNomenclatureActuality::find()