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