public function testStore()
 {
     Session::start();
     $date = '2015-01-01';
     $time = '20:00';
     $payload = ['date' => $date, 'time' => $time, 'customers' => [$this->customers[0]->id, $this->customers[1]->id], '_token' => csrf_token()];
     $response = $this->call('POST', route('attendance.store', [$this->group->id]), $payload);
     $this->assertRedirectedTo('/auth/login');
     $this->be($this->user);
     $response = $this->call('POST', route('attendance.store', [$this->group->id]), $payload);
     $this->assertRedirectedTo(route('attendance.index', [$this->group->id]));
     $this->assertSessionHas('status');
     $attendance = \App\Attendance::where('group_id', $this->group->id)->where('was_at', sprintf('%s %s', $date, $time))->get();
     $this->assertEquals(2, count($attendance));
 }
 public function traineeHome()
 {
     $id = Auth::user()->id;
     $regId = Registration::where('user_id', '=', Auth::user()->id)->pluck('id');
     $user_id = Auth::user()->id;
     $course_ids = TraineeCourse::where('trainee_id', $user_id)->select('course_id')->get();
     //$course_ids=Info::where('trainee_login_id', $user_id)->get();
     $courseAttendance = [];
     foreach ($course_ids as $course_id) {
         $course_name = $this->course_name_by_course_id($course_id->course_id);
         if (!$course_name->isempty()) {
             $absent = Attendance::where('course_id', $course_id->course_id)->where('trainee_id', $user_id)->where('trainee_attendance', '=', 'A')->count('id');
             $courseAttendance[] = array('course_name' => $course_name, 'absent' => $absent);
         }
     }
     $info = Info::wheretrainee_login_id($user_id)->firstOrFail();
     return view('trainee.trainee', compact('regId', 'courseAttendance', 'info'));
     //dd($regId);
     return view('trainee.trainee', compact('regId'))->with('id', $id);
 }
    public function absence_raison_today()
    {
        if (\Request::ajax()) {
            $status = \Input::get('status');
            $att = Attendance::where('user_id', \Auth::user()->id)->where('title', $status)->whereRaw('EXTRACT(year from start) = ?', [Carbon::now()->year])->whereRaw('EXTRACT(month from start) = ?', [Carbon::now()->month])->whereRaw('EXTRACT(day from start) = ?', [Carbon::now()->day])->orderBy('start', 'desc')->get();
            foreach ($att as $t) {
                if ($t->child->photo) {
                    $photo = asset('uploads/' . $t->child->photo);
                } else {
                    $photo = asset('images/no_avatar.jpg');
                }
                if ($t->title == 'Maladie') {
                    $class = 'label-info';
                    $text = 'Non Justifiée';
                } elseif ($t->title == 'Normal') {
                    $class = 'label-primary';
                    $text = 'Justifiée';
                } else {
                    $class = 'retard';
                    $text = 'Retard';
                }
                echo '  <tr>
                            <td><div class="minimal single-row">
                                    <div class="checkbox_liste">
                                        <input type="checkbox" value="' . $t->id . '"  name="select[]">

                                    </div>
                                </div></td>
                            <td><img class="avatar"
                                     src="' . $photo . '"></td>
                            <td>' . ucwords($t->child->nom_enfant) . '</td>
                            <td>' . Carbon::parse($t->start)->format('d-m-Y') . '</td>


                                <td><span class="label ' . $class . ' label-mini">' . $text . '</span></td>

                            <td>
                                <a href="' . action('StatisticsController@delete_att', [$t]) . '" class="actions_icons delete-att">
                                    <i class="fa fa-trash-o liste_icons"></i></a>
                              <!--  <a class="archive-att" href="' . action('StatisticsController@archive_att', [$t]) . '"><i class="fa fa-archive liste_icons"></i>
                                </a>-->
                            </td>

                            <td><a href="' . action('AttendancesController@show', [$t->child->id]) . '"><div  class="btn_details">Détails</div></a></td>
                        </tr>';
            }
        }
    }
 public function updateAjaxEntry()
 {
     $field = \Input::get('field');
     $dateF = Carbon::parse(\Input::get('date'));
     $id = \Input::get('id');
     $input = \Input::get('entry');
     $entry = Labor::find($id)->attendance()->where('att_date', $dateF->format('Y-m-d H:i:s'))->first();
     $att_date = Attendance::where('att_date', $dateF->format('Y-m-d H:i:s'))->first();
     $result = 2;
     if (is_null($att_date)) {
         if ($dateF > Carbon::today()) {
             //return an error
             $response = ['result' => 5, 'field' => $field, 'date' => $dateF->format('Y-m-d'), 'en' => $id, 'entry' => $input];
             echo json_encode($response);
             die;
         } else {
             //initialize the date
             $date_init = new Attendance();
             $date_init->att_date = $dateF;
             $holiday = 0;
             if ($dateF->format('l') == 'Friday' || Holiday::where('holidate', $dateF)->first() != null) {
                 $holiday = 1;
             }
             $date_init->holiday = $holiday;
             $date_init->save();
         }
     }
     if (is_null($entry)) {
         //initialize entry
         $att_date = Attendance::where('att_date', $dateF->format('Y-m-d H:i:s'))->first();
         $att_date->labor()->attach($id);
         $att_entry = $att_date->labor()->find($id);
         $att_entry->pivot->attended = 0;
         $att_entry->pivot->ot = 0;
         $att_entry->pivot->bot = 0;
         $att_entry->pivot->site = '—';
         $att_entry->pivot->locked = 'true';
         $att_entry->pivot->save();
     }
     $entry = Labor::find($id)->attendance()->where('att_date', $dateF->format('Y-m-d H:i:s'))->first();
     if ($field == 'attended') {
         $entry->pivot->attended = $input;
         if ($input == '0') {
             $input = '—';
             $entry->pivot->ot = 0;
             $entry->pivot->bot = 0;
             $result = 0;
         }
     } elseif ($field == 'ot') {
         if ($input != "") {
             if ($entry->holiday == 1) {
                 $ot = intval($input) * 1.2;
             } else {
                 $ot = intval($input);
             }
         } else {
             $ot = 0;
         }
         $entry->pivot->ot = $ot;
     } elseif ($field == 'bot') {
         $bot = $input == "" ? 0 : $input;
         $entry->pivot->bot = $bot;
     } elseif ($field == 'site') {
         if ($input == '') {
             $entry->pivot->site = '—';
             $result = 3;
         } else {
             $entry->pivot->site = $input;
             $result = 6;
         }
     }
     if (isset($ot) && $ot != 0 || isset($bot) && $bot != 0) {
         $entry->pivot->attended = 1;
         $result = 1;
     }
     $entry->pivot->save();
     $response = ['result' => $result, 'field' => $field, 'date' => $dateF->format('Y-m-d'), 'en' => $id, 'entry' => $input];
     echo json_encode($response);
     die;
 }