/** * 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é! "); } }
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); } } }
public function price_bills_store(Request $request) { $trans = Transport::where('user_id', \Auth::user()->id)->first(); if ($trans) { $trans->somme = $request->somme; $trans->save(); } else { Transport::create(['somme' => $request->somme, 'user_id' => \Auth::user()->id]); } $niveau_id = $request->niveau; $price = $request->price; $user_id = \Auth::user()->id; $ann_scol = '2015-2016'; $checkPrice = PriceBill::where('user_id', $user_id)->where('niveau', $niveau_id)->where('ann_scol', $ann_scol)->where('school_year_id', $request->school_year)->first(); if ($checkPrice) { $checkPrice->prix = $price; $checkPrice->save(); } else { $priceBill = new PriceBill(); $priceBill->niveau = $niveau_id; $priceBill->prix = $price; $priceBill->ann_scol = $ann_scol; $priceBill->user_id = $user_id; $priceBill->school_year_id = $request->school_year; $priceBill->save(); } return redirect()->back()->with('success', 'Bien enregistré'); }
/** * 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; } }*/ } }