Skip to content

Commit

Permalink
Merge pull request #7 from yogi70/fixInvalidTaxIfZero
Browse files Browse the repository at this point in the history
Fix invalid tax if zero
  • Loading branch information
horstoeko authored Dec 20, 2024
2 parents 8054662 + ebfbaf5 commit 8a4d16f
Show file tree
Hide file tree
Showing 5 changed files with 514 additions and 6 deletions.
1 change: 1 addition & 0 deletions build/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<file>../tests/testcases/CiiToUblTechnical3Test.php</file>
<file>../tests/testcases/CiiToUblTechnical4Test.php</file>
<file>../tests/testcases/CiiToUblTechnical5Test.php</file>
<file>../tests/testcases/CiiToUblWithoutTaxTest.php</file>
<file>../tests/testcases/UblToCiiSimpleTest.php</file>
<file>../tests/testcases/UblToCiiSimple2Test.php</file>
</testsuite>
Expand Down
10 changes: 10 additions & 0 deletions src/XmlConverterCiiToUbl.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,14 @@ function ($taxTotalAmountNode) {
'currencyID',
$taxTotalAmountNode->getAttribute('currencyID')
);
},
function() use ($invoiceHeaderSettlement) {
$this->destination->elementWithAttribute(
'cbc:TaxAmount',
0.0,
'currencyID',
$this->source->queryValue('./ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)
);
}
);

Expand All @@ -1236,12 +1244,14 @@ function ($tradeTaxNode) use ($invoiceHeaderSettlement) {
$this->formatAmount($this->source->queryValue('./ram:BasisAmount', $tradeTaxNode)),
'currencyID',
$this->source->queryValue('./ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount/@currencyID', $invoiceHeaderSettlement)
?? $this->source->queryValue('./ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)
);
$this->destination->elementWithAttribute(
'cbc:TaxAmount',
$this->formatAmount($this->source->queryValue('./ram:CalculatedAmount', $tradeTaxNode)),
'currencyID',
$this->source->queryValue('./ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount/@currencyID', $invoiceHeaderSettlement)
?? $this->source->queryValue('./ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)
);

$this->destination->startElement('cac:TaxCategory');
Expand Down
15 changes: 9 additions & 6 deletions src/XmlDocumentReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,12 @@ public function whenExists(string $expression, ?DOMNode $contextNode, $callback,
public function whenNotExists(string $expression, ?DOMNode $contextNode, $callback, $callbackElse = null): XmlDocumentReader
{
if (!$this->exists($expression, $contextNode)) {
$this->fireCallback($callback);
} else {
$this->fireCallback(
$callback,
$callbackElse,
$this->query($expression, $contextNode)->item(0),
$this->query($expression, $contextNode)->item(0)->parentNode
);
} else {
$this->fireCallback($callbackElse);
$this->query($expression, $contextNode)->item(0)->parentNode);
}

return $this;
Expand Down Expand Up @@ -330,7 +329,11 @@ public function whenNotEquals(string $expression, ?DOMNode $contextNode, $values
if ($equals === false) {
$this->fireCallback($callback);
} else {
$this->fireCallback($callbackElse);
$this->fireCallback(
$callbackElse,
$this->query($expression, $contextNode)->item(0),
$this->query($expression, $contextNode)->item(0)->parentNode
);
}

return $this;
Expand Down
186 changes: 186 additions & 0 deletions tests/assets/cii/4_cii_without_tax.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:a="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:10" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rsm:ExchangedDocumentContext>
<ram:BusinessProcessSpecifiedDocumentContextParameter>
<ram:ID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</ram:ID>
</ram:BusinessProcessSpecifiedDocumentContextParameter>
<ram:GuidelineSpecifiedDocumentContextParameter>
<ram:ID>urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>
</rsm:ExchangedDocumentContext>
<rsm:ExchangedDocument>
<ram:ID>471102</ram:ID>
<ram:TypeCode>380</ram:TypeCode>
<ram:IssueDateTime>
<udt:DateTimeString format="102">20180305</udt:DateTimeString>
</ram:IssueDateTime>
<ram:IncludedNote>
<ram:Content>Rechnung gemäß Bestellung vom 01.03.2018.</ram:Content>
</ram:IncludedNote>
<ram:IncludedNote>
<ram:Content>Lieferant GmbH
Lieferantenstraße 20
80333 München
Deutschland
Geschäftsführer: Hans Muster
Handelsregisternummer: H A 123

</ram:Content>
<ram:SubjectCode>REG</ram:SubjectCode>
</ram:IncludedNote>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>TB100A4</ram:LineID>
<ram:IncludedNote>
<ram:Content>Bemerkung zu Trennblättern</ram:Content>
</ram:IncludedNote>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:GlobalID schemeID="0160">4012345001234</ram:GlobalID>
<ram:SellerAssignedID>TB100A4</ram:SellerAssignedID>
<ram:Name>Trennblätter A4</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount>9.90</ram:ChargeAmount>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="H87">20.00</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>K</ram:CategoryCode>
<ram:ExemptionReasonCode>VATEX-EU-IC</ram:ExemptionReasonCode>
<ram:RateApplicablePercent>0.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount>198.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>ARNR2</ram:LineID>
<ram:IncludedNote>
<ram:Content>Bemerkung zur Banane</ram:Content>
</ram:IncludedNote>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:GlobalID schemeID="0160">4012345001235</ram:GlobalID>
<ram:SellerAssignedID>ARNR2</ram:SellerAssignedID>
<ram:Name>Joghurt Banane</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount>5.50</ram:ChargeAmount>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="H87">50.00</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>K</ram:CategoryCode>
<ram:ExemptionReasonCode>VATEX-EU-IC</ram:ExemptionReasonCode>
<ram:RateApplicablePercent>0.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount>275.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:ApplicableHeaderTradeAgreement>
<ram:BuyerReference>34676-342323</ram:BuyerReference>
<ram:SellerTradeParty>
<ram:ID>549910</ram:ID>
<ram:Name>Lieferant GmbH</ram:Name>
<ram:DefinedTradeContact>
<ram:PersonName>Heinz Mükker</ram:PersonName>
<ram:DepartmentName>Buchhaltung</ram:DepartmentName>
<ram:TelephoneUniversalCommunication>
<ram:CompleteNumber>+49-111-2222222</ram:CompleteNumber>
</ram:TelephoneUniversalCommunication>
<ram:EmailURIUniversalCommunication>
<ram:URIID>hmuekker@example.com</ram:URIID>
</ram:EmailURIUniversalCommunication>
</ram:DefinedTradeContact>
<ram:PostalTradeAddress>
<ram:PostcodeCode>80333</ram:PostcodeCode>
<ram:LineOne>Lieferantenstraße 20</ram:LineOne>
<ram:CityName>München</ram:CityName>
<ram:CountryID>DE</ram:CountryID>
</ram:PostalTradeAddress>
<ram:URIUniversalCommunication>
<ram:URIID schemeID="EM">seller@example.com</ram:URIID>
</ram:URIUniversalCommunication>
<ram:SpecifiedTaxRegistration>
<ram:ID schemeID="VA">DE123456789</ram:ID>
</ram:SpecifiedTaxRegistration>
</ram:SellerTradeParty>
<ram:BuyerTradeParty>
<ram:ID>GE2020211</ram:ID>
<ram:Name>Kunden AG Mitte</ram:Name>
<ram:PostalTradeAddress>
<ram:PostcodeCode>1717</ram:PostcodeCode>
<ram:LineOne>Pont Adolphe</ram:LineOne>
<ram:CityName>Hollerich Luxembourg</ram:CityName>
<ram:CountryID>LU</ram:CountryID>
</ram:PostalTradeAddress>
<ram:URIUniversalCommunication>
<ram:URIID schemeID="EM">customer@example.com</ram:URIID>
</ram:URIUniversalCommunication>
<ram:SpecifiedTaxRegistration>
<ram:ID schemeID="VA">LU12345678</ram:ID>
</ram:SpecifiedTaxRegistration>
</ram:BuyerTradeParty>
</ram:ApplicableHeaderTradeAgreement>
<ram:ApplicableHeaderTradeDelivery>
<ram:ShipToTradeParty>
<ram:ID>GE2020212</ram:ID>
<ram:Name>Kunden AG Mitte</ram:Name>
<ram:PostalTradeAddress>
<ram:PostcodeCode>1717</ram:PostcodeCode>
<ram:LineOne>Pont Adolphe</ram:LineOne>
<ram:CityName>Hollerich Luxembourg</ram:CityName>
<ram:CountryID>LU</ram:CountryID>
</ram:PostalTradeAddress>
</ram:ShipToTradeParty>
<ram:ActualDeliverySupplyChainEvent>
<ram:OccurrenceDateTime>
<udt:DateTimeString format="102">20180305</udt:DateTimeString>
</ram:OccurrenceDateTime>
</ram:ActualDeliverySupplyChainEvent>
</ram:ApplicableHeaderTradeDelivery>
<ram:ApplicableHeaderTradeSettlement>
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
<ram:SpecifiedTradeSettlementPaymentMeans>
<ram:TypeCode>58</ram:TypeCode>
<ram:PayeePartyCreditorFinancialAccount>
<ram:IBANID>DE12500105170648489890</ram:IBANID>
</ram:PayeePartyCreditorFinancialAccount>
</ram:SpecifiedTradeSettlementPaymentMeans>
<ram:ApplicableTradeTax>
<ram:CalculatedAmount>0.00</ram:CalculatedAmount>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:BasisAmount>473.00</ram:BasisAmount>
<ram:CategoryCode>K</ram:CategoryCode>
<ram:ExemptionReasonCode>VATEX-EU-IC</ram:ExemptionReasonCode>
<ram:RateApplicablePercent>0.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradePaymentTerms>
<ram:Description>Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3% Skonto innerhalb 10 Tagen bis 15.03.2018</ram:Description>
</ram:SpecifiedTradePaymentTerms>
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
<ram:LineTotalAmount>473.00</ram:LineTotalAmount>
<ram:TaxBasisTotalAmount>473.00</ram:TaxBasisTotalAmount>
<ram:GrandTotalAmount>473.00</ram:GrandTotalAmount>
<ram:DuePayableAmount>473.00</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>
Loading

0 comments on commit 8a4d16f

Please sign in to comment.