From c28584bf71ca6a576354bbe1687a141178f0ff88 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 3 Dec 2024 17:03:54 +0300 Subject: [PATCH] =?utf8?q?[ERP-242]=20=D1=87=D0=B8=D1=81=D0=BB=D0=B0=20?= =?utf8?q?=D1=81=20=D0=BF=D1=80=D0=BE=D0=B4=D1=83=D0=BA=D1=82=D0=B0=D0=BC?= =?utf8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/ShiftTransferController.php | 15 ++++++++++ erp24/views/shift-transfer/update.php | 2 +- erp24/web/js/shift-transfer/update.js | 30 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index 0617d72e..e9fc994a 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -156,6 +156,21 @@ class ShiftTransferController extends Controller return ['groupLabel' => $productClass->tip ?? 'other_items', 'price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0]; } + public function actionGetProductsWithRemains() { + Yii::$app->response->format = Response::FORMAT_JSON; + $storeGuid = Yii::$app->request->post('storeGuid'); + $balance = ArrayHelper::map(Balances::find()->select(['quantity', 'product_id'])->where(['store_id' => $storeGuid])->all(), 'product_id', 'quantity'); + $products = ArrayHelper::map(Products1c::find()->select(['id', 'name']) + ->where(['tip' => 'products'])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'); + $result = []; + foreach ($products as $key => $name) { + if (isset($balance[$key])) { + $result[$key] = $name . ' - ' . $balance[$key]; + } + } + return $result; + } + public function actionView($id) { if (Yii::$app->request->post()) { diff --git a/erp24/views/shift-transfer/update.php b/erp24/views/shift-transfer/update.php index ffed0866..b1f0aecc 100644 --- a/erp24/views/shift-transfer/update.php +++ b/erp24/views/shift-transfer/update.php @@ -48,7 +48,7 @@ $this->registerCss('
- field($shiftTransfer, 'store_guid')->dropDownList($storeNameById) ?> + field($shiftTransfer, 'store_guid')->dropDownList($storeNameById, ['onchange' => 'updateProductsWithBalanceAll();']) ?>
diff --git a/erp24/web/js/shift-transfer/update.js b/erp24/web/js/shift-transfer/update.js index e50d2c82..aea5b7e0 100644 --- a/erp24/web/js/shift-transfer/update.js +++ b/erp24/web/js/shift-transfer/update.js @@ -4,6 +4,35 @@ const param24 = $('meta[name=csrf-param]').attr('content'); const token24 = $('meta[name=csrf-token]').attr('content'); +function updateProductsWithBalance(currentIndex, row) { + const store = $('#shifttransfer-store_guid'); + const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid'); + productGuid.empty(); + $.ajax({ + type: 'POST', + url: '/shift-transfer/get-products-with-remains', + data: { storeGuid: store.val(), [param24]: token24 }, + dataType: 'json', + success: (data) => { + console.log(data); + $.each(data, (key, el) => { + console.log(key, el) + const opt = document.createElement('option'); + opt.text = el; + opt.value = key; + productGuid.append(opt); + }) + } + }); +} + +function updateProductsWithBalanceAll() { + const rows = $('.multiple-input-list__item'); + for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) { + updateProductsWithBalance(currentIndex + 1, rows[currentIndex]); + } +} + function checkInputRow(currentIndex, row, errorContainer) { const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid'); const productName = $(row).find('#select2-shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid-container').text(); @@ -43,6 +72,7 @@ function checkInputs() { } function setMultipleInputHandlers(currentIndex, row) { + updateProductsWithBalance(currentIndex, row); const store = $('#shifttransfer-store_guid'); const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label'); const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid'); -- 2.39.5