repository = $allowance; parent::__construct(); } /** * Display a list of allowance. * * @return Response */ public function index(AllowanceRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('allowance::allowance.names').' :: '); return $this->theme->of('allowance::admin.allowance.index')->render(); } /** * Display a list of allowance. * * @return Response */ public function getJson(AllowanceRequest $request) { $pageLimit = $request->input('pageLimit'); $allowances = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Payroll\\Allowance\\Repositories\\Presenter\\AllowanceListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $allowances['recordsTotal'] = $allowances['meta']['pagination']['total']; $allowances['recordsFiltered'] = $allowances['meta']['pagination']['total']; $allowances['request'] = $request->all(); return response()->json($allowances, 200); } /** * Display allowance. * * @param Request $request * @param Model $allowance * * @return Response */ public function show(AllowanceRequest $request, Allowance $allowance) { if (!$allowance->exists) { return response()->view('allowance::admin.allowance.new', compact('allowance')); } Form::populate($allowance); return response()->view('allowance::admin.allowance.show', compact('allowance')); } /** * Show the form for creating a new allowance. * * @param Request $request * * @return Response */ public function create(AllowanceRequest $request) { $allowance = $this->repository->newInstance([]); Form::populate($allowance); return response()->view('allowance::admin.allowance.create', compact('allowance')); } /** * Create new allowance. * * @param Request $request * * @return Response */ public function store(AllowanceRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $allowance = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('allowance::allowance.name')]), 'code' => 204, 'redirect' => trans_url('/admin/allowance/allowance/'.$allowance->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show allowance for editing. * * @param Request $request * @param Model $allowance * * @return Response */ public function edit(AllowanceRequest $request, Allowance $allowance) { Form::populate($allowance); return response()->view('allowance::admin.allowance.edit', compact('allowance')); } /** * Update the allowance. * * @param Request $request * @param Model $allowance * * @return Response */ public function update(AllowanceRequest $request, Allowance $allowance) { try { $attributes = $request->all(); $allowance->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('allowance::allowance.name')]), 'code' => 204, 'redirect' => trans_url('/admin/allowance/allowance/'.$allowance->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/allowance/allowance/'.$allowance->getRouteKey()), ], 400); } } /** * Remove the allowance. * * @param Model $allowance * * @return Response */ public function destroy(AllowanceRequest $request, Allowance $allowance) { try { $t = $allowance->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('allowance::allowance.name')]), 'code' => 202, 'redirect' => trans_url('/admin/allowance/allowance/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/allowance/allowance/'.$allowance->getRouteKey()), ], 400); } } }