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