$creditHistory = new CreditHistory; | $creditHistory = new CreditHistory; | ||||
$creditHistory->id_user = $this->id_user; | $creditHistory->id_user = $this->id_user; | ||||
$creditHistory->id_user_action = Yii::$app->user->identity->id; | $creditHistory->id_user_action = Yii::$app->user->identity->id; | ||||
$creditHistory->id_producer = Producer::getCurrentId() ; | |||||
$creditHistory->id_producer = Producer::getId() ; | |||||
$creditHistory->type = $this->type ; | $creditHistory->type = $this->type ; | ||||
$creditHistory->comment = $this->comment ; | $creditHistory->comment = $this->comment ; | ||||
$creditHistory->amount = $this->amount ; | $creditHistory->amount = $this->amount ; | ||||
// on prévient l'utilisateur que son compte vient d'être crédité | // on prévient l'utilisateur que son compte vient d'être crédité | ||||
if($this->send_mail) { | if($this->send_mail) { | ||||
$user = User::findOne($this->id_user) ; | $user = User::findOne($this->id_user) ; | ||||
$producer = Producer::getCurrent() ; | |||||
$producer = Producer::get() ; | |||||
$userProducer = UserProducer::searchOne([ | $userProducer = UserProducer::searchOne([ | ||||
'id_user' => $this->id_user | 'id_user' => $this->id_user | ||||
]); | ]); |
$pk = $class::tableName().'.'.$pk[0] ; | $pk = $class::tableName().'.'.$pk[0] ; | ||||
if (!isset($params[$options['attribute_id_producer']]) && !Yii::$app->user->isGuest) { | if (!isset($params[$options['attribute_id_producer']]) && !Yii::$app->user->isGuest) { | ||||
$params[$options['attribute_id_producer']] = Producer::getCurrentId(); | |||||
$params[$options['attribute_id_producer']] = Producer::getId(); | |||||
} | } | ||||
if(!isset($options['type_search'])) { | if(!isset($options['type_search'])) { |
return $this->hasOne( | return $this->hasOne( | ||||
DevelopmentPriority::className(), | DevelopmentPriority::className(), | ||||
['id_development' => 'id']) | ['id_development' => 'id']) | ||||
->where(['id_producer' => Producer::getCurrentId()]) | |||||
->where(['id_producer' => Producer::getId()]) | |||||
->with('producer'); | ->with('producer'); | ||||
} | } | ||||
*/ | */ | ||||
class Distribution extends \yii\db\ActiveRecord | class Distribution extends \yii\db\ActiveRecord | ||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
/** | /** | ||||
* Retourne si un produit est actif ou non. | * Retourne si un produit est actif ou non. | ||||
* | * | ||||
* @param integer $id_produit | |||||
* @param integer $idProduit | |||||
* @return boolean | * @return boolean | ||||
*/ | */ | ||||
public function isActiveProduct($idProduit) | public function isActiveProduct($idProduit) | ||||
$distribution = new Distribution; | $distribution = new Distribution; | ||||
$distribution->date = $date; | $distribution->date = $date; | ||||
$distribution->delivery = 1; | $distribution->delivery = 1; | ||||
$distribution->id_producer = Producer::getCurrentId(); | |||||
$distribution->id_producer = Producer::getId(); | |||||
$distribution->save(); | $distribution->save(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $production ; | |||||
return $distribution ; | |||||
} | } | ||||
} | } |
*/ | */ | ||||
public function save($runValidation = true, $attributeNames = NULL) | public function save($runValidation = true, $attributeNames = NULL) | ||||
{ | { | ||||
$this->id_producer = Producer::getCurrentId(); | |||||
$this->id_producer = Producer::getId(); | |||||
return parent::save($runValidation, $attributeNames); | return parent::save($runValidation, $attributeNames); | ||||
} | } | ||||
*/ | */ | ||||
public static function count() | public static function count() | ||||
{ | { | ||||
return self::searchCount(['id_producer' => Producer::getCurrentId()]) ; | |||||
return self::searchCount(['id_producer' => Producer::getId()]) ; | |||||
} | } | ||||
/** | /** |
class PointSaleDistribution extends \yii\db\ActiveRecord | class PointSaleDistribution extends \yii\db\ActiveRecord | ||||
{ | { | ||||
var $point_sale_distribution; | |||||
var $points_sale_distribution; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc |
{ | { | ||||
if (strlen($config)) { | if (strlen($config)) { | ||||
if (!$idProducer) { | if (!$idProducer) { | ||||
$idProducer = Producer::getCurrentId() ; | |||||
$idProducer = Producer::getId() ; | |||||
} | } | ||||
$producer = self::findOne($idProducer); | $producer = self::findOne($idProducer); | ||||
* Retourne le producteur courant (le producteur auquel l'utilisateur | * Retourne le producteur courant (le producteur auquel l'utilisateur | ||||
* connecté est rattaché). | * connecté est rattaché). | ||||
* | * | ||||
* @return boolean | |||||
* @return integer|boolean | |||||
*/ | */ | ||||
public static function getCurrentId() | |||||
public static function getId() | |||||
{ | { | ||||
if(!Yii::$app->user->isGuest) { | if(!Yii::$app->user->isGuest) { | ||||
return Yii::$app->user->identity->id_producer ; | return Yii::$app->user->identity->id_producer ; | ||||
* | * | ||||
* @return Producer|boolean | * @return Producer|boolean | ||||
*/ | */ | ||||
public static function getCurrent() | |||||
public static function get() | |||||
{ | { | ||||
if(self::getCurrentId()) { | |||||
if(self::getId()) { | |||||
return self::searchOne() ; | return self::searchOne() ; | ||||
} | } | ||||
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\components\ActiveRecordCommon ; | |||||
/** | /** | ||||
* This is the model class for table "produit". | * This is the model class for table "produit". | ||||
* @property double $poids | * @property double $poids | ||||
* @property string $recette | * @property string $recette | ||||
*/ | */ | ||||
class Product extends \yii\db\ActiveRecord | |||||
class Product extends ActiveRecordCommon | |||||
{ | { | ||||
var $total = 0; | var $total = 0; | ||||
*/ | */ | ||||
public function save($runValidation = true, $attributeNames = NULL) | public function save($runValidation = true, $attributeNames = NULL) | ||||
{ | { | ||||
$this->id_producer = Producer::getCurrentId(); | |||||
$this->id_producer = Producer::getId(); | |||||
return parent::save($runValidation, $attributeNames); | return parent::save($runValidation, $attributeNames); | ||||
} | } | ||||
* @param integer $idDistribution | * @param integer $idDistribution | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
public function searchByDistribution($idDistribution) | |||||
public static function searchByDistribution($idDistribution) | |||||
{ | { | ||||
return Product::find() | return Product::find() | ||||
->leftJoin('product_distribution', 'product.id = product_distribution.id_product') | ->leftJoin('product_distribution', 'product.id = product_distribution.id_product') | ||||
->where([ | ->where([ | ||||
'id_producer' => Producer::getCurrentId(), | |||||
'id_producer' => Producer::getId(), | |||||
'product_distribution.id_distribution' => $idDistribution | 'product_distribution.id_distribution' => $idDistribution | ||||
]) | ]) | ||||
->orderBy('product_distribution.active DESC, product.order ASC') | ->orderBy('product_distribution.active DESC, product.order ASC') |
use yii\web\IdentityInterface; | use yii\web\IdentityInterface; | ||||
use yii\db\Query ; | use yii\db\Query ; | ||||
use common\components\ActiveRecordCommon ; | |||||
/** | /** | ||||
* User model | * User model | ||||
* | * | ||||
* @property string $password write-only password | * @property string $password write-only password | ||||
* @property boolean $confiance | * @property boolean $confiance | ||||
*/ | */ | ||||
class User extends ActiveRecord implements IdentityInterface | |||||
class User extends ActiveRecordCommon implements IdentityInterface | |||||
{ | { | ||||
const STATUS_DELETED = 0; | const STATUS_DELETED = 0; | ||||
public static function findBy($params = []) | public static function findBy($params = []) | ||||
{ | { | ||||
if (!isset($params['id_producer'])) { | if (!isset($params['id_producer'])) { | ||||
$params['id_producer'] = Producer::getCurrentId() ; | |||||
$params['id_producer'] = Producer::getId() ; | |||||
} | } | ||||
$query = (new Query()) | $query = (new Query()) | ||||
public function sendMailWelcome($password) | public function sendMailWelcome($password) | ||||
{ | { | ||||
if (strlen($this->email)) { | if (strlen($this->email)) { | ||||
$producer = Producer::findOne(Producer::getCurrentId()); | |||||
$producer = Producer::findOne(Producer::getId()); | |||||
Yii::$app->mailer->compose(); | Yii::$app->mailer->compose(); | ||||
$mail = Yii::$app->mailer->compose( | $mail = Yii::$app->mailer->compose( | ||||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password] | ['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password] | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public static function getCurrentId() { | |||||
public static function getId() { | |||||
if(!Yii::$app->user->isGuest) { | if(!Yii::$app->user->isGuest) { | ||||
return Yii::$app->user->identity->id ; | return Yii::$app->user->identity->id ; | ||||
} | } | ||||
return false ; | return false ; | ||||
} | } | ||||
/** | |||||
* Retourne le status de l'utilisateur courant connecté. | |||||
* | |||||
* @return integer|boolean | |||||
*/ | |||||
public static function getStatus() | |||||
{ | |||||
if(!Yii::$app->user->isGuest) { | |||||
return Yii::$app->user->identity->status ; | |||||
} | |||||
return false ; | |||||
} | |||||
} | } |
$producer = Producer::findOne($this->id_producer); | $producer = Producer::findOne($this->id_producer); | ||||
$userProducerExist = UserProducer::searchOne([ | $userProducerExist = UserProducer::searchOne([ | ||||
'id_user' => User::getCurrentId(), | |||||
'id_user' => User::getId(), | |||||
'active' => 0 | 'active' => 0 | ||||
]) ; | ]) ; | ||||
$userProducerExist->save(); | $userProducerExist->save(); | ||||
} else { | } else { | ||||
$userProducer = new UserProducer(); | $userProducer = new UserProducer(); | ||||
$userProducer->id_user = User::getCurrentId(); | |||||
$userProducer->id_user = User::getId(); | |||||
$userProducer->id_producer = $this->id_producr; | $userProducer->id_producer = $this->id_producr; | ||||
$userProducer->credit = 0; | $userProducer->credit = 0; | ||||
$userProducer->actif = 1; | $userProducer->actif = 1; |