change procurement product selection, keytoggle redirect change
This commit is contained in:
@@ -25,6 +25,8 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||
public $productIdentifier;
|
||||
public $id_account;
|
||||
|
||||
public $_product;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -40,11 +42,11 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
return [
|
||||
[['id_warehouse', 'count', 'purchase_price' ], 'required'],
|
||||
[['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ,'id_account'], 'required' , 'on' => 'create_general'],
|
||||
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price','id_account'], 'integer'],
|
||||
[['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ], 'required' , 'on' => 'create_general'],
|
||||
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price' ], 'integer'],
|
||||
[['description'], 'string', 'max' => 255],
|
||||
[['productIdentifier'], 'string', 'max' => 128],
|
||||
[['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general']
|
||||
[['id_product'] ,'validateProduct', 'on' => 'create_general','skipOnEmpty' => false, 'skipOnError' => false]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -68,28 +70,14 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
|
||||
|
||||
public function validateProductIdentifier($attribute,$params){
|
||||
$product = null;
|
||||
public function validateProduct($attribute,$params){
|
||||
$this->_product = null;
|
||||
|
||||
if ( isset($this->productIdentifier)){
|
||||
$name = $this->productIdentifier;
|
||||
$id = Helper::fixAsciiChars( $this->productIdentifier );
|
||||
// $conditionProductName = ['name' =>$id];
|
||||
$conditionProductNumber = ['product_number' =>$id];
|
||||
$conditionBarcode= ['barcode' =>$id];
|
||||
$query = Product::find()
|
||||
->andWhere(['or', ['product_number' =>$id] ,['barcode' =>$id] ] );
|
||||
if ( Helper::isProductVisibilityAccount() ){
|
||||
$query->andWhere(['id_account' => $this->id_account]);
|
||||
}
|
||||
$products = $query->all();
|
||||
if ( count($products) == 1 ){
|
||||
$product = $products[0];
|
||||
$this->id_product = $product->id_product;
|
||||
}
|
||||
$this->_product = Product::findOne($this->id_product);
|
||||
}
|
||||
|
||||
if ( $product == null ){
|
||||
if ( $this->_product == null ){
|
||||
$this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product"));
|
||||
}
|
||||
|
||||
|
||||
@@ -244,6 +244,22 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
]);
|
||||
}
|
||||
|
||||
public static function modelToMapIdNameLong($product,$default = null){
|
||||
|
||||
if ( $product == null ){
|
||||
return $default;
|
||||
}
|
||||
|
||||
return ArrayHelper::toArray($product, [
|
||||
'common\models\Product' => [
|
||||
'id_product',
|
||||
'name' => function ($product) {
|
||||
return $product->name . " - " .$product->productCategoryName . " (" . $product->accountName . ")";
|
||||
},
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function sellProduct($product,$count){
|
||||
$product->stock = $product->stock - $count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user