public function store(Request $request)
 {
     $rules = ['school_year_id' => 'required|exists:school_years,id', 'name' => 'required|min:4|max:255', 'start' => 'required|date', 'end' => 'required|date'];
     $messages = ['name.required' => 'Es necesario asignar un nombre al periodo.', 'name.min' => 'Ingrese un nombre adecuado.', 'start.required' => 'Es necesario definir la fecha de inicio.', 'end.required' => 'Es necesario definir la fecha de fin.'];
     $v = Validator::make($request->all(), $rules, $messages);
     if ($v->fails()) {
         return back()->withErrors($v)->withInput();
     }
     // Custom validations
     if ($request->get('start') > $request->get('end')) {
         $errors['range'] = 'Las fechas son inconsistentes.';
     }
     $year = SchoolYear::find($request->get('school_year_id'));
     if ($request->get('start') < $year->start) {
         $errors['start'] = 'La fecha de inicio debe ser posterior al inicio del año lectivo.';
     }
     if ($request->get('end') > $year->end) {
         $errors['end'] = 'La fecha de fin debe ser anterior al fin del año lectivo.';
     }
     if (isset($errors)) {
         return back()->withErrors($errors)->withInput();
     }
     Period::create($request->all());
     return back()->with('success', 'Periodo lectivo registrado exitosamente.');
 }
 public function create()
 {
     $school_year = SchoolYear::orderBy('id', 'desc')->first();
     $grades = Grade::all();
     $sections = $grades->first()->sections;
     return view('matriculas.matricular')->with(compact(['school_year', 'grades', 'sections']));
 }
 public function store(Request $request)
 {
     $rules = ['name' => 'required|unique:school_years|min:4|max:255', 'start' => 'required|date', 'end' => 'required|date', 'course_handbook_id' => 'required|exists:course_handbooks,id'];
     $messages = ['name.required' => 'Por favor indique un nombre para el año lectivo.', 'name.min' => 'Ingrese un nombre adecuado.', 'start.required' => 'Es necesario definir la fecha de inicio.', 'end.required' => 'Es necesario definir la fecha de fin.'];
     $v = Validator::make($request->all(), $rules, $messages);
     if ($v->fails()) {
         return back()->withErrors($v)->withInput();
     }
     if ($request->get('start') > $request->get('end')) {
         return back()->withErrors(['range' => 'Las fechas son inconsistentes.'])->withInput();
     }
     SchoolYear::create($request->all());
     return back()->with('success', 'Año lectivo registrado exitosamente.');
 }
Ejemplo n.º 4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $aboutfacture = SchoolYear::checkNextMonth();
     PromotionStatus::fillStatusesFirst();
     $client = new Google_Client();
     $client->setClientId('548520090024-i8jmtdmdi5ijvj3mn2sbqe2u3a431gh6.apps.googleusercontent.com');
     $client->setClientSecret('IX-SilXd0ctCrKUX1a5oP9is');
     $client->setRedirectUri('http://laravel.dev:8000/schools/boite');
     $client->addScope('https://mail.google.com');
     $service = new Google_Service_Gmail($client);
     $count = Attendance::whereRaw('EXTRACT(year from start) = ?', [Carbon::now()->year])->whereRaw('EXTRACT(month from start) = ?', [Carbon::now()->month])->whereRaw('EXTRACT(day from start) = ?', [Carbon::now()->day])->where('user_id', \Auth::user()->id)->groupBy('child_id')->get();
     $count = $count->count();
     return view('index')->with(['client' => $client, 'service' => $service, 'count' => $count, 'aboutfacture' => $aboutfacture]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $carbon = Carbon::now('America/Lima');
     // Current year
     $year = $carbon->year;
     // Getting the current school year
     $schoolYear = SchoolYear::all()->last();
     // Calculating the middle date
     $middle = clone $schoolYear->start;
     $middle->addMonths(6);
     // First period of the current school year
     Period::create(['school_year_id' => $schoolYear->id, 'name' => $year . '-I', 'start' => $schoolYear->start, 'end' => $middle]);
     // Last period of the current school year
     Period::create(['school_year_id' => $schoolYear->id, 'name' => $year . '-II', 'start' => $middle->addDay(), 'end' => $schoolYear->end]);
 }
Ejemplo n.º 6
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]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $carbon = Carbon::now('America/Lima');
     $year = $carbon->year;
     $start = clone $carbon;
     $start->firstOfYear();
     $end = clone $carbon;
     $end->lastOfYear();
     $prev_start = clone $start;
     $prev_start->subYear();
     $prev_end = clone $end;
     $prev_end->subYear();
     // A past school year
     SchoolYear::create(['name' => 'Año ' . ($year - 1), 'start' => $prev_start, 'end' => $prev_end, 'course_handbook_id' => 1]);
     // Current school year
     SchoolYear::create(['name' => 'Año ' . $year, 'start' => $start, 'end' => $end, 'course_handbook_id' => 1]);
 }
Ejemplo n.º 8
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(schoolYearsRequest $request)
 {
     $tableau = explode('-', $request->ann_scol);
     $year1 = $tableau[0];
     $year2 = $tableau[1];
     $yearNow = Carbon::now()->year;
     $year_prec = Carbon::now()->year - 1;
     $year_next = Carbon::now()->year + 1;
     if ($year1 > $yearNow && $year2 > $year_next) {
         return redirect()->back()->withErrors("Désolé vous ne pouvez pas ajouter cette année scolaire en ce moment !");
     }
     $ann_scol = $request->ann_scol;
     $trim_semis = $request->TrimSemis;
     $champ1start = Carbon::parse($request->champ1start);
     $champ1end = Carbon::parse($request->champ1end);
     $champ2start = Carbon::parse($request->champ2start);
     $champ2end = Carbon::parse($request->champ2end);
     if (!is_null($request->champ3start) && !is_null($request->champ3end)) {
         $champ3start = Carbon::parse($request->champ3start);
         $champ3end = Carbon::parse($request->champ3end);
     }
     // vérifier l'enchainement semistrielle
     if ($trim_semis == 'Semis') {
         if ($champ1start < $champ1end && $champ1end < $champ2start && $champ2start < $champ2end && $champ1start->diffInMonths($champ2end) >= 8 && $champ1start->year == $year1 && $champ2end->year == $year2) {
         } else {
             return redirect()->back()->withErrors("l'enchainement des dates est incorrect\n                    ou durée totale est moins de 8 mois\n                    ou Correspondance avec l'année scolaire est incorrecte ");
         }
     }
     // vérifier l'enchainement trimistrielle
     if ($trim_semis == 'Trim') {
         if ($champ1start < $champ1end && $champ1end < $champ2start && $champ2start < $champ2end && $champ2end < $champ3start && $champ3start < $champ3end && $champ1start->diffInMonths($champ3end) >= 8 && $champ1start->year == $year1 && $champ3end->year == $year2) {
         } else {
             return redirect()->back()->withErrors("l'enchainement des dates est\n                    incorrect ou durée totale est moins de 8 mois ou\n                     Correspondance avec l'année scolaire est incorrecte");
         }
     }
     // early inscription for Next Year
     if (Carbon::now()->month >= 1 && $year1 == $yearNow && $year2 == $year_next && $champ1start->month == 9 || $champ1start->month == 10) {
         // si trouvé une mise à jour
         $sc_year = SchoolYear::where('user_id', \Auth::user()->id)->where('ann_scol', $ann_scol)->first();
         if ($sc_year) {
             $sc_year->startch1 = $champ1start;
             $sc_year->endch1 = $champ1end;
             $sc_year->startch2 = $champ2start;
             $sc_year->endch2 = $champ2end;
             if ($trim_semis == 'Trim') {
                 $sc_year->startch3 = $champ3start;
                 $sc_year->endch3 = $champ3end;
             } else {
                 $sc_year->startch3 = null;
                 $sc_year->endch3 = null;
             }
             $sc_year->type = $trim_semis;
             $sc_year->current = 0;
             $sc_year->save();
         } else {
             // créer l'année scolaire pour l'année prochaine
             $sc = new SchoolYear();
             $sc->ann_scol = $ann_scol;
             $sc->type = $trim_semis;
             $sc->startch1 = $champ1start;
             $sc->endch1 = $champ1end;
             $sc->startch2 = $champ2start;
             $sc->endch2 = $champ2end;
             $sc->current = 0;
             if ($trim_semis == 'Trim') {
                 $sc->startch3 = $champ3start;
                 $sc->endch3 = $champ3end;
             }
             $sc->user_id = \Auth::user()->id;
             $sc->save();
             Grade::AddGradesAndLevels(\Auth::user()->id, $sc->id);
         }
     }
     if ($year1 == $year_prec && $year2 == $yearNow && Carbon::now()->month <= 6) {
         $sc_year = SchoolYear::where('user_id', \Auth::user()->id)->where('ann_scol', $ann_scol)->first();
         if ($sc_year) {
             $sc_year->startch1 = $champ1start;
             $sc_year->endch1 = $champ1end;
             $sc_year->startch2 = $champ2start;
             $sc_year->endch2 = $champ2end;
             if ($trim_semis == 'Trim') {
                 $sc_year->startch3 = $champ3start;
                 $sc_year->endch3 = $champ3end;
             } else {
                 $sc_year->startch3 = null;
                 $sc_year->endch3 = null;
             }
             $sc_year->type = $trim_semis;
             $sc_year->save();
         } else {
             $sc = new SchoolYear();
             $sc->ann_scol = $ann_scol;
             $sc->type = $trim_semis;
             $sc->startch1 = $champ1start;
             $sc->endch1 = $champ1end;
             $sc->startch2 = $champ2start;
             $sc->endch2 = $champ2end;
             $sc->current = 1;
             if ($trim_semis == 'Trim') {
                 $sc->startch3 = $champ3start;
                 $sc->endch3 = $champ3end;
             }
             $sc->user_id = \Auth::user()->id;
             $sc->save();
             if ($sc->id) {
                 Grade::AddGradesAndLevels(\Auth::user()->id, $sc->id);
             }
             /* if ($sc->id) {
                    $forCurrentYear = SchoolYear::where('user_id', \Auth::user()->id)
                        ->get();
                    foreach ($forCurrentYear as $ok) {
                        $yes = SchoolYear::where('user_id', \Auth::user()->id)
                            ->where('id', '!=', $sc->id)->first();
                        if ($yes) {
                            $yes->current = 0;
                            $yes->save();
                        }
                    }
                }*/
         }
     }
     return redirect()->back()->with('success', 'Bien Enregistrés');
 }
Ejemplo n.º 9
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é! ");
     }
 }
Ejemplo n.º 10
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'));
 }
Ejemplo n.º 11
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'));
 }
Ejemplo n.º 12
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);
         }
     }
 }
Ejemplo n.º 13
0
 public function scopeCurrentYear($query)
 {
     $query->where('school_year_id', SchoolYear::getSchoolYearId());
 }
Ejemplo n.º 14
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'));
 }
Ejemplo n.º 15
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();
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (Carbon::now()->toDateString() == Carbon::now()->startOfMonth()->toDateString()) {
         $users = User::where('type', 'ecole')->get();
         foreach ($users as $user) {
             $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first();
             if ($sc->type == 'Semis' && Carbon::now()->between($sc->startch1, $sc->endch2)) {
                 foreach ($user->children as $child) {
                     foreach ($child->bills as $bill) {
                         $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first();
                         if ($getChild) {
                             $facture = new Bill();
                             $facture->start = $getChild->end->toDateString();
                             $facture->end = $getChild->end->addMonth()->toDateString();
                             $facture->status = 0;
                             $facture->user_id = $getChild->user_id;
                             $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first();
                             $taman = '';
                             $transportStatus = $enfant->transport;
                             foreach ($enfant->levels as $level) {
                                 $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first();
                                 $taman = $getPriceOfLevel->prix;
                             }
                             $transportStatus == 0 ? $facture->somme = $taman : ($facture->somme = $taman + Transport::where('user_id', $getChild->user_id)->first()->somme);
                             $facture->nbrMois = $getChild->nbrMois;
                             $facture->reductionPrix = null;
                             $facture->school_year_id = $getChild->school_year_id;
                             $facture->reduction = 0;
                             $facture->child_id = $getChild->child_id;
                             $facture->f_id = $getChild->f_id;
                             $facture->save();
                             break;
                         }
                     }
                 }
             } elseif ($sc->type == 'Trim' && Carbon::now()->between($sc->startch1, $sc->endch3)) {
                 foreach ($user->children as $child) {
                     foreach ($child->bills as $bill) {
                         $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first();
                         if ($getChild) {
                             $facture = new Bill();
                             $facture->start = $getChild->end->toDateString();
                             $facture->end = $getChild->end->addMonth()->toDateString();
                             $facture->status = 0;
                             $facture->user_id = $getChild->user_id;
                             $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first();
                             $taman = '';
                             $transportStatus = $enfant->transport;
                             foreach ($enfant->levels as $level) {
                                 $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first();
                                 $taman = $getPriceOfLevel->prix;
                             }
                             $transportStatus == 0 ? $facture->somme = $taman : ($facture->somme = $taman + Transport::where('user_id', $getChild->user_id)->first()->somme);
                             $facture->nbrMois = $getChild->nbrMois;
                             $facture->reductionPrix = null;
                             $facture->school_year_id = $getChild->school_year_id;
                             $facture->reduction = 0;
                             $facture->child_id = $getChild->child_id;
                             $facture->f_id = $getChild->f_id;
                             $facture->save();
                             break;
                         }
                     }
                 }
             }
         }
         /*  $enfants =  Child::has('bills')->get();
                 foreach($enfants as $e)
                 {
                     foreach($e->bills as $b)
                     {
                        $d = Bill::where('child_id',$b->child_id)->orderBy('id','desc')->first();
                        $bill = new Bill();
                         $bill->start =$d->end->toDateString();
                         $nextMonth7 =$d->end->addMonth()->toDateString();
                         if(Carbon::parse($nextMonth7)->month == 7)
                         {
                             $bill->end = Carbon::parse($nextMonth7)->addMonths(2)->toDateString();
                         }else{
                             $bill->end = $nextMonth7;
                         }
                         $bill->status = 0;
                         $bill->user_id = $d->user_id;
                         $bill->somme =  $d->somme;
                         $bill->child_id =$d->child_id;
                         $bill->f_id = $d->f_id;
                         $bill->save();
                         break;
         
         
                     }
                 }*/
     }
 }
Ejemplo n.º 17
0
 public function promotion()
 {
     $total = SchoolYear::countTotalYear();
     return view('schools.promotion', compact('total'));
 }