ConnectingEurope / eInvoicing-EN16931

Validation artefacts for the European eInvoicing standard EN 16931
Other
138 stars 54 forks source link

UBL - BT-146, 147, 148 - Price details #49

Closed jurajmarkovic closed 6 years ago

jurajmarkovic commented 6 years ago

In UBL validation there are [UBL-DT-01]-Amounts shall be decimal up to two fraction digits which raise the error when using more then 2 decimals on Item price discount (BT-147) and Item gross price (BT-148):

<cac:Price>
    <cbc:PriceAmount currencyID="HRK">0.1212</cbc:PriceAmount>
    <cbc:BaseQuantity unitCode="EA">1</cbc:BaseQuantity>
    <cac:AllowanceCharge>
        <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
[UBL-DT-01]-Amounts shall be decimal up to two fraction digits 
        <cbc:Amount currencyID="HRK">0.0022</cbc:Amount>
[UBL-DT-01]-Amounts shall be decimal up to two fraction digits 
        <cbc:BaseAmount currencyID="HRK">0.1234</cbc:BaseAmount>
    </cac:AllowanceCharge>
</cac:Price>

According to the EN 16931-1 Semantic data model document, p. 93-94, Table 26 - Allowed number of decimals, there is no restriction on maximum allowed number of decimals for Item net price (BT-146), Item price discount (BT-147) and Item gross price (BT-148). However, in the same table, Invoice line net amount (BT-131), Invoice line allowance amount (BT-136) and base amount (BT-137), Invoice line charge amount (BT-141) and base amount (BT-142) are restricted to two decimal digits which is all right. Item net price can be more than 2 digits, but gross price and discount amount cannot.

The dilemma is if this is a validation issue or way of rounding Item prices and discounts.

phax commented 6 years ago

Hi. Can you please provide the whole InvoiceLine - so far I don't see the problem. Okay, PriceAmount has more than 2 digits, but LineExtensionAmount has no. E.g. the following example works for me:

    <cac:InvoiceLine>
        <cbc:ID>1</cbc:ID>
        <cbc:InvoicedQuantity unitCode="EA">2</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="EUR">19.90</cbc:LineExtensionAmount>
        <cac:Item>
            <cbc:Name>PATAT FRITES 10MM 10KG</cbc:Name>
            <cac:SellersItemIdentification>
                <cbc:ID>166022</cbc:ID>
            </cac:SellersItemIdentification>
            <cac:ClassifiedTaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>6</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VA</cbc:ID>
                </cac:TaxScheme>
            </cac:ClassifiedTaxCategory>
       </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="EUR">9.9473</cbc:PriceAmount>
        </cac:Price>
    </cac:InvoiceLine>
jurajmarkovic commented 6 years ago

Hi, thanks for your fast reply. I will try to explain more precisely what seems to me could be a problem. PriceAmount has more than 2 digits (and this is OK), but also Price discount has more than 2 digits and this seems to be a problem (InvoiceLine/Price/AllowanceCharge/Amount and BaseAmount). Here is the whole InvoiceLine

<cac:InvoiceLine>
    <cbc:ID>1</cbc:ID>
    <cbc:InvoicedQuantity unitCode="EA">100.000</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount currencyID="HRK">12.12</cbc:LineExtensionAmount>
    <cac:Item>
        <cbc:Name>stavka 1</cbc:Name>
        <cac:OriginCountry>
            <cbc:IdentificationCode>HR</cbc:IdentificationCode>
        </cac:OriginCountry>
        <cac:ClassifiedTaxCategory>
            <cbc:ID>S</cbc:ID>
            <cbc:Percent>25</cbc:Percent>
            <cac:TaxScheme>
                <cbc:ID>VAT</cbc:ID>
            </cac:TaxScheme>
        </cac:ClassifiedTaxCategory>
    </cac:Item>
    <cac:Price>
        <cbc:PriceAmount currencyID="HRK">0.1212</cbc:PriceAmount>
        <cbc:BaseQuantity unitCode="EA">1</cbc:BaseQuantity>
        <cac:AllowanceCharge>
            <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
            <cbc:Amount currencyID="HRK">0.0022</cbc:Amount>
            <cbc:BaseAmount currencyID="HRK">0.1234</cbc:BaseAmount>
        </cac:AllowanceCharge>
    </cac:Price>
</cac:InvoiceLine>
phax commented 6 years ago

I see your problem. As soon as <cbc:Amount currencyID="HRK">0.0022</cbc:Amount> is added to the XML, the validation fails (with UBL-DT-01). Reason: the selector //*[ends-with(name(), 'Amount') and not(ends-with(name(),'PriceAmount'))] is too vague!

oriol commented 6 years ago

exclusion of AllowanceCharge amounts added in the selector.

oriol commented 6 years ago

Will revert this change as in the Norm, table 26 states that allowance and base amount must have a maximum of 2 digits.

phax commented 6 years ago

For "InvoiceLine Allowance Amount" I fully agree, but for the "non-binding" Price I think it is something different. So I suggest instead of adding and not(ancestor::cac:AllowanceCharge) I suggest to add and not(../../cac:Price/cac:AllowanceCharge)

phax commented 6 years ago

@jurajmarkovic can you please cross check, if that solution works for you - thanks.

jurajmarkovic commented 6 years ago

Sure, we will check now. I have already tried it on http://13.80.11.48:8000/invoice/upload (not sure if it is the same validator) and we've got an error that something is wrong with sch file: "An error occurred during the validation [Schematron file [/validator/invoice/ubl/schematron/EN16931-UBL-model.sch] is invalid]"

phax commented 6 years ago

Weird - is this your validator? Did you resolve the error?

jurajmarkovic commented 6 years ago

Unfortunatelly, we are still facing the same (fatal) errors: [SVRLFailedAssert@0x-128ae031: diagnosticRefs=[]; text=[UBL-DT-01]-Amounts shall be decimal up to two fraction digits; location=/Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:Amount; test=string-length(substring-after(.,'.'))<=2; flag=FATAL_ERROR] [SVRLFailedAssert@0x18ebb84b: diagnosticRefs=[]; text=[UBL-DT-01]-Amounts shall be decimal up to two fraction digits; location=/Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount; test=string-length(substring-after(.,'.'))<=2; flag=FATAL_ERROR]

Here is the whole Invoice xml: `<?xml version="1.0" encoding="UTF-8"?>

urn:cen.eu:en16931:2017 P1 test decimal 1 2018-02-05 2018-02-28 380 HRK HRK 46830600751 ULICA 1 SPLIT 10000 ULICA 1, 10000 SPLIT HR HR46830600751 VAT HEP SPLIT 086374645 12346830600751 VUKOVARSKA PROMJENA ADRESE ZAGREB 10000 VUKOVARSKA PROMJENA ADRESE 20, 10000 ZAGREB HR HR46830600751 VAT HEP-OPERATOR DISTRIBUCIJSKOG SUSTAVA D.O.O. ZA DISTRIBUCIJU I OPSKRBU ELEKTRICNE ENERGIJE 08634543 4 3.03 12.12 3.03 S 25 VAT 12.12 12.12 15.15 15.15 1 100.000 12.12 stavka 1 HR S 25 VAT 0.1212 1 false 0.0022 0.1234 `
oriol commented 6 years ago

the xpath should be not(ancestor::cac:Price/cac:AllowanceCharge)

jurajmarkovic commented 6 years ago

Thanks, we will check this first thing in the morning

jurajmarkovic commented 6 years ago

Everything OK now. Thanks

phax commented 6 years ago

Thanks for cross-checking and thanks for the error report!