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