From: marina Date: Tue, 17 Dec 2024 10:08:43 +0000 (+0300) Subject: ERP-259 Доработка второго шага передачи смен X-Git-Tag: 1.7~156^2~3 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=06ac82262f1659e5fdd573bda9d04f408eda27ad;p=erp24_rep%2Fyii-erp24%2F.git ERP-259 Доработка второго шага передачи смен --- 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); } });