1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

peppol schematron validation

This commit is contained in:
David Bomba 2024-10-29 22:22:36 +11:00
parent 6a10262533
commit 8f7c4d09aa
4 changed files with 283 additions and 265 deletions

View File

@ -127,7 +127,7 @@ class StorecoveTransformer implements TransformerInterface
foreach($peppolLine->Price->AllowanceCharge as $allowance)
{
$reason = $allowance->ChargeIndicator ? ctrans('texts.fee') : ctrans('texts.discount');
$reason = isset($allowance->ChargeIndicator) ? ctrans('texts.discount') : ctrans('texts.fee');
$amount = $allowance->Amount->amount;
$ac = new AllowanceCharges(reason: $reason, amountExcludingTax: $amount);
@ -202,7 +202,7 @@ class StorecoveTransformer implements TransformerInterface
return $this;
}
private function resolveJurisdication($ctc, $peppolInvoice): string
{
if(isset($ctc->TaxTotal[0]->JurisdictionRegionAddress->Country->IdentificationCode->value))

View File

@ -553,7 +553,7 @@ class Peppol extends AbstractService
// Add Allowance Charge to Price
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
$allowanceCharge->ChargeIndicator = false; // false = discount
$allowanceCharge->ChargeIndicator = 'false'; // false = discount
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->Amount->amount = (string)$this->calc->getTotalDiscount();
@ -577,7 +577,7 @@ class Peppol extends AbstractService
// Add Allowance Charge to Price
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
$allowanceCharge->ChargeIndicator = true; // false = discount
// $allowanceCharge->ChargeIndicator = true; // false = discount
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->Amount->amount = (string)$this->invoice->custom_surcharge1;
@ -593,7 +593,7 @@ class Peppol extends AbstractService
// Add Allowance Charge to Price
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
$allowanceCharge->ChargeIndicator = true; // false = discount
// $allowanceCharge->ChargeIndicator = true; // false = discount
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->Amount->amount = (string)$this->invoice->custom_surcharge2;
@ -609,7 +609,7 @@ class Peppol extends AbstractService
// Add Allowance Charge to Price
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
$allowanceCharge->ChargeIndicator = true; // false = discount
// $allowanceCharge->ChargeIndicator = true; // false = discount
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->Amount->amount = (string)$this->invoice->custom_surcharge3;
@ -625,7 +625,7 @@ class Peppol extends AbstractService
// Add Allowance Charge to Price
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
$allowanceCharge->ChargeIndicator = true; // false = discount
// $allowanceCharge->ChargeIndicator = true; // false = discount
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->Amount->amount = (string)$this->invoice->custom_surcharge4;
@ -824,18 +824,18 @@ class Peppol extends AbstractService
$basePrice = new Price();
$basePriceAmount = new PriceAmount();
$basePriceAmount->currencyID = $this->invoice->client->currency()->code;
$basePriceAmount->amount = (string)$this->getBasePrice($item);
$basePriceAmount->amount = (string)($item->cost - $this->calculateDiscountAmount($item));
$basePrice->PriceAmount = $basePriceAmount;
// Add Allowance Charge to Price
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
$allowanceCharge->ChargeIndicator = false; // false = discount
$allowanceCharge->ChargeIndicator = 'false'; // false = discount
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->Amount->amount = (string)$this->calculateDiscountAmount($item);
$allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
$allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
$allowanceCharge->BaseAmount->amount = (string)$this->getBasePrice($item);
$allowanceCharge->BaseAmount->amount = (string)$item->cost;
// Add percentage if available
if ($item->discount > 0 && !$item->is_amount_discount) {
@ -864,20 +864,15 @@ class Peppol extends AbstractService
return $lines;
}
private function getBasePrice($item): float
{
return $item->cost * $item->quantity;
}
private function calculateDiscountAmount($item): float
{
if ($item->is_amount_discount) {
return $item->discount; // Per unit discount amount
return $item->discount / $item->quantity; // Per unit discount amount
}
return ($item->cost * $item->quantity) * ($item->discount / 100);
return ($item->cost / $item->quantity) * ($item->discount / 100);
}
@ -1147,6 +1142,13 @@ class Peppol extends AbstractService
$ts->ID = $vatID;
$pts->TaxScheme = $ts;
//@todo if we have an exact GLN/routing number we should update this, otherwise Storecove will proxy and update on transit
$id = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\EndpointID();
$id->value = $this->company->settings->vat_number;
$id->schemeID = $this->resolveScheme();
$party->EndpointID = $id;
$party->PartyTaxScheme[] = $pts;
}
@ -1230,6 +1232,18 @@ class Peppol extends AbstractService
$party_name = new PartyName();
$party_name->Name = $this->invoice->client->present()->name();
//@todo if we have an exact GLN/routing number we should update this, otherwise Storecove will proxy and update on transit
if(strlen($this->invoice->client->routing_id ?? '') > 1)
{
$id = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\EndpointID();
$id->value = $this->invoice->client->routing_id;
$id->schemeID = $this->resolveScheme(true);
$party->EndpointID = $id;
}
$party->PartyName[] = $party_name;
$address = new Address();
@ -1504,12 +1518,12 @@ class Peppol extends AbstractService
return $this->standardizeTaxSchemeId($tax_name);
}
private function resolveScheme(): string
private function resolveScheme(bool $is_client=false): string
{
$vat_number = $this->company->settings->vat_number;
$tax_number = $this->company->settings->id_number;
$country_code = $this->company->country()->iso_3166_2;
$vat_number = $is_client ? $this->invoice->client->vat_number : $this->company->settings->vat_number;
$tax_number = $is_client ? $this->invoice->client->id_number : $this->company->settings->id_number;
$country_code = $is_client ? $this->invoice->client->country->iso_3166_2 : $this->company->country()->iso_3166_2;
switch ($country_code) {
case 'FR': // France

460
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -200,19 +200,30 @@ class PeppolTest extends TestCase
// $fib->Name = 'Deutsche Bank';
$pfa = new PayeeFinancialAccount();
$pfa->ID = 'DE89370400440532013000';
$id = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\ID();
$id->value = 'DE89370400440532013000';
$pfa->ID = $id;
$pfa->Name = 'PFA-NAME';
// $pfa->AliasName = 'PFA-Alias';
$pfa->AccountTypeCode = 'CHECKING';
$pfa->AccountFormatCode = 'IBAN';
$pfa->CurrencyCode = 'EUR';
// $code = new \InvoiceNinja\EInvoice\Models\Peppol\CodeType\AccountTypeCode();
// $code->value = 'CHECKING';
// $pfa->AccountTypeCode = $code;
// $code = new \InvoiceNinja\EInvoice\Models\Peppol\CodeType\AccountFormatCode();
// $code->value = 'IBAN';
// $pfa->AccountFormatCode = $code;
// $code = new \InvoiceNinja\EInvoice\Models\Peppol\CodeType\CurrencyCode();
// $code->value = 'EUR';
// $pfa->CurrencyCode = $code;
$pfa->FinancialInstitutionBranch = $fib;
$pm = new PaymentMeans();
$pm->PayeeFinancialAccount = $pfa;
$pmc = new \InvoiceNinja\EInvoice\Models\Peppol\CodeType\PaymentMeansCode();
$pmc->value = '59';
$pmc->value = '30';
$pm->PaymentMeansCode = $pmc;
@ -308,14 +319,7 @@ class PeppolTest extends TestCase
$this->assertCount(0, $errors);
// nlog($peppol->getInvoice());
// nlog($peppol->toXml());
// nlog($peppol->toJson());
// ->toXml();
$peppol->toXml();
$peppol->toXml();
}