$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)
$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'));
}
/* @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('
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');
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);
});
});