255], [['adresse', 'localite', 'horaires_lundi', 'horaires_mardi', 'horaires_mercredi', 'horaires_jeudi', 'horaires_vendredi', 'horaires_samedi', 'horaires_dimanche'], 'string'], [['point_fabrication', 'vrac', 'pain', 'credit_pain', 'livraison_lundi', 'livraison_mardi', 'livraison_mercredi', 'livraison_jeudi', 'livraison_vendredi', 'livraison_samedi', 'livraison_dimanche'], 'boolean'], ['point_fabrication', 'default', 'value' => 0], ['id_etablissement', 'integer'], ['id_etablissement', 'required'], [['users', 'users_commentaire', 'code'], 'safe'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'nom' => 'Nom', 'adresse' => 'Adresse', 'localite' => 'Localité', 'point_fabrication' => 'Point de fabrication', 'horaires_lundi' => 'Lundi', 'horaires_mardi' => 'Mardi', 'horaires_mercredi' => 'Mercredi', 'horaires_jeudi' => 'Jeudi', 'horaires_vendredi' => 'Vendredi', 'horaires_samedi' => 'Samedi', 'horaires_dimanche' => 'Dimanche', 'vrac' => 'Livraison de vrac', 'pain' => 'Livraison de pain', 'acces_restreint' => 'Accès restreint', 'credit_pain' => 'Activer le Crédit Pain', 'livraison_lundi' => 'Lundi', 'livraison_mardi' => 'Mardi', 'livraison_mercredi' => 'Mercredi', 'livraison_jeudi' => 'Jeudi', 'livraison_vendredi' => 'Vendredi', 'livraison_samedi' => 'Samedi', 'livraison_dimanche' => 'Dimanche', 'code' => 'Code', ]; } public function getPointVenteUser() { return $this->hasMany(PointVenteUser::className(), ['id_point_vente' => 'id']); } public function getProductionPointVente() { return $this->hasMany(ProductionPointVente::className(), ['id_point_vente' => 'id']); } public function initCommandes($commandes) { $this->commandes = []; $this->recettes = 0; $this->recettes_pain = 0; $this->recettes_vrac = 0; foreach ($commandes as $c) { if ($this->id == $c->id_point_vente) { $this->commandes[] = $c; $this->recettes += (float) $c->montant; $this->recettes_pain += (float) $c->montant_pain; $this->recettes_vrac += (float) $c->montant_vrac; } } } 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) { $this->id_etablissement = Yii::$app->user->identity->id_etablissement; $this->pain = 1; return parent::save($runValidation, $attributeNames); } public function gestionPointFabrication() { if ($this->point_fabrication) { PointVente::updateAll( ['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement] ); $this->point_fabrication = 1; $this->save(); } } public function gestionAccesRestreint() { PointVenteUser::deleteAll(['id_point_vente' => $this->id]); if (is_array($this->users) && count($this->users)) { foreach ($this->users as $key => $val) { $user = User::findOne($val); if ($user) { $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])) $point_vente_user->commentaire = $this->users_commentaire[$val]; $point_vente_user->save(); } } } } public function getCommentaire() { if (isset($this->pointVenteUser)) { foreach ($this->pointVenteUser as $pvu) { if ($pvu->id_user == Yii::$app->user->identity->id) { return $pvu->commentaire; } } } } public static function count() { return PointVente::find() ->where([ 'id_etablissement' => Yii::$app->user->identity->id_etablissement ]) ->count(); } public function verifCode($code) { if (strlen($this->code)) { if (trim(strtolower($code)) == trim(strtolower($this->code))) { return true; } else { return false; } } else { return true; } } }