"; if ($employee != null && Employee::where('email', $employee[0])->where('created_by', \Auth::user()->creatorId())->exists()) { $email = $employee[0]; } else { $email_data[] = $employee[0]; } } } $totalattendance = count($attendance) - 1; $errorArray = []; $startTime = Utility::getValByName('company_start_time'); $endTime = Utility::getValByName('company_end_time'); if (!empty($attendanceData)) { $errorArray[] = $attendanceData; } else { foreach ($attendance as $key => $value) { if ($key != 0) { $employeeData = Employee::where('email', $value[0])->where('created_by', \Auth::user()->creatorId())->first(); // $employeeId = 0; if (!empty($employeeData)) { $employeeId = $employeeData->id; $clockIn = $value[2]; $clockOut = $value[3]; if ($clockIn) { $status = "present"; } else { $status = "leave"; } $totalLateSeconds = strtotime($clockIn) - strtotime($startTime); $hours = floor($totalLateSeconds / 3600); $mins = floor($totalLateSeconds / 60 % 60); $secs = floor($totalLateSeconds % 60); $late = sprintf('%02d:%02d:%02d', $hours, $mins, $secs); $totalEarlyLeavingSeconds = strtotime($endTime) - strtotime($clockOut); $hours = floor($totalEarlyLeavingSeconds / 3600); $mins = floor($totalEarlyLeavingSeconds / 60 % 60); $secs = floor($totalEarlyLeavingSeconds % 60); $earlyLeaving = sprintf('%02d:%02d:%02d', $hours, $mins, $secs); if (strtotime($clockOut) > strtotime($endTime)) { //Overtime $totalOvertimeSeconds = strtotime($clockOut) - strtotime($endTime); $hours = floor($totalOvertimeSeconds / 3600); $mins = floor($totalOvertimeSeconds / 60 % 60); $secs = floor($totalOvertimeSeconds % 60); $overtime = sprintf('%02d:%02d:%02d', $hours, $mins, $secs); } else { $overtime = '00:00:00'; } $check = AttendanceEmployee::where('employee_id', $employeeId)->where('date', $value[1])->first(); if ($check) { $check->update([ 'late' => $late, 'early_leaving' => ($earlyLeaving > 0) ? $earlyLeaving : '00:00:00', 'overtime' => $overtime, 'clock_in' => $value[2], 'clock_out' => $value[3], ]); } else { $time_sheet = AttendanceEmployee::create([ 'employee_id' => $employeeId, 'date' => $value[1], 'status' => $status, 'late' => $late, 'early_leaving' => ($earlyLeaving > 0) ? $earlyLeaving : '00:00:00', 'overtime' => $overtime, 'clock_in' => $value[2], 'clock_out' => $value[3], 'created_by' => \Auth::user()->id, ]); } } } else { $email_data = implode(' And ', $email_data); } } if (!empty($email_data)) { return redirect()->back()->with('status', 'This record is not import. ' . '' . $email_data); } else { if (empty($errorArray)) { $data['status'] = 'success'; $data['msg'] = __('Record successfully imported'); } else { $data['status'] = 'error'; $data['msg'] = count($errorArray) . ' ' . __('Record imported fail out of' . ' ' . $totalattendance . ' ' . 'record'); foreach ($errorArray as $errorData) { $errorRecord[] = implode(',', $errorData->toArray()); } \Session::put('errorArray', $errorRecord); } return redirect()->back()->with($data['status'], $data['msg']); } } } }