add changes to procurement
This commit is contained in:
@@ -37,10 +37,11 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_warehouse', 'id_user', 'id_product', 'count'], 'required'],
|
||||
[['id_warehouse', 'count', 'purchase_price' ], 'required'],
|
||||
[['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ], 'required' , 'on' => 'create_general'],
|
||||
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['description'], 'string', 'max' => 255],
|
||||
[['productIdentifier'], 'string', 'max' => 128],
|
||||
[['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general']
|
||||
];
|
||||
}
|
||||
@@ -68,12 +69,16 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||
public function validateProductIdentifier($attribute,$params){
|
||||
$product = null;
|
||||
|
||||
if ( isset($this->attribute)){
|
||||
$id = $this->$attribute;
|
||||
if ( isset($this->productIdentifier)){
|
||||
$id = $this->productIdentifier;
|
||||
$conditionProductName = ['name' =>$id];
|
||||
$conditionProductNumber = ['product_number' =>$id];
|
||||
$conditionBarcode= ['barcode' =>$id];
|
||||
$product = Product::findOne(['or',[ $conditionProductName,$conditionProductNumber,$conditionBarcode ]]);
|
||||
$products = Product::find()->andWhere(['or', ['name' =>$id] , ['product_number' =>$id] ,['barcode' =>$id] ] )->all();
|
||||
if ( count($products) == 1 ){
|
||||
$product = $products[0];
|
||||
$this->id_product = $product->id_product;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $product == null ){
|
||||
@@ -111,7 +116,7 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||
////////////////////////////////
|
||||
public function getUser() {
|
||||
return $this->hasOne ( User::className (), [
|
||||
'id_user' => 'id_user'
|
||||
'id' => 'id_user'
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
@@ -110,4 +110,19 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
|
||||
* */
|
||||
public static function read($forceIncludeObjectWithId = null){
|
||||
$warehouses = null;
|
||||
|
||||
if ( $forceIncludeObjectWithId == null){
|
||||
$warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->all();
|
||||
}else{
|
||||
$warehouses = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->all();
|
||||
}
|
||||
|
||||
return $warehouses;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -209,4 +209,21 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
|
||||
* */
|
||||
public static function read($forceIncludeObjectWithId = null){
|
||||
$warehouses = null;
|
||||
|
||||
if ( $forceIncludeObjectWithId == null){
|
||||
$warehouses = User::find()->andWhere(['status' => User::STATUS_ACTIVE])->all();
|
||||
}else{
|
||||
$warehouses = User::find()->andWhere( ['or', ['status' => User::STATUS_ACTIVE], ['id' => $forceIncludeObjectWithId ] ])->all();
|
||||
}
|
||||
|
||||
return $warehouses;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user