josemmo / einvoicing

Library for reading and creating European-compliant electronic invoices (EN 16931)
https://josemmo.github.io/einvoicing/
MIT License
117 stars 30 forks source link

Reader shows BR-49 error when no cac:PaymentMeans is present, but cac:PaymentTerms is #56

Open yulkusal opened 4 months ago

yulkusal commented 4 months ago

Hello,

I received an invoice that shows BusinessRuleId BR-49, even if no cac:PaymentMeans is in the invoice. I played a little with several eInvoices and it looks like the presence of cac:PaymentTerms when cac:PaymentMeans is missing triggers the issue.

josemmo commented 4 months ago

Hello @yulkusal,

Could you provide an XML example? I don't fully understand what the issue is.

yulkusal commented 4 months ago

Example (names, descriptions, VATid modified from the original) `<?xml version="1.0" encoding="utf-8"?> <Invoice xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2">

urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.1 75366203 2024-06-19 2024-08-18 380 RO25 INGB 5001 0088 2833 0610 (EUR) RO76 INGB 5001 0088 2833 8710 (RON) RO68 INGB 5001 0088 2833 4710 (USD) DAP RON 7059287935 7059287935 Soseaua Bucuresti-Tunari nr.8 SECTOR1 010000 RO-B RO RO123456789 VAT XYZ Romania SRL J40/xxxx/xxxx credit@xyz.com.ro J40/YYYY/ZZZZ Str. Verde, Nr. 65 SECTOR1 020000 RO-B RO RO987654321 VAT CUSTOMER SRL J40/YYYY/ZZZZ 0311000100 sales@customer.ro 2024-06-19 Str. Testului 20, Warehouse Bucuresti SECTOR1 020001 RO-B 012978 RO Warehouse Bucuresti I060 166.42 875.88 166.42 S 19.00 VAT 875.88 875.88 1042.30 0.00 0.00 0.00 0.00 1042.30 00001 55418 / 0.18 2.000 875.88 7059287935 true Allowance 0.18 0.00 XXXXXXXXXXXXXXXXXXXXXXXXXX 0000000000YYYYYYYYYYYY S 19 VAT 437.94 ` The issue seems to be /src/Traits/InvoiceValidationTrait.php, line 170 ` if ($inv->getPayment() !== null && $inv->getPayment()->getMeansCode() === null)` My solution was to modify to `if ($inv->getPayment() !== null) { if ($inv->getPayment()->getTerms() !== null) return; if (($inv->getPayment()->getMeansCode() === null) && ($inv->getPayment()->getTerms() === null)) { return "A Payment instruction (BG-16) shall specify the Payment means type code (BT-81)"; } }`
josemmo commented 4 months ago

Got it, thanks! I'm preparing a fix.