|
|
|
|
|
|
|
|
class ProductPrice extends ActiveRecordCommon |
|
|
class ProductPrice extends ActiveRecordCommon |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function tableName() |
|
|
|
|
|
{ |
|
|
|
|
|
return 'product_price'; |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function tableName() |
|
|
|
|
|
{ |
|
|
|
|
|
return 'product_price'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
*/ |
|
|
|
|
|
public function rules() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
[ |
|
|
|
|
|
'id_user', |
|
|
|
|
|
'required', |
|
|
|
|
|
'when' => function ($model) { |
|
|
|
|
|
return !$model->id_point_sale && !$model->id_user_group; |
|
|
|
|
|
}, |
|
|
|
|
|
'message' => 'Vous devez renseigner au moins un utilisateur, un point de vente ou un groupe d\'utilisateur' |
|
|
|
|
|
], |
|
|
|
|
|
[ |
|
|
|
|
|
'id_point_sale', |
|
|
|
|
|
'required', |
|
|
|
|
|
'when' => function ($model) { |
|
|
|
|
|
return !$model->id_user && !$model->id_user_group; |
|
|
|
|
|
}, |
|
|
|
|
|
'message' => 'Vous devez renseigner au moins un utilisateur, un point de vente ou un groupe d\'utilisateur' |
|
|
|
|
|
], |
|
|
|
|
|
[ |
|
|
|
|
|
'id_user_group', |
|
|
|
|
|
'required', |
|
|
|
|
|
'when' => function ($model) { |
|
|
|
|
|
return !$model->id_user && !$model->id_point_sale; |
|
|
|
|
|
}, |
|
|
|
|
|
'message' => 'Vous devez renseigner au moins un utilisateur, un point de vente ou un groupe d\'utilisateur' |
|
|
|
|
|
], |
|
|
|
|
|
[['id_product', 'price'], 'required'], |
|
|
|
|
|
[['id_product', 'id_user', 'id_point_sale', 'id_user_group', 'percent'], 'integer'], |
|
|
|
|
|
[['price', 'from_quantity'], 'double'], |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
*/ |
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'id' => 'ID', |
|
|
|
|
|
'id_product' => 'Produit', |
|
|
|
|
|
'id_user' => 'Utilisateur', |
|
|
|
|
|
'id_point_sale' => 'Point de vente', |
|
|
|
|
|
'id_user_group' => "Groupe d'utilisateur", |
|
|
|
|
|
'price' => 'Prix (HT)', |
|
|
|
|
|
'percent' => 'Pourcentage', |
|
|
|
|
|
'from_quantity' => 'À partir de la quantité', |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Relations |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public function getProduct() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
Product::className(), |
|
|
|
|
|
['id' => 'id_product'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getPointSale() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
PointSale::className(), |
|
|
|
|
|
['id' => 'id_point_sale'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUserGroup() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
UserGroup::className(), |
|
|
|
|
|
['id' => 'id_user_group'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUser() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
User::className(), |
|
|
|
|
|
['id' => 'id_user'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les options de base nécessaires à la fonction de recherche. |
|
|
|
|
|
* |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function defaultOptionsSearch() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'with' => ['user', 'pointSale'], |
|
|
|
|
|
'join_with' => ['product'], |
|
|
|
|
|
'orderby' => '', |
|
|
|
|
|
'attribute_id_producer' => 'product.id_producer' |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static function percentValues() |
|
|
|
|
|
{ |
|
|
|
|
|
$percentValues = [ |
|
|
|
|
|
'' => 'Aucun' |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
for ($i = -50; $i < 51; $i = $i + 5) { |
|
|
|
|
|
$percentValues[$i] = $i . ' %'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
*/ |
|
|
|
|
|
public function rules() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
['id_user', 'required', 'when' => function($model) { |
|
|
|
|
|
return !$model->id_point_sale && !$model->id_user_group ; |
|
|
|
|
|
}, 'message' => 'Vous devez renseigner au moins un utilisateur, un point de vente ou un groupe d\'utilisateur'], |
|
|
|
|
|
['id_point_sale', 'required', 'when' => function($model) { |
|
|
|
|
|
return !$model->id_user && !$model->id_user_group ; |
|
|
|
|
|
}, 'message' => 'Vous devez renseigner au moins un utilisateur, un point de vente ou un groupe d\'utilisateur'], |
|
|
|
|
|
['id_user_group', 'required', 'when' => function($model) { |
|
|
|
|
|
return !$model->id_user && !$model->id_point_sale ; |
|
|
|
|
|
}, 'message' => 'Vous devez renseigner au moins un utilisateur, un point de vente ou un groupe d\'utilisateur'], |
|
|
|
|
|
[['id_product', 'price'], 'required'], |
|
|
|
|
|
[['id_product', 'id_user', 'id_point_sale', 'id_user_group', 'percent'], 'integer'], |
|
|
|
|
|
[['price', 'from_quantity'], 'double'], |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
*/ |
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'id' => 'ID', |
|
|
|
|
|
'id_product' => 'Produit', |
|
|
|
|
|
'id_user' => 'Utilisateur', |
|
|
|
|
|
'id_point_sale' => 'Point de vente', |
|
|
|
|
|
'id_user_group' => "Groupe d'utilisateur", |
|
|
|
|
|
'price' => 'Prix (HT)', |
|
|
|
|
|
'percent' => 'Pourcentage', |
|
|
|
|
|
'from_quantity' => 'À partir de la quantité', |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Relations |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public function getProduct() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
Product::className(), |
|
|
|
|
|
['id' => 'id_product'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getPointSale() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
PointSale::className(), |
|
|
|
|
|
['id' => 'id_point_sale'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUserGroup() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
UserGroup::className(), |
|
|
|
|
|
['id' => 'id_user_group'] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUser() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne( |
|
|
|
|
|
User::className(), |
|
|
|
|
|
['id' => 'id_user'] |
|
|
|
|
|
) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les options de base nécessaires à la fonction de recherche. |
|
|
|
|
|
* |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function defaultOptionsSearch() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'with' => ['user', 'pointSale'], |
|
|
|
|
|
'join_with' => ['product'], |
|
|
|
|
|
'orderby' => '', |
|
|
|
|
|
'attribute_id_producer' => 'product.id_producer' |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static function percentValues() |
|
|
|
|
|
{ |
|
|
|
|
|
$percentValues = [ |
|
|
|
|
|
'' => 'Aucun' |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
|
|
|
for($i = -50 ; $i < 51 ; $i = $i + 5) { |
|
|
|
|
|
$percentValues[$i] = $i.' %' ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $percentValues ; |
|
|
|
|
|
|
|
|
return $percentValues; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static function getPriorityMatchOfSpecificPriceArray($specificPriceArray, $user, $pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach($specificPriceArray as $specificPrice) { |
|
|
|
|
|
if($specificPrice->matchUser($user, $pointSale)) { |
|
|
|
|
|
return 'matchUser'; |
|
|
|
|
|
} |
|
|
|
|
|
if($specificPrice->matchUserGroup($user, $pointSale)) { |
|
|
|
|
|
return 'matchUserGroup'; |
|
|
|
|
|
} |
|
|
|
|
|
if($specificPrice->matchPointSale($user, $pointSale)) { |
|
|
|
|
|
return 'matchPointSale'; |
|
|
|
|
|
} |
|
|
|
|
|
if($specificPrice->matchUserPointSale($user, $pointSale)) { |
|
|
|
|
|
return 'matchUserPointSale'; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function matchUser($user, $pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
return $user |
|
|
|
|
|
&& $this->id_user |
|
|
|
|
|
&& !$this->id_point_sale |
|
|
|
|
|
&& !$this->id_user_group |
|
|
|
|
|
&& $this->id_user == $user->id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function matchUserGroup($user, $pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
return $user |
|
|
|
|
|
&& $this->id_user_group |
|
|
|
|
|
&& !$this->id_point_sale |
|
|
|
|
|
&& !$this->id_user |
|
|
|
|
|
&& $user->belongsToUserGroup($this->id_user_group); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function matchPointSale($user, $pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
return $pointSale |
|
|
|
|
|
&& $this->id_point_sale |
|
|
|
|
|
&& !$this->id_user |
|
|
|
|
|
&& !$this->id_user_group |
|
|
|
|
|
&& $this->id_point_sale == $pointSale->id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function matchUserPointSale($user, $pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
return $pointSale && $user |
|
|
|
|
|
&& $this->id_point_sale |
|
|
|
|
|
&& $this->id_user |
|
|
|
|
|
&& $this->id_point_sale == $pointSale->id |
|
|
|
|
|
&& $this->id_user == $user->id; |
|
|
|
|
|
} |
|
|
} |
|
|
} |