]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-251] сообщения об ошибках
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 29 Nov 2024 11:17:52 +0000 (14:17 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 29 Nov 2024 11:17:52 +0000 (14:17 +0300)
erp24/controllers/ShiftTransferController.php
erp24/views/matrix_erp/index.php
erp24/views/shift-transfer/update.php
erp24/views/shift-transfer/view.php
erp24/web/js/shift-transfer/update.js

index 13f7f759b262bb67de31f4024e833ef668344078..e475929cefcb5055e104779538407328adc83696 100644 (file)
@@ -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) {
index c82e806edc9422643c4cc0bff4f52a3d5ab326c6..0adaf92252b300d0297af695c515ae3a55df719f 100644 (file)
@@ -113,7 +113,7 @@ $this->params['breadcrumbs'][] = $this->title;
                             <?php
                             echo $form->field($filterModel, 'activeFilter')->dropDownList(
                                 ['' => 'Все', 1 => 'Активная', 0 => 'Не активная',],
-                                ['class' => 'form-control'])->label('Активность');
+                                ['class' => 'form-control', 'onchange' => 'this.form.submit();'])->label('Активность');
                             ?>
                         </div>
 
index 2506ae9e57d4cef72b7328deab569168299e8b7f..4d76d82cfd6591f5490259ce1e950f4facf6d827 100644 (file)
@@ -26,6 +26,7 @@ $this->registerCss('
         width: 40px;
     }
 ');
+
 ?>
 
 <div class="shiftTransferCreate m-5">
@@ -35,7 +36,11 @@ $this->registerCss('
     <h1><?= $isCreate ? 'Создание' : 'Обновление' ?> передачи смены</h1>
 
     <?php $form = ActiveForm::begin([
+        'enableClientScript' => false,
         'action' => ['/shift-transfer/update', 'id' => Yii::$app->request->get('id')],
+        'options' => [
+            'onsubmit' => 'if (!checkInputs()) { event.preventDefault(); }'
+        ],
     ]) ?>
 
     <?= $form->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' => 'Ð\9fÑ\80одÑ\83кÑ\82',
+                    'name'  => 'group_label',
+                    'title' => 'Ð\9dазвание Ð³Ñ\80Ñ\83ппÑ\8b',
                     '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'] ?? '';
                     },
index cd485d1b2a92d016d5d118b8ef52906dad806b72..5f5290a511d73a985e6c53c83cef345f0c0eab19 100644 (file)
@@ -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' => 'Розничная цена, руб',
index cdd4939356d700b35291e173e7c0943181bc3d53..943948f65c455b73c0dcbb6619f557c80c80d18b 100644 (file)
@@ -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); }