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