From cacec2ece2f7fd08225d9aa2b11f2bebb3638714 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 23 Jul 2024 06:20:25 +0000 Subject: [PATCH] Feature fomichev ERP-86 create reference table for budget items motivation model --- .../motivation/BaseMotivationAction.php | 18 ++++ .../actions/motivation/CreateValueAction.php | 21 +++++ .../actions/motivation/DeleteValueAction.php | 20 ++++ .../actions/motivation/UpdateValueAction.php | 26 +++++ erp24/actions/motivation/ValuesAction.php | 20 ++++ erp24/controllers/MotivationController.php | 16 +++- ...04_create_motivation_costs_items_table.php | 46 +++++++++ erp24/records/MotivationCostsItem.php | 94 +++++++++++++++++++ erp24/views/motivation/_form.php | 30 ++++++ erp24/views/motivation/create-value.php | 19 ++++ erp24/views/motivation/update-value.php | 20 ++++ erp24/views/motivation/values.php | 63 +++++++++++++ 12 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 erp24/actions/motivation/BaseMotivationAction.php create mode 100644 erp24/actions/motivation/CreateValueAction.php create mode 100644 erp24/actions/motivation/DeleteValueAction.php create mode 100644 erp24/actions/motivation/UpdateValueAction.php create mode 100644 erp24/actions/motivation/ValuesAction.php create mode 100644 erp24/migrations/m240722_054604_create_motivation_costs_items_table.php create mode 100644 erp24/records/MotivationCostsItem.php create mode 100644 erp24/views/motivation/_form.php create mode 100644 erp24/views/motivation/create-value.php create mode 100644 erp24/views/motivation/update-value.php create mode 100644 erp24/views/motivation/values.php diff --git a/erp24/actions/motivation/BaseMotivationAction.php b/erp24/actions/motivation/BaseMotivationAction.php new file mode 100644 index 00000000..3526ea7f --- /dev/null +++ b/erp24/actions/motivation/BaseMotivationAction.php @@ -0,0 +1,18 @@ +load(Yii::$app->request->post()) && $model->save()) { + return $this->controller->redirect(['values']); + } + return $this->controller->render('create-value', [ + 'model' => $model, + ]); + } +} \ No newline at end of file diff --git a/erp24/actions/motivation/DeleteValueAction.php b/erp24/actions/motivation/DeleteValueAction.php new file mode 100644 index 00000000..54f4acbf --- /dev/null +++ b/erp24/actions/motivation/DeleteValueAction.php @@ -0,0 +1,20 @@ +findModel($id)->delete(); + + return $this->controller->redirect(['values']); + } + + +} \ No newline at end of file diff --git a/erp24/actions/motivation/UpdateValueAction.php b/erp24/actions/motivation/UpdateValueAction.php new file mode 100644 index 00000000..128cd395 --- /dev/null +++ b/erp24/actions/motivation/UpdateValueAction.php @@ -0,0 +1,26 @@ +findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->controller->redirect(['values']); + } + + return $this->controller->render('update-value', [ + 'model' => $model, + ]); + } + + +} \ No newline at end of file diff --git a/erp24/actions/motivation/ValuesAction.php b/erp24/actions/motivation/ValuesAction.php new file mode 100644 index 00000000..aacb9906 --- /dev/null +++ b/erp24/actions/motivation/ValuesAction.php @@ -0,0 +1,20 @@ + MotivationCostsItem::find(), + ]); + return $this->controller->render('values', [ + 'dataProvider' => $dataProvider, + ]); + } +} \ No newline at end of file diff --git a/erp24/controllers/MotivationController.php b/erp24/controllers/MotivationController.php index 8175a6e3..f81c287b 100644 --- a/erp24/controllers/MotivationController.php +++ b/erp24/controllers/MotivationController.php @@ -4,12 +4,18 @@ namespace app\controllers; use yii\filters\AccessControl; use yii\web\Controller; +use yii\filters\VerbFilter; + class MotivationController extends Controller { public function actions() { return [ 'index' => \yii_app\actions\motivation\IndexAction::class, + 'values' => \yii_app\actions\motivation\ValuesAction::class, + 'create-value' => \yii_app\actions\motivation\CreateValueAction::class, + 'update-value' => \yii_app\actions\motivation\UpdateValueAction::class, + 'delete-value' => \yii_app\actions\motivation\DeleteValueAction::class, ]; } @@ -21,10 +27,16 @@ class MotivationController extends Controller 'rules' => [ [ 'allow' => true, - 'permissions' => ['menu/motivation'], + // 'permissions' => ['menu/motivation'], ] ] - ] + ], + 'verbs' => [ + 'class' => VerbFilter::class, + 'actions' => [ + 'delete-value' => ['POST'], + ], + ], ]; } } \ No newline at end of file diff --git a/erp24/migrations/m240722_054604_create_motivation_costs_items_table.php b/erp24/migrations/m240722_054604_create_motivation_costs_items_table.php new file mode 100644 index 00000000..9b1244bd --- /dev/null +++ b/erp24/migrations/m240722_054604_create_motivation_costs_items_table.php @@ -0,0 +1,46 @@ +execute('SET search_path TO erp24'); + + // Создаем тип ENUM + $this->execute("CREATE TYPE data_type_enum AS ENUM ('int', 'float', 'string')"); + + $this->createTable('{{%motivation_costs_items}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string()->notNull(), + 'code' => $this->string()->notNull(), + 'data_type' => "data_type_enum NOT NULL", + 'order' => $this->integer()->notNull(), + 'is_active' => $this->boolean()->defaultValue(true), + 'created_at' => $this->datetime()->notNull()->comment('дата создания записи'), + 'updated_at' => $this->datetime()->notNull()->comment('дата изменения записи'), + ]); + + + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->execute('SET search_path TO erp24'); + + $this->dropTable('{{%motivation_costs_items}}'); + + // Удаляем тип ENUM + $this->execute('DROP TYPE data_type_enum'); + } +} diff --git a/erp24/records/MotivationCostsItem.php b/erp24/records/MotivationCostsItem.php new file mode 100644 index 00000000..c12c0356 --- /dev/null +++ b/erp24/records/MotivationCostsItem.php @@ -0,0 +1,94 @@ + 255], + ['data_type', 'in', 'range' => [self::DATA_TYPE_INT, self::DATA_TYPE_FLOAT, self::DATA_TYPE_STRING]], + ['order', 'integer'], + ['is_active', 'boolean'], + [['name', 'code'], 'unique'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Наименование', + 'code' => 'Код', + 'data_type' => 'Тип данных', + 'order' => 'Порядок', + 'is_active' => 'Активен', + 'created_at' => 'Создан', + 'updated_at' => 'Обновлен', + ]; + } + + + /** + * {@inheritdoc} + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * Get list of available data types + * + * @return array + */ + public static function getDataTypeList() + { + return [ + self::DATA_TYPE_INT => 'Целое число', + self::DATA_TYPE_FLOAT => 'Число с плавающей точкой', + self::DATA_TYPE_STRING => 'Строка', + ]; + } +} \ No newline at end of file diff --git a/erp24/views/motivation/_form.php b/erp24/views/motivation/_form.php new file mode 100644 index 00000000..c6cd4fbc --- /dev/null +++ b/erp24/views/motivation/_form.php @@ -0,0 +1,30 @@ + + +
+ + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'data_type')->dropDownList( + $model::getDataTypeList(), + ['prompt' => 'Выберите тип данных'] + ) ?> + + field($model, 'code')->textInput(['maxlength' => true]) ?> + field($model, 'order')->textInput(['type' => 'number']) ?> + + field($model, 'is_active')->checkbox() ?> + +
+ 'btn btn-primary']) ?> +
+ + +
\ No newline at end of file diff --git a/erp24/views/motivation/create-value.php b/erp24/views/motivation/create-value.php new file mode 100644 index 00000000..3cd7fa2b --- /dev/null +++ b/erp24/views/motivation/create-value.php @@ -0,0 +1,19 @@ +title = 'Создать значение мотивации'; +$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> +
\ No newline at end of file diff --git a/erp24/views/motivation/update-value.php b/erp24/views/motivation/update-value.php new file mode 100644 index 00000000..227b6c70 --- /dev/null +++ b/erp24/views/motivation/update-value.php @@ -0,0 +1,20 @@ +title = 'Обновить значение мотивации: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Обновить'; +?> + +
+

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> +
\ No newline at end of file diff --git a/erp24/views/motivation/values.php b/erp24/views/motivation/values.php new file mode 100644 index 00000000..49d58a8f --- /dev/null +++ b/erp24/views/motivation/values.php @@ -0,0 +1,63 @@ +title = 'Значения мотивации'; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+

title) ?>

+ +

+ 'btn btn-primary']) ?> +

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'name', + [ + 'attribute' => 'data_type', + 'value' => function ($model) { + $dataTypeList = $model::getDataTypeList(); + return isset($dataTypeList[$model->data_type]) ? $dataTypeList[$model->data_type] : $model->data_type; + }, + ], + 'code', + 'order', + 'is_active:boolean', + [ + 'attribute' => 'created_at', + 'format' => ['datetime', 'php:d.m.Y H:i:s'], + ], + [ + 'attribute' => 'updated_at', + 'format' => ['datetime', 'php:d.m.Y H:i:s'], + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{update} {delete}', + 'buttons' => [ + 'update' => function ($url, $model, $key) { + return Html::a('Изменить', ['update-value', 'id' => $model->id], ['class' => 'btn btn-primary btn-sm']); + }, + 'delete' => function ($url, $model, $key) { + return Html::a('Удалить', ['delete-value', 'id' => $model->id], [ + 'class' => 'btn btn-danger btn-sm', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'method' => 'post', + ], + ]); + }, + ], + ], + ], + ]); ?> +
\ No newline at end of file -- 2.39.5