Exemplo n.º 1
0
 public function index($year1 = null, $year2 = null)
 {
     if (isset($year1) && isset($year2)) {
         $both = $year1 . '-' . $year2;
         $result = \Auth::user()->schoolyears()->where('ann_scol', $both)->first();
         $classrooms = \Auth::user()->classrooms()->where('school_year_id', $result->id)->paginate(10);
         $branches = Branch::where('user_id', \Auth::user()->id)->get();
         $niveaux = Level::where('user_id', \Auth::user()->id)->where('school_year_id', SchoolYear::getSchoolYearId())->get();
         return view('classrooms.index')->with(['classrooms' => $classrooms, 'branches' => $branches, 'niveaux' => $niveaux, 'year1' => $year1, 'year2' => $year2]);
     } else {
         $classrooms = Classroom::where('user_id', \Auth::user()->id)->CurrentYear()->paginate(10);
         $branches = Branch::where('user_id', \Auth::user()->id)->get();
         $niveaux = Level::where('user_id', \Auth::user()->id)->where('school_year_id', SchoolYear::getSchoolYearId())->get();
         return view('classrooms.index')->with(['classrooms' => $classrooms, 'branches' => $branches, 'niveaux' => $niveaux]);
     }
 }
Exemplo n.º 2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $children = \Auth::user()->children()->where('school_year_id', SchoolYear::getSchoolYearId())->paginate(10);
     return view('attendances.index', compact('children'));
 }
Exemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(FormValidationChildFamilyRequest $request)
 {
     $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
     if ($cr->children()->CurrentYear()->count() > $cr->capacite_classe) {
         return redirect()->back()->withErrors("la classe est saturée");
     }
     // promotion Exceptional check
     if (PromotionExceptional::checkExceptionalPromotion()) {
         if (PromotionExceptional::checkExcTimeOfPromotionIfExpired()) {
             if (PromotionExceptional::checkExcPriceandReturnIt() == 'no') {
                 return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais aucun prix n'est défini")->withInput();
             } else {
                 $prix_exc = PromotionExceptional::checkExcPriceandReturnIt();
             }
         } else {
             return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais la durée est expirée");
         }
     }
     // promotion advanced check
     $prix_advance = '';
     if (PromotionAdvance::checkAdvancePromotion()) {
         if ($request->nbr_month > 1) {
             if (PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month) !== false) {
                 $prix_advance = PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month);
             } else {
                 return redirect()->back()->withErrors("Aucun prix n'est\n                    défini pour cette Promotion de " . $request->nbr_month . ' Mois');
             }
         }
     }
     $niveau_global = \Auth::user()->grades()->where('id', $request->grade)->first()->name;
     // famille for family profile
     $famille = Family::where('user_id', \Auth::user()->id)->where('email_responsable', $request->email_responsable)->first();
     if (!$famille) {
         $family = new Family();
         $family->nom_pere = ucfirst($request->nom_pere);
         $family->nom_mere = ucfirst($request->nom_mere);
         $family->email_responsable = $request->email_responsable;
         $family->adresse = $request->adresse;
         $family->numero_fixe = $request->numero_fixe;
         $family->numero_portable = $request->numero_portable;
         $family->cin = strtoupper($request->cin);
         $family->responsable = $request->responsable;
         $family->user_id = \Auth::user()->id;
         $family->school_year_id = SchoolYear::getSchoolYearId();
         $family->save();
         if ($family->id) {
             $father = Family::findOrFail($family->id);
             $child = new Child();
             $child->date_naissance = Carbon::parse($request->date_naissance);
             $child->transport = $request->transport;
             $child->sexe = $request->sexe;
             $child->nom_enfant = ucfirst($request->nom_enfant);
             $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
             $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr;
             $child->user_id = \Auth::user()->id;
             $child->school_year_id = SchoolYear::getSchoolYearId();
             $image = Input::file('photo');
             if (!$image && empty($image)) {
                 $filename = '';
             } else {
                 $filename = $image->getClientOriginalName();
                 $path = public_path('uploads/' . $filename);
                 Image::make($image->getRealPath())->resize(313, 300)->save($path);
             }
             $child->photo = $filename;
             $child->family_id = $family->id;
             $child->save();
             if ($child->id) {
                 $ch = Child::find($child->id);
                 if ($niveau_global == 'Lycée') {
                     $ch->branches()->attach([$request->branche]);
                 }
                 if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') {
                     $ch->levels()->attach([$request->niveau]);
                 }
                 /*if($niveau_global == 'Crèche')
                   {
                       $ch->classrooms()->attach([$request->classe]);
                   }*/
                 //classe
                 $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
                 $cr->children()->attach([$child->id]);
                 $bill = new Bill();
                 $bill->status = 0;
                 // if no promotion is active
                 if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) {
                     if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                         $bill->reductionPrix = $request->reduction;
                         $bill->reduction = 1;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     } else {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                         $bill->reduction = 0;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     }
                 }
                 if (PromotionAdvance::checkAdvancePromotion()) {
                     if ($request->nbr_month >= 3) {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month);
                         $bill->reduction = 1;
                         $bill->reductionPrix = $prix_advance;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     }
                     if ($request->nbr_month == 1) {
                         if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                             $bill->reductionPrix = $request->reduction;
                             $bill->reduction = 1;
                             $bill->school_year_id = SchoolYear::getSchoolYearId();
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                             $bill->reduction = 0;
                             $bill->school_year_id = SchoolYear::getSchoolYearId();
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                 }
                 if (PromotionExceptional::checkExceptionalPromotion()) {
                     $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                     $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                     $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc);
                     $bill->reductionPrix = $prix_exc;
                     $bill->reduction = 1;
                     $bill->school_year_id = SchoolYear::getSchoolYearId();
                     $bill->nbrMois = $request->nbr_month;
                 }
                 $bill->child_id = $child->id;
                 $bill->user_id = \Auth::user()->id;
                 $bill->save();
                 $enfant = Child::findOrFail($child->id);
                 if ($father->responsable == 0) {
                     $resp = $father->nom_mere;
                 } else {
                     $resp = $father->nom_pere;
                 }
                 event(new SendEmailToRespAfterRegistrationEvent($child->id, $resp, $enfant->nom_enfant, $enfant->created_at->toDateString(), $enfant->created_at->addMonth()->toDateString(), $father->email_responsable, $father->responsable, str_random(6)));
             }
         }
         return redirect()->back()->with('success', "l'élève et les parents ont bien été ajoutés! ");
     } else {
         // if the parent already in the database
         $child = new Child();
         $child->date_naissance = Carbon::parse($request->date_naissance);
         $child->nom_enfant = $request->nom_enfant;
         $child->sexe = $request->sexe;
         $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
         $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr;
         $child->school_year_id = SchoolYear::getSchoolYearId();
         $child->transport = $request->transport;
         $child->user_id = \Auth::user()->id;
         $image = Input::file('photo');
         if (!$image && empty($image)) {
             $filename = '';
         } else {
             $filename = $image->getClientOriginalName();
             $path = public_path('uploads/' . $filename);
             Image::make($image->getRealPath())->resize(313, 300)->save($path);
         }
         $child->photo = $filename;
         $child->family_id = $famille->id;
         $resp = Family::findOrFail($famille->id);
         $user = User::where('email', $resp->email_responsable)->first();
         if ($user) {
             $child->f_id = $user->id;
             $child->save();
             if ($child->id) {
                 $ch = Child::find($child->id);
                 if ($niveau_global == 'Lycée') {
                     $ch->branches()->attach([$request->branche]);
                 }
                 if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') {
                     $ch->levels()->attach([$request->niveau]);
                 }
                 if ($niveau_global == 'Crèche') {
                     $ch->classrooms()->attach([$request->classe]);
                 }
                 $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
                 $cr->children()->attach([$child->id]);
                 $bill = new Bill();
                 $bill->status = 0;
                 if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) {
                     if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                         $bill->reductionPrix = $request->reduction;
                         $bill->reduction = 1;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     } else {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                         $bill->reduction = 0;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     }
                 }
                 if (PromotionAdvance::checkAdvancePromotion()) {
                     if ($request->nbr_month >= 3) {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month);
                         $bill->reduction = 1;
                         $bill->reductionPrix = $prix_advance;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     }
                     if ($request->nbr_month == 1) {
                         if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                             $bill->reductionPrix = $request->reduction;
                             $bill->reduction = 1;
                             $bill->school_year_id = SchoolYear::getSchoolYearId();
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                             $bill->reduction = 0;
                             $bill->school_year_id = SchoolYear::getSchoolYearId();
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                 }
                 if (PromotionExceptional::checkExceptionalPromotion()) {
                     $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                     $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                     $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc);
                     $bill->reductionPrix = $prix_exc;
                     $bill->reduction = 1;
                     $bill->school_year_id = SchoolYear::getSchoolYearId();
                     $bill->nbrMois = $request->nbr_month;
                 }
                 $bill->child_id = $child->id;
                 $bill->f_id = $user->id;
                 $bill->user_id = \Auth::user()->id;
                 $bill->save();
             }
         }
         return redirect()->back()->with('success', "l'élève a bien été ajouté! ");
     }
 }
Exemplo n.º 4
0
 public function index()
 {
     $branches = Branch::where('user_id', \Auth::user()->id)->where('school_year_id', SchoolYear::getSchoolYearId())->paginate(10);
     return view('branches.index', compact('branches'));
 }
Exemplo n.º 5
0
 public function scopeCurrentYear($query)
 {
     $query->where('school_year_id', SchoolYear::getSchoolYearId());
 }
Exemplo n.º 6
0
 public function gestion()
 {
     $matter_count = Matter::where('user_id', \Auth::user()->id)->count();
     $branch_count = \Auth::user()->branches()->where('school_year_id', \App\SchoolYear::getSchoolYearId())->count();
     $level_count = \Auth::user()->leslevels()->where('school_year_id', \App\SchoolYear::getSchoolYearId())->count();
     $cr_count = Classroom::where('user_id', \Auth::user()->id)->CurrentYear()->count();
     $room_count = Room::where('user_id', \Auth::user()->id)->count();
     return view('statistics.gestion', compact('matter_count', 'branch_count', 'level_count', 'cr_count', 'room_count'));
 }
Exemplo n.º 7
0
 public function enregistrer()
 {
     if (\Request::ajax()) {
         $salle_id = \Input::get('salle_id');
         $color = \Input::get('color');
         $time = \Input::get('time');
         $dayname = \Input::get('dayname');
         $cr_id = \Input::get('cr_id');
         $mat = \Input::get('matiere');
         $matiere_id = \Input::get('matiere_id');
         $ts = Timesheet::where('time', $time)->where('dayname', $dayname)->where('classroom_id', $cr_id)->where('user_id', \Auth::user()->id)->where('matter_id', '!=', 0)->first();
         if (isset($salle_id) && !empty($salle_id)) {
             if ($ts) {
                 $room = Room::find($salle_id);
                 $yes = DB::table('matter_room')->where('matter_id', $ts->matter_id)->where('room_id', $salle_id)->first();
                 if (!$yes) {
                     $room->matters()->attach([$ts->matter_id]);
                 }
             }
         }
         $livingDaylights = ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'];
         $times = ['08:00:00', '09:00:00', '10:00:00', '11:00:00', '12:00:00', '13:00:00', '14:00:00', '15:00:00', '16:00:00', '17:00:00'];
         if ($dayname == 'lundi') {
             $ts = new Timesheet();
             $ts->lundi = $dayname;
             $ts->classroom_id = $cr_id;
             $ts->user_id = \Auth::user()->id;
             $ts->time = $time;
             $ts->matiere = $mat;
             $ts->matter_id = $matiere_id;
             $ts->color = $color;
             $ts->dayname = $dayname;
             $ts->room_id = $salle_id ?: 0;
             $ts->school_year_id = SchoolYear::getSchoolYearId();
             $ts->save();
         } elseif ($dayname == 'mardi') {
             $ts = new Timesheet();
             $ts->mardi = $dayname;
             $ts->classroom_id = $cr_id;
             $ts->user_id = \Auth::user()->id;
             $ts->time = $time;
             $ts->matiere = $mat;
             $ts->matter_id = $matiere_id;
             $ts->color = $color;
             $ts->dayname = $dayname;
             $ts->room_id = $salle_id ?: 0;
             $ts->school_year_id = SchoolYear::getSchoolYearId();
             $ts->save();
         } elseif ($dayname == 'mercredi') {
             $ts = new Timesheet();
             $ts->mercredi = $dayname;
             $ts->classroom_id = $cr_id;
             $ts->user_id = \Auth::user()->id;
             $ts->time = $time;
             $ts->matiere = $mat;
             $ts->matter_id = $matiere_id;
             $ts->color = $color;
             $ts->dayname = $dayname;
             $ts->room_id = $salle_id ?: 0;
             $ts->school_year_id = SchoolYear::getSchoolYearId();
             $ts->save();
         } elseif ($dayname == 'jeudi') {
             $ts = new Timesheet();
             $ts->jeudi = $dayname;
             $ts->classroom_id = $cr_id;
             $ts->user_id = \Auth::user()->id;
             $ts->time = $time;
             $ts->matiere = $mat;
             $ts->matter_id = $matiere_id;
             $ts->color = $color;
             $ts->dayname = $dayname;
             $ts->room_id = $salle_id ?: 0;
             $ts->school_year_id = SchoolYear::getSchoolYearId();
             $ts->save();
         } elseif ($dayname == 'vendredi') {
             $ts = new Timesheet();
             $ts->vendredi = $dayname;
             $ts->classroom_id = $cr_id;
             $ts->user_id = \Auth::user()->id;
             $ts->time = $time;
             $ts->matiere = $mat;
             $ts->matter_id = $matiere_id;
             $ts->color = $color;
             $ts->dayname = $dayname;
             $ts->room_id = $salle_id ?: 0;
             $ts->school_year_id = SchoolYear::getSchoolYearId();
             $ts->save();
         } elseif ($dayname == 'samedi') {
             $ts = new Timesheet();
             $ts->samedi = $dayname;
             $ts->classroom_id = $cr_id;
             $ts->user_id = \Auth::user()->id;
             $ts->time = $time;
             $ts->matiere = $mat;
             $ts->matter_id = $matiere_id;
             $ts->color = $color;
             $ts->dayname = $dayname;
             $ts->room_id = $salle_id ?: 0;
             $ts->school_year_id = SchoolYear::getSchoolYearId();
             $ts->save();
         }
     }
 }
Exemplo n.º 8
0
 public function addchild(Request $request, $id = null)
 {
     if (\Request::isMethod('get')) {
         $family = Family::where('user_id', \Auth::user()->id)->where('id', $id)->first();
         return view('families.addchild', compact('family'));
     } elseif (\Request::isMethod('post')) {
         // promotion Exceptional check
         if (PromotionExceptional::checkExceptionalPromotion()) {
             if (PromotionExceptional::checkExcTimeOfPromotionIfExpired()) {
                 if (PromotionExceptional::checkExcPriceandReturnIt() == 'no') {
                     return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais aucun prix n'est défini")->withInput();
                 } else {
                     $prix_exc = PromotionExceptional::checkExcPriceandReturnIt();
                 }
             } else {
                 return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais la durée est expirée");
             }
         }
         // promotion advanced check
         $prix_advance = '';
         if (PromotionAdvance::checkAdvancePromotion()) {
             if ($request->nbr_month > 1) {
                 if (PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month) !== false) {
                     $prix_advance = PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month);
                 } else {
                     return redirect()->back()->withErrors("Aucun prix n'est\n                    défini pour cette Promotion de " . $request->nbr_month . ' Mois');
                 }
             }
         }
         $validator = Validator::make([$request->all(), 'nom_enfant' => $request->nom_enfant, 'date_naissance' => $request->date_naissance, 'photo' => $request->photo, 'classe' => $request->classe, 'branche' => $request->branche, 'niveau' => $request->niveau], ['nom_enfant' => 'required', 'date_naissance' => 'required', 'photo' => 'image', 'niveau' => 'integer', 'classe' => 'integer', 'grade' => 'integer'], ['photo.image' => "L'image doit etre de type valide JPEG\\PNG", 'nom_enfant.required' => 'Le Nom de L\'enfant est obligatoire', 'date_naissance.required' => 'La Date de Naissance est Obligatoire', 'classe.integer' => "vous devez choisir une classe", 'niveau.integer' => "vous devez choisir un niveau", 'grade.integer' => "Vous devez chosir un niveau global"]);
         // if the parent already in the database
         if ($validator->passes()) {
             $niveau_global = \Auth::user()->grades()->where('id', $request->grade)->first()->name;
             $child = new Child();
             $child->date_naissance = Carbon::parse($request->date_naissance);
             $child->nom_enfant = $request->nom_enfant;
             $child->sexe = $request->sexe;
             $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
             $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr;
             $child->school_year_id = SchoolYear::getSchoolYearId();
             $child->transport = $request->transport;
             $child->user_id = \Auth::user()->id;
             $image = \Input::file('photo');
             if (!$image && empty($image)) {
                 $filename = '';
             } else {
                 $filename = $image->getClientOriginalName();
                 $path = public_path('uploads/' . $filename);
                 Image::make($image->getRealPath())->resize(313, 300)->save($path);
             }
             $child->photo = $filename;
             $child->family_id = $request->familyid;
             $resp = Family::findOrFail($request->familyid);
             $user = User::where('email', $resp->email_responsable)->first();
             if ($user) {
                 $child->f_id = $user->id;
                 $child->save();
                 if ($child->id) {
                     $ch = Child::find($child->id);
                     if ($niveau_global == 'Lycée') {
                         $ch->branches()->attach([$request->branche]);
                     }
                     if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') {
                         $ch->levels()->attach([$request->niveau]);
                     }
                     /*  if($niveau_global == 'Crèche')
                         {
                             $ch->classrooms()->attach([$request->classe]);
                         }*/
                     $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
                     $cr->children()->attach([$child->id]);
                     $bill = new Bill();
                     $bill->status = 0;
                     if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) {
                         if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                             $bill->reductionPrix = $request->reduction;
                             $bill->reduction = 1;
                             $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                             $bill->reduction = 0;
                             $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                     if (PromotionAdvance::checkAdvancePromotion()) {
                         if ($request->nbr_month >= 3) {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month);
                             $bill->reduction = 1;
                             $bill->reductionPrix = $prix_advance;
                             $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                             $bill->nbrMois = $request->nbr_month;
                         }
                         if ($request->nbr_month == 1) {
                             if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                                 $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                                 $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                                 $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                                 $bill->reductionPrix = $request->reduction;
                                 $bill->reduction = 1;
                                 $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                                 $bill->nbrMois = $request->nbr_month;
                             } else {
                                 $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                                 $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                                 $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                                 $bill->reduction = 0;
                                 $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                                 $bill->nbrMois = $request->nbr_month;
                             }
                         }
                     }
                     if (PromotionExceptional::checkExceptionalPromotion()) {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc);
                         $bill->reductionPrix = $prix_exc;
                         $bill->reduction = 1;
                         $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                         $bill->nbrMois = $request->nbr_month;
                     }
                     $bill->child_id = $child->id;
                     $bill->f_id = $user->id;
                     $bill->user_id = \Auth::user()->id;
                     $bill->save();
                 }
             }
             return redirect()->back()->with('success', "l'élève a bien été ajouté! ");
         } else {
             return redirect()->back()->withErrors($validator);
         }
     }
 }