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;
*/
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,
]);
}
$logQuery = Product1cReplacementLog::find()
->where(['replacement_id' => $replacements])
- ->orderBy(['date' => SORT_DESC]);
+ ->orderBy(['date' => SORT_ASC]);
$dataProvider = new \yii\data\ActiveDataProvider([
'query' => $logQuery,
]);
$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;
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 */
$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);
},
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: ?>
<?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',
$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',
+ ],
+
],
]);
</div>
- <?php Pjax::end(); ?>
+
</div>