From: Vladimir Fomichev Date: Fri, 22 Aug 2025 09:48:26 +0000 (+0300) Subject: Рефакторинг X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=542ffcb8ce62067517ea3e3509a02b8068940c3e;p=erp24_rep%2Fyii-erp24%2F.git Рефакторинг --- diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index 3003c2b7..4de295f4 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -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()