num-num / ubl-invoice

A modern object-oriented PHP library to create valid UBL and Peppol BIS files
MIT License
81 stars 70 forks source link

Validation error due TaxTotal in InvoiceLine #5

Closed dragonfly4 closed 4 years ago

dragonfly4 commented 4 years ago

Using the sample of Version 1.5 to test your wonderful plugin.

The generated file does not pass UBL validation.

https://peppol.helger.com/public/locale-en_US/menuitem-validation-upload UBL Invoice 2.1

XML Schema - schemas/ubl21/maindoc/UBL-Invoice-2.1.xsd Error Location: file:///root/sample.php01.xml(71:18) Error message: [SAX] cvc-complex-type.2.4.b: The content of element 'cac:TaxTotal' is not complete. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":TaxAmount}' is expected. Technical details: cvc-complex-type.2.4.b: The content of element 'cac:TaxTotal' is not complete. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":TaxAmount}' is expected.

This is due the presence of a tag in InvoiceLine. If I comment out this line the file passes validation.

InvoiceLine.php#L195

        Schema::CAC . 'TaxTotal' => $this->taxTotal,

Is this a bug or did you add that line for a reason please?

dragonfly4 commented 4 years ago

After analyzing the code this is just a sample problem. Just add the tax tags for each line. This is quick & dirty so cleanup for own use.

// item tax $itemTax = new NumNum\UBL\TaxTotal(); $itemTax->setTaxAmount("10.00"); $itemTaxSub = new NumNum\UBL\TaxSubTotal(); $itemTaxSub->setTaxableAmount("10.00"); $itemTaxSub->setTaxAmount("2.00"); $itemTaxSub->setPercent("21.00"); $itemTaxCat = new NumNum\UBL\TaxCategory; $itemTaxCat->setId("S"); $itemTaxCat->setName("BTW 21%"); $itemTaxCat->setPercent("21.00"); $ItemTaxScheme = new NumNum\UBL\TaxScheme(); $ItemTaxScheme->setId("VAT"); $itemTaxCat->setTaxScheme($ItemTaxScheme); $itemTaxSub->setTaxCategory($itemTaxCat); $itemTax->addTaxSubTotal($itemTaxSub);

$invoiceLine->setTaxTotal($itemTax);

brtdv commented 4 years ago

Thanks. Yeah exactly, you can use the library to generate invalid XML's if you ommit a child tag or something. The example folder in this repo should be totally checked & recreated.

brtdv commented 4 years ago

I added a valid example in the tests/ folder in the fa55d62d49c9d933ec77a2b0bc9be46df04d8282 commit.