/** * @Post("time/attendance/employee-records") * * @author Bertrand Kintanar */ public function show() { $work_date = Input::get('work_date'); $start_date = Carbon::parse($work_date); $end_date = Carbon::parse($work_date)->endOfMonth(); $period = new DatePeriod($start_date, new DateInterval('P1D'), $end_date); $month = []; foreach ($period as $row) { $attendance = Attendance::where('work_date', '>=', $row->toDateString())->where('work_date', '<=', $row->toDateString())->whereEmployeeId(Input::get('employee_id'))->first(); if ($attendance == null) { $month[$row->toDateString()] = null; continue; } $month[$row->toDateString()] = $attendance; } $this->data['employee_id'] = Input::get('employee_id'); $this->data['work_date'] = $work_date; $this->data['attendance'] = $month; $this->data['pageTitle'] = 'Employee Records'; return $this->template('pages.time.attendance.employee-records'); }
/** * Execute the console command. * * @author Bertrand Kintanar */ public function handle() { $employee_ids = [2, 3, 4, 5, 6, 7, 8, 10, 11, 19]; foreach ($employee_ids as $employee_id) { $start = Carbon::parse('2015-01-01'); $end = Carbon::parse('2015-01-31'); while ($start <= $end) { $employee = Employee::whereId($employee_id)->first(); $timelog = $employee->getTimeLog($start->toDateString()); $next_day = $employee->getTimeLog(Carbon::parse($start)->addDay()->toDateString()); if ($next_day['in_time'] == null and $next_day['out_time'] == null or $timelog['in_time'] == null and $timelog['out_time'] == null) { $start = $start->addDay(1); continue; } $data = ['employee_id' => $employee->id, 'work_date' => $start->toDateString(), 'in_time' => $timelog['in_time'], 'out_time' => $timelog['out_time']]; $attendance = Attendance::updateOrCreate($data); $this->info($attendance); Log::info($attendance); $start = $start->addDay(1); } } }