From a96d16f09e11ef61e9ee3fb12861765c16f1499e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 2 Nov 2024 19:32:07 +1100 Subject: [PATCH] Overriding VAT numbers --- app/Services/EDocument/Jobs/SendEDocument.php | 4 ++-- app/Services/EDocument/Standards/Peppol.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Services/EDocument/Jobs/SendEDocument.php b/app/Services/EDocument/Jobs/SendEDocument.php index b1143b007c..d8cb20f672 100644 --- a/app/Services/EDocument/Jobs/SendEDocument.php +++ b/app/Services/EDocument/Jobs/SendEDocument.php @@ -56,7 +56,7 @@ class SendEDocument implements ShouldQueue $p = new Peppol($model); $p->run(); - $identifiers = $p->getStorecoveMeta(); + $identifiers = $p->gateway->mutator->getStorecoveMeta(); $result = $storecove->build($model); @@ -65,7 +65,7 @@ class SendEDocument implements ShouldQueue $payload = [ 'legal_entity_id' => $model->company->legal_entity_id, - 'document' => base64_encode($xml), + // 'document' => base64_encode($xml), 'tenant_id' => $model->company->company_key, 'identifiers' => $identifiers, // 'e_invoicing_token' => $model->company->e_invoicing_token, diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index 1203a97e7c..551a1e869c 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -64,6 +64,8 @@ class Peppol extends AbstractService * Exclusive Taxes * */ + + private ?string $override_vat_number; /** @var array $InvoiceTypeCodes */ private array $InvoiceTypeCodes = [ @@ -163,6 +165,8 @@ class Peppol extends AbstractService */ public function run(): self { + $this->getJurisdiction(); + /** Invoice Level Props */ $id = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\CustomizationID(); $id->value = $this->customizationID; @@ -951,14 +955,14 @@ class Peppol extends AbstractService $pi = new PartyIdentification(); $vatID = new ID(); $vatID->schemeID = $this->resolveScheme(); - $vatID->value = $this->company->settings->vat_number; //todo if we are cross border - switch to the supplier local vat number + $vatID->value = $this->override_vat_number ?? $this->company->settings->vat_number; //todo if we are cross border - switch to the supplier local vat number $pi->ID = $vatID; $party->PartyIdentification[] = $pi; $pts = new \InvoiceNinja\EInvoice\Models\Peppol\PartyTaxSchemeType\PartyTaxScheme(); $companyID = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\CompanyID(); - $companyID->value = $this->invoice->company->settings->vat_number; + $companyID->value = $this->override_vat_number ?? $this->company->settings->vat_number; $pts->CompanyID = $companyID; $ts = new TaxScheme(); @@ -1282,6 +1286,9 @@ class Peppol extends AbstractService //EU Sale if($this->company->tax_data->regions->EU->has_sales_above_threshold || !$this->invoice->client->has_valid_vat_number){ //over threshold - tax in buyer country $country_code = $this->invoice->client->country->iso_3166_2; + + if(isset($this->ninja_invoice->company->tax_data->regions->EU->subregions->{$country_code}->vat_number)) + $this->override_vat_number = $this->ninja_invoice->company->tax_data->regions->EU->subregions->{$country_code}->vat_number; } }