repository = $attendance; parent::__construct(); } /** * Display a list of attendance. * * @return Response */ public function index(AttendanceRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('attendance::attendance.names').' :: '); return $this->theme->of('attendance::admin.attendance.index')->render(); } /** * Display a list of attendance. * * @return Response */ public function getJson(AttendanceRequest $request) { $pageLimit = $request->input('pageLimit'); $attendances = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Payroll\\Attendance\\Repositories\\Presenter\\AttendanceListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $attendances['recordsTotal'] = $attendances['meta']['pagination']['total']; $attendances['recordsFiltered'] = $attendances['meta']['pagination']['total']; $attendances['request'] = $request->all(); return response()->json($attendances, 200); } /** * Display attendance. * * @param Request $request * @param Model $attendance * * @return Response */ public function show(AttendanceRequest $request, Attendance $attendance) { if (!$attendance->exists) { return response()->view('attendance::admin.attendance.new', compact('attendance')); } Form::populate($attendance); return response()->view('attendance::admin.attendance.show', compact('attendance')); } /** * Show the form for creating a new attendance. * * @param Request $request * * @return Response */ public function create(AttendanceRequest $request) { $attendance = $this->repository->newInstance([]); Form::populate($attendance); return response()->view('attendance::admin.attendance.create', compact('attendance')); } /** * Create new attendance. * * @param Request $request * * @return Response */ public function store(AttendanceRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $attendance = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('attendance::attendance.name')]), 'code' => 204, 'redirect' => trans_url('/admin/attendance/attendance/'.$attendance->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show attendance for editing. * * @param Request $request * @param Model $attendance * * @return Response */ public function edit(AttendanceRequest $request, Attendance $attendance) { Form::populate($attendance); return response()->view('attendance::admin.attendance.edit', compact('attendance')); } /** * Update the attendance. * * @param Request $request * @param Model $attendance * * @return Response */ public function update(AttendanceRequest $request, Attendance $attendance) { try { $attributes = $request->all(); $attendance->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('attendance::attendance.name')]), 'code' => 204, 'redirect' => trans_url('/admin/attendance/attendance/'.$attendance->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/attendance/attendance/'.$attendance->getRouteKey()), ], 400); } } /** * Remove the attendance. * * @param Model $attendance * * @return Response */ public function destroy(AttendanceRequest $request, Attendance $attendance) { try { $t = $attendance->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('attendance::attendance.name')]), 'code' => 202, 'redirect' => trans_url('/admin/attendance/attendance/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/attendance/attendance/'.$attendance->getRouteKey()), ], 400); } } }