diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 3d28584b02..74a48d13dd 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -247,6 +247,8 @@ class Invoice extends BaseModel public const STATUS_UNPAID = -2; //status < 4 || < 3 && !is_deleted && !trashed() + public const STATUS_REPLACED = 7; // handle the case where the invoice is replaced by another invoice. + public function toSearchableArray() { $locale = $this->company->locale(); diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 714fdea6bd..2d56cd823c 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -244,10 +244,13 @@ class InvoiceService public function markDeleted() { - // $this->removeUnpaidGatewayFees(); $this->invoice = (new MarkInvoiceDeleted($this->invoice))->run(); + if($this->invoice->company->verifactuEnabled()) { + $this->deleteVerifactu(); + } + return $this; } @@ -674,8 +677,16 @@ class InvoiceService } - //@todo - verifactu - public function sendVerifactu() + + /** + * sendVerifactu + * @todo - send the invoice to AEAT + * ONLY send when the transaction is ES => ES + * Ensure we run all sending syncronously to ensure chronology + * + * @return self + */ + public function sendVerifactu(): self { // if($this->invoice->company->verifactuEnabled()) { // (new SendVerifactu($this->invoice))->handle(); @@ -683,6 +694,20 @@ class InvoiceService return $this; } + + /** + * deleteVerifactu + * @todo - handle "cancelling" the invoice in AEAT + * @return self + */ + public function deleteVerifactu(): self + { + // if($this->invoice->company->verifactuEnabled()) { + // (new DeleteVerifactu($this->invoice))->handle(); + // } + + return $this; + } /** * Saves the invoice. * @return Invoice object