OSDN Git Service

Добавлено цветовое уведомление о уже учтённом предмете/оборудовании (красным) и о...
[invent/invent.git] / models / Moving.php
index ed74c2c..ae8bddf 100644 (file)
@@ -45,16 +45,16 @@ class Moving extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['date', 'item_id', 'location_id', 'state_id'], 'required'],
-            [['date'],        'safe'],
-            [['date'],        'date', 'format' => 'dd.MM.yyyy' ],
-            [['date'], 'checkValidDate'],
-            [['item_id', 'location_id', 'state_id'], 'default', 'value' => null],
-            [['id', 'item_id', 'location_id', 'state_id'], 'integer'],
-            [['comment'],     'string'],
-            [['item_id'],     'exist', 'skipOnError' => true, 'targetClass' => Items::className(),     'targetAttribute' => ['item_id' => 'id']],
-            [['location_id'], 'exist', 'skipOnError' => true, 'targetClass' => Locations::className(), 'targetAttribute' => ['location_id' => 'id']],
-            [['state_id'],    'exist', 'skipOnError' => true, 'targetClass' => Status::className(),    'targetAttribute' => ['state_id' => 'id']],
+            [[ 'date', 'item_id', 'location_id', 'state_id'], 'required' ],
+            [[ 'date', 'itemModel' ], 'safe' ],
+            [[ 'date'],        'date', 'format' => 'dd.MM.yyyy' ],
+            [[ 'date'],        'checkValidDate' ],
+            [[ 'item_id', 'location_id', 'state_id' ], 'default', 'value' => NULL ],
+            [[ 'id', 'item_id', 'location_id', 'state_id' ], 'integer' ],
+            [[ 'comment' ],     'string'],
+            [[ 'item_id' ],     'exist', 'skipOnError' => true, 'targetClass' => Items::className(),     'targetAttribute' => [ 'item_id' => 'id' ]],
+            [[ 'location_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Locations::className(), 'targetAttribute' => [ 'location_id' => 'id' ]],
+            [[ 'state_id' ],    'exist', 'skipOnError' => true, 'targetClass' => Status::className(),    'targetAttribute' => [ 'state_id' => 'id' ]],
         ];
     }
 
@@ -96,9 +96,9 @@ class Moving extends \yii\db\ActiveRecord
                 $this->addError('date', Yii::t('moving', 'The date cannot be more than today'));
             } else
             {
-                if ($date < strtotime('01.01.1990'))
+                if ($date < strtotime('01.01.1900'))
                 {
-                    $this->addError('date', Yii::t('moving', 'Date cannot be less than {date}', [ 'date' => '01.01.1990' ]));
+                    $this->addError('date', Yii::t('moving', 'Date cannot be less than {date}', [ 'date' => '01.01.1900' ]));
                 } else
                 {
                     $item_id = $this->item_id;
@@ -157,6 +157,16 @@ class Moving extends \yii\db\ActiveRecord
         return $this->hasOne(Items::className(), [ 'id' => 'item_id' ]);
     }
 
+    public function getModels()
+    {
+        return $this->getItems()->select(Models::tableName() . '.*')->joinWith('models');
+    }
+
+    public function getTypes()
+    {
+        return $this->getModels()->select(Types::tableName() . '.*')->joinWith('types');
+    }
+
     /**
      * Получение связанной таблицы места размещения.
      *