'Id Production', 'id_point_vente' => 'Id Point Vente', 'livraison' => 'Livraison', ]; } public function getProduction() { return $this->hasOne(Production::className(), ['id' => 'id_production']) ; } public function getPointVente() { return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']) ; } public static function setAll($id_production, $bool_livraison) { $count_productions_point_vente = self::find()-> where([ 'id_production' => $id_production ]) ->count() ; if(!$count_productions_point_vente) { $points_vente = PointVente::find() ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) ->all(); foreach($points_vente as $pv) { $production_pv = new ProductionPointVente() ; $production_pv->id_production = $id_production ; $production_pv->id_point_vente = $pv->id ; $production_pv->save() ; } } $production = Production::findOne($id_production) ; if($production) { $jour = date('N', strtotime($production->date)) ; $productions_point_vente = self::find() ->with(['production','pointVente']) ->where([ 'id_production' => $id_production ]) ->all() ; foreach($productions_point_vente as $production_pv) { if($bool_livraison && ( ($jour == 1 && $production_pv->pointVente->livraison_lundi) || ($jour == 2 && $production_pv->pointVente->livraison_mardi) || ($jour == 3 && $production_pv->pointVente->livraison_mercredi) || ($jour == 4 && $production_pv->pointVente->livraison_jeudi) || ($jour == 5 && $production_pv->pointVente->livraison_vendredi) || ($jour == 6 && $production_pv->pointVente->livraison_samedi) || ($jour == 7 && $production_pv->pointVente->livraison_dimanche) || $production_pv->pointVente->point_fabrication )) { $production_pv->livraison = 1 ; } else { $production_pv->livraison = 0 ; } $production_pv->save() ; } } } }