/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\FormValidationChildFamilyRequest $request) { // famille for family profile $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->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->nom_enfant = ucfirst($request->nom_enfant); $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now()); $child->user_id = \Auth::user()->id; $image = Input::file('photo'); $filename = $image->getClientOriginalName(); $path = public_path('uploads/' . $filename); if (Image::make($image->getRealPath())->resize(313, 300)->save($path)) { $child->photo = $filename; $child->family_id = $family->id; $child->save(); if ($child->id) { $bill = new Bill(); $bill->start = Carbon::now()->toDateString(); $bill->end = Carbon::now()->addMonth()->toDateString(); $bill->status = 0; if ($request->transport == 1) { if (Transport::where('user_id', \Auth::user()->id)->exists()) { $transport_somme = Transport::where('user_id', \Auth::user()->id)->first()->somme; $bill_somme = CategoryBill::getYear(Carbon::parse($request->date_naissance)); $bill->somme = $transport_somme + $bill_somme; } else { $bill->somme = CategoryBill::getYear(Carbon::parse($request->date_naissance)); } } else { $bill->somme = CategoryBill::getYear(Carbon::parse($request->date_naissance)); } $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, str_random(6))); } } } return redirect()->back()->with('success', "l'enfant et les parents ont bien été ajoutés! "); }
/** * 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é! "); } }
/** * Execute the console command. * * @return mixed */ public function fire() { // $file = fopen("/home/daniel/Downloads/new_file.csv", "r"); while (!feof($file)) { print_r(fgetcsv($file)); $row = fgetcsv($file); $family_name = $row[1]; $user_name = $row[2]; $church_id = 1; $church = Church::find($church_id); // $zone_hash = {}; // $zone_hash["0"] = $church->zones()->where("name","=","Zone 0")->first()->id; // $zone_hash["1"] = $church->zones()->where("name","=","Zone 1")->first()->id; // $zone_hash["2"] = $church->zones()->where("name","=","Zone 2")->first()->id; // $zone_hash["3"] = $church->zones()->where("name","=","Zone 3")->first()->id; // $zone_hash["4"] = $church->zones()->where("name","=","Zone 4")->first()->id; // $zone_hash["5"] = $church->zones()->where("name","=","Zone 5")->first()->id; // $no_zone = $church->zones()->where("name","=","No Zone")->first()->id; $user = App\User::where("name", "=", $user_name)->where("church_id", "=", $church_id)->first(); $family = App\Family::where("name", "=", $family_name)->first(); if ($user) { if ($family) { $family_id = $family->id; if ($family_id == $user->family_id) { } else { $user->family_id = $family_id; $user->save(); } } else { $new_family = new Family(); $new_family->name = $row[1]; $new_family->save(); User::whereIn("id", $user->id)->update(["family_id" => $new_family->id]); } } else { $new_user = new User(); $new_user->name = $row[2]; $new_user->dob = $row[4]; $new_user->weddingDate = $row[5]; $new_user->baptism_taken = trim($row[6]) == "YES" ? true : false; $new_user->annointing_taken = trim($row[7]) == "YES" ? true : false; $new_user->phone_number = $row[8]; $new_user->email = $row[9]; $new_user->member_type = trim($row[10]) == "YES" ? 0 : 2; $new_user->address = $row[11] + $row[12] + $row[13] + $row[14]; switch (trim($row[15])) { case "0": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 0")->first()->id; break; case "1": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 1")->first()->id; break; case "2": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 2")->first()->id; break; case "3": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 3")->first()->id; break; case "4": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 4")->first()->id; break; case "5": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 5")->first()->id; break; default: $new_user->zone_id = $church->zones()->where("name", "=", "No Zone")->first()->id; } $new_user->church_id = $church_id; if ($family) { $family_id = $family->id; $new_user->family_id = $family_id; $new_user->save(); } else { $new_family = new Family(); $new_family->name = $row[1]; $new_family->save(); $new_user->family_id = $new_family->id; $new_user->save(); } } } fclose($file); }