// taskFilter 3000-3500
$filterModel = DynamicModel::validateData([
- 'activeFilter',
+ 'activeFilter' => 1,
'nameFilter',
'groupNameFilter',
]);
}
+ public function actionDelete($id) {
+ $matrixErp = MatrixErp::findOne($id);
+ $matrixErp->active = 0;
+ $matrixErp->deleted_at = date('Y-m-d H:i:s');
+ $matrixErp->deleted_by = Yii::$app->user->id;
+ $matrixErp->save();
+
+ return $this->redirect('index');
+ }
/**
* Finds the MatrixErp model based on its primary key value.
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m241128_124631_alter_table_matrix_erp_add_column_deleted_at_deleted_by
+ */
+class m241128_124631_alter_table_matrix_erp_add_column_deleted_at_deleted_by extends Migration
+{
+ const TABLE_NAME = 'erp24.matrix_erp';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->addColumn(self::TABLE_NAME, 'deleted_at', $this->dateTime()->null()->comment('Дата и время удаления'));
+ $this->addColumn(self::TABLE_NAME, 'deleted_by', $this->integer()->null()->comment('ID удалившего пользователя'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn(self::TABLE_NAME, 'deleted_by');
+ $this->dropColumn(self::TABLE_NAME, 'deleted_at');
+ }
+}
namespace yii_app\records;
use Yii;
+use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQueryInterface;
+use yii\db\Expression;
use yii_app\helpers\DataHelper;
/**
* @property int|null $created_at
* @property int|null $updated_admin_id
* @property int|null $updated_at
+ * @property string|null $deleted_at
+ * @property int|null $deleted_by
*/
class MatrixErp extends \yii\db\ActiveRecord
{
return 'matrix_erp';
}
+ public function behaviors()
+ {
+ return [
+ [
+ 'class' => TimestampBehavior::class,
+ 'createdAtAttribute' => 'created_at',
+ 'updatedAtAttribute' => 'updated_at',
+ 'value' => new Expression('NOW()'),
+ ],
+ ];
+ }
+
/**
* {@inheritdoc}
*/
return [
[['guid', 'date_from'], 'required'],
[['category_id', 'active', 'created_admin_id', 'created_at', 'updated_admin_id', 'updated_at'], 'integer'],
- [['components'], 'string'],
- [['id'], 'integer'],
+ [['components', 'deleted_at'], 'string'],
+ [['id', 'deleted_by'], 'integer'],
[['guid', 'parent_id', 'group_name', 'code', 'articule', 'date_from', 'date_to'], 'string', 'max' => 100],
[['name'], 'string', 'max' => 255],
];
}
$editUrl = Html::a("Редактировать", ['/matrix-erp/update', 'id' => $item->id], ['class' => 'btn btn-primary', 'target'=>'blank']);
+ $deleteUrl = Html::a("Удалить", ['/matrix-erp/delete', 'id' => $item->id], [
+ 'class' => 'btn btn-danger', 'data' => [
+ 'confirm' => 'Вы уверены, что хотите удалить этот элемент?',
+ 'method' => 'post',
+ ]
+ ]);
$image = '';
<td><?= $item-> date_from ?></td>
<td><?= $item->date_to ?></td>
<td><?= (($item->active) ? 'Активна': 'Не активна') ?></td>
- <td><?= $editUrl?></td>
+ <td><span style="white-space:nowrap;"><?= $editUrl . " " . $deleteUrl ?></span></td>
</tr>
<tr style="display:none">