mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Split einvoice gateways
This commit is contained in:
parent
737e18aa42
commit
bfbf7f5c6a
@ -28,6 +28,12 @@ interface MutatorInterface
|
||||
|
||||
public function setCompanySettings($company_settings): self;
|
||||
|
||||
public function getClientSettings(): mixed;
|
||||
|
||||
public function getCompanySettings(): mixed;
|
||||
|
||||
public function getInvoice(): mixed;
|
||||
|
||||
// Country-specific methods
|
||||
public function DE(): self;
|
||||
|
||||
|
@ -12,11 +12,20 @@
|
||||
namespace App\Services\EDocument\Gateway;
|
||||
|
||||
use App\Exceptions\PeppolValidationException;
|
||||
use App\Services\EDocument\Gateway\MutatorInterface;
|
||||
use App\Services\EDocument\Standards\Settings\PropertyResolver;
|
||||
use InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\CustomerAssignedAccountID;
|
||||
|
||||
/**
|
||||
* Class MutatorUtil
|
||||
*
|
||||
* Utility class for e-document mutations.
|
||||
*/
|
||||
class MutatorUtil
|
||||
{
|
||||
|
||||
/**
|
||||
* MutatorUtil constructor.
|
||||
*/
|
||||
public function __construct(public MutatorInterface $mutator)
|
||||
{
|
||||
}
|
||||
@ -30,11 +39,13 @@ class MutatorUtil
|
||||
*/
|
||||
public function setPaymentMeans(bool $required = false): self
|
||||
{
|
||||
$peppol = $this->mutator->getPeppol();
|
||||
|
||||
if(isset($this->mutator->p_invoice->PaymentMeans)) {
|
||||
if(isset($peppol->PaymentMeans)) {
|
||||
return $this;
|
||||
} elseif($paymentMeans = $this->getSetting('Invoice.PaymentMeans')) {
|
||||
$this->mutator->p_invoice->PaymentMeans = is_array($paymentMeans) ? $paymentMeans : [$paymentMeans];
|
||||
$peppol->PaymentMeans = is_array($paymentMeans) ? $paymentMeans : [$paymentMeans];
|
||||
$this->mutator->setPeppol($peppol);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -51,7 +62,7 @@ class MutatorUtil
|
||||
*/
|
||||
public function getClientSetting(string $property_path): mixed
|
||||
{
|
||||
return PropertyResolver::resolve($this->mutator->_client_settings, $property_path);
|
||||
return PropertyResolver::resolve($this->mutator->getClientSettings(), $property_path);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +73,7 @@ class MutatorUtil
|
||||
*/
|
||||
public function getCompanySetting(string $property_path): mixed
|
||||
{
|
||||
return PropertyResolver::resolve($this->mutator->_company_settings, $property_path);
|
||||
return PropertyResolver::resolve($this->mutator->getCompanySettings(), $property_path);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,11 +87,11 @@ class MutatorUtil
|
||||
public function getSetting(string $property_path): mixed
|
||||
{
|
||||
|
||||
if($prop_value = PropertyResolver::resolve($this->mutator->p_invoice, $property_path)) {
|
||||
if($prop_value = PropertyResolver::resolve($this->mutator->getPeppol(), $property_path)) {
|
||||
return $prop_value;
|
||||
} elseif($prop_value = PropertyResolver::resolve($this->mutator->_client_settings, $property_path)) {
|
||||
} elseif($prop_value = PropertyResolver::resolve($this->mutator->getClientSettings(), $property_path)) {
|
||||
return $prop_value;
|
||||
} elseif($prop_value = PropertyResolver::resolve($this->mutator->_company_settings, $property_path)) {
|
||||
} elseif($prop_value = PropertyResolver::resolve($this->mutator->getCompanySettings(), $property_path)) {
|
||||
return $prop_value;
|
||||
}
|
||||
return null;
|
||||
@ -111,19 +122,23 @@ class MutatorUtil
|
||||
*/
|
||||
public function setCustomerAssignedAccountId(bool $required = false): self
|
||||
{
|
||||
$peppol = $this->mutator->getPeppol();
|
||||
$invoice = $this->mutator->getInvoice();
|
||||
|
||||
//@phpstan-ignore-next-line
|
||||
if(isset($this->mutator->p_invoice->AccountingCustomerParty->CustomerAssignedAccountID)) {
|
||||
if(isset($peppol->AccountingCustomerParty->CustomerAssignedAccountID)) {
|
||||
return $this;
|
||||
} elseif($customer_assigned_account_id = $this->getSetting('Invoice.AccountingCustomerParty.CustomerAssignedAccountID')) {
|
||||
|
||||
$this->mutator->p_invoice->AccountingCustomerParty->CustomerAssignedAccountID = $customer_assigned_account_id;
|
||||
$peppol->AccountingCustomerParty->CustomerAssignedAccountID = $customer_assigned_account_id;
|
||||
$this->mutator->setPeppol($peppol);
|
||||
return $this;
|
||||
} elseif(strlen($this->mutator->invoice->client->id_number ?? '') > 1) {
|
||||
} elseif(strlen($invoice->client->id_number ?? '') > 1) {
|
||||
|
||||
$customer_assigned_account_id = new CustomerAssignedAccountID();
|
||||
$customer_assigned_account_id->value = $this->mutator->invoice->client->id_number;
|
||||
$customer_assigned_account_id->value = $invoice->client->id_number;
|
||||
|
||||
$this->mutator->p_invoice->AccountingCustomerParty->CustomerAssignedAccountID = $customer_assigned_account_id;
|
||||
$peppol->AccountingCustomerParty->CustomerAssignedAccountID = $customer_assigned_account_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Services\EDocument\Gateway\Qvalia;
|
||||
|
||||
use App\Services\EDocument\Gateway\MutatorUtil;
|
||||
use App\Services\EDocument\Gateway\MutatorInterface;
|
||||
|
||||
class Mutator implements MutatorInterface
|
||||
@ -24,8 +25,11 @@ class Mutator implements MutatorInterface
|
||||
|
||||
private $invoice;
|
||||
|
||||
private MutatorUtil $mutator_util;
|
||||
|
||||
public function __construct(public Qvalia $qvalia)
|
||||
{
|
||||
$this->mutator_util = new MutatorUtil($this);
|
||||
}
|
||||
|
||||
public function setInvoice($invoice): self
|
||||
@ -45,6 +49,16 @@ class Mutator implements MutatorInterface
|
||||
return $this->p_invoice;
|
||||
}
|
||||
|
||||
public function getClientSettings(): mixed
|
||||
{
|
||||
return $this->_client_settings;
|
||||
}
|
||||
|
||||
public function getCompanySettings(): mixed
|
||||
{
|
||||
return $this->_company_settings;
|
||||
}
|
||||
|
||||
public function setClientSettings($client_settings): self
|
||||
{
|
||||
$this->_client_settings = $client_settings;
|
||||
@ -57,6 +71,11 @@ class Mutator implements MutatorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInvoice(): mixed
|
||||
{
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* senderSpecificLevelMutators
|
||||
*
|
||||
|
@ -19,13 +19,13 @@ use App\Services\EDocument\Gateway\Storecove\StorecoveRouter;
|
||||
class Mutator implements MutatorInterface
|
||||
{
|
||||
|
||||
public \InvoiceNinja\EInvoice\Models\Peppol\Invoice $p_invoice;
|
||||
private \InvoiceNinja\EInvoice\Models\Peppol\Invoice $p_invoice;
|
||||
|
||||
public ?\InvoiceNinja\EInvoice\Models\Peppol\Invoice $_client_settings;
|
||||
private ?\InvoiceNinja\EInvoice\Models\Peppol\Invoice $_client_settings;
|
||||
|
||||
public ?\InvoiceNinja\EInvoice\Models\Peppol\Invoice $_company_settings;
|
||||
private ?\InvoiceNinja\EInvoice\Models\Peppol\Invoice $_company_settings;
|
||||
|
||||
public $invoice;
|
||||
private $invoice;
|
||||
|
||||
private array $storecove_meta = [];
|
||||
|
||||
@ -94,6 +94,21 @@ class Mutator implements MutatorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClientSettings(): mixed
|
||||
{
|
||||
return $this->_client_settings;
|
||||
}
|
||||
|
||||
public function getCompanySettings(): mixed
|
||||
{
|
||||
return $this->_company_settings;
|
||||
}
|
||||
|
||||
public function getInvoice(): mixed
|
||||
{
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* senderSpecificLevelMutators
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user