From: fomichev Date: Sun, 17 Nov 2024 21:02:43 +0000 (+0300) Subject: Добавление имен товаров в логи X-Git-Tag: 1.7~226^2~8 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=c265d6f462a20bacf965395b4d0882422f8882a2;p=erp24_rep%2Fyii-erp24%2F.git Добавление имен товаров в логи --- diff --git a/erp24/controllers/crud/Product1cReplacementController.php b/erp24/controllers/crud/Product1cReplacementController.php index ba073cce..9b10681d 100644 --- a/erp24/controllers/crud/Product1cReplacementController.php +++ b/erp24/controllers/crud/Product1cReplacementController.php @@ -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, diff --git a/erp24/records/Product1cReplacementSearch.php b/erp24/records/Product1cReplacementSearch.php index 91ab1b72..862f0a1f 100644 --- a/erp24/records/Product1cReplacementSearch.php +++ b/erp24/records/Product1cReplacementSearch.php @@ -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; diff --git a/erp24/views/crud/product1c-replacement/index.php b/erp24/views/crud/product1c-replacement/index.php index 918d8f27..a34bbc34 100644 --- a/erp24/views/crud/product1c-replacement/index.php +++ b/erp24/views/crud/product1c-replacement/index.php @@ -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); }, diff --git a/erp24/views/crud/product1c-replacement/log-history.php b/erp24/views/crud/product1c-replacement/log-history.php index cfa0f525..12222e03 100644 --- a/erp24/views/crud/product1c-replacement/log-history.php +++ b/erp24/views/crud/product1c-replacement/log-history.php @@ -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; ?>
-

title) ?> ( )

+ $guid], ['class' => 'btn btn-danger mb-4']) ?> +

title) ?>

( )

getTotalCount() > 0): ?> $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 : 'Неизвестно'; }, ], - - ], ]); ?> diff --git a/erp24/views/crud/product1c-replacement/view.php b/erp24/views/crud/product1c-replacement/view.php index 160127e9..290656ed 100644 --- a/erp24/views/crud/product1c-replacement/view.php +++ b/erp24/views/crud/product1c-replacement/view.php @@ -1,81 +1,39 @@ title = $model->product->name; $this->params['breadcrumbs'][] = ['label' => 'Product1c Replacements', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; \yii\web\YiiAsset::register($this); -$this->registerJs(<<
- + 'btn btn-danger mb-4']) ?>

Замены для title) ?>

$model->guid], ['class' => 'btn btn-primary']) ?> - 'btn btn-danger']) ?> + $model->guid], ['class' => 'btn btn-success']) ?>

- 'pjax-container']); ?> +
$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( - '', - $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
- +