From 06ac82262f1659e5fdd573bda9d04f408eda27ad Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Dec 2024 13:08:43 +0300 Subject: [PATCH] =?utf8?q?ERP-259=20=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?utf8?q?=D1=82=D0=BA=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B3=D0=BE?= =?utf8?q?=20=D1=88=D0=B0=D0=B3=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4?= =?utf8?q?=D0=B0=D1=87=D0=B8=20=D1=81=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/ShiftTransferController.php | 27 +++++++++++++------ erp24/web/js/shift-transfer/replacement.js | 5 +++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index 24db308a..17bef758 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -85,8 +85,7 @@ class ShiftTransferController extends Controller foreach ($products as $key => $data) { if (isset($balance[$key]) && $balance[$key] > 0) { $productGuids[$key] = $data['name'] . ' (арт. ' . $data['articule'] . ')'; - } - else { + } else { if (!$normal) { $productGuids[$key] = $data['name']; } @@ -329,7 +328,7 @@ class ShiftTransferController extends Controller ->andWhere(['shift_transfer_id' => $id]) ->andWhere(['<', 'fact_and_1c_diff', 0]) ->select('product_guid')->column()]), - 'id', function($model) { + 'id', function ($model) { return $model->name . ' (арт. ' . $model->articule . ')'; }); @@ -366,7 +365,7 @@ class ShiftTransferController extends Controller ->select(['guid_replacement']) ->column()]) ->all(), - 'id', function($model) { + 'id', function ($model) { return $model->name . ' (арт. ' . $model->articule . ')'; }); @@ -422,10 +421,20 @@ class ShiftTransferController extends Controller return Json::encode($data); } - public function actionGetMaxQuantity(string $productName, int $shiftTransferId) + public function actionGetMaxQuantity(string $productReplacementName, string $productName, int $shiftTransferId) { \Yii::$app->response->format = Response::FORMAT_JSON; + if (preg_match('/^[a-f0-9\-]{36}$/i', $productReplacementName)) { + $productReplacementId = $productReplacementName; + } else { + if (preg_match('/^(.*)\s\(арт\.\s(\d+)\)$/', $productReplacementName, $matches)) { + $productReplacementId = Products1c::findOne(['name' => $matches[1], 'articule' => $matches[2]])->id; + } else { + $productReplacementId = null; + } + } + if (preg_match('/^[a-f0-9\-]{36}$/i', $productName)) { $productId = $productName; } else { @@ -437,12 +446,14 @@ class ShiftTransferController extends Controller } $product = Products1c::findOne(['id' => $productId]); + $productReplacement = Products1c::findOne(['id' => $productReplacementId]); if ($product) { - $shiftRemain = ShiftRemains::findOne(['shift_transfer_id' => $shiftTransferId, 'product_guid' => $product->id]); - if ($shiftRemain) { + $shiftRemainProduct = ShiftRemains::findOne(['shift_transfer_id' => $shiftTransferId, 'product_guid' => $product->id]); + $shiftRemainReplacement = ShiftRemains::findOne(['shift_transfer_id' => $shiftTransferId, 'product_guid' => $productReplacement->id]); + if ($shiftRemainProduct && $shiftRemainReplacement) { return [ - 'maxValue' => $shiftRemain->fact_and_1c_diff ?? 0, + 'maxValue' => min(abs($shiftRemainProduct->fact_and_1c_diff), abs($shiftRemainReplacement->fact_and_1c_diff)) ?? 0, ]; } diff --git a/erp24/web/js/shift-transfer/replacement.js b/erp24/web/js/shift-transfer/replacement.js index d700f55f..e8682129 100644 --- a/erp24/web/js/shift-transfer/replacement.js +++ b/erp24/web/js/shift-transfer/replacement.js @@ -226,6 +226,8 @@ function setDynamicMaxValue(inputElement, rowId) { return; } + + var productReplacementName = $('#shifttransfer-equalizationremains-' + rowId + '-product_id').val(); var productName = $('#shifttransfer-equalizationremains-' + rowId + '-product_replacement_id').val(); var shiftTransferId = getUrlParameter('id'); @@ -238,6 +240,7 @@ function setDynamicMaxValue(inputElement, rowId) { type: 'GET', data: { productName: productName, + productReplacementName: productReplacementName, shiftTransferId: shiftTransferId }, success: function (response) { @@ -261,7 +264,7 @@ $('.field-shifttransfer-equalizationremains').on('input change', '.list-cell__pr if (value > max) { alert('Максимальное допустимое значение: ' + max); - $(inputElement).val(max); + $(inputElement).val(max); } }); -- 2.39.5