repository = $costcenter; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Buyer\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(\B2buy\Buyer\Repositories\Presenter\CostcenterPresenter::class) ->$function(); } $costcenters = $this->repository->paginate(); return $this->response->setMetaTitle(trans('buyer::costcenter.names')) ->view('buyer::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 = 'buyer::costcenter.show'; } else { $view = 'buyer::costcenter.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('buyer::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('buyer::costcenter.name')) ->view('buyer::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('buyer::costcenter.name')])) ->code(204) ->status('success') ->url(guard_url('buyer/costcenter/' . $costcenter->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/buyer/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('buyer::costcenter.name')) ->view('buyer::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('buyer::costcenter.name')])) ->code(204) ->status('success') ->url(guard_url('buyer/costcenter/' . $costcenter->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('buyer/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('buyer::costcenter.name')])) ->code(202) ->status('success') ->url(guard_url('buyer/costcenter/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('buyer/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('buyer::costcenter.name')])) ->status("success") ->code(202) ->url(guard_url('buyer/costcenter')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/buyer/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('buyer::costcenter.name')])) ->status("success") ->code(202) ->url(guard_url('/buyer/costcenter')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/buyer/costcenter/')) ->redirect(); } } }