/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { //date_default_timezone_set("Asia/Makassar"); $outtime = date('H:i:s', strtotime('17:00:00')); $dt = date('Y-m-d'); $currenttime = date('H:i:s'); $ipAddress = ''; $lokasi = ''; // IP CLIENT if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && '' !== trim($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ipAddress = trim($_SERVER['HTTP_X_FORWARDED_FOR']); } else { if (isset($_SERVER['REMOTE_ADDR']) && '' !== trim($_SERVER['REMOTE_ADDR'])) { $ipAddress = trim($_SERVER['REMOTE_ADDR']); } } $absen = new Absen(); //pke DB Absen // CEK LOKASI DARI IP if (stripos($ipAddress, '10.28.254.') !== false) { $lokasi = 'PESIAPAN'; $absen->setConnection('mysql'); } elseif (stripos($ipAddress, '10.28.31.') !== false) { $lokasi = 'LOMBOK'; $absen->setConnection('mysqlabsen'); } elseif (stripos($ipAddress, '192.168.43.') !== false) { $lokasi = 'BATAM'; $absen->setConnection('mysql'); } else { $lokasi = 'DEV'; $absen->setConnection('mysql'); } //Cek NIK exist $user = User::where('nik', '=', $request->nik)->first(); if (is_null($user)) { $request->session()->flash('alert-danger', 'Periksa NIK yang Anda input'); } else { $absen->nik = $request->nik; $absen->tanggal = $dt; $absen->time = $currenttime; $absen->addip = $ipAddress; $absen->lokasi = $lokasi; if ($currenttime < $outtime) { $absen->tipe = "IN"; } else { $absen->tipe = "OUT"; } try { $absen->save(); $request->session()->flash('alert-success', 'Data absen dengan NIK : ' . $request->nik . ' tersimpan - ' . $currenttime . ' '); } catch (\Illuminate\Database\QueryException $e) { $request->session()->flash('alert-warning', 'Database offline/Data absen dengan NIK : ' . $request->nik . ' sudah ada '); } } return redirect('/absen'); }
public function getDataAbsen(Request $request) { $user = Auth::user()->nik; //$getstart = $request->start; //$getend = $request->end; $data = Absen::select('nik', 'tipe', 'tanggal', 'time', 'lokasi', 'addip')->whereRaw('month(tanggal)=month(curdate()) AND year(tanggal)=year(curdate())')->where('nik', '=', "{$user}")->get(); return response()->json($data); }