mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Clean up for Peppol
This commit is contained in:
parent
c1f45a8319
commit
638c823722
@ -262,6 +262,38 @@ class Peppol extends AbstractService
|
|||||||
$this->setSettings()->setInvoice();
|
$this->setSettings()->setInvoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point for building document
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function run(): self
|
||||||
|
{
|
||||||
|
$this->p_invoice->ID = $this->invoice->number;
|
||||||
|
$this->p_invoice->IssueDate = new \DateTime($this->invoice->date);
|
||||||
|
|
||||||
|
if($this->invoice->due_date) {
|
||||||
|
$this->p_invoice->DueDate = new \DateTime($this->invoice->due_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->p_invoice->InvoiceTypeCode = 380; //
|
||||||
|
$this->p_invoice->AccountingSupplierParty = $this->getAccountingSupplierParty();
|
||||||
|
$this->p_invoice->AccountingCustomerParty = $this->getAccountingCustomerParty();
|
||||||
|
$this->p_invoice->InvoiceLine = $this->getInvoiceLines();
|
||||||
|
|
||||||
|
// $this->p_invoice->TaxTotal = $this->getTotalTaxes(); it only wants the aggregate here!!
|
||||||
|
$this->p_invoice->LegalMonetaryTotal = $this->getLegalMonetaryTotal();
|
||||||
|
|
||||||
|
$this->senderSpecificLevelMutators()
|
||||||
|
->receiverSpecificLevelMutators();
|
||||||
|
|
||||||
|
$this->invoice->e_invoice = $this->toObject();
|
||||||
|
$this->invoice->save();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rehydrates an existing e invoice - or - scaffolds a new one
|
* Rehydrates an existing e invoice - or - scaffolds a new one
|
||||||
*
|
*
|
||||||
@ -300,6 +332,11 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getInvoice
|
||||||
|
*
|
||||||
|
* @return InvoiceNinja\EInvoice\Models\Peppol\Invoice
|
||||||
|
*/
|
||||||
public function getInvoice(): \InvoiceNinja\EInvoice\Models\Peppol\Invoice
|
public function getInvoice(): \InvoiceNinja\EInvoice\Models\Peppol\Invoice
|
||||||
{
|
{
|
||||||
//@todo - need to process this and remove null values
|
//@todo - need to process this and remove null values
|
||||||
@ -307,6 +344,11 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toXml
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function toXml(): string
|
public function toXml(): string
|
||||||
{
|
{
|
||||||
$e = new EInvoice();
|
$e = new EInvoice();
|
||||||
@ -322,6 +364,11 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toJson
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function toJson(): string
|
public function toJson(): string
|
||||||
{
|
{
|
||||||
$e = new EInvoice();
|
$e = new EInvoice();
|
||||||
@ -331,43 +378,31 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toObject
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function toObject(): mixed
|
public function toObject(): mixed
|
||||||
{
|
{
|
||||||
return json_decode($this->toJson());
|
return json_decode($this->toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toArray
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return json_decode($this->toJson(), true);
|
return json_decode($this->toJson(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
/**
|
||||||
{
|
* getLegalMonetaryTotal
|
||||||
$this->p_invoice->ID = $this->invoice->number;
|
*
|
||||||
$this->p_invoice->IssueDate = new \DateTime($this->invoice->date);
|
* @return LegalMonetaryTotal
|
||||||
|
*/
|
||||||
if($this->invoice->due_date) {
|
|
||||||
$this->p_invoice->DueDate = new \DateTime($this->invoice->due_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->p_invoice->InvoiceTypeCode = 380; //
|
|
||||||
$this->p_invoice->AccountingSupplierParty = $this->getAccountingSupplierParty();
|
|
||||||
$this->p_invoice->AccountingCustomerParty = $this->getAccountingCustomerParty();
|
|
||||||
$this->p_invoice->InvoiceLine = $this->getInvoiceLines();
|
|
||||||
|
|
||||||
// $this->p_invoice->TaxTotal = $this->getTotalTaxes(); it only wants the aggregate here!!
|
|
||||||
$this->p_invoice->LegalMonetaryTotal = $this->getLegalMonetaryTotal();
|
|
||||||
|
|
||||||
$this->senderSpecificLevelMutators()
|
|
||||||
->receiverSpecificLevelMutators();
|
|
||||||
|
|
||||||
$this->invoice->e_invoice = $this->toObject();
|
|
||||||
$this->invoice->save();
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getLegalMonetaryTotal(): LegalMonetaryTotal
|
private function getLegalMonetaryTotal(): LegalMonetaryTotal
|
||||||
{
|
{
|
||||||
$taxable = $this->getTaxable();
|
$taxable = $this->getTaxable();
|
||||||
@ -397,6 +432,11 @@ class Peppol extends AbstractService
|
|||||||
return $lmt;
|
return $lmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTotalTaxAmount
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
private function getTotalTaxAmount(): float
|
private function getTotalTaxAmount(): float
|
||||||
{
|
{
|
||||||
if(!$this->invoice->total_taxes) {
|
if(!$this->invoice->total_taxes) {
|
||||||
@ -408,6 +448,11 @@ class Peppol extends AbstractService
|
|||||||
return $this->calcAmountLineTax($this->invoice->tax_rate1, $this->invoice->amount) ?? 0;
|
return $this->calcAmountLineTax($this->invoice->tax_rate1, $this->invoice->amount) ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTotalTaxes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function getTotalTaxes(): array
|
private function getTotalTaxes(): array
|
||||||
{
|
{
|
||||||
$taxes = [];
|
$taxes = [];
|
||||||
@ -572,7 +617,13 @@ class Peppol extends AbstractService
|
|||||||
return $lines;
|
return $lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function costWithDiscount($item)
|
/**
|
||||||
|
* costWithDiscount
|
||||||
|
*
|
||||||
|
* @param mixed $item
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
private function costWithDiscount($item): float
|
||||||
{
|
{
|
||||||
$cost = $item->cost;
|
$cost = $item->cost;
|
||||||
|
|
||||||
@ -587,6 +638,11 @@ class Peppol extends AbstractService
|
|||||||
return $cost;
|
return $cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* zeroTaxAmount
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function zeroTaxAmount(): array
|
private function zeroTaxAmount(): array
|
||||||
{
|
{
|
||||||
$blank_tax = [];
|
$blank_tax = [];
|
||||||
@ -623,6 +679,12 @@ class Peppol extends AbstractService
|
|||||||
return $blank_tax;
|
return $blank_tax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getItemTaxes
|
||||||
|
*
|
||||||
|
* @param object $item
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function getItemTaxes(object $item): array
|
private function getItemTaxes(object $item): array
|
||||||
{
|
{
|
||||||
$item_taxes = [];
|
$item_taxes = [];
|
||||||
@ -748,6 +810,11 @@ class Peppol extends AbstractService
|
|||||||
return $item_taxes;
|
return $item_taxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getAccountingSupplierParty
|
||||||
|
*
|
||||||
|
* @return AccountingSupplierParty
|
||||||
|
*/
|
||||||
private function getAccountingSupplierParty(): AccountingSupplierParty
|
private function getAccountingSupplierParty(): AccountingSupplierParty
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -819,6 +886,11 @@ class Peppol extends AbstractService
|
|||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getAccountingCustomerParty
|
||||||
|
*
|
||||||
|
* @return AccountingCustomerParty
|
||||||
|
*/
|
||||||
private function getAccountingCustomerParty(): AccountingCustomerParty
|
private function getAccountingCustomerParty(): AccountingCustomerParty
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -878,6 +950,11 @@ class Peppol extends AbstractService
|
|||||||
return $acp;
|
return $acp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTaxable
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
private function getTaxable(): float
|
private function getTaxable(): float
|
||||||
{
|
{
|
||||||
$total = 0;
|
$total = 0;
|
||||||
@ -926,6 +1003,11 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
///////////////// Helper Methods /////////////////////////
|
///////////////// Helper Methods /////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getClientRoutingCode
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
private function getClientRoutingCode(): string
|
private function getClientRoutingCode(): string
|
||||||
{
|
{
|
||||||
// $receiver_identifiers = $this->routing_rules[$this->invoice->client->country->iso_3166_2];
|
// $receiver_identifiers = $this->routing_rules[$this->invoice->client->country->iso_3166_2];
|
||||||
@ -1007,15 +1089,28 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getClientSetting
|
||||||
|
*
|
||||||
|
* @param string $property_path
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
private function getClientSetting(string $property_path): mixed
|
private function getClientSetting(string $property_path): mixed
|
||||||
{
|
{
|
||||||
return PropertyResolver::resolve($this->_client_settings, $property_path);
|
return PropertyResolver::resolve($this->_client_settings, $property_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getCompanySetting
|
||||||
|
*
|
||||||
|
* @param string $property_path
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
private function getCompanySetting(string $property_path): mixed
|
private function getCompanySetting(string $property_path): mixed
|
||||||
{
|
{
|
||||||
return PropertyResolver::resolve($this->_company_settings, $property_path);
|
return PropertyResolver::resolve($this->_company_settings, $property_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* senderSpecificLevelMutators
|
* senderSpecificLevelMutators
|
||||||
*
|
*
|
||||||
@ -1171,7 +1266,6 @@ class Peppol extends AbstractService
|
|||||||
*/
|
*/
|
||||||
private function buildRouting(array $identifiers): array
|
private function buildRouting(array $identifiers): array
|
||||||
{
|
{
|
||||||
|
|
||||||
return
|
return
|
||||||
[
|
[
|
||||||
"routing" => [
|
"routing" => [
|
||||||
@ -1182,6 +1276,12 @@ class Peppol extends AbstractService
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setEmailRouting
|
||||||
|
*
|
||||||
|
* @param string $email
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function setEmailRouting(string $email): self
|
private function setEmailRouting(string $email): self
|
||||||
{
|
{
|
||||||
nlog($email);
|
nlog($email);
|
||||||
@ -1217,6 +1317,11 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getStorecoveMeta
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getStorecoveMeta(): array
|
public function getStorecoveMeta(): array
|
||||||
{
|
{
|
||||||
return $this->storecove_meta;
|
return $this->storecove_meta;
|
||||||
@ -1225,9 +1330,6 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////// Country level mutators /////////////////////////////////////
|
////////////////////////// Country level mutators /////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1342,6 +1444,11 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FI
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function FI(): self
|
private function FI(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1405,6 +1512,11 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IT
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function IT(): self
|
private function IT(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1451,6 +1563,11 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* client_IT
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function client_IT(): self
|
private function client_IT(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1468,12 +1585,22 @@ class Peppol extends AbstractService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MY
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function MY(): self
|
private function MY(): self
|
||||||
{
|
{
|
||||||
//way too much to digest here, delayed.
|
//way too much to digest here, delayed.
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NL
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function NL(): self
|
private function NL(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1484,12 +1611,22 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NZ
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function NZ(): self
|
private function NZ(): self
|
||||||
{
|
{
|
||||||
// New Zealand uses a GLN to identify businesses. In addition, when sending invoices to a New Zealand customer, make sure you include the pseudo identifier NZ:GST as their tax identifier.
|
// New Zealand uses a GLN to identify businesses. In addition, when sending invoices to a New Zealand customer, make sure you include the pseudo identifier NZ:GST as their tax identifier.
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PL
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function PL(): self
|
private function PL(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1516,6 +1653,11 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RO
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function RO(): self
|
private function RO(): self
|
||||||
{
|
{
|
||||||
// Because using this network is not yet mandatory, the default workflow is to not use this network. Therefore, you have to force its use, as follows:
|
// Because using this network is not yet mandatory, the default workflow is to not use this network. Therefore, you have to force its use, as follows:
|
||||||
@ -1550,6 +1692,11 @@ class Peppol extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SG
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
private function SG(): self
|
private function SG(): self
|
||||||
{
|
{
|
||||||
//delayed - stage 2
|
//delayed - stage 2
|
||||||
|
Loading…
Reference in New Issue
Block a user