add inventory changes
This commit is contained in:
@@ -5,12 +5,16 @@ namespace common\models;
|
||||
use Yii;
|
||||
use common\components\UserAwareBehavior;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\db\Query;
|
||||
use backend\models\InventoryItemForm;
|
||||
use common\components\AccountAwareBehavior;
|
||||
|
||||
/**
|
||||
* This is the model class for table "inventory".
|
||||
*
|
||||
* @property integer $id_inventory
|
||||
* @property integer $id_user
|
||||
* @property integer $id_account
|
||||
* @property string $name
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
@@ -26,6 +30,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
return 'inventory';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -33,7 +38,8 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name'], 'string']
|
||||
[['name'], 'string'],
|
||||
[['id_account'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -46,6 +52,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'),
|
||||
'name' => Yii::t('common/inventory', 'Megnevezés'),
|
||||
'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'),
|
||||
];
|
||||
@@ -59,7 +66,47 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
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]);
|
||||
|
||||
}
|
||||
// $query->andWhere("product.id_inventory_group is null");
|
||||
$products = $query->all();
|
||||
|
||||
echo "Products found: " . count($products);
|
||||
|
||||
$inventoryGroups = InventoryGroup::find()->all();
|
||||
|
||||
|
||||
foreach ($products as $product){
|
||||
$form = new InventoryItemForm(
|
||||
[
|
||||
'inventory' => $this,
|
||||
'id_product' => $product->id_product,
|
||||
'product' => $product,
|
||||
'type' => 'product'
|
||||
]
|
||||
);
|
||||
$form->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user