From 90c6fae10ea0e9476557840327d2da4cf0b81c50 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 13 Dec 2024 17:12:10 +0300 Subject: [PATCH] =?utf8?q?=D0=9B=D0=B8=D1=81=D1=82=20=D1=81=20=D0=BE=D1=81?= =?utf8?q?=D1=82=D0=B0=D1=82=D0=BA=D0=B0=D0=BC=D0=B8=20GUID?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/ShiftTransferController.php | 21 +++++++++++++++++-- erp24/views/shift-transfer/update.php | 2 ++ erp24/web/js/shift-transfer/update.js | 16 +++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index 4a88e1b1..4269dd8c 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -126,7 +126,15 @@ class ShiftTransferController extends Controller $shiftTransfer->shiftRemainsCopy = $loadDataShiftRemains ?? $shiftTransfer->shiftRemains; - return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById', 'productGuids')); + $existingKeys = ArrayHelper::getColumn($shiftTransfer->shiftRemainsCopy, 'product_guid'); + $productGuidsForRest = []; + foreach ($productGuids as $key => $value) { + if (!in_array($key, $existingKeys)) { + $productGuidsForRest[$key] = $value; + } + } + return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById', + 'productGuids', 'productGuidsForRest')); } public function actionUpdate($id = null) @@ -204,7 +212,16 @@ class ShiftTransferController extends Controller $shiftTransfer->shiftRemainsCopy = $loadDataShiftRemains ?? $shiftTransfer->shiftRemains; - return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById', 'productGuids')); + $existingKeys = ArrayHelper::getColumn($shiftTransfer->shiftRemainsCopy, 'product_guid'); + $productGuidsForRest = []; + foreach ($productGuids as $key => $value) { + if (!in_array($key, $existingKeys)) { + $productGuidsForRest[$key] = $value; + } + } + + return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById', + 'productGuids', 'productGuidsForRest')); } diff --git a/erp24/views/shift-transfer/update.php b/erp24/views/shift-transfer/update.php index ea439526..395ae244 100644 --- a/erp24/views/shift-transfer/update.php +++ b/erp24/views/shift-transfer/update.php @@ -17,7 +17,9 @@ use yii_app\records\ProductsClass; /* @var $shiftTransfer ShiftTransfer */ /* @var $storeNameById array */ /* @var $productGuids array */ +/* @var $productGuidsForRest array */ +$this->registerJs('var productGuidsForRest = ' . \yii\helpers\Json::encode($productGuidsForRest), \yii\web\View::POS_END); $this->registerJsFile('/js/shift-transfer/update.js', ['position' => \yii\web\View::POS_END]); $this->registerCss(' diff --git a/erp24/web/js/shift-transfer/update.js b/erp24/web/js/shift-transfer/update.js index 2cb3a787..d251aabc 100644 --- a/erp24/web/js/shift-transfer/update.js +++ b/erp24/web/js/shift-transfer/update.js @@ -43,6 +43,19 @@ function checkInputs() { return noError; } +function setOptionsForProductGuid(row) { + const currentIndex = $(row).find('.list-cell__index').find('input').val() - 1; + const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid'); + + productGuid.empty(); + $.each(productGuidsForRest, (key, value) => { + const opt = document.createElement('OPTION'); + opt.text = value; + opt.value = value; + productGuid.append($(opt)); + }) +} + function setMultipleInputHandlers(row) { const currentIndex = $(row).find('.list-cell__index').find('input').val() - 1; const store = $('#shifttransfer-store_guid'); @@ -102,8 +115,9 @@ $(document).ready(() => { makeInputReadonly(rows[currentIndex]); } }).on('afterAddRow', function(e, row, currentIndex) { - setMultipleInputHandlers(row); const index = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-index'); index.val(currentIndex+1); + setMultipleInputHandlers(row); + setOptionsForProductGuid(row); }); }); -- 2.39.5