]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Лист с остатками GUID
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 13 Dec 2024 14:12:10 +0000 (17:12 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 13 Dec 2024 14:12:10 +0000 (17:12 +0300)
erp24/controllers/ShiftTransferController.php
erp24/views/shift-transfer/update.php
erp24/web/js/shift-transfer/update.js

index 4a88e1b155a706d72620e57aaedae31f12d19111..4269dd8cc361f2d17c3ffec428f80d1d15115f3a 100644 (file)
@@ -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'));
     }
 
 
index ea439526e7f86bc3ae105e5a560e33fc68e3b655..395ae2446898e460ff02577650cbd3c7e8b36001 100644 (file)
@@ -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('
index 2cb3a7874b8f08abfc43847f1aedeaff7e1e72b4..d251aabc923196b7d1995ed2b69e0b6d4ed59b50 100644 (file)
@@ -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);
     });
 });