From: Alexander Smirnov Date: Fri, 29 Nov 2024 11:17:52 +0000 (+0300) Subject: [ERP-251] сообщения об ошибках X-Git-Tag: 1.7~218^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=844bd892d8582da6e72f6678f22badede5b63367;p=erp24_rep%2Fyii-erp24%2F.git [ERP-251] сообщения об ошибках --- diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index 13f7f759..e475929c 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -81,6 +81,8 @@ class ShiftTransferController extends Controller $modelsShiftRemain->shift_transfer_id = $shiftTransfer->id; if ($modelsShiftRemain->validate()) { $modelsShiftRemain->save(); + } else { + var_dump($modelsShiftRemain->getErrors()); die; } } return $this->redirect(['/shift-transfer/view', 'id' => $shiftTransfer->id]); @@ -96,22 +98,15 @@ class ShiftTransferController extends Controller 'admins')); } - public function actionGetProductsByGroupLabel() { - Yii::$app->response->format = Response::FORMAT_JSON; - - $productsClass = ProductsClass::find()->select('category_id') - ->where(['tip' => Yii::$app->request->post('groupLabel')])->column(); - - return ArrayHelper::map(Products1c::find()->select(['id', 'name']) - ->where(['parent_id' => $productsClass])->all(), 'id', 'name'); - } - public function actionGetProductPriceSelfCostAndRemains() { Yii::$app->response->format = Response::FORMAT_JSON; $productGuid = Yii::$app->request->post('productGuid'); $storeGuid = Yii::$app->request->post('storeGuid'); + $product = Products1c::find()->where(['id' => $productGuid])->one(); + $productClass = ProductsClass::find()->where(['category_id' => $product->parent_id])->one(); + $price = Prices::find()->select(['price'])->where(['product_id' => $productGuid])->one(); $storeEIT = ExportImportTable::find()->select(['entity_id'])->where(['entity' => 'city_store', 'export_val' => $storeGuid, 'export_id' => 1])->one(); @@ -120,7 +115,7 @@ class ShiftTransferController extends Controller $balance = Balances::find()->select(['quantity'])->where(['store_id' => $storeGuid, 'product_id' => $productGuid])->one(); - return ['price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0]; + return ['groupLabel' => $productClass->tip ?? 'other_items', 'price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0]; } public function actionView($id) { diff --git a/erp24/views/matrix_erp/index.php b/erp24/views/matrix_erp/index.php index c82e806e..0adaf922 100644 --- a/erp24/views/matrix_erp/index.php +++ b/erp24/views/matrix_erp/index.php @@ -113,7 +113,7 @@ $this->params['breadcrumbs'][] = $this->title; field($filterModel, 'activeFilter')->dropDownList( ['' => 'Все', 1 => 'Активная', 0 => 'Не активная',], - ['class' => 'form-control'])->label('Активность'); + ['class' => 'form-control', 'onchange' => 'this.form.submit();'])->label('Активность'); ?> diff --git a/erp24/views/shift-transfer/update.php b/erp24/views/shift-transfer/update.php index 2506ae9e..4d76d82c 100644 --- a/erp24/views/shift-transfer/update.php +++ b/erp24/views/shift-transfer/update.php @@ -26,6 +26,7 @@ $this->registerCss(' width: 40px; } '); + ?>
@@ -35,7 +36,11 @@ $this->registerCss('

передачи смены

false, 'action' => ['/shift-transfer/update', 'id' => Yii::$app->request->get('id')], + 'options' => [ + 'onsubmit' => 'if (!checkInputs()) { event.preventDefault(); }' + ], ]) ?> field($shiftTransfer, 'id')->hiddenInput()->label(false) ?> @@ -142,30 +147,28 @@ $this->registerCss(' 'max' => 100, 'columns' => [ [ - 'name' => 'group_label', - 'title' => 'Название группы', - 'type' => BaseColumn::TYPE_DROPDOWN, - 'items' => ProductsClass::getHints(), + 'name' => 'product_guid', + 'title' => 'Продукт', + 'type' => Select2::class, + 'options' => [ + 'data' => ArrayHelper::map(Products1c::find()->select(['id', 'name']) + ->where(['tip' => 'products'])->all(), 'id', 'name'), + ], 'value' => function($data) { - return $data['group_label'] ?? ''; + return $data['product_guid'] ?? ''; }, 'headerOptions' => [ 'style' => 'width: 70px;', ] ], [ - 'name' => 'product_guid', - 'title' => 'Продукт', + 'name' => 'group_label', + 'title' => 'Название группы', 'type' => BaseColumn::TYPE_DROPDOWN, - 'items' => function($data) { - $productsClass = ProductsClass::find()->select('category_id') - ->where(['tip' => $data['group_label'] ?? null])->column(); - - return ArrayHelper::map(Products1c::find()->select(['id', 'name']) - ->where(['parent_id' => $productsClass])->all(), 'id', 'name'); - }, + 'items' => ProductsClass::getHints(), + 'options' => ['readonly' => true], 'value' => function($data) { - return $data['product_guid'] ?? ''; + return ProductsClass::getHints()[$data['group_label'] ?? 'other_items']; }, 'headerOptions' => [ 'style' => 'width: 70px;', @@ -211,7 +214,7 @@ $this->registerCss(' 'name' => 'remains_count', 'title' => 'Фактические остатки кол-во, шт', 'type' => BaseColumn::TYPE_TEXT_INPUT, - 'options' => ['type' => 'number', 'step' => 0.01, 'min' => 0], + 'options' => ['type' => 'number', 'step' => 1, 'min' => 0], 'value' => function($data) { return $data['remains_count'] ?? ''; }, diff --git a/erp24/views/shift-transfer/view.php b/erp24/views/shift-transfer/view.php index cd485d1b..5f5290a5 100644 --- a/erp24/views/shift-transfer/view.php +++ b/erp24/views/shift-transfer/view.php @@ -67,28 +67,24 @@ use yii_app\records\Products1c; ]), // 'showFooter' => true, 'columns' => [ - [ - 'attribute' => 'group_label', - 'label' => 'Название группы', -// 'footer' => 'Итого:', - 'pageSummary' => 'Итого:', - 'value' => function($data) { - return ProductsClass::getHints()[$data['group_label']] ?? ''; - }, - ], [ 'attribute' => 'product_guid', 'label' => 'Продукт', + 'pageSummary' => 'Итого:', 'value' => function($data) { - $productsClass = ProductsClass::find()->select('category_id') - ->where(['tip' => $data['group_label'] ?? null])->column(); - $products = ArrayHelper::map(Products1c::find()->select(['id', 'name']) - ->where(['parent_id' => $productsClass])->all(), 'id', 'name'); + ->where(['id' => $data['product_guid']])->all(), 'id', 'name'); return $products[$data['product_guid']] ?? ''; }, ], + [ + 'attribute' => 'group_label', + 'label' => 'Название группы', + 'value' => function($data) { + return ProductsClass::getHints()[$data['group_label']] ?? ''; + }, + ], [ 'attribute' => 'retail_price', 'label' => 'Розничная цена, руб', diff --git a/erp24/web/js/shift-transfer/update.js b/erp24/web/js/shift-transfer/update.js index cdd49393..943948f6 100644 --- a/erp24/web/js/shift-transfer/update.js +++ b/erp24/web/js/shift-transfer/update.js @@ -1,8 +1,47 @@ /* jshint esversion: 6 */ +/* jshint strict: false */ const param24 = $('meta[name=csrf-param]').attr('content'); const token24 = $('meta[name=csrf-token]').attr('content'); +function checkInputRow(currentIndex, row, errorContainer) { + const groupLabel = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-group_label'); + const productGuid = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-product_guid'); + const productName = $(row).find('#select2-shifttransfer-shiftremains-' + currentIndex + '-product_guid-container').text(); + const retailPrice = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-retail_price'); + const selfCost = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-self_cost'); + const remains1c = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_1c'); + const remains_summ = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_summ'); + const remains_count = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_count'); + const fact_and_1c_diff = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-fact_and_1c_diff'); + function checkField(field, currentIndex, productName, msg, errorContainer) { + if (field.val() === '') { errorContainer.push(msg + ' Продукт: ' + productName + ' Строка: ' + (currentIndex + 1)); return false; } + return true; + } + + return checkField(groupLabel, currentIndex, productName, 'Пустое название группы.', errorContainer) && + checkField(productGuid, currentIndex, productName, 'Не выбран продукт.', errorContainer) && + checkField(retailPrice, currentIndex, productName, 'Не назначена розничная цена.', errorContainer) && + checkField(selfCost, currentIndex, productName, 'Отсутствует себестоимость.', errorContainer) && + checkField(remains1c, currentIndex, productName, 'Отсутствует информация об остатках в 1с.', errorContainer) && + checkField(remains_summ, currentIndex, productName, 'Не подсчитана сумма остатков.', errorContainer) && + checkField(remains_count, currentIndex, productName, 'Не подсчитано количество остатков.', errorContainer) && + checkField(fact_and_1c_diff, currentIndex, productName, 'Не подсчитано разность количество остатков в 1с и в ERP.', errorContainer); +} + +function checkInputs() { + const rows = $('.multiple-input-list__item'); + let noError = true; + const errorContainer = []; + for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) { + noError = checkInputRow(currentIndex, rows[currentIndex], errorContainer) && noError; + } + if (errorContainer.length > 0) { + alert(errorContainer.join('\n')); + } + return noError; +} + function setMultipleInputHandlers(currentIndex, row) { const store = $('#shifttransfer-store_guid'); const groupLabel = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-group_label'); @@ -19,24 +58,6 @@ function setMultipleInputHandlers(currentIndex, row) { remains_summ.val(remains_count.val() * retailPrice.val()) } - groupLabel.on('change', (e) => { - $.ajax({ - type: 'POST', - url: '/shift-transfer/get-products-by-group-label', - data: { groupLabel: e.target.value, [param24]: token24 }, - dataType: 'json', - success: (data) => { - productGuid.empty(); - $.each(data, (guid, name) => { - const option = document.createElement('option'); - option.text = name; - option.value = guid; - productGuid.append(option); - }) - } - }); - }); - productGuid.on('change', (e) => { $.ajax({ type: 'POST', @@ -44,6 +65,7 @@ function setMultipleInputHandlers(currentIndex, row) { data: { productGuid: e.target.value, storeGuid: store.val(), [param24]: token24 }, dataType: 'json', success: (data) => { + if (data.groupLabel) { groupLabel.val(data.groupLabel); } if (data.price) { retailPrice.val(data.price); } if (data.selfCost) { selfCost.val(data.selfCost); } if (data.quantity) { remains1c.val(data.quantity); }