protected function save() { $this->file->invoice->addValidation(new ValidateFileNotNullOrEmpty()); $this->post->invoice_id->addValidation(new ValidateInputNotNullOrEmpty()); $this->post->due_date->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputDate()]); $this->post->amount->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputFloat()]); if (!$this->hasErrors()) { $invoice = new OrganisationInvoice(); if ($this->file->invoice instanceof InputFile) { $path = $this->uploadS3($this->file->invoice->tmpname, $this->input('invoice_id') . '.' . File::getExtension($this->file->invoice->name)); $invoice->path = $path; } $invoice->organisation_id = $this->organisation->id; $invoice->invoice_id = $this->input('invoice_id'); $invoice->due_date = Date::toDate(strtotime($this->input('due_date'))); $invoice->amount_total = $this->input('amount'); $invoice->payed = $this->input('payed'); $invoice->save(); if (!$invoice->payed) { $this->sendCustomerMail($invoice); } $this->setMessage(lang('Invoice has been created'), 'success'); response()->refresh(); } }
public function __construct() { parent::__construct(); $this->prependSiteTitle(lang('Invoices')); $this->invoices = OrganisationInvoice::getByOrganisationId($this->activeOrganisation->id); }