From: Vladimir Fomichev Date: Thu, 14 Aug 2025 11:29:04 +0000 (+0300) Subject: Слияние смежных интервалов и коррекции по представлению X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=32b7e63a80a8587926bf9d2e6e9abfc40678cb01;p=erp24_rep%2Fyii-erp24%2F.git Слияние смежных интервалов и коррекции по представлению --- diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index 6f645f01..222cde25 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -338,11 +338,14 @@ 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'); + /** @var Products1cNomenclatureActuality[] $hits */ $hits = Products1cNomenclatureActuality::find() ->where(['guid' => $guid]) - ->andWhere('date_to >= :from', [':from' => $from]) - ->andWhere('date_from <= :to', [':to' => $to]) + ->andWhere('date_to >= :fromAdj', [':fromAdj' => $fromAdj]) + ->andWhere('date_from <= :toAdj', [':toAdj' => $toAdj]) ->orderBy(['date_from' => SORT_ASC]) ->all(); @@ -360,10 +363,12 @@ class Products1cNomenclatureActualityController extends Controller continue; } - $allFrom = array_map(fn($r) => $r->date_from, $hits); - $allTo = array_map(fn($r) => $r->date_to, $hits); - $minFrom = min($from, min($allFrom)); - $maxTo = max($to, max($allTo)); + $minFrom = $from; + $maxTo = $to; + foreach ($hits as $h) { + if ($h->date_from < $minFrom) { $minFrom = $h->date_from; } + if ($h->date_to > $maxTo) { $maxTo = $h->date_to; } + } $master = array_shift($hits); $master->date_from = $minFrom; @@ -378,6 +383,46 @@ class Products1cNomenclatureActualityController extends Controller foreach ($hits as $dup) { $dup->delete(); } + + while (true) { + $leftBound = (new \DateTime($master->date_from))->modify('-1 second')->format('Y-m-d H:i:s'); + $rightBound = (new \DateTime($master->date_to))->modify('+1 second')->format('Y-m-d H:i:s'); + + /** @var Products1cNomenclatureActuality[] $neighbors */ + $neighbors = Products1cNomenclatureActuality::find() + ->where(['guid' => $guid]) + ->andWhere(['<>', 'id', $master->id]) + ->andWhere('date_to >= :leftBound', [':leftBound' => $leftBound]) + ->andWhere('date_from <= :rightBound', [':rightBound' => $rightBound]) + ->orderBy(['date_from' => SORT_ASC]) + ->all(); + + if (empty($neighbors)) { + break; + } + + foreach ($neighbors as $nei) { + if ($nei->date_from < $master->date_from) + { + $master->date_from = $nei->date_from; + } + if ($nei->date_to > $master->date_to) + { + $master->date_to = $nei->date_to; + } + } + $master->updated_at = $now; + $master->updated_by = $userId; + + if (!$master->save()) { + Yii::error("Ошибка повторного обновления GUID={$guid}: " . json_encode($master->getErrors(), JSON_UNESCAPED_UNICODE)); + break; + } + + foreach ($neighbors as $nei) { + $nei->delete(); + } + } } } diff --git a/erp24/views/products1c-nomenclature-actuality/index.php b/erp24/views/products1c-nomenclature-actuality/index.php index b3ed7faa..a8be5ac6 100644 --- a/erp24/views/products1c-nomenclature-actuality/index.php +++ b/erp24/views/products1c-nomenclature-actuality/index.php @@ -57,6 +57,7 @@ foreach ($months as $k => $v) {
+
Номенклатура
@@ -201,7 +202,8 @@ foreach ($months as $k => $v) {
-
+
+
Поставщики
@@ -224,11 +226,13 @@ foreach ($months as $k => $v) {
-
- 'btn btn-primary']) ?> -
+
+
+ 'btn btn-primary w-100']) ?> + +
diff --git a/erp24/web/js/products1cNomenclatureActuality/index.js b/erp24/web/js/products1cNomenclatureActuality/index.js index 88b227d5..ccfb2f43 100644 --- a/erp24/web/js/products1cNomenclatureActuality/index.js +++ b/erp24/web/js/products1cNomenclatureActuality/index.js @@ -19,9 +19,9 @@ document.addEventListener("DOMContentLoaded", () => { actualIdx++; const newRow = ` - - - ${name} (${guid}) + + +
${name} (${guid})
Новая запись. Заполните интервал