From af926a394cb652f5c76302be8c940023e2030eb2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 13 Aug 2025 14:39:50 +1000 Subject: [PATCH] Wiring up verifactu sending --- app/DataMapper/InvoiceBackup.php | 2 +- app/Http/Requests/EInvoice/Peppol/RetrySendRequest.php | 2 +- app/Services/EDocument/Standards/Verifactu/SendToAeat.php | 6 ++++++ app/Services/Invoice/TriggeredActions.php | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/DataMapper/InvoiceBackup.php b/app/DataMapper/InvoiceBackup.php index dcc60ee164..062c21cdff 100644 --- a/app/DataMapper/InvoiceBackup.php +++ b/app/DataMapper/InvoiceBackup.php @@ -23,7 +23,7 @@ use Illuminate\Support\Collection; class InvoiceBackup implements Castable { public function __construct( - public string $guid = '', // The E-INVOICE SENT GUID reference + public string $guid = '', // The E-INVOICE SENT GUID reference - or enum to advise the document has been successfully sent. public Cancellation $cancellation = new Cancellation(0,0), public ?string $parent_invoice_id = null, // The id of the invoice that was cancelled public ?string $parent_invoice_number = null, // The number of the invoice that was cancelled diff --git a/app/Http/Requests/EInvoice/Peppol/RetrySendRequest.php b/app/Http/Requests/EInvoice/Peppol/RetrySendRequest.php index f58fb77e07..8692e68b2d 100644 --- a/app/Http/Requests/EInvoice/Peppol/RetrySendRequest.php +++ b/app/Http/Requests/EInvoice/Peppol/RetrySendRequest.php @@ -29,7 +29,7 @@ class RetrySendRequest extends Request return true; } - return $user->account->isPaid() && $user->isAdmin() && $user->company()->legal_entity_id != null; + return $user->account->isPaid() && $user->isAdmin() && ($user->company()->legal_entity_id != null || $user->company()->verifactuEnabled()); } /** diff --git a/app/Services/EDocument/Standards/Verifactu/SendToAeat.php b/app/Services/EDocument/Standards/Verifactu/SendToAeat.php index 4aa1e5fbfa..b6fd53ebf5 100644 --- a/app/Services/EDocument/Standards/Verifactu/SendToAeat.php +++ b/app/Services/EDocument/Standards/Verifactu/SendToAeat.php @@ -73,6 +73,12 @@ class SendToAeat implements ShouldQueue $invoice = Invoice::withTrashed()->find($this->invoice_id); + if($invoice->client->country->iso_3166_2 != 'ES') { + $invoice->backup->guid = 'NOT_ES'; + $invoice->saveQuietly(); + return; + } + switch($this->action) { case 'create': $this->createInvoice($invoice); diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index 54eda85dff..2dfb4e4492 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -81,7 +81,7 @@ class TriggeredActions extends AbstractService $company->save(); } - if($this->request->has('retry_e_send') && $this->request->input('retry_e_send') == 'true' && strlen($this->invoice->backup->guid ?? '') < 2 && $this->invoice->client->peppolSendingEnabled()) { + if($this->request->has('retry_e_send') && $this->request->input('retry_e_send') == 'true' && strlen($this->invoice->backup->guid ?? '') == 0 && $this->invoice->client->peppolSendingEnabled()) { \App\Services\EDocument\Jobs\SendEDocument::dispatch(get_class($this->invoice), $this->invoice->id, $this->invoice->company->db); }