/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $classroom = new Classroom();
     $data = $request->all();
     $data["schedule_date_from"] = date("Y-m-d H:i:s", strtotime($data["schedule_date_from"]));
     $data["schedule_date_to"] = date("Y-m-d H:i:s", strtotime($data["schedule_date_to"]));
     $data["rel_instructor_id"] = Auth::user()->id;
     $classroom->fill($data);
     $classroom->save();
     return redirect('classrooms');
 }
 public function obtainClassroom(Request $request)
 {
     if ($request->ajax()) {
         $block = Input::get("block");
         $query = Classroom::select()->where('block_id', '=', $block)->get();
         return $query;
     }
     return 'none';
 }
Exemple #3
0
 function room($roomId)
 {
     $data['system'] = $this->system;
     $room = Classroom::findOrFail($roomId);
     $data['room_id'] = $roomId;
     $data['room_name'] = $room->legacycode;
     $data['location'] = $room->location;
     $data['days'] = Day::where('id', '!=', 8)->get();
     $data['times'] = Time::all();
     $schedCollection = new SchedCollection();
     $data['table_day'] = $schedCollection->getSchedRoom($roomId, $this->system);
     return view('edp.room_sched', $data);
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     if (DB::connection() instanceof \Illuminate\Database\SQLiteConnection) {
         DB::statement(DB::raw('PRAGMA foreign_keys=1'));
     }
     Validator::extend('overlap_room', function ($attribute, $value, $parameters, $validator) {
         $time = strtotime($value);
         $time = date('G:i:s', $time);
         $overlap = Classroom::select('classrooms.*')->Join('rooms', 'classrooms.room_id', '=', 'rooms.id')->where([['classrooms.from', '<=', $time], ['classrooms.to', '>=', $time], ['classrooms.day', Input::get('day')], ['rooms.name', Input::get('room')]])->get();
         $from = strtotime(Input::get('from'));
         $from = date('G:i:s', $from);
         //convert to 24 hr format
         $to = strtotime(Input::get('to'));
         $to = date('G:i:s', $to);
         //convert to 24 hr format
         $overlapBetween = Classroom::select('classrooms.*')->Join('rooms', 'classrooms.room_id', '=', 'rooms.id')->where([['classrooms.day', Input::get('day')], ['rooms.name', Input::get('room')]])->whereBetween('classrooms.from', [$from, $to])->get();
         if ($overlap->count() || $overlapBetween->count()) {
             return false;
         }
         return true;
     });
     Validator::extend('overlap_course', function ($attribute, $value, $parameters, $validator) {
         $time = strtotime($value);
         $time = date('G:i:s', $time);
         $overlap = Classroom::select('classrooms.*')->Join('courses', 'classrooms.course_code', '=', 'courses.code')->where([['classrooms.from', '<=', $time], ['classrooms.to', '>=', $time], ['classrooms.day', Input::get('day')], ['courses.name', Input::get('course_name')]])->get();
         $from = strtotime(Input::get('from'));
         $to = strtotime(Input::get('to'));
         $from = date('G:i:s', $from);
         //convert to 24 hr format
         $to = date('G:i:s', $to);
         //convert to 24 hr format
         $overlapBetween = Classroom::select('classrooms.*')->Join('courses', 'classrooms.course_code', '=', 'courses.code')->where([['classrooms.day', Input::get('day')], ['courses.name', Input::get('course_name')]])->whereBetween('classrooms.from', [$from, $to])->get();
         if ($overlap->count() || $overlapBetween->count()) {
             return false;
         }
         return true;
     });
     Validator::extend('duration_check', function ($attribute, $value, $parameters, $validator) {
         $from = strtotime(Input::get('from'));
         $to = strtotime(Input::get('to'));
         $duration = round(abs($to - $from) / 60, 2);
         //time difference=(to-from)minute
         if ($duration >= 50) {
             return true;
         } else {
             return false;
         }
     });
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $classRooms = DB::select(DB::raw("select classrooms.id,classrooms.block from classrooms"));
     $array = [];
     foreach ($classRooms as $classRoom) {
         $array[] = Block::select()->where('name', '=', $classRoom->block)->get()->first()->id;
     }
     Schema::table('classrooms', function ($table) {
         $table->dropColumn('block');
         $table->integer('block_id')->unsigned()->nullable();
         $table->foreign('block_id')->references('id')->on('blocks');
     });
     $index = 0;
     $classRoom = Classroom::all();
     foreach ($classRoom as $value) {
         $value->block_id = $array[$index];
         $value->save();
         $index++;
     }
 }
 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'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Request $request, $id)
 {
     $item = Classroom::find($id);
     if ($request->ajax()) {
         $list = Input::get('id');
         return $this->edit_ajax($list, $item);
     }
     if ($item == null) {
         return Redirect::to(URL::to('datatables', ['salones', 'see']))->with('error', 'id-nn');
     }
     $item->location = explode(' - ', $item->location)[1];
     return view('classroom.createdit', compact('item'));
 }
Exemple #8
0
 public function trierparsalle()
 {
     if (\Request::ajax()) {
         $room_id = \Input::get('room_id');
         $plans = Timesheet::where('user_id', \Auth::user()->id)->CurrentYear()->where('matter_id', '!=', 0)->get();
         foreach ($plans as $plan) {
             $salle = Timesheet::where("classroom_id", $plan->classroom_id)->where("time", $plan->time)->where("user_id", \Auth::user()->id)->where("color", "#525252")->where("dayname", $plan->dayname)->CurrentYear()->first();
             if ($salle && $salle->room_id == $room_id) {
                 echo '<tr>';
                 echo '    <td> ' . Classroom::where('id', $plan->classroom_id)->CurrentYear()->first()->nom_classe . '</td>';
                 echo '  <td>
                                 ' . Matter::where('id', $plan->matter_id)->first()->nom_matiere . '
                             </td>';
                 echo '   <td>';
                 foreach (Matter::where('id', $plan->matter_id)->first()->lesteachers->unique() as $item) {
                     echo $item->nom_teacher;
                 }
                 echo '</td>';
                 echo '<td>';
                 echo $plan->dayname;
                 echo '</td>';
                 echo '<td>';
                 echo substr(Carbon::parse($plan->time)->toTimeString(), 0, -3);
                 echo '</td>';
                 echo '<td>';
                 $salle = Timesheet::where("classroom_id", $plan->classroom_id)->where("time", $plan->time)->where("user_id", \Auth::user()->id)->where("color", "#525252")->CurrentYear()->where("dayname", $plan->dayname)->first();
                 if ($salle) {
                     echo \Auth::user()->rooms()->where('id', $salle->room_id)->first()->nom_salle;
                 }
                 echo '</td>';
                 echo '<td>';
                 $classroom = Classroom::where('id', $plan->classroom_id)->CurrentYear()->first();
                 foreach ($classroom->lesNiveaux as $niveau) {
                     echo $niveau->niveau;
                 }
                 foreach ($classroom->levels as $niveau) {
                     echo $niveau->niveau;
                 }
                 echo '</td>';
                 echo '<td>';
                 $classroom = Classroom::where('id', $plan->classroom_id)->CurrentYear()->first();
                 if ($classroom->branches->isEmpty()) {
                     echo '--';
                 } else {
                     foreach ($classroom->branches as $br) {
                         echo $br->nom_branche;
                     }
                 }
                 echo '</td>';
                 echo ' </tr>';
             }
         }
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $classroom = Classroom::findOrFail($id);
     $classroom->delete();
     return redirect()->route('classrooms.index')->with('message', 'Item deleted successfully.');
 }
 /**
  * Get room schedule for the selected room & day
  * @param Request $request
  */
 public function getRoomSchedule(Request $request)
 {
     if ($request->ajax()) {
         $classrooms = Classroom::select('classrooms.course_code', 'classrooms.from', 'classrooms.to')->Join('rooms', 'classrooms.room_id', '=', 'rooms.id')->where([['classrooms.day', $request->input('day')], ['rooms.name', $request->input('room_name')]])->orderBy('classrooms.from')->get();
         foreach ($classrooms as $classroom) {
             $classroom->from = date('h:i A', strtotime($classroom->from));
             $classroom->to = date('h:i A', strtotime($classroom->to));
         }
         return response($classrooms);
         //            return response()->json(['message' => 'Successfully added to cart']);
     }
 }
 public function getBranchWhenClassid()
 {
     if (\Request::ajax()) {
         $classe_id = \Input::get('classe_id');
         $classe = Classroom::where('id', $classe_id)->first();
         foreach ($classe->branches->unique() as $branch) {
             echo '<option value="' . $branch->id . '">' . $branch->nom_branche . '</option>';
         }
     }
 }
    public function trierparbranche()
    {
        if (\Request::ajax()) {
            $br = \Input::get('branche');
            $branches = Classroom::where('user_id', \Auth::user()->id)->where('branche', $br)->get();
            foreach ($branches as $ts) {
                echo '   <tr>
                            <td><div class="minimal single-row">
                                    <div class="checkbox_liste ">
                                        <input type="checkbox"  value="' . $ts->id . '" name="select[]">

                                    </div>
                                </div></td>
                            <td>' . $ts->nom_classe . '</td>
                            <td>' . $ts->branche . '</td>
                            <td>
                                <a href="' . action('TimesheetsController@delete', [$ts]) . '" class="actions_icons delete-ts">
                                    <i class="fa fa-trash-o liste_icons"></i></a>
                                <a href="#"><i class="fa fa-archive liste_icons"></i>
                                </a>
                            </td>
                            <td><a href="' . action('TimesheetsController@edit', [$ts]) . '">
                                    <div  class="btn_details">Détails</div></a></td>

                        </tr>';
            }
        }
    }
 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 exportPdf($ids = null)
 {
     $ids = explode(',', substr($ids, 0, -1));
     $ids = array_unique($ids);
     $model = Classroom::whereIn('id', $ids)->where('user_id', \Auth::user()->id)->get(['nom_classe', 'code_classe', 'capacite_classe', 'niveau', 'branche']);
     Excel::create('La liste des Classes', function ($excel) use($model, $ids) {
         $excel->sheet('La liste des Classes', function ($sheet) use($model, $ids) {
             foreach ($model as $item) {
                 if ($item->niveau) {
                     $item->niveau = \Auth::user()->leslevels()->where('id', $item->niveau)->first()->niveau;
                 } else {
                     $item->niveau = '--';
                 }
                 if ($item->branche) {
                     $item->branche = \Auth::user()->branches()->where('id', $item->branche)->first()->nom_branche;
                 } else {
                     $item->branche = '--';
                 }
             }
             $sheet->setWidth('A', 15);
             $sheet->setWidth('B', 15);
             $sheet->setWidth('C', 15);
             $sheet->setWidth('D', 15);
             $sheet->setWidth('E', 15);
             $sheet->fromModel($model);
             $sheet->setAllBorders('thin');
             $sheet->setFontFamily('OpenSans');
             $sheet->setFontSize(13);
             $sheet->setFontBold(false);
             $sheet->setAllBorders('thin');
             for ($i = 1; $i <= count($ids) + 1; $i++) {
                 $sheet->setHeight($i, 25);
                 $sheet->row($i, function ($rows) {
                     $rows->setFontColor('#556b7b');
                     $rows->setAlignment('center');
                 });
                 $sheet->cells('A' . $i . ':' . 'E' . $i, function ($cells) {
                     $cells->setValignment('middle');
                     $cells->setFontColor('#556b7b');
                     $cells->setFont(array('family' => 'OpenSans', 'size' => '13', 'bold' => false));
                 });
             }
             // normal header
             $sheet->cells('A1:E1', function ($cells) {
                 $cells->setBackground('#e9f1f3');
                 $cells->setFontColor('#556b7b');
                 $cells->setFont(array('family' => 'OpenSans', 'size' => '15', 'bold' => true));
             });
             $sheet->row(1, array('Nom de la Classe', 'Code de la Classe', 'Capacité de la Classe', 'Niveau', 'Branche'));
         });
     })->export('pdf');
 }
 public function returnClassrooms()
 {
     $blocks = explode(",", Input::get("data"));
     foreach ($blocks as $key => $value) {
         $blocks[$key] = 'name = "' . $value . '"';
     }
     $idBlock = Block::select()->whereRaw(implode(' or ', $blocks))->lists("id");
     $classRooms = Classroom::select()->whereIn('block_id', $idBlock)->orderBy('location')->get();
     return $classRooms;
 }
 public function destroy($id)
 {
     $classrooms = Classroom::find($id);
     $classrooms->delete();
     return response()->json(['id' => $id]);
 }
 /**
  * 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()->where('school_year_id', $request->id_ann_scol)->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 = $request->id_ann_scol;
         $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 = $request->id_ann_scol;
             $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($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->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($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     }
                 }
                 if (PromotionAdvance::checkAdvancePromotion()) {
                     if ($request->nbr_month >= 3) {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                         $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($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->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($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                 }
                 if (PromotionExceptional::checkExceptionalPromotion()) {
                     $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                     $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                     $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 = $request->id_ann_scol;
         $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($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     } else {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     }
                 }
                 if (PromotionAdvance::checkAdvancePromotion()) {
                     if ($request->nbr_month >= 3) {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                         $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($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                 }
                 if (PromotionExceptional::checkExceptionalPromotion()) {
                     $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                     $bill->end = SchoolYear::find($request->id_ann_scol)->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 = $request->id_ann_scol;
                     $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é! ");
     }
 }
Exemple #18
0
                            <td>
                                <?php 
$classroom = \App\Classroom::where('id', $plan->classroom_id)->first();
foreach ($classroom->lesNiveaux as $niveau) {
    echo $niveau->niveau;
}
foreach ($classroom->levels as $niveau) {
    echo $niveau->niveau;
}
?>

                            </td>
                            <td>
                                <?php 
$classroom = \App\Classroom::where('id', $plan->classroom_id)->first();
if ($classroom->branches->isEmpty()) {
    echo '--';
} else {
    foreach ($classroom->branches as $br) {
        if ($br->nom_branche) {
            echo $br->nom_branche;
        } else {
            echo '--';
        }
    }
}
?>
                            </td>
                        </tr>
                        @endif
    public function getmatieres()
    {
        if (\Request::ajax()) {
            $value = \Input::get('value');
            $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $value)->first();
            foreach ($cr->matters as $m) {
                echo '   <div class="form_champ">
                    <label for="cname" class="control-label col-lg-3">' . $m->nom_matiere . '</label>
                    <input type="hidden" value="' . $m->id . '" name="matiere[]">
                    <div class="form_ajout">
                        <select  name="teacher[]" class="form_ajout_input prof">
                        ';
                foreach ($m->teachers as $t) {
                    echo '<option value="' . $t->id . ',' . $m->id . '">' . $t->nom_teacher . '</option>';
                }
                echo '</select>

                    </div>
                </div>';
            }
        }
    }