$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();
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;
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();
+ }
+ }
}
}
<!-- 1-я колонка: основные фильтры -->
<div class="col-6 ">
+ <div class="mb-2 fw-bold">Номенклатура</div>
<div class="row mb-3">
<div class="col">
<div class="d-flex justify-content-between">
</div>
<!-- 3-я колонка: поставщик/плантация + кнопка Применить -->
- <div class="col-3 ps-4" style="border-left: #ccc solid 1px">
+ <div class="col-2 ps-4" style="border-left: #ccc solid 1px">
+ <div class="mb-2 fw-bold">Поставщики</div>
<div class="mb-3">
<div class="input-group">
</div>
</div>
</div>
- <div class="text-end">
- <?= Html::submitButton('Применить', ['class' => 'btn btn-primary']) ?>
- </div>
+
</div>
+ <div class="col-1 ps-4 d-flex justify-content-end align-items-end" >
+ <?= Html::submitButton('Применить', ['class' => 'btn btn-primary w-100']) ?>
+
+ </div>
</div>
<?php ActiveForm::end(); ?>