]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление имен товаров в логи
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Sun, 17 Nov 2024 21:02:43 +0000 (00:02 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Sun, 17 Nov 2024 21:02:43 +0000 (00:02 +0300)
erp24/controllers/crud/Product1cReplacementController.php
erp24/records/Product1cReplacementSearch.php
erp24/views/crud/product1c-replacement/index.php
erp24/views/crud/product1c-replacement/log-history.php
erp24/views/crud/product1c-replacement/view.php

index ba073cce2ea95565cd1cff93dcd50dd55651f4d9..9b10681d857c8c30a9826b5c928e7af85b8bc72a 100644 (file)
@@ -5,6 +5,7 @@ namespace yii_app\controllers\crud;
 use Yii;
 use yii\behaviors\TimestampBehavior;
 use yii\data\ActiveDataProvider;
+use yii_app\records\Admin;
 use yii_app\records\Product1cReplacement;
 use yii_app\records\Product1cReplacementLog;
 use yii_app\records\Product1cReplacementSearch;
@@ -81,21 +82,46 @@ class Product1cReplacementController extends Controller
      */
     public function actionView($id)
     {
-
         $replacementsQuery = Product1cReplacement::find()
             ->where(['guid' => $id])
             ->andWhere(['deleted_at' => null]);
 
-        $replacementsDataProvider = new ActiveDataProvider([
+        $replacementsDataProvider = new \yii\data\ActiveDataProvider([
             'query' => $replacementsQuery,
             'pagination' => [
                 'pageSize' => 10,
             ],
         ]);
 
+
+        $replacements = $replacementsQuery->all();
+        $lastLogs = [];
+        foreach ($replacements as $replacement) {
+            $lastLog = Product1cReplacementLog::find()
+                ->where(['replacement_id' => $replacement->id])
+                ->orderBy(['date' => SORT_DESC])
+                ->one();
+
+            if ($lastLog) {
+
+                $adminName = null;
+                if ($lastLog->admin_id) {
+                    $admin = Admin::findOne($lastLog->admin_id);
+                    $adminName = $admin ? $admin->name : 'Неизвестно';
+                }
+
+
+                $lastLogs[$replacement->id] = [
+                    'lastLog' => $lastLog,
+                    'adminName' => $adminName,
+                ];
+            }
+        }
+
         return $this->render('view', [
             'model' => $this->findModelByGuid($id),
             'replacements' => $replacementsDataProvider,
+            'lastLogs' => $lastLogs,
         ]);
     }
 
@@ -263,7 +289,7 @@ class Product1cReplacementController extends Controller
 
         $logQuery = Product1cReplacementLog::find()
             ->where(['replacement_id' => $replacements])
-            ->orderBy(['date' => SORT_DESC]);
+            ->orderBy(['date' => SORT_ASC]);
 
         $dataProvider = new \yii\data\ActiveDataProvider([
             'query' => $logQuery,
index 91ab1b72b18d7102e3d7cc78efdf4185982eb53b..862f0a1f0f05be0d3574074ac11404d0de3bd6f9 100644 (file)
@@ -63,8 +63,8 @@ class Product1cReplacementSearch extends Product1cReplacement
         ]);
 
         $query->andFilterWhere(['ilike', 'guid', $this->guid])
-            ->andFilterWhere(['ilike', 'guid_replacement', $this->guid_replacement])
-            ->andFilterWhere(['ilike', 'products_1c.name', $this->productName]); // Поиск по имени
+           // ->andFilterWhere(['ilike', 'guid_replacement', $this->guid_replacement])
+            ->orWhere(['ilike', 'products_1c.name', $this->guid]); // Поиск по имени
 
 
         return $dataProvider;
index 918d8f27a963e63b460dad42c9eed58cf7745877..a34bbc34b4e002746f5f8640cf8902ac2b7d6e53 100644 (file)
@@ -9,7 +9,7 @@ use yii_app\records\Product1cReplacementSearch;
 use yii_app\records\Products1c;
 
 /* @var $this yii\web\View */
-/* @var $searchModel app\records\Product1cReplacementSearch */
+/* @var $searchModel yii_app\records\Product1cReplacementSearch */
 /* @var $dataProvider yii\data\ActiveDataProvider */
 /* @var $groupedReplacements array */
 
@@ -39,7 +39,9 @@ $this->params['breadcrumbs'][] = $this->title;
 
                     $product = $model->product;
                     if ($product) {
-                        return Html::encode($product->name . ' (' . $model->guid . ', ' . $product->code . ', ' . $product->articule . ')');
+                        $codeProduct = $product->code ? (', ' . $product->code) : '';
+                        $articuleProduct = $product->articule ? (', ' . $product->articule) : '';
+                        return Html::encode($product->name . ' (' . $model->guid . $codeProduct . $articuleProduct . ')');
                     }
                     return Html::encode($model->guid);
                 },
index cfa0f525fff915a120cb051164cb58625d505a4f..12222e039ec47a6cbea5ffecc27f5a6d06fca304 100644 (file)
@@ -3,39 +3,61 @@
 use yii\grid\GridView;
 use yii\helpers\Html;
 use yii_app\records\Admin;
+use yii_app\records\Products1c;
 
 /* @var $this yii\web\View */
 /* @var $dataProvider yii\data\ActiveDataProvider */
 /* @var $guid string */
 /* @var $name string */
 
-$this->title = 'История логов для GUI: ';
+$this->title = 'История логов для GUID: ';
 $this->params['breadcrumbs'][] = $this->title;
 ?>
 <div class="log-history-index p-4">
-    <h1><?= Html::encode($this->title) ?> <?= $name  ?> ( <?= $guid  ?> ) </h1>
+    <?= Html::a('Назад', ['view', 'id' => $guid], ['class' => 'btn btn-danger mb-4']) ?>
+    <h1><?= Html::encode($this->title) ?> <br> <?= Html::encode($name) ?>  <br> ( <?= Html::encode($guid) ?> )</h1>
 
     <?php if ($dataProvider && $dataProvider->getTotalCount() > 0): ?>
         <?= GridView::widget([
             'dataProvider' => $dataProvider,
             'columns' => [
-                ['class' => 'yii\grid\SerialColumn'],
 
                 'replacement_id',
-                'state_before',
-                'state_after',
+                [
+                    'attribute' => 'state_before',
+                    'label' => 'Предыдущее состояние',
+                    'value' => function ($model) {
+                        if (in_array($model->state_before, ['Запись создана', 'Запись удалена'])) {
+                            return $model->state_before;
+                        }
+
+                        $product = Products1c::findOne(['id' => $model->state_before, 'tip' => 'products']);
+                        return $product ? $product->name . ' (' . $model->state_before . ')' : $model->state_before;
+                    },
+                    'format' => 'raw',
+                ],
+                [
+                    'attribute' => 'state_after',
+                    'label' => 'Новое состояние',
+                    'value' => function ($model) {
+                        if (in_array($model->state_after, ['Запись создана', 'Запись удалена'])) {
+                            return $model->state_after;
+                        }
+
+                        $product = Products1c::findOne(['id' => $model->state_after, 'tip' => 'products']);
+                        return $product ? $product->name . ' (' . $model->state_after . ')' : $model->state_after;
+                    },
+                    'format' => 'raw',
+                ],
                 'date',
                 [
                     'attribute' => 'admin_id',
                     'label' => 'Имя пользователя',
                     'value' => function ($model) {
-                        // Получаем имя пользователя по admin_id
                         $admin = Admin::findOne($model->admin_id);
                         return $admin ? $admin->name : 'Неизвестно';
                     },
                 ],
-
-
             ],
         ]); ?>
     <?php else: ?>
index 160127e99755b9829be8384828d2368e87cff8b5..290656ed37c7103bdc3cf41b94b80372724f84a6 100644 (file)
@@ -1,81 +1,39 @@
 <?php
 
-use kartik\grid\ActionColumn;
+
 use kartik\grid\GridView;
 use yii\helpers\Html;
-use yii\widgets\DetailView;
-use yii\widgets\Pjax;
 use yii_app\records\Products1c;
 
 /** @var yii\web\View $this */
 /** @var yii_app\records\Product1cReplacement $model */
-/** @var  yii_app\records\Product1cReplacement $replacements  */
+/** @var yii\data\ActiveDataProvider $replacements */
+/** @var array $lastLogs */
 
 $this->title = $model->product->name;
 $this->params['breadcrumbs'][] = ['label' => 'Product1c Replacements', 'url' => ['index']];
 $this->params['breadcrumbs'][] = $this->title;
 \yii\web\YiiAsset::register($this);
 
-$this->registerJs(<<<JS
-$(document).ready(function () {
-    $(document).on('click', '.soft-delete', function(e) {
-        e.preventDefault();
-        if (!confirm($(this).data('confirm'))) {
-            return;
-        }
-
-        var url = $(this).attr('href');
-        $.ajax({
-            url: url,
-            type: 'POST',
-            success: function(data) {
-                console.log(data);
-                if (data.success) {
-                    // Перезагрузка через Pjax после успешного удаления
-                    $.pjax.reload({container: '#pjax-container', async: false});
-                } else {
-                    alert(data.message || 'Ошибка при удалении записи.');
-                }
-            },
-            error: function() {
-                alert('Ошибка при выполнении запроса.');
-            }
-        });
-    });
-});
-
-JS
-);
+
 ?>
 <div class="product1-creplacement-view p-4">
-
+    <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger mb-4']) ?>
     <h1>Замены для <?= Html::encode($this->title) ?></h1>
 
     <p>
         <?= Html::a('Редактировать', ['update', 'id' => $model->guid], ['class' => 'btn btn-primary']) ?>
-        <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger']) ?>
+
 
         <?= Html::a('Просмотр логов', ['log-history', 'guid' => $model->guid], ['class' => 'btn btn-success']) ?>
     </p>
-    <?php Pjax::begin(['id' => 'pjax-container']); ?>
+
     <div id="grid-container">
     <?= GridView::widget([
         'dataProvider' => $replacements,
 
         'columns' => [
-            /*[
-                'attribute' => 'guid',
-                'label' => 'GUID, который заменяют',
-                'value' => function ($model) {
 
-                    $product = $model->product;
-                    if ($product) {
-                        return Html::encode($product->name . ' (' . $model->guid . ', ' . $product->code . ', ' . $product->articule . ')');
-                    }
-                    return Html::encode($model->guid);
-                },
-                'format' => 'raw',
-            ],*/
             [
                 'label' => 'GUIDы замены',
                 'attribute' => 'replacement_guid',
@@ -83,33 +41,36 @@ JS
 
                     $product = Products1c::findOne(['id' => $model->guid_replacement, 'tip' => 'products']);
                     if ($product) {
-                        return Html::encode($product->name . ' (' . $model->guid . ', ' . $product->code . ', ' . $product->articule . ')');
+
+                        $code = $product->code ? (', ' . $product->code) : '';
+                        $articule = $product->articule ? (', ' . $product->articule) : '';
+                        return Html::encode($product->name . ' (' . $model->guid . $code . $articule . ')');
                     }
                     return Html::encode($model->guid_replacement);
                 },
                 'format' => 'raw',
             ],
-            /*[
-                'class' => ActionColumn::class,
-                'template' => '{delete}',
-                'buttons' => [
-                    'delete' => function ($url, $model) {
-                        return Html::a(
-                            '<span class="glyphicon glyphicon-trash"></span>',
-                            $url,
-                            [
-                                'title' => 'Удалить',
-                                'aria-label' => 'Удалить',
-                                'data-pjax' => '0',
-                                'class' => 'soft-delete',
-                                'data-method' => false,
-                                //'data-confirm' => 'Вы уверены, что хотите удалить эту запись?',
-                                'data-id' => $model->id
-                            ]
-                        );
-                    },
-                ],
-            ],*/
+            [
+                'label' => 'Последнее редактирование',
+                'value' => function ($model) use ($lastLogs) {
+                    if (isset($lastLogs[$model->id])) {
+                        return Html::encode($lastLogs[$model->id]['lastLog']->date);
+                    }
+                    return 'Нет данных';
+                },
+                'format' => 'raw',
+            ],
+            [
+                'label' => 'Пользователь',
+                'value' => function ($model) use ($lastLogs) {
+                    if (isset($lastLogs[$model->id])) {
+                        return Html::encode($lastLogs[$model->id]['adminName']);
+                    }
+                    return 'Неизвестно';
+                },
+                'format' => 'raw',
+            ],
+
         ],
     ]);
 
@@ -119,6 +80,6 @@ JS
 
 
     </div>
-    <?php Pjax::end(); ?>
+
 
 </div>