public function archive($year1 = null, $year2 = null) { if (is_null($year1) && is_null($year2)) { $yearNow = Carbon::now()->year; $yearNext = Carbon::now()->year + 1; $children = \Auth::user()->children()->where('school_year_id', '!=', SchoolYear::getSchoolYearId())->orderBy('id', 'desc')->paginate(10); return view('statistics.archive', compact('children')); } else { $annee = $year1 . '-' . $year2; $schoolYear = SchoolYear::where('user_id', \Auth::user()->id)->where('ann_scol', $annee)->where('current', 0)->first(); if ($schoolYear) { $children = \Auth::user()->children()->where('school_year_id', $schoolYear->id)->paginate(10); return view('statistics.archive', compact("children", "year1", "year2")); } else { return redirect()->back(); } } }
/** * 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'); }
/** * 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; } }*/ } }