]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
change motivation values table to mjtivation costs items
authorvladfo <fvv2011@gmail.com>
Mon, 22 Jul 2024 06:13:41 +0000 (09:13 +0300)
committervladfo <fvv2011@gmail.com>
Mon, 22 Jul 2024 06:13:41 +0000 (09:13 +0300)
12 files changed:
erp24/actions/motivation/CreateValueAction.php
erp24/actions/motivation/DeleteValueAction.php
erp24/actions/motivation/UpdateValueAction.php
erp24/actions/motivation/ValuesAction.php
erp24/migrations/m240719_090134_create_motivation_values_table.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/records/MotivationValue.php [deleted file]
erp24/views/motivation/_form.php
erp24/views/motivation/create-value.php
erp24/views/motivation/update-value.php
erp24/views/motivation/values.php

index 5fdabf2c274351df0d577880dfdbd865909767a5..6fb539fd8360d910d83e8fc1f95453a7c23736f7 100644 (file)
@@ -4,13 +4,13 @@ namespace yii_app\actions\motivation;
 
 use Yii;
 use yii\base\Action;
-use yii_app\records\MotivationValue;
+use yii_app\records\MotivationCostsItem;
 
 class CreateValueAction extends Action
 {
     public function run()
     {
-        $model = new MotivationValue();
+        $model = new MotivationCostsItem();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->controller->redirect(['values']);
         }
index 4976ca3c4d6c26765f9b94ffdea9c4fee8c4bf52..d6dc6ea9e7426b1cb2c2c1334d33de9c0a20b580 100644 (file)
@@ -3,7 +3,7 @@
 namespace yii_app\actions\motivation;
 
 use Yii;
-use yii_app\records\MotivationValue;
+use yii_app\records\MotivationCostsItem;
 use yii\web\NotFoundHttpException;
 use yii\base\Action;
 
@@ -18,7 +18,7 @@ class DeleteValueAction extends Action
 
     private function findModel($id)
     {
-        if (($model = MotivationValue::findOne($id)) !== null) {
+        if (($model = MotivationCostsItem::findOne($id)) !== null) {
             return $model;
         }
 
index 8a7764546f9e0cfd616a5f278d8c5564e28032fa..9b9ebd755774c22d365e12c28a4ce6d75b77a8c5 100644 (file)
@@ -3,7 +3,7 @@
 namespace yii_app\actions\motivation;
 
 use Yii;
-use yii_app\records\MotivationValue;
+use yii_app\records\MotivationCostsItem;
 use yii\web\NotFoundHttpException;
 use yii\base\Action;
 
@@ -24,7 +24,7 @@ class UpdateValueAction extends Action
 
     private function findModel($id)
     {
-        if (($model = MotivationValue::findOne($id)) !== null) {
+        if (($model = MotivationCostsItem::findOne($id)) !== null) {
             return $model;
         }
 
index 90396f7c044914fe9ae0ac4cacd2a772d581e12a..aacb99061b3ca706f01b34da676aeb69bdb76ee1 100644 (file)
@@ -4,14 +4,14 @@ namespace yii_app\actions\motivation;
 
 use yii\base\Action;
 use yii\data\ActiveDataProvider;
-use yii_app\records\MotivationValue;
+use yii_app\records\MotivationCostsItem;
 
 class ValuesAction extends Action
 {
     public function run()
     {
         $dataProvider = new ActiveDataProvider([
-            'query' => MotivationValue::find(),
+            'query' => MotivationCostsItem::find(),
         ]);
         return $this->controller->render('values', [
             'dataProvider' => $dataProvider,
index bf9022ef20c90587a64b41eae76c612752386b16..d55d37f610d1dc608cec205cc2b679c9b7726ca9 100644 (file)
@@ -3,7 +3,7 @@
 use yii\db\Migration;
 
 /**
- * Handles the creation of table `{{%motivation_values}}`.
+ * Handles the creation of table `{{%motivation_costs_items}}`.
  */
 
 class m240719_090134_create_motivation_values_table extends Migration
@@ -13,21 +13,23 @@ class m240719_090134_create_motivation_values_table extends Migration
      */
     public function safeUp()
     {
-        $this->execute('SET search_path TO erp24');
+        //$this->execute('SET search_path TO erp24');
         
         // Создаем тип ENUM
-        $this->execute("CREATE TYPE data_type_enum AS ENUM ('int', 'float', 'string')");
+        //$this->execute("CREATE TYPE data_type_enum AS ENUM ('int', 'float', 'string')");
         
-        $this->createTable('{{%motivation_values}}', [
-            'id' => $this->primaryKey(),
-            'name' => $this->string()->notNull(),
-            'data_type' => "data_type_enum NOT NULL",
-            'is_active' => $this->boolean()->defaultValue(true),
-            'created_at' => $this->datetime()->notNull()->comment('дата создания записи'),
-            'updated_at' => $this->datetime()->notNull()->comment('дата изменения записи'),
-        ]);
+        // $this->createTable('{{%motivation_values}}', [
+        //     '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('дата изменения записи'),
+        // ]);
 
-        $this->createIndex('idx-motivation_values-name', '{{%motivation_values}}', 'name', true);
+        //$this->createIndex('idx-motivation_values-name', '{{%motivation_values}}', 'name', true);
     }
 
     /**
@@ -35,11 +37,11 @@ class m240719_090134_create_motivation_values_table extends Migration
      */
     public function safeDown()
     {
-        $this->execute('SET search_path TO erp24');
+        //$this->execute('SET search_path TO erp24');
         
-        $this->dropTable('{{%motivation_values}}');
+        //$this->dropTable('{{%motivation_values}}');
         
         // Удаляем тип ENUM
-        $this->execute('DROP TYPE data_type_enum');
+        //$this->execute('DROP TYPE data_type_enum');
     }
 }
\ 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..31553f7
--- /dev/null
@@ -0,0 +1,47 @@
+<?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('дата изменения записи'),
+        ]);
+
+        $this->createIndex('idx-motivation_costs_items-name', '{{%motivation_costs_items}}', 'name', true);
+        $this->createIndex('idx-motivation_costs_items-code', '{{%motivation_costs_items}}', 'code', true);
+    }
+
+    /**
+     * {@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/records/MotivationValue.php b/erp24/records/MotivationValue.php
deleted file mode 100644 (file)
index 51cfd79..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-<?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_values}}".
- *
- * @property int $id
- * @property string $name
- * @property string $data_type
- * @property bool $is_active
- * @property string $created_at
- * @property string $updated_at
- */
-class MotivationValue extends ActiveRecord
-{
-    const DATA_TYPE_INT = 'int';
-    const DATA_TYPE_FLOAT = 'float';
-    const DATA_TYPE_STRING = 'string';
-
-    /**
-     * {@inheritdoc}
-     */
-    public static function tableName()
-    {
-        return '{{%motivation_values}}';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function rules()
-    {
-        return [
-            [['name', 'data_type'], 'required'],
-            ['name', 'string', 'max' => 255],
-            ['data_type', 'in', 'range' => [self::DATA_TYPE_INT, self::DATA_TYPE_FLOAT, self::DATA_TYPE_STRING]],
-            ['is_active', 'boolean'],
-        ];
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function behaviors()
-    {
-        return [
-            [
-                'class' => TimestampBehavior::class,
-                'value' => new Expression('NOW()'),
-            ],
-        ];
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function attributeLabels()
-    {
-        return [
-            'id' => 'ID',
-            'name' => 'Наименование',
-            'data_type' => 'Тип данных',
-            'is_active' => 'Активен',
-            'created_at' => 'Создан',
-            'updated_at' => 'Обновлен',
-        ];
-    }
-
-    /**
-     * 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
index a8deb6c62c488eef223a580f7a535a9867f8e753..c6cd4fbc884e6190fbac5e233b4b019da5c89fdc 100644 (file)
@@ -3,7 +3,7 @@ use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 
 /** @var $this yii\web\View */
-/** @var $model app\models\MotivationValue */
+/** @var $model app\models\MotivationCostsItem */
 /** @var $form yii\widgets\ActiveForm */
 ?>
 
@@ -17,6 +17,9 @@ use yii\widgets\ActiveForm;
         ['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">
index ecb60a14b981148ee8b6ffb926329a285db1a9fc..3cd7fa2b83c06ded5502d49ff63e2ccde0a83a39 100644 (file)
@@ -3,7 +3,7 @@
 use yii\helpers\Html;
 
 /** @var $this yii\web\View */
-/** @var $model app\models\MotivationValue */
+/** @var $model app\models\MotivationCostsItem */
 
 $this->title = 'Создать значение мотивации';
 $this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']];
index 1ef89a9ae53e54f7bc6a9998c8d5d30af773f869..227b6c70d16535ecef11c31bfc8c1775a98f7637 100644 (file)
@@ -3,7 +3,7 @@
 use yii\helpers\Html;
 
 /** @var $this yii\web\View */
-/** @var $model app\models\MotivationValue */
+/** @var $model app\models\MotivationCostsItem */
 
 $this->title = 'Обновить значение мотивации: ' . $model->name;
 $this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']];
index 6cff73e6a0e192bfa3a73690d3e4b18c6f916e27..15f950f611d513fd7e5ff974806684da9a0c4cf4 100644 (file)
@@ -23,6 +23,8 @@ $this->params['breadcrumbs'][] = $this->title;
             ['class' => 'yii\grid\SerialColumn'],
             'name',
             'data_type',
+            'code',
+            'order',
             'is_active:boolean',
             [
                 'attribute' => 'created_at',