atgp / factur-x

PHP library to manage your Factur-X / ZUGFeRD 2.0 PDF invoices files
MIT License
94 stars 22 forks source link

Error when I do not check the xsd #18

Closed thierryler closed 1 year ago

thierryler commented 1 year ago

When I do not check the xsd, there is a small bug.

Doing that

$pdfInvoiceFile = '/var/pdf/f4/invoice-' . $invoice->id . '.pdf';
$pdfInvoicexFile = '/var/pdf/f4/invoicex-' . $invoice->id . '.pdf';

$facturx = new Facturx();
$generatedFacturxFile = $facturx->generateFacturxFromFiles(
  $pdfInvoiceFile,
  $xmlInvoiceFile,
  'autodetect', // facturxProfil
  false, // checkXsd
  '/var/pdf/f4/xml', // outputFilePath
  [], // additionalAttachments
  true, // addFacturxLogo
  'Data' // relationship
);

I get this error:

Un erreur s'est produite ! 500 Internal Server Error - Error details: [0] FPDF error: Unsupported image type: /img/ in /var/web/f4/www/vendor/setasign/fpdf/fpdf.php on line 273. Backtrace: 
#0 /var/web/f4/www/vendor/setasign/fpdf/fpdf.php(888): FPDF->Error() 
#1 /var/web/f4/www/vendor/atgp/factur-x/src/Facturx.php(234): FPDF->Image() 
#2 /var/web/f4/www/src/Services/InvoiceService.php(110): Atgp\FacturX\Facturx->generateFacturxFromFiles() 
#3 /var/web/f4/www/src/Actions/Invoice/UserInvoiceController.php(113): App\Services\InvoiceService->generateInvoicePdf() 
#4 /var/web/f4/www/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(43): 

Actually, it is because $this->profil is null here:

$pdfWriter->Image(__DIR__.'/../img/'.static::FACTURX_LOGO[$this->profil], 197, 2.5, 7);

It is null because checkXsd is false, and profil is set in checkFacturxXsd().

Th.

lucas-gp commented 1 year ago

Hi, Fixed here d262d2b Thanks for feedback ;)

thierryler commented 1 year ago

Did you released a new version ?

lucas-gp commented 1 year ago

@thierryler just released v1.0.4

thierryler commented 1 year ago

Hello. The bug is solves but there is an other problem.

Using the same code with version 1.0.4.

Even when checkXsd is false, it still checks the xml.

Here is my XML:

<?xml version='1.0' encoding='UTF-8' ?>
<todo>

</todo>

As you can figure out, it is obviously wrong. But as checkXsd is false, it should not check. But it does and I get this error:

Un erreur s'est produite ! 500 Internal Server Error - Error details: [0] This XML is not a Factur-X XML because it misses the XML tag ExchangedDocumentContext/GuidelineSpecifiedDocumentContextParameter/ram:ID. in /.../www/vendor/atgp/factur-x/src/Facturx.php on line 287. Backtrace: #0 /.../www/vendor/atgp/factur-x/src/Facturx.php(221): Atgp\FacturX\Facturx->getFacturxProfil() #1 /.../www/src/Services/InvoiceService.php(176): Atgp\FacturX\Facturx->generateFacturxFromFiles() #2 /.../www/src/Actions/Invoice/UserInvoiceController.php(121): App\Services\InvoiceService->generateInvoicePdf() #3