|
|
|
|
|
|
|
|
* @property string $adresse |
|
|
* @property string $adresse |
|
|
* @property integer $id_boulangerie |
|
|
* @property integer $id_boulangerie |
|
|
*/ |
|
|
*/ |
|
|
class PointVente extends \yii\db\ActiveRecord { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PointVente extends \yii\db\ActiveRecord |
|
|
|
|
|
{ |
|
|
var $commandes = []; |
|
|
var $commandes = []; |
|
|
var $recettes = 0; |
|
|
var $recettes = 0; |
|
|
var $recettes_pain = 0; |
|
|
var $recettes_pain = 0; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public static function tableName() { |
|
|
|
|
|
|
|
|
public static function tableName() |
|
|
|
|
|
{ |
|
|
return 'point_vente'; |
|
|
return 'point_vente'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function rules() { |
|
|
|
|
|
|
|
|
public function rules() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
[['nom'], 'required'], |
|
|
[['nom'], 'required'], |
|
|
[['acces_restreint'], 'boolean'], |
|
|
[['acces_restreint'], 'boolean'], |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function attributeLabels() { |
|
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
'id' => 'ID', |
|
|
'id' => 'ID', |
|
|
'nom' => 'Nom', |
|
|
'nom' => 'Nom', |
|
|
|
|
|
|
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPointVenteUser() { |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Relations |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public function getPointVenteUser() |
|
|
|
|
|
{ |
|
|
return $this->hasMany(PointVenteUser::className(), ['id_point_vente' => 'id']); |
|
|
return $this->hasMany(PointVenteUser::className(), ['id_point_vente' => 'id']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getProductionPointVente() { |
|
|
|
|
|
|
|
|
public function getProductionPointVente() |
|
|
|
|
|
{ |
|
|
return $this->hasMany(ProductionPointVente::className(), ['id_point_vente' => 'id']); |
|
|
return $this->hasMany(ProductionPointVente::className(), ['id_point_vente' => 'id']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function initCommandes($commandes) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Initialise les commandes liées au point de vente. |
|
|
|
|
|
* |
|
|
|
|
|
* @param array $commandes |
|
|
|
|
|
*/ |
|
|
|
|
|
public function initCommandes($commandes) |
|
|
|
|
|
{ |
|
|
$this->commandes = []; |
|
|
$this->commandes = []; |
|
|
$this->recettes = 0; |
|
|
$this->recettes = 0; |
|
|
$this->recettes_pain = 0; |
|
|
$this->recettes_pain = 0; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCommandes() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les commandes liées à ce point de vente. |
|
|
|
|
|
* |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getCommandes() |
|
|
|
|
|
{ |
|
|
return $this->commandes; |
|
|
return $this->commandes; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function strListeVrac() { |
|
|
|
|
|
|
|
|
|
|
|
$str = ''; |
|
|
|
|
|
$produits = Produit::find()->orderBy('order ASC')->all(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($produits as $p) { |
|
|
|
|
|
if ($p->vrac) { |
|
|
|
|
|
$quantite = Commande::getQuantiteProduit($p->id, $this->commandes); |
|
|
|
|
|
if ($quantite) { |
|
|
|
|
|
$str .= $quantite . ' ' . Html::encode($p->diminutif) . ', '; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return substr($str, 0, strlen($str) - 2); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function save($runValidation = true, $attributeNames = NULL) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Enregistre le point de vente. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $runValidation |
|
|
|
|
|
* @param array $attributeNames |
|
|
|
|
|
* @return type |
|
|
|
|
|
*/ |
|
|
|
|
|
public function save($runValidation = true, $attributeNames = NULL) |
|
|
|
|
|
{ |
|
|
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
$this->pain = 1; |
|
|
$this->pain = 1; |
|
|
return parent::save($runValidation, $attributeNames); |
|
|
return parent::save($runValidation, $attributeNames); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function gestionPointFabrication() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Traite la mise à jour de l'attribut 'point_fabrication'. |
|
|
|
|
|
*/ |
|
|
|
|
|
public function gestionPointFabrication() |
|
|
|
|
|
{ |
|
|
if ($this->point_fabrication) { |
|
|
if ($this->point_fabrication) { |
|
|
PointVente::updateAll( |
|
|
PointVente::updateAll( |
|
|
['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement] |
|
|
['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement] |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function gestionAccesRestreint() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Traite les accès restreints d'un point de vente. |
|
|
|
|
|
*/ |
|
|
|
|
|
public function gestionAccesRestreint() |
|
|
|
|
|
{ |
|
|
PointVenteUser::deleteAll(['id_point_vente' => $this->id]); |
|
|
PointVenteUser::deleteAll(['id_point_vente' => $this->id]); |
|
|
|
|
|
|
|
|
if (is_array($this->users) && count($this->users)) { |
|
|
if (is_array($this->users) && count($this->users)) { |
|
|
|
|
|
|
|
|
$point_vente_user = new PointVenteUser; |
|
|
$point_vente_user = new PointVenteUser; |
|
|
$point_vente_user->id_user = $val; |
|
|
$point_vente_user->id_user = $val; |
|
|
$point_vente_user->id_point_vente = $this->id; |
|
|
$point_vente_user->id_point_vente = $this->id; |
|
|
if (isset($this->users_commentaire[$val]) && strlen($this->users_commentaire[$val])) |
|
|
|
|
|
|
|
|
if (isset($this->users_commentaire[$val]) && strlen($this->users_commentaire[$val])) { |
|
|
$point_vente_user->commentaire = $this->users_commentaire[$val]; |
|
|
$point_vente_user->commentaire = $this->users_commentaire[$val]; |
|
|
|
|
|
} |
|
|
$point_vente_user->save(); |
|
|
$point_vente_user->save(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCommentaire() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le commentaire de l'utilisateur courant lié au point de vente. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string|null |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getCommentaire() |
|
|
|
|
|
{ |
|
|
if (isset($this->pointVenteUser)) { |
|
|
if (isset($this->pointVenteUser)) { |
|
|
foreach ($this->pointVenteUser as $pvu) { |
|
|
foreach ($this->pointVenteUser as $pvu) { |
|
|
if ($pvu->id_user == Yii::$app->user->identity->id) { |
|
|
if ($pvu->id_user == Yii::$app->user->identity->id) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return null ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static function count() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le nombre de points de vente pour l'établissement courant. |
|
|
|
|
|
* |
|
|
|
|
|
* @return integer |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function count() |
|
|
|
|
|
{ |
|
|
return PointVente::find() |
|
|
return PointVente::find() |
|
|
->where([ |
|
|
->where([ |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
|
|
|
|
|
|
->count(); |
|
|
->count(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function verifCode($code) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Vérifie le code d'accès à un point de vente. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $code |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
*/ |
|
|
|
|
|
public function verifCode($code) |
|
|
|
|
|
{ |
|
|
if (strlen($this->code)) { |
|
|
if (strlen($this->code)) { |
|
|
if (trim(strtolower($code)) == trim(strtolower($this->code))) { |
|
|
if (trim(strtolower($code)) == trim(strtolower($this->code))) { |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les jours de livraison du point de vente sous forme d'une chaine |
|
|
|
|
|
* de caractères. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
public function strJoursLivraison() { |
|
|
public function strJoursLivraison() { |
|
|
$str = '' ; |
|
|
$str = '' ; |
|
|
if($this->livraison_lundi) $str .= 'lundi, ' ; |
|
|
if($this->livraison_lundi) $str .= 'lundi, ' ; |
|
|
|
|
|
|
|
|
return '' ; |
|
|
return '' ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne un commentaire informant l'utilisateur sur les détails de |
|
|
|
|
|
* livraison d'un point de vente et pour un jour donné. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $jour |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
public function strInfos($jour) { |
|
|
public function strInfos($jour) { |
|
|
$str = '' ; |
|
|
$str = '' ; |
|
|
$champs = 'horaires_'.$jour ; |
|
|
$champs = 'horaires_'.$jour ; |