public function reportByDate(Request $request) { $start_date = Input::get('start_date'); $end_date = Input::get('end_date'); $counselors = array(); if (Input::has('start_date') && Input::has('start_date')) { $checkings = DB::table('checking')->whereBetween('day_event', [$start_date, $end_date])->get(); foreach ($checkings as $i => $checking) { $accreditation = DB::table('accreditation')->where('id', $checking->accreditation_id)->first(); $counselor = Counselor::find($accreditation->counselor_id); array_push($counselors, $counselor); } } $items = collect($counselors); $total = count($counselors); $page = Input::get('page', 1); $perPage = 10; $counselors = new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page); return view('reports.index', compact('counselors', 'start_date', 'end_date', 'total')); }
public function checking(Request $request) { $checking = Request::all(); $accreditation = DB::table('accreditation')->where('counselor_id', $checking['counselor'])->first(); $counselor = Counselor::find($checking['counselor']); $checking_db = DB::table('checking')->whereAccreditationIdAndDayEvent($accreditation->id, $checking['day_event'])->get(); if (!empty($checking_db)) { Session::flash('error', $counselor->name . " Já realizou o checking no dia " . date("d/m/Y", strtotime($checking['day_event']))); return redirect()->back(); } elseif (empty($checking_db)) { DB::table('checking')->insert(['accreditation_id' => $accreditation->id, 'confirmed' => 1, 'day_event' => $checking['day_event'], 'created_at' => new \DateTime('NOW'), 'updated_at' => new \DateTime('NOW')]); DB::table('counselors')->where('id', $counselor->id)->update(['function' => $checking['function']]); Session::flash('success', 'Checking realizado com sucesso.'); return redirect('counselors'); } Session::flash('error', 'Codigo de barra inválido.'); return redirect()->back(); }