repository = $timesheet; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Hrm\Timesheet\Repositories\Criteria\TimesheetResourceCriteria::class); } /** * Display a list of timesheet. * * @return Response */ public function index(TimesheetRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Hrm\Timesheet\Repositories\Presenter\TimesheetPresenter::class) ->$function(); } $timesheets = $this->repository->paginate(); return $this->response->setMetaTitle(trans('timesheet::timesheet.names')) ->view('timesheet::timesheet.index', true) ->data(compact('timesheets', 'view')) ->output(); } /** * Display timesheet. * * @param Request $request * @param Model $timesheet * * @return Response */ public function show(TimesheetRequest $request, Timesheet $timesheet) { if ($timesheet->exists) { $view = 'timesheet::timesheet.show'; } else { $view = 'timesheet::timesheet.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('timesheet::timesheet.name')) ->data(compact('timesheet')) ->view($view, true) ->output(); } /** * Show the form for creating a new timesheet. * * @param Request $request * * @return Response */ public function create(TimesheetRequest $request) { $timesheet = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('timesheet::timesheet.name')) ->view('timesheet::timesheet.create', true) ->data(compact('timesheet')) ->output(); } /** * Create new timesheet. * * @param Request $request * * @return Response */ public function store(TimesheetRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $timesheet = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('timesheet::timesheet.name')])) ->code(204) ->status('success') ->url(guard_url('timesheet/timesheet/' . $timesheet->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/timesheet/timesheet')) ->redirect(); } } /** * Show timesheet for editing. * * @param Request $request * @param Model $timesheet * * @return Response */ public function edit(TimesheetRequest $request, Timesheet $timesheet) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('timesheet::timesheet.name')) ->view('timesheet::timesheet.edit', true) ->data(compact('timesheet')) ->output(); } /** * Update the timesheet. * * @param Request $request * @param Model $timesheet * * @return Response */ public function update(TimesheetRequest $request, Timesheet $timesheet) { try { $attributes = $request->all(); $timesheet->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('timesheet::timesheet.name')])) ->code(204) ->status('success') ->url(guard_url('timesheet/timesheet/' . $timesheet->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('timesheet/timesheet/' . $timesheet->getRouteKey())) ->redirect(); } } /** * Remove the timesheet. * * @param Model $timesheet * * @return Response */ public function destroy(TimesheetRequest $request, Timesheet $timesheet) { try { $timesheet->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('timesheet::timesheet.name')])) ->code(202) ->status('success') ->url(guard_url('timesheet/timesheet/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('timesheet/timesheet/' . $timesheet->getRouteKey())) ->redirect(); } } /** * Remove multiple timesheet. * * @param Model $timesheet * * @return Response */ public function delete(TimesheetRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('timesheet::timesheet.name')])) ->status("success") ->code(202) ->url(guard_url('timesheet/timesheet')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/timesheet/timesheet')) ->redirect(); } } /** * Restore deleted timesheets. * * @param Model $timesheet * * @return Response */ public function restore(TimesheetRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('timesheet::timesheet.name')])) ->status("success") ->code(202) ->url(guard_url('/timesheet/timesheet')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/timesheet/timesheet/')) ->redirect(); } } }