Yii::t('common/inventory', 'Leltár azonosító'), 'name' => Yii::t('common/inventory', 'Megnevezés'), 'status' => Yii::t('common/inventory', 'Státusz'), 'id_user' => Yii::t('common/inventory', 'Felhasználó'), 'id_account' => Yii::t('common/inventory', 'Kassza'), 'created_at' => Yii::t('common/inventory', 'Létrehozás'), 'updated_at' => Yii::t('common/inventory', 'Módosítás'), ]; } public function validateOnlyClosed($attribute,$params){ $opened = Inventory::find()->andWhere(['status' => Inventory::$STATUS_OPEN])->all(); if ( count($opened) > 0 ){ $this->addError("name","Kérem előbb zárjon le minden másik leltárt"); } } /** * @inheritdoc */ public function behaviors() { return ArrayHelper::merge( [ [ 'class' => UserAwareBehavior::className(), ], [ 'class' => AccountAwareBehavior::className() ] ], parent::behaviors()); } public function afterSave($insert, $changedAttributes){ if ( $insert ){ $query = Product::find(); if ( isset($this->id_account) && is_numeric($this->id_account)){ $query->andWhere(['id_account' => $this->id_account]); } $products = $query->all(); $inventoryGroups = InventoryGroup::find()->all(); foreach ($products as $product){ $form = new InventoryItemForm( [ 'inventory' => $this, 'id_product' => $product->id_product, 'product' => $product, 'type' => 'product' ] ); $form->save(); } foreach ($inventoryGroups as $group){ $form = new InventoryItemForm( [ 'inventory' => $this, 'id_product' => $group->id_inventory_group, 'inventoryGroup' => $group, 'type' => 'group' ] ); $form->save(); } } } public static function statuses(){ return [ Inventory::$STATUS_CLOSED => "Lezárva", Inventory::$STATUS_OPEN => "Nyitva" ]; } public function getStatusHuman(){ return Helper::getArrayValue(self::statuses(), $this->status, "NA"); } public function isOpen(){ return $this->status == self::$STATUS_OPEN; } }