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