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