|
|
@@ -51,8 +51,8 @@ use common\models\ProductionPointVente; |
|
|
|
* @property string $adresse |
|
|
|
* @property integer $id_boulangerie |
|
|
|
*/ |
|
|
|
class PointVente extends \yii\db\ActiveRecord { |
|
|
|
|
|
|
|
class PointVente extends \yii\db\ActiveRecord |
|
|
|
{ |
|
|
|
var $commandes = []; |
|
|
|
var $recettes = 0; |
|
|
|
var $recettes_pain = 0; |
|
|
@@ -65,14 +65,16 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public static function tableName() { |
|
|
|
public static function tableName() |
|
|
|
{ |
|
|
|
return 'point_vente'; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function rules() { |
|
|
|
public function rules() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
[['nom'], 'required'], |
|
|
|
[['acces_restreint'], 'boolean'], |
|
|
@@ -89,7 +91,8 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function attributeLabels() { |
|
|
|
public function attributeLabels() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'id' => 'ID', |
|
|
|
'nom' => 'Nom', |
|
|
@@ -118,16 +121,27 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPointVenteUser() { |
|
|
|
/* |
|
|
|
* Relations |
|
|
|
*/ |
|
|
|
|
|
|
|
public function getPointVenteUser() |
|
|
|
{ |
|
|
|
return $this->hasMany(PointVenteUser::className(), ['id_point_vente' => 'id']); |
|
|
|
} |
|
|
|
|
|
|
|
public function getProductionPointVente() { |
|
|
|
public function getProductionPointVente() |
|
|
|
{ |
|
|
|
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->recettes = 0; |
|
|
|
$this->recettes_pain = 0; |
|
|
@@ -146,34 +160,35 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function getCommandes() { |
|
|
|
/** |
|
|
|
* Retourne les commandes liées à ce point de vente. |
|
|
|
* |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function getCommandes() |
|
|
|
{ |
|
|
|
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->pain = 1; |
|
|
|
return parent::save($runValidation, $attributeNames); |
|
|
|
} |
|
|
|
|
|
|
|
public function gestionPointFabrication() { |
|
|
|
/** |
|
|
|
* Traite la mise à jour de l'attribut 'point_fabrication'. |
|
|
|
*/ |
|
|
|
public function gestionPointFabrication() |
|
|
|
{ |
|
|
|
if ($this->point_fabrication) { |
|
|
|
PointVente::updateAll( |
|
|
|
['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement] |
|
|
@@ -183,7 +198,11 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function gestionAccesRestreint() { |
|
|
|
/** |
|
|
|
* Traite les accès restreints d'un point de vente. |
|
|
|
*/ |
|
|
|
public function gestionAccesRestreint() |
|
|
|
{ |
|
|
|
PointVenteUser::deleteAll(['id_point_vente' => $this->id]); |
|
|
|
|
|
|
|
if (is_array($this->users) && count($this->users)) { |
|
|
@@ -193,15 +212,22 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
$point_vente_user = new PointVenteUser; |
|
|
|
$point_vente_user->id_user = $val; |
|
|
|
$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->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)) { |
|
|
|
foreach ($this->pointVenteUser as $pvu) { |
|
|
|
if ($pvu->id_user == Yii::$app->user->identity->id) { |
|
|
@@ -209,9 +235,16 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
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() |
|
|
|
->where([ |
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
@@ -219,7 +252,14 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
->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 (trim(strtolower($code)) == trim(strtolower($this->code))) { |
|
|
|
return true; |
|
|
@@ -231,6 +271,12 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne les jours de livraison du point de vente sous forme d'une chaine |
|
|
|
* de caractères. |
|
|
|
* |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function strJoursLivraison() { |
|
|
|
$str = '' ; |
|
|
|
if($this->livraison_lundi) $str .= 'lundi, ' ; |
|
|
@@ -247,6 +293,13 @@ class PointVente extends \yii\db\ActiveRecord { |
|
|
|
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) { |
|
|
|
$str = '' ; |
|
|
|
$champs = 'horaires_'.$jour ; |