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