Generate documents with versions

Hello everyone,
Is there an easy way to change from overwriting generated documents to a mode where the existing files are kept for good and new files are saved with consecutive version numbers?
I’ve tried and search for answers on different plattforms. Please forgive me if the answer is already written somewhere.

As I understood, if a PDF is generated (Invoice, Purchase Order, …) this (one many?) path is taken:

include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
-> $obj->generateDocument
-> CommonObject::commonGenerateDocument
-> $obj->write_file

If the call comes from a custom module the method is defined at core/modules/MyModuleName/doc/pdf_MyModuleName_ReportName.modules.php and member of ‘class pdf_MyModuleName_ReportName extends CommonDocGenerator’

public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) is where the PDF is designed and written to file.

By default (what the module builder creates) the name of the file is defined here
$objectref = dol_sanitizeFileName($object->ref);
$dir = $conf->lims->dir_output."/".$objectref;
$file = $dir."/".$objectref.".pdf";
and could be later changed by hook beforePDFCreation

After object $pdf has been prepared, this will finally write the document:
$pdf->Close();
$pdf->Output($file, ‘F’);

As I understand, $file could be manipulated so that the file doesn’t get constantly overwritten.
For example the original (1st generated file) has name FancyReport_0010.pdf, the next time the report is generated using FancyReport_0001-1.pdf.

How do other people solve a versioning of reports? Is there a better way?
Thanks!!

Dolibarr 12 and higher would be ok.
No need to check for compatibility for older versions.

Now I’m not sure if I understood you correctly. What did you mean with ‘check compatibility’ … ?

Well, even this is an older thread, here is the answer: Use MAIN_DOC_USE_TIMING to add a timestamp to your document.
(I don’t know when this was introduced. It works for me with version 15.0.2.)

1 Like

I tried this but did not work

what will i be missing

i gave 1

image

MAIN_DOC_USE_TIMING ► Add a timestamp at end of generated document. Value must be format of timestamp. For example: %Y%m%d%H%M (only for ODT files)

i see this only works for ODT files

any work around for pdf file

Hello,

Either you make your own PDF document template, or you buy external modules like :

1 Like