atgp / factur-x

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

Generated file name #17

Closed thierryler closed 1 year ago

thierryler commented 1 year ago

Is it possible to add code to specify the wanted name (next to outputFilePath) for the generated file?

Now, I have to copy the file to change the name:

$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
);
// rename($generatedFacturxFile, $pdfInvoicexFile);
copy($generatedFacturxFile, $pdfInvoicexFile);
lucas-gp commented 1 year ago

Hi @thierryler,

Indeed, could you make a pull request about it to allow to use outputFilePath to be a directory or a file ?

thierryler commented 1 year ago

I do not have the skills to create a pull request on php.

In the code, I think we can simply add $outputFileName = '' in the function parameters.

And replace

$facturxGeneratedFileName = 'invoice-facturx-'.date('Ymdhis').'.pdf';

by

$facturxGeneratedFileName = $outputFileName;
if(empty($facturxGeneratedFileName)) {
    $facturxGeneratedFileName = 'invoice-facturx-'.date('Ymdhis').'.pdf';
}
benito103e commented 1 year ago

I would like to split the method generateFacturxFromFiles into 2 new ones :

I can also remove the option to export on a file, because it's easy to use a file_put_content or a a resource.

benito103e commented 1 year ago

Closed with #28 : I remove the method to save into file. You can use your own code to save to a file.

$writer = new \Atgp\FacturX\Writer();
$facturxPdf = $writer->generate($pdf, $facturxXml);

file_put_content('my-facturx.pdf', $facturxPdf);