foreach ($equalizationRemains as $er) {
$equalizationRemain = new EqualizationRemains();
$equalizationRemain->setAttributes([
- 'shift_id' => $shift_transfer_id,
+ 'shift_transfer_id' => $shift_transfer_id,
'product_id' => $er['product_id'],
'product_count' => $er['product_replacement_count'],
'product_price' => $er['product_price'],
public static function setData($shiftTransfer)
{
- EqualizationRemains::deleteAll(['shift_id' => $shiftTransfer->id]);
+ EqualizationRemains::deleteAll(['shift_transfer_id' => $shiftTransfer->id]);
$plus = ShiftRemains::find()
->where(['shift_transfer_id' => $shiftTransfer->id])
foreach ($intersect as $key => $item) {
$eqRemains = self::find()
->select(['SUM(product_count)'])
- ->where(['shift_id' => $shiftTransfer->id, 'product_id' => $key])
- ->groupBy(['shift_id', 'product_replacement_id'])
+ ->where(['shift_transfer_id' => $shiftTransfer->id, 'product_id' => $key])
+ ->groupBy(['shift_transfer_id', 'product_replacement_id'])
->scalar();
$diff = $eqRemains
if (self::find()
->select(['SUM(product_count)'])
- ->where(['shift_id' => $shiftTransfer->id])
+ ->where(['shift_transfer_id' => $shiftTransfer->id])
->andWhere(['product_id' => $key])
- ->groupBy(['shift_id', 'product_id'])
+ ->groupBy(['shift_transfer_id', 'product_id'])
->having(['SUM(product_count)' => abs($item['fact_and_1c_diff'])])
->scalar() == abs($item['fact_and_1c_diff'])) {
break;
$model = new EqualizationRemains();
$model->setAttributes([
- 'shift_id' => $shiftTransfer->id,
+ 'shift_transfer_id' => $shiftTransfer->id,
'product_id' => $key,
'product_count' => $diff,
'product_price' => $item['retail_price'],
$.ajax({
url: '/shift-transfer/get-product-data',
type: 'GET',
- data: { productGuid, shiftTransferId },
- success: function(response) {
+ data: {productGuid, shiftTransferId},
+ success: function (response) {
let data;
try {
data = JSON.parse(response);
replacementSelect.append(`<option value="${id}">${name}</option>`);
});
- replacementSelect.css({ visibility: 'visible', height: 'auto', width: '100%' })
+ 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() {
+ error: function () {
alert('Ошибка запроса!');
clearFields($this); // Очищаем поля в случае ошибки запроса
},
- complete: function() {
+ complete: function () {
isRequestInProgress = false;
}
});
'#shifttransfer-equalizationremains-' + index + '-balance_self_cost'
];
- fieldsToClear.forEach(function(selector) {
+ fieldsToClear.forEach(function (selector) {
const element = $(selector);
if (element.length) {
if (element.is('select')) {
$.ajax({
url: '/shift-transfer/get-product-replacement-price',
type: 'GET',
- data: { productGuid, shiftTransferId },
- success: function(response) {
+ data: {productGuid, shiftTransferId},
+ success: function (response) {
let data;
try {
data = JSON.parse(response);
quantityInput.attr('max', maxQuantity);
// Обработчик события изменения значения в поле
- quantityInput.on('input', function() {
+ quantityInput.on('input', function () {
let currentQuantity = parseFloat(quantityInput.val()) || 0;
if (currentQuantity > maxQuantity) {
});
}
},
- error: function() {
+ error: function () {
alert('Ошибка запроса!');
},
- complete: function() {
+ complete: function () {
isRequestInProgressPrice = false;
}
});
}
-$('.field-shifttransfer-equalizationremains').on('input', '.list-cell__product_replacement_count input', function() {
+$('.field-shifttransfer-equalizationremains').on('input', '.list-cell__product_replacement_count input', function () {
const $this = $(this);
const id = $this.attr('id');
const indexMatch = id.match(/shifttransfer-equalizationremains-(\d+)-/);
$('#shifttransfer-equalizationremains-' + index + '-balance').val(balanceCalculation.toFixed(2)).trigger('change');
$('#shifttransfer-equalizationremains-' + index + '-balance_self_cost').val(balanceSelfCost.toFixed(2)).trigger('change');
});
+
+function setDynamicMaxValue(inputElement, rowId) {
+ var currentMax = $(inputElement).attr('max');
+
+ if (currentMax !== undefined) {
+ return;
+ }
+
+ var productName = $('#shifttransfer-equalizationremains-' + rowId + '-product_replacement_id').val();
+ var shiftTransferId = getUrlParameter('id');
+
+ if (!shiftTransferId) {
+ return;
+ }
+
+ $.ajax({
+ url: '/shift-transfer/get-max-quantity',
+ type: 'GET',
+ data: {
+ productName: productName,
+ shiftTransferId: shiftTransferId
+ },
+ success: function (response) {
+ if (response.maxValue !== undefined) {
+ $(inputElement).attr('max', response.maxValue);
+ }
+ },
+ error: function () {}
+ });
+}
+
+$('.field-shifttransfer-equalizationremains').on('input', '.list-cell__product_replacement_count input', function () {
+ var inputElement = $(this);
+ var rowId = inputElement.closest('tr').index();
+ var max = $(inputElement).attr('max');
+ var value = $(inputElement).val();
+
+ setDynamicMaxValue(inputElement, rowId);
+
+ if (value > max) {
+ alert('Максимальное допустимое значение: ' + max);
+ $(inputElement).val(max);
+ }
+});
+
+
+
+
+
+