]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-243 Действия по замене (II этап)
authormarina <m.zozirova@gmail.com>
Mon, 2 Dec 2024 06:12:40 +0000 (09:12 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 2 Dec 2024 06:12:40 +0000 (09:12 +0300)
erp24/views/shift-transfer/_replacement.php
erp24/web/js/shift-transfer/equalization-remains.js [deleted file]
erp24/web/js/shift-transfer/replacement.js [new file with mode: 0644]

index 8cf258b282b018ae45ed9bfd04c759e3fd4c3806..d9cf7bbc9ee4e12ec92d4b232aaa7612c0b010b8 100644 (file)
@@ -15,6 +15,8 @@ use yii\widgets\ActiveForm;
 /* @var $isAcceptance bool */
 /* @var $products array */
 
+$this->registerJsFile('/js/shift-transfer/replacement.js', ['position' => \yii\web\View::POS_END]);
+
 $form = \yii\widgets\ActiveForm::begin();
 if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIONS, ShiftTransfer::STATUS_ID_INPUT_FACT_REMAINS])
     && Yii::$app->user->id === $shiftTransfer->end_shift_admin_id) {
diff --git a/erp24/web/js/shift-transfer/equalization-remains.js b/erp24/web/js/shift-transfer/equalization-remains.js
deleted file mode 100644 (file)
index f163af0..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-let isRequestInProgress = false;
-let isRequestInProgressQuantity = false;
-let isRequestInProgressPrice = false;
-
-function getUrlParameter(name) {
-    return new URLSearchParams(window.location.search).get(name);
-}
-
-function setProductData() {
-    if (isRequestInProgress) return;  // Если запрос уже в процессе, выходим
-
-    isRequestInProgress = true;  // Устанавливаем флаг запроса
-    const $this = $(this);
-    const productGuid = $this.closest('tr').find('select').val();
-    const shiftTransferId = getUrlParameter('id');
-
-    if (!productGuid) return;  // Если productGuid не найден, выходим
-
-    $.ajax({
-        url: '/shift-transfer/get-product-data',
-        type: 'GET',
-        data: { productGuid, shiftTransferId },
-        success: function(response) {
-            let data;
-            try {
-                data = JSON.parse(response);
-            } catch (e) {
-                alert('Ошибка при обработке данных');
-                return;
-            }
-
-            if (!data.success) {
-                alert('Ошибка: ' + data.message);
-                return;
-            }
-
-            const index = $this.closest('tr').data('index');
-            $('#shifttransfer-equalizationremains-' + index + '-product_price').val(data.product_price);
-
-            const replacementSelect = $('#shifttransfer-equalizationremains-' + index + '-product_replacement_id');
-            replacementSelect.empty().append('<option value="">Выберите товар</option>');
-
-            Object.entries(data.product_replacement || {}).forEach(([id, name]) => {
-                replacementSelect.append(`<option value="${id}">${name}</option>`);
-            });
-
-            replacementSelect.css({ visibility: 'visible', height: 'auto', width: '100%' })
-                .trigger('change')
-                .val(replacementSelect.val() || replacementSelect.find('option').first().val())
-                .trigger('change');
-
-            $('#shifttransfer-equalizationremains-' + index + '-product_self_cost').val(data.product_self_cost || '');
-        },
-        error: function() {
-            alert('Ошибка запроса!');
-        },
-        complete: function() {
-            isRequestInProgress = false;  // Снимаем флаг, когда запрос завершен
-        }
-    });
-}
-
-function setReplacementPriceData() {
-    if (isRequestInProgressPrice) return;  // Если запрос уже в процессе, выходим
-
-    isRequestInProgressPrice = true;  // Устанавливаем флаг запроса
-    const $this = $(this);
-    const productGuid = $this.val();
-    const shiftTransferId = getUrlParameter('id');
-
-    if (!productGuid) return;  // Если productGuid не найден, выходим
-
-    $.ajax({
-        url: '/shift-transfer/get-product-replacement-price',
-        type: 'GET',
-        data: { productGuid, shiftTransferId },
-        success: function(response) {
-            let data;
-            try {
-                data = JSON.parse(response);
-            } catch (e) {
-                alert('Ошибка при обработке данных');
-                return;
-            }
-
-            if (!data.success) {
-                alert('Ошибка: ' + data.message);
-                return;
-            }
-
-            const index = $this.closest('tr').data('index');
-            const priceInput = $('#shifttransfer-equalizationremains-' + index + '-product_replacement_price');
-            const replacementSelfCostInput = $('#shifttransfer-equalizationremains-' + index + '-product_replacement_self_cost');
-
-            if (priceInput.length) {
-                priceInput.val(data.product_price).trigger('change');
-            }
-
-            if (replacementSelfCostInput.length) {
-                replacementSelfCostInput.val(data.product_replacement_self_cost || '').trigger('change');
-            }
-        },
-        error: function() {
-            alert('Ошибка запроса!');
-        },
-        complete: function() {
-            isRequestInProgressPrice = false;  // Снимаем флаг, когда запрос завершен
-        }
-    });
-}
-
-$(document).on('input', '.list-cell__product_replacement_count input', function() {
-    const $this = $(this);
-    const id = $this.attr('id');
-    const indexMatch = id.match(/shifttransfer-equalizationremains-(\d+)-/);
-
-    if (!indexMatch) {
-        alert('Ошибка: Невозможно извлечь индекс из ID');
-        return;
-    }
-
-    const index = indexMatch[1];
-    const quantity = parseFloat($this.val());
-    if (isNaN(quantity) || quantity < 0) {
-        alert('Введите корректное количество!');
-        return;
-    }
-
-    const productPrice = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_price input`).val());
-    const productSelfCost = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_self_cost input`).val());
-    const productReplacementPrice = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_replacement_price input`).val());
-    const productReplacementSelfCost = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_replacement_self_cost input`).val());
-
-    if (isNaN(productPrice) || isNaN(productSelfCost) || isNaN(productReplacementPrice) || isNaN(productReplacementSelfCost)) {
-        alert('Введите корректные значения для цены или себестоимости!');
-        return;
-    }
-
-    const balance = (productPrice - productReplacementPrice) * quantity;
-    const balanceSelfCost = (productSelfCost - productReplacementSelfCost) * quantity;
-
-    $('#shifttransfer-equalizationremains-' + index + '-balance').val(balance.toFixed(2)).trigger('change');
-    $('#shifttransfer-equalizationremains-' + index + '-balance_self_cost').val(balanceSelfCost.toFixed(2)).trigger('change');
-});
diff --git a/erp24/web/js/shift-transfer/replacement.js b/erp24/web/js/shift-transfer/replacement.js
new file mode 100644 (file)
index 0000000..f163af0
--- /dev/null
@@ -0,0 +1,144 @@
+let isRequestInProgress = false;
+let isRequestInProgressQuantity = false;
+let isRequestInProgressPrice = false;
+
+function getUrlParameter(name) {
+    return new URLSearchParams(window.location.search).get(name);
+}
+
+function setProductData() {
+    if (isRequestInProgress) return;  // Если запрос уже в процессе, выходим
+
+    isRequestInProgress = true;  // Устанавливаем флаг запроса
+    const $this = $(this);
+    const productGuid = $this.closest('tr').find('select').val();
+    const shiftTransferId = getUrlParameter('id');
+
+    if (!productGuid) return;  // Если productGuid не найден, выходим
+
+    $.ajax({
+        url: '/shift-transfer/get-product-data',
+        type: 'GET',
+        data: { productGuid, shiftTransferId },
+        success: function(response) {
+            let data;
+            try {
+                data = JSON.parse(response);
+            } catch (e) {
+                alert('Ошибка при обработке данных');
+                return;
+            }
+
+            if (!data.success) {
+                alert('Ошибка: ' + data.message);
+                return;
+            }
+
+            const index = $this.closest('tr').data('index');
+            $('#shifttransfer-equalizationremains-' + index + '-product_price').val(data.product_price);
+
+            const replacementSelect = $('#shifttransfer-equalizationremains-' + index + '-product_replacement_id');
+            replacementSelect.empty().append('<option value="">Выберите товар</option>');
+
+            Object.entries(data.product_replacement || {}).forEach(([id, name]) => {
+                replacementSelect.append(`<option value="${id}">${name}</option>`);
+            });
+
+            replacementSelect.css({ visibility: 'visible', height: 'auto', width: '100%' })
+                .trigger('change')
+                .val(replacementSelect.val() || replacementSelect.find('option').first().val())
+                .trigger('change');
+
+            $('#shifttransfer-equalizationremains-' + index + '-product_self_cost').val(data.product_self_cost || '');
+        },
+        error: function() {
+            alert('Ошибка запроса!');
+        },
+        complete: function() {
+            isRequestInProgress = false;  // Снимаем флаг, когда запрос завершен
+        }
+    });
+}
+
+function setReplacementPriceData() {
+    if (isRequestInProgressPrice) return;  // Если запрос уже в процессе, выходим
+
+    isRequestInProgressPrice = true;  // Устанавливаем флаг запроса
+    const $this = $(this);
+    const productGuid = $this.val();
+    const shiftTransferId = getUrlParameter('id');
+
+    if (!productGuid) return;  // Если productGuid не найден, выходим
+
+    $.ajax({
+        url: '/shift-transfer/get-product-replacement-price',
+        type: 'GET',
+        data: { productGuid, shiftTransferId },
+        success: function(response) {
+            let data;
+            try {
+                data = JSON.parse(response);
+            } catch (e) {
+                alert('Ошибка при обработке данных');
+                return;
+            }
+
+            if (!data.success) {
+                alert('Ошибка: ' + data.message);
+                return;
+            }
+
+            const index = $this.closest('tr').data('index');
+            const priceInput = $('#shifttransfer-equalizationremains-' + index + '-product_replacement_price');
+            const replacementSelfCostInput = $('#shifttransfer-equalizationremains-' + index + '-product_replacement_self_cost');
+
+            if (priceInput.length) {
+                priceInput.val(data.product_price).trigger('change');
+            }
+
+            if (replacementSelfCostInput.length) {
+                replacementSelfCostInput.val(data.product_replacement_self_cost || '').trigger('change');
+            }
+        },
+        error: function() {
+            alert('Ошибка запроса!');
+        },
+        complete: function() {
+            isRequestInProgressPrice = false;  // Снимаем флаг, когда запрос завершен
+        }
+    });
+}
+
+$(document).on('input', '.list-cell__product_replacement_count input', function() {
+    const $this = $(this);
+    const id = $this.attr('id');
+    const indexMatch = id.match(/shifttransfer-equalizationremains-(\d+)-/);
+
+    if (!indexMatch) {
+        alert('Ошибка: Невозможно извлечь индекс из ID');
+        return;
+    }
+
+    const index = indexMatch[1];
+    const quantity = parseFloat($this.val());
+    if (isNaN(quantity) || quantity < 0) {
+        alert('Введите корректное количество!');
+        return;
+    }
+
+    const productPrice = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_price input`).val());
+    const productSelfCost = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_self_cost input`).val());
+    const productReplacementPrice = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_replacement_price input`).val());
+    const productReplacementSelfCost = parseFloat($this.closest('tr').find(`.field-shifttransfer-equalizationremains-${index}-product_replacement_self_cost input`).val());
+
+    if (isNaN(productPrice) || isNaN(productSelfCost) || isNaN(productReplacementPrice) || isNaN(productReplacementSelfCost)) {
+        alert('Введите корректные значения для цены или себестоимости!');
+        return;
+    }
+
+    const balance = (productPrice - productReplacementPrice) * quantity;
+    const balanceSelfCost = (productSelfCost - productReplacementSelfCost) * quantity;
+
+    $('#shifttransfer-equalizationremains-' + index + '-balance').val(balance.toFixed(2)).trigger('change');
+    $('#shifttransfer-equalizationremains-' + index + '-balance_self_cost').val(balanceSelfCost.toFixed(2)).trigger('change');
+});