Split einvoice gateways

This commit is contained in:
David Bomba 2024-09-16 13:52:46 +10:00
parent bfbf7f5c6a
commit 9c6568aae1
5 changed files with 26 additions and 29 deletions

View File

@ -34,6 +34,8 @@ interface MutatorInterface
public function getInvoice(): mixed; public function getInvoice(): mixed;
public function getSetting(string $property_path): mixed;
// Country-specific methods // Country-specific methods
public function DE(): self; public function DE(): self;

View File

@ -76,6 +76,11 @@ class Mutator implements MutatorInterface
return $this->invoice; return $this->invoice;
} }
public function getSetting(string $property_path): mixed
{
return $this->mutator_util->getSetting($property_path);
}
/** /**
* senderSpecificLevelMutators * senderSpecificLevelMutators
* *

View File

@ -109,6 +109,10 @@ class Mutator implements MutatorInterface
return $this->invoice; return $this->invoice;
} }
public function getSetting(string $property_path): mixed
{
return $this->mutator_util->getSetting($property_path);
}
/** /**
* senderSpecificLevelMutators * senderSpecificLevelMutators
* *

View File

@ -51,11 +51,6 @@ class SendEDocument implements ShouldQueue
$model = $this->entity::find($this->id); $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) if(Ninja::isSelfHost() && ($model instanceof Invoice) && $model->company->legal_entity_id)
{ {

View File

@ -313,8 +313,8 @@ class Peppol extends AbstractService
$this->company = $invoice->company; $this->company = $invoice->company;
$this->calc = $this->invoice->calc(); $this->calc = $this->invoice->calc();
$this->e = new EInvoice(); $this->e = new EInvoice();
$this->setSettings()->setInvoice();
$this->gateway = new $this->api_network; $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->InvoiceLine = $this->getInvoiceLines();
$this->p_invoice->LegalMonetaryTotal = $this->getLegalMonetaryTotal(); $this->p_invoice->LegalMonetaryTotal = $this->getLegalMonetaryTotal();
$this->setOrderReference(); $this->setOrderReference();
$this->p_invoice = $this->gateway $this->p_invoice = $this->gateway
->mutator ->mutator
->setInvoice($this->invoice)
->setPeppol($this->p_invoice)
->setClientSettings($this->_client_settings)
->setCompanySettings($this->_company_settings)
->senderSpecificLevelMutators() ->senderSpecificLevelMutators()
->receiverSpecificLevelMutators() ->receiverSpecificLevelMutators()
->getPeppol(); ->getPeppol();
@ -379,6 +374,13 @@ class Peppol extends AbstractService
$this->p_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $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(); $this->setInvoiceDefaults();
return $this; 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 private function getTaxType(string $tax_id = ''): string
{ {
$tax_type = null; $tax_type = null;
@ -895,9 +886,9 @@ class Peppol extends AbstractService
$party->PhysicalLocation = $address; $party->PhysicalLocation = $address;
$contact = new Contact(); $contact = new Contact();
$contact->ElectronicMail = $this->getSetting('Invoice.AccountingSupplierParty.Party.Contact') ?? $this->invoice->company->owner()->present()->email(); $contact->ElectronicMail = $this->gateway->mutator->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->Telephone = $this->gateway->mutator->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->Name = $this->gateway->mutator->getSetting('Invoice.AccountingSupplierParty.Party.Name') ?? $this->invoice->company->owner()->present()->name();
$party->Contact = $contact; $party->Contact = $contact;
@ -1082,7 +1073,7 @@ class Peppol extends AbstractService
//only scans for top level props //only scans for top level props
foreach($settings as $prop => $visibility) { 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; $this->p_invoice->{$prop} = $prop_value;
} }