add changes to procurement

This commit is contained in:
2015-09-25 08:57:05 +02:00
parent e2fe006899
commit 28caac03dc
12 changed files with 609 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "procurement".
*
* @property integer $id_procurement
* @property integer $id_warehouse
* @property integer $id_user
* @property integer $id_product
* @property integer $count
* @property integer $stock
* @property integer $purchase_price
* @property string $description
* @property string $created_at
* @property string $updated_at
*/
class Procurement extends \common\models\BaseFitnessActiveRecord
{
public $productIdentifier;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'procurement';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_warehouse', 'id_user', 'id_product', 'count'], 'required'],
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['description'], 'string', 'max' => 255],
[['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_procurement' => Yii::t('common/procurement', 'Id Procurement'),
'id_warehouse' => Yii::t('common/procurement', 'Id Warehouse'),
'id_user' => Yii::t('common/procurement', 'Id User'),
'id_product' => Yii::t('common/procurement', 'Id Product'),
'count' => Yii::t('common/procurement', 'Count'),
'stock' => Yii::t('common/procurement', 'Stock'),
'purchase_price' => Yii::t('common/procurement', 'Purchase Price'),
'description' => Yii::t('common/procurement', 'Description'),
'created_at' => Yii::t('common/procurement', 'Created At'),
'updated_at' => Yii::t('common/procurement', 'Updated At'),
];
}
public function validateProductIdentifier($attribute,$params){
$product = null;
if ( isset($this->attribute)){
$id = $this->$attribute;
$conditionProductName = ['name' =>$id];
$conditionProductNumber = ['product_number' =>$id];
$conditionBarcode= ['barcode' =>$id];
$product = Product::findOne(['or',[ $conditionProductName,$conditionProductNumber,$conditionBarcode ]]);
}
if ( $product == null ){
$this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product"));
}
}
////////////////////////////////
// PRODUCT
////////////////////////////////
public function getProduct() {
return $this->hasOne ( Product::className (), [
'id_product' => 'id_product'
] );
}
public function getProductName() {
return $this->product->name;
}
////////////////////////////////
// WAREHOUSE
////////////////////////////////
public function getWarehouse() {
return $this->hasOne ( Warehouse::className (), [
'id_warehouse' => 'id_warehouse'
] );
}
public function getWarehouseName(){
return $this->warehouse->name;
}
////////////////////////////////
// USER
////////////////////////////////
public function getUser() {
return $this->hasOne ( User::className (), [
'id_user' => 'id_user'
] );
}
public function getUserName(){
return $this->user->username;
}
}

View File

@@ -82,5 +82,21 @@ class Warehouse extends \yii\db\ActiveRecord
}
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 = Warehouse::find()->andWhere(['status' => Warehouse::STATUS_ACTIVE])->all();
}else{
$warehouses = Warehouse::find()->andWhere( ['or', ['status' => Warehouse::STATUS_ACTIVE], ['id_warehouse' => $forceIncludeObjectWithId ] ])->all();
}
return $warehouses;
}
}