]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Feature fomichev ERP-86 create reference table for budget items motivation model
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 23 Jul 2024 06:20:25 +0000 (06:20 +0000)
committerMarina Zozirova <marina.zozirova@erp-flowers.ru>
Tue, 23 Jul 2024 06:20:25 +0000 (06:20 +0000)
12 files changed:
erp24/actions/motivation/BaseMotivationAction.php [new file with mode: 0644]
erp24/actions/motivation/CreateValueAction.php [new file with mode: 0644]
erp24/actions/motivation/DeleteValueAction.php [new file with mode: 0644]
erp24/actions/motivation/UpdateValueAction.php [new file with mode: 0644]
erp24/actions/motivation/ValuesAction.php [new file with mode: 0644]
erp24/controllers/MotivationController.php
erp24/migrations/m240722_054604_create_motivation_costs_items_table.php [new file with mode: 0644]
erp24/records/MotivationCostsItem.php [new file with mode: 0644]
erp24/views/motivation/_form.php [new file with mode: 0644]
erp24/views/motivation/create-value.php [new file with mode: 0644]
erp24/views/motivation/update-value.php [new file with mode: 0644]
erp24/views/motivation/values.php [new file with mode: 0644]

diff --git a/erp24/actions/motivation/BaseMotivationAction.php b/erp24/actions/motivation/BaseMotivationAction.php
new file mode 100644 (file)
index 0000000..3526ea7
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use yii\base\Action;
+use yii_app\records\MotivationCostsItem;
+use yii\web\NotFoundHttpException;
+
+abstract class BaseMotivationAction extends Action
+{
+    protected function findModel($id)
+    {
+        if ($model = MotivationCostsItem::findOne($id)) {
+            return $model;
+        }
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
\ No newline at end of file
diff --git a/erp24/actions/motivation/CreateValueAction.php b/erp24/actions/motivation/CreateValueAction.php
new file mode 100644 (file)
index 0000000..6fb539f
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii\base\Action;
+use yii_app\records\MotivationCostsItem;
+
+class CreateValueAction extends Action
+{
+    public function run()
+    {
+        $model = new MotivationCostsItem();
+        if ($model->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 (file)
index 0000000..54f4acb
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii_app\records\MotivationCostsItem;
+use yii\web\NotFoundHttpException;
+use yii\base\Action;
+
+class DeleteValueAction extends BaseMotivationAction
+{
+    public function run($id)
+    {
+        $this->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 (file)
index 0000000..128cd39
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii_app\records\MotivationCostsItem;
+use yii\web\NotFoundHttpException;
+use yii\base\Action;
+
+class UpdateValueAction extends BaseMotivationAction
+{
+    public function run($id)
+    {
+        $model = $this->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 (file)
index 0000000..aacb990
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use yii\base\Action;
+use yii\data\ActiveDataProvider;
+use yii_app\records\MotivationCostsItem;
+
+class ValuesAction extends Action
+{
+    public function run()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => MotivationCostsItem::find(),
+        ]);
+        return $this->controller->render('values', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+}
\ No newline at end of file
index 8175a6e3d7720583df8b68f038801552bfccaea8..f81c287b1ea0a236d5b7568d2d636b96200be6f7 100644 (file)
@@ -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 (file)
index 0000000..9b1244b
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%motivation_costs_items}}`.
+ */
+class m240722_054604_create_motivation_costs_items_table extends Migration
+{
+   /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->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 (file)
index 0000000..c12c035
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+
+namespace yii_app\records;
+
+use yii\db\ActiveRecord;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+
+/**
+ * This is the model class for table "{{%motivation_costs_items}}".
+ *
+ * @property int $id
+ * @property string $name
+ * @property string $code
+ * @property string $data_type
+ * @property int $order
+ * @property bool $is_active
+ * @property string $created_at
+ * @property string $updated_at
+ */
+class MotivationCostsItem extends ActiveRecord
+{
+    const DATA_TYPE_INT = 'int';
+    const DATA_TYPE_FLOAT = 'float';
+    const DATA_TYPE_STRING = 'string';
+
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%motivation_costs_items}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['name', 'code', 'data_type', 'order'], 'required'],
+            [['name', 'code'], 'string', 'max' => 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 (file)
index 0000000..c6cd4fb
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var $this yii\web\View */
+/** @var $model app\models\MotivationCostsItem */
+/** @var $form yii\widgets\ActiveForm */
+?>
+
+<div class="motivation-value-form">
+    <?php $form = ActiveForm::begin(); ?>
+
+    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'data_type')->dropDownList(
+        $model::getDataTypeList(),
+        ['prompt' => 'Выберите тип данных']
+    ) ?>
+
+    <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
+    <?= $form->field($model, 'order')->textInput(['type' => 'number']) ?>
+
+    <?= $form->field($model, 'is_active')->checkbox() ?>
+
+    <div class="form-group">
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+</div>
\ 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 (file)
index 0000000..3cd7fa2
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var $this yii\web\View */
+/** @var $model app\models\MotivationCostsItem */
+
+$this->title = 'Создать значение мотивации';
+$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="motivation-create-value m-5">
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+</div>
\ 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 (file)
index 0000000..227b6c7
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var $this yii\web\View */
+/** @var $model app\models\MotivationCostsItem */
+
+$this->title = 'Обновить значение мотивации: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Обновить';
+?>
+
+<div class="motivation-update-value m-5">
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+</div>
\ No newline at end of file
diff --git a/erp24/views/motivation/values.php b/erp24/views/motivation/values.php
new file mode 100644 (file)
index 0000000..49d58a8
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/** @var $this yii\web\View */
+/** @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Значения мотивации';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="motivation-values m-5">
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Создать новое значение', ['create-value'], ['class' => 'btn btn-primary']) ?>
+    </p>
+
+    <?= GridView::widget([
+        'dataProvider' => $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',
+                            ],
+                        ]);
+                    },
+                ],
+            ],
+        ],
+    ]); ?>
+</div>
\ No newline at end of file