]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-259 Доработка второго шага передачи смен
authormarina <m.zozirova@gmail.com>
Tue, 17 Dec 2024 10:08:43 +0000 (13:08 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 17 Dec 2024 10:08:43 +0000 (13:08 +0300)
erp24/controllers/ShiftTransferController.php
erp24/web/js/shift-transfer/replacement.js

index 24db308afafedb44159be6b286c5f78bfbd529ee..17bef758bca6dbfc7328ff7d8d99de78b1e54e10 100644 (file)
@@ -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,
                 ];
 
             }
index d700f55fe5cf16cb0a4296f30edce466be22f8d2..e8682129f0bfbf8f31aecf146082559e47c4b90c 100644 (file)
@@ -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);
     }
 });