Add tax type for PEPPOL

This commit is contained in:
David Bomba 2024-09-14 19:16:54 +10:00
parent fc3ca1c124
commit d93e3a77b3
3 changed files with 84 additions and 6 deletions

View File

@ -238,6 +238,49 @@ class Peppol extends AbstractService
"Other" => ["B","DUNS, GLN, LEI",false,"DUNS, GLN, LEI"], "Other" => ["B","DUNS, GLN, LEI",false,"DUNS, GLN, LEI"],
]; ];
private array $tax_codes = [
'AE' => [
'name' => 'Vat Reverse Charge',
'description' => 'Code specifying that the standard VAT rate is levied from the invoicee.'
],
'E' => [
'name' => 'Exempt from Tax',
'description' => 'Code specifying that taxes are not applicable.'
],
'S' => [
'name' => 'Standard rate',
'description' => 'Code specifying the standard rate.'
],
'Z' => [
'name' => 'Zero rated goods',
'description' => 'Code specifying that the goods are at a zero rate.'
],
'G' => [
'name' => 'Free export item, VAT not charged',
'description' => 'Code specifying that the item is free export and taxes are not charged.'
],
'O' => [
'name' => 'Services outside scope of tax',
'description' => 'Code specifying that taxes are not applicable to the services.'
],
'K' => [
'name' => 'VAT exempt for EEA intra-community supply of goods and services',
'description' => 'A tax category code indicating the item is VAT exempt due to an intra-community supply in the European Economic Area.'
],
'L' => [
'name' => 'Canary Islands general indirect tax',
'description' => 'Impuesto General Indirecto Canario (IGIC) is an indirect tax levied on goods and services supplied in the Canary Islands (Spain) by traders and professionals, as well as on import of goods.'
],
'M' => [
'name' => 'Tax for production, services and importation in Ceuta and Melilla',
'description' => 'Impuesto sobre la Producción, los Servicios y la Importación (IPSI) is an indirect municipal tax, levied on the production, processing and import of all kinds of movable tangible property, the supply of services and the transfer of immovable property located in the cities of Ceuta and Melilla.'
],
'B' => [
'name' => 'Transferred (VAT), In Italy',
'description' => 'VAT not to be paid to the issuer of the invoice but directly to relevant tax authority. This code is allowed in the EN 16931 for Italy only based on the Italian A-deviation.'
]
];
private Company $company; private Company $company;
private InvoiceSum | InvoiceSumInclusive $calc; private InvoiceSum | InvoiceSumInclusive $calc;
@ -456,6 +499,44 @@ 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;
} }
private function getTaxType($item): string
{
$tax_type = null;
switch ($name) {
case Product::PRODUCT_TYPE_SERVICE:
case Product::PRODUCT_TYPE_DIGITAL:
case Product::PRODUCT_TYPE_PHYSICAL:
case Product::PRODUCT_TYPE_SHIPPING:
case Product::PRODUCT_TYPE_REDUCED_TAX:
$tax_type = 'S';
break;
case Product::PRODUCT_TYPE_EXEMPT:
$tax_type = 'E';
break;
case Product::PRODUCT_TYPE_ZERO_RATED:
$tax_type = 'Z';
break;
case Product::PRODUCT_TYPE_REVERSE_TAX:
$tax_type = 'AE';
break;
}
$eu_states = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "EL", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS", "LI", "NO", "CH"];
if (empty($tax_type)) {
if ((in_array($this->document->company->country()->iso_3166_2, $eu_states) && in_array($this->document->client->country->iso_3166_2, $eu_states)) && $this->document->company->country()->iso_3166_2 != $this->document->client->country->iso_3166_2) {
$tax_type = 'K';
} elseif (!in_array($this->document->client->country->iso_3166_2, $eu_states)) {
$tax_type = 'O';
} elseif ($this->document->client->country->iso_3166_2 == "ES-CN") {
$tax_type = 'L';
} elseif (in_array($this->document->client->country->iso_3166_2, ["ES-CE", "ES-ML"])) {
$tax_type = 'M';
} else {
$tax_type = 'S';
}
}
return $tax_type;
}
/** /**
* getTotalTaxes * getTotalTaxes
* *
@ -467,8 +548,6 @@ class Peppol extends AbstractService
$type_id = $this->invoice->line_items[0]->type_id; $type_id = $this->invoice->line_items[0]->type_id;
// if(strlen($this->invoice->tax_name1 ?? '') > 1) {
$tax_amount = new TaxAmount(); $tax_amount = new TaxAmount();
$tax_amount->currencyID = $this->invoice->client->currency()->code; $tax_amount->currencyID = $this->invoice->client->currency()->code;
$tax_amount->amount = $this->getTotalTaxAmount(); $tax_amount->amount = $this->getTotalTaxAmount();
@ -498,7 +577,7 @@ class Peppol extends AbstractService
$tax_total->TaxSubtotal[] = $tax_subtotal; $tax_total->TaxSubtotal[] = $tax_subtotal;
$taxes[] = $tax_total; $taxes[] = $tax_total;
// }
if(strlen($this->invoice->tax_name2 ?? '') > 1) { if(strlen($this->invoice->tax_name2 ?? '') > 1) {
@ -597,7 +676,6 @@ class Peppol extends AbstractService
$lea = new LineExtensionAmount(); $lea = new LineExtensionAmount();
$lea->currencyID = $this->invoice->client->currency()->code; $lea->currencyID = $this->invoice->client->currency()->code;
// $lea->amount = $item->line_total;
$lea->amount = $this->invoice->uses_inclusive_taxes ? $item->line_total - $this->calcInclusiveLineTax($item->tax_rate1, $item->line_total) : $item->line_total; $lea->amount = $this->invoice->uses_inclusive_taxes ? $item->line_total - $this->calcInclusiveLineTax($item->tax_rate1, $item->line_total) : $item->line_total;
$line->LineExtensionAmount = $lea; $line->LineExtensionAmount = $lea;
$line->Item = $_item; $line->Item = $_item;
@ -625,6 +703,7 @@ class Peppol extends AbstractService
return $lines; return $lines;
} }
/** /**
* costWithDiscount * costWithDiscount
* *

File diff suppressed because one or more lines are too long

View File

@ -348,7 +348,7 @@
"src": "resources/js/setup/setup.js" "src": "resources/js/setup/setup.js"
}, },
"resources/sass/app.scss": { "resources/sass/app.scss": {
"file": "assets/app-106dcc58.css", "file": "assets/app-23f93261.css",
"isEntry": true, "isEntry": true,
"src": "resources/sass/app.scss" "src": "resources/sass/app.scss"
} }