From: Alexander Smirnov Date: Tue, 3 Dec 2024 14:03:54 +0000 (+0300) Subject: [ERP-242] числа с продуктами X-Git-Tag: 1.7~196^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=c28584bf71ca6a576354bbe1687a141178f0ff88;p=erp24_rep%2Fyii-erp24%2F.git [ERP-242] числа с продуктами --- 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');