diff --git a/app/Services/EDocument/Gateway/MutatorInterface.php b/app/Services/EDocument/Gateway/MutatorInterface.php index 15a4bdc51ce4..65174ce7ff34 100644 --- a/app/Services/EDocument/Gateway/MutatorInterface.php +++ b/app/Services/EDocument/Gateway/MutatorInterface.php @@ -34,6 +34,8 @@ interface MutatorInterface public function getInvoice(): mixed; + public function getSetting(string $property_path): mixed; + // Country-specific methods public function DE(): self; diff --git a/app/Services/EDocument/Gateway/Qvalia/Mutator.php b/app/Services/EDocument/Gateway/Qvalia/Mutator.php index 8a2d02004ed1..4af130c55ac4 100644 --- a/app/Services/EDocument/Gateway/Qvalia/Mutator.php +++ b/app/Services/EDocument/Gateway/Qvalia/Mutator.php @@ -76,6 +76,11 @@ class Mutator implements MutatorInterface return $this->invoice; } + public function getSetting(string $property_path): mixed + { + return $this->mutator_util->getSetting($property_path); + } + /** * senderSpecificLevelMutators * diff --git a/app/Services/EDocument/Gateway/Storecove/Mutator.php b/app/Services/EDocument/Gateway/Storecove/Mutator.php index da566641b78d..fd964fb2a752 100644 --- a/app/Services/EDocument/Gateway/Storecove/Mutator.php +++ b/app/Services/EDocument/Gateway/Storecove/Mutator.php @@ -109,6 +109,10 @@ class Mutator implements MutatorInterface return $this->invoice; } + public function getSetting(string $property_path): mixed + { + return $this->mutator_util->getSetting($property_path); + } /** * senderSpecificLevelMutators * diff --git a/app/Services/EDocument/Jobs/SendEDocument.php b/app/Services/EDocument/Jobs/SendEDocument.php index 7528fc227a42..faf4f774c80b 100644 --- a/app/Services/EDocument/Jobs/SendEDocument.php +++ b/app/Services/EDocument/Jobs/SendEDocument.php @@ -51,11 +51,6 @@ class SendEDocument implements ShouldQueue $model = $this->entity::find($this->id); - // $e_invoice_standard = $model->client ? $model->client->getSetting('e_invoice_type') : $model->company->getSetting('e_invoice_type'); - - // if($e_invoice_standard != 'PEPPOL') - // return; - if(Ninja::isSelfHost() && ($model instanceof Invoice) && $model->company->legal_entity_id) { diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index a547387723ae..3937bcd81ae9 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -313,8 +313,8 @@ class Peppol extends AbstractService $this->company = $invoice->company; $this->calc = $this->invoice->calc(); $this->e = new EInvoice(); - $this->setSettings()->setInvoice(); $this->gateway = new $this->api_network; + $this->setSettings()->setInvoice(); } /** @@ -337,16 +337,11 @@ class Peppol extends AbstractService $this->p_invoice->InvoiceLine = $this->getInvoiceLines(); $this->p_invoice->LegalMonetaryTotal = $this->getLegalMonetaryTotal(); - $this->setOrderReference(); $this->p_invoice = $this->gateway ->mutator - ->setInvoice($this->invoice) - ->setPeppol($this->p_invoice) - ->setClientSettings($this->_client_settings) - ->setCompanySettings($this->_company_settings) ->senderSpecificLevelMutators() ->receiverSpecificLevelMutators() ->getPeppol(); @@ -379,6 +374,13 @@ class Peppol extends AbstractService $this->p_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); + $this->gateway + ->mutator + ->setInvoice($this->invoice) + ->setPeppol($this->p_invoice) + ->setClientSettings($this->_client_settings) + ->setCompanySettings($this->_company_settings); + $this->setInvoiceDefaults(); return $this; @@ -528,22 +530,11 @@ class Peppol extends AbstractService } /** - * getTotalTaxAmount + * getTaxType * - * @return float + * @param string $tax_id + * @return string */ - // private function getTotalTaxAmount(): float - // { - // if(!$this->invoice->total_taxes) { - // return 0; - // } elseif($this->invoice->uses_inclusive_taxes) { - // return $this->invoice->total_taxes; - // } - - // return $this->calcAmountLineTax($this->invoice->tax_rate1, $this->invoice->amount) ?? 0; - // } - - private function getTaxType(string $tax_id = ''): string { $tax_type = null; @@ -895,9 +886,9 @@ class Peppol extends AbstractService $party->PhysicalLocation = $address; $contact = new Contact(); - $contact->ElectronicMail = $this->getSetting('Invoice.AccountingSupplierParty.Party.Contact') ?? $this->invoice->company->owner()->present()->email(); - $contact->Telephone = $this->getSetting('Invoice.AccountingSupplierParty.Party.Telephone') ?? $this->invoice->company->getSetting('phone'); - $contact->Name = $this->getSetting('Invoice.AccountingSupplierParty.Party.Name') ?? $this->invoice->company->owner()->present()->name(); + $contact->ElectronicMail = $this->gateway->mutator->getSetting('Invoice.AccountingSupplierParty.Party.Contact') ?? $this->invoice->company->owner()->present()->email(); + $contact->Telephone = $this->gateway->mutator->getSetting('Invoice.AccountingSupplierParty.Party.Telephone') ?? $this->invoice->company->getSetting('phone'); + $contact->Name = $this->gateway->mutator->getSetting('Invoice.AccountingSupplierParty.Party.Name') ?? $this->invoice->company->owner()->present()->name(); $party->Contact = $contact; @@ -1082,7 +1073,7 @@ class Peppol extends AbstractService //only scans for top level props foreach($settings as $prop => $visibility) { - if($prop_value = $this->getSetting($prop)) { + if($prop_value = $this->gateway->mutator->getSetting($prop)) { $this->p_invoice->{$prop} = $prop_value; }