Skip to content

Commit

Permalink
Updated rounding unit tests
Browse files Browse the repository at this point in the history
- Updated InvoiceTotalsTest class
- Added "peppol-rounding.xml" integration test sample

> Related to #31
  • Loading branch information
josemmo committed Dec 4, 2022
1 parent f5e6f0e commit 0b60be1
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function testCanRecreatePeppolAllowanceExample(): void {
$this->importAndExportInvoice(__DIR__ . "/peppol-allowance.xml");
}

public function testCanRecreatePeppolRoundingExample(): void {
$this->importAndExportInvoice(__DIR__ . "/peppol-rounding.xml");
}

public function testCanRecreateCiusRoTaxCurrencyCodeExample(): void {
$this->importAndExportInvoice(__DIR__ . "/cius-ro-tax-currency-code.xml");
}
Expand Down
100 changes: 100 additions & 0 deletions tests/Integration/peppol-rounding.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Based on example from https://github.com/josemmo/einvoicing/issues/31 -->
<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0</cbc:CustomizationID>
<cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID>SampleForDecimals</cbc:ID>
<cbc:IssueDate>2022-11-03</cbc:IssueDate>
<cbc:DueDate>2022-11-11</cbc:DueDate>
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cac:AccountingSupplierParty>
<cac:Party>
<cbc:EndpointID schemeID="EM">[email protected]</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID>12345678</cbc:ID>
</cac:PartyIdentification>
<cac:PostalAddress>
<cbc:StreetName>Yellow Brick Road</cbc:StreetName>
<cbc:CityName>Kuki</cbc:CityName>
<cbc:PostalZone>400001</cbc:PostalZone>
<cbc:CountrySubentity>RO-CJ</cbc:CountrySubentity>
<cac:Country>
<cbc:IdentificationCode>RO</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>12345678</cbc:CompanyID>
<cac:TaxScheme/>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>Test S.r.o</cbc:RegistrationName>
<cbc:CompanyID>J12/1234/2016</cbc:CompanyID>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PostalAddress>
<cbc:StreetName>Strada Zebreiou 432</cbc:StreetName>
<cbc:CityName>Bacau</cbc:CityName>
<cbc:PostalZone>57433</cbc:PostalZone>
<cbc:CountrySubentity>RO-BC</cbc:CountrySubentity>
<cac:Country>
<cbc:IdentificationCode>RO</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>RO17364910</cbc:CompanyID>
<cac:TaxScheme/>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>POP Alexandra SRL</cbc:RegistrationName>
<cbc:CompanyID>RO17364910</cbc:CompanyID>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:PaymentMeans>
<cbc:PaymentMeansCode>31</cbc:PaymentMeansCode>
</cac:PaymentMeans>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="EUR">1279.45</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="EUR">6733.95</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="EUR">1279.45</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>19</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:LineExtensionAmount currencyID="EUR">6733.95</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID="EUR">6733.95</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID="EUR">8013.4</cbc:TaxInclusiveAmount>
<cbc:PayableAmount currencyID="EUR">8013.4</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>101</cbc:ID>
<cbc:InvoicedQuantity unitCode="H87">26935.78</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">6733.95</cbc:LineExtensionAmount>
<cac:Item>
<cbc:Name>Test</cbc:Name>
<cac:ClassifiedTaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>19</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:ClassifiedTaxCategory>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="EUR">0.25</cbc:PriceAmount>
</cac:Price>
</cac:InvoiceLine>
</Invoice>
15 changes: 14 additions & 1 deletion tests/Models/InvoiceTotalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class InvoiceTotalsTest extends TestCase {
private $invoice;

protected function setUp(): void {
$this->invoice = new Invoice();
$this->invoice = (new Invoice)->setRoundingMatrix(['' => 3]);
}

public function testClassConstructors(): void {
Expand All @@ -29,6 +29,19 @@ public function testClassConstructors(): void {
$this->assertEquals(100, $totalsB->payableAmount);
}

public function testRoundingOfTotals(): void {
$line = (new InvoiceLine())
->setPrice(0.25)
->setQuantity(26935.78)
->setVatRate(19);
$this->invoice->addLine($line);

$totals = $this->invoice->getTotals();
$this->assertEquals(6733.945, $totals->taxExclusiveAmount);
$this->assertEquals(1279.45, $totals->vatAmount);
$this->assertEquals(8013.395, $totals->taxInclusiveAmount);
}

public function testVatExemptionReasons(): void {
$firstLine = (new InvoiceLine())
->setName('Line #1')
Expand Down

0 comments on commit 0b60be1

Please sign in to comment.