dolibarr 25.0.0-alpha
pdf_ledger.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Nick Fragoulis
10 * Copyright (C) 2024-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
33require_once DOL_DOCUMENT_ROOT.'/core/modules/accountancy/modules_accountancy.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
38
43{
47 public $db;
48
52 public $name;
53
57 public $description;
58
62 public $update_main_doc_field;
63
67 public $type;
68
73 public $version = 'dolibarr';
74
78 public $fromDate;
79
83 public $toDate;
84
88 public $ledgerType;
89
95 public function __construct(DoliDB $db)
96 {
97 global $langs, $mysoc;
98
99 $this->name = "ledger";
100 $this->description = $langs->trans("PDFAccountancyLedgerDescription");
101 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
102
103 // Dimension page
104 $this->type = 'pdf';
105 $formatarray = pdf_getFormat();
106 $this->page_largeur = $formatarray['width'];
107 $this->page_hauteur = $formatarray['height'];
108 $this->format = array($this->page_largeur, $this->page_hauteur);
109 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
110 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
111 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
112 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
113 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
114 $this->option_logo = 1; // Display logo
115 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
116 $this->watermark = '';
117
118 if ($mysoc === null) {
119 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
120 return;
121 }
122
123 // Get source company
124 $this->emetteur = $mysoc;
125 if (empty($this->emetteur->country_code)) {
126 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
127 }
128
129 $this->tabTitleHeight = 5; // default height
130
131 parent::__construct($db);
132 }
133
134 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
144 public function write_file(BookKeeping $object, Translate $outputlangs, string $srctemplatepath = '', bool $directDownload = true)
145 {
146 // phpcs:enable
147 global $user, $conf, $langs, $hookmanager;
148
149 $hidedesc = $hidedetails = $hideref = 0;
150
151 $object->fetch_thirdparty();
152
153 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
154 if (getDolGlobalString('MAIN_USE_FPDF')) {
155 $outputlangs->charset_output = 'ISO-8859-1';
156 }
157
158 // Load traductions files required by page
159 $outputlangs->loadLangs(array("main", "bills", "orders", "companies", "other", "accountancy", "compta"));
160
161 global $outputlangsbis;
162 $outputlangsbis = null;
163 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
164 $outputlangsbis = new Translate('', $conf);
165 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
166 $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "other", "propal", "sendings", "productbatch", "compta"));
167 }
168
169 $nblines = count($object->lines);
170
171 if (!$conf->accounting->multidir_output[$conf->entity]) {
172 $this->error = $langs->transnoentities("ErrorAccountancyDirectoryNotDefined");
173 return 0;
174 }
175
176 // Definition of $dir and $file
177 $dir = $conf->accounting->multidir_output[$conf->entity]."/export";
178 if ($object->specimen) {
179 $file = "{$dir}/SPECIMEN_{$this->name}.pdf";
180 } else {
181 $expref = dol_sanitizeFileName($object->ref);
182 $date = date('YmdHis', dol_now());
183 $file = "{$dir}/{$this->name}_{$date}.pdf";
184 }
185
186 if (!file_exists($dir)) {
187 if (dol_mkdir($dir) < 0) {
188 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
189 return 0;
190 }
191 }
192
193 // Add pdfgeneration hook
194 if (!is_object($hookmanager)) {
195 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
196 $hookmanager = new HookManager($this->db);
197 }
198 $hookmanager->initHooks(array('pdfgeneration'));
199 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
200 global $action;
201 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
202
203 // Set nblines with the new facture lines content after hook
204 $nblines = is_array($object->lines) ? count($object->lines) : 0;
205
206 $pdf = pdf_getInstance($this->format);
207 $default_font_size = pdf_getPDFFontSize($outputlangs) - 2;
208 $heightforinfotot = 8; // Height reserved to output the info and total part
209 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
210 $heightforfooter = $this->marge_basse + 14; // Height reserved to output the footer (value include bottom margin)
211 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
212 $heightforfooter += 6;
213 }
214 $pdf->setAutoPageBreak(true, 0);
215
216 if (class_exists('TCPDF')) {
217 $pdf->setPrintHeader(false);
218 $pdf->setPrintFooter(false);
219 }
220 $pdf->SetFont(pdf_getPDFFont($outputlangs));
221 // Set path to the background PDF File
222 if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
223 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
224 $tplidx = $pdf->importPage(1);
225 }
226
227 $pdf->Open();
228 $pagenb = 0;
229 $pdf->SetDrawColor(128, 128, 128);
230
231 if (method_exists($pdf, 'AliasNbPages')) {
232 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
233 }
234
235 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
236 if ($this->ledgerType == "sub") {
237 $pdf->SetSubject($outputlangs->transnoentities("BookkeepingSubAccount"));
238 } else {
239 $pdf->SetSubject($outputlangs->transnoentities("AccountancyLedger"));
240 }
241 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
242 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
243 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("AccountancyLedger"));
244 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
245 $pdf->SetCompression(false);
246 }
247
248 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
249 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
250
251 // New page
252 $pdf->AddPage();
253 if (!empty($tplidx)) {
254 $pdf->useTemplate($tplidx);
255 }
256 $pagenb++;
257 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
258 $pdf->SetFont('', '', $default_font_size - 1);
259 $pdf->MultiCell(0, 3, ''); // Set interline to 3
260 $pdf->SetTextColor(0, 0, 0);
261
262 $tab_top = 40; // position of top tab
263 $tab_top_newpage = (getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 10 : $tab_top);
264
265 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
266
267 $this->posxdesc = $this->marge_gauche + 1;
268
269 // Displays notes. Here we are still on code executed only for the first page.
270 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
271
272 // Use new auto column system
273 $this->prepareArrayColumnField($object, $outputlangs);
274
275 // Table simulation to know the height of the title line
276 $pdf->startTransaction();
277 $pdf->SetFont('', 'B', $default_font_size - 1);
278 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
279 $pdf->SetFont('', '', $default_font_size - 1);
280 $pdf->rollbackTransaction(true);
281
282
283 $curY = $nexY = $tab_top + $this->tabTitleHeight;
284
285 // Loop on each lines
286 $pageposbeforeprintlines = $pdf->getPage();
287 $pagenb = $pageposbeforeprintlines;
288
289 // Knowing how many month our period covers
290 $fromYear = date('Y', $this->fromDate);
291 $fromMonth = date('m', $this->fromDate);
292 $toYear = date('Y', $this->toDate);
293 $toMonth = date('m', $this->toDate);
294 $nbMonths = (((int) $toYear - (int) $fromYear) * 12) + ((int) $toMonth - (int) $fromMonth) + 1;
295 $datePlusOneMonth = strtotime("-1 month", $this->fromDate);
296 $dates = [];
297 for ($i = 0; $i < $nbMonths; $i++) {
298 $datePlusOneMonth = strtotime("+1 month", $datePlusOneMonth);
299 $dates[$datePlusOneMonth] = dol_print_date($datePlusOneMonth, "%B %Y");
300 }
301
302 $account = '';
303 $accountDebit = $accountCredit = $totalDebit = $totalCredit = 0;
304 for ($i = 0; $i < $nblines; $i++) {
305 // Show total line / title line when account has changed
306 if ($this->ledgerType == "sub") {
307 if (empty($account) || $account != $object->lines[$i]->subledger_account) {
308 // Add the subtotal line
309 if (!empty($account)) {
310 $this->addTotalLine(
311 $pdf,
312 $curY,
313 $nexY,
314 $default_font_size,
315 $langs->trans('Total'),
316 $tab_top_newpage,
317 $accountDebit,
318 $accountCredit
319 );
320 }
321
322 // Add the title line
323 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
324 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
325 }
326 $this->addTitleLine(
327 $pdf,
328 $curY,
329 $nexY,
330 $default_font_size,
331 'piece_num',
332 $langs->trans('SubledgerAccount') . ' ' . length_accounta($object->lines[$i]->subledger_account) . ' - ' . $object->lines[$i]->subledger_label,
333 $tab_top_newpage
334 );
335
336 $account = $object->lines[$i]->subledger_account;
337 $accountDebit = $accountCredit = 0;
338 }
339 } else {
340 if (empty($account) || $account != $object->lines[$i]->numero_compte) {
341 $accountingAccount = new AccountingAccount($this->db);
342 $accountingAccount->fetch(0, $object->lines[$i]->numero_compte, true);
343
344 // Add the subtotal line
345 if (!empty($account)) {
346 $this->addTotalLine(
347 $pdf,
348 $curY,
349 $nexY,
350 $default_font_size,
351 $langs->transnoentities('Total'),
352 $tab_top_newpage,
353 $accountDebit,
354 $accountCredit
355 );
356 }
357
358 // Add the title line
359 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
360 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
361 }
362 $this->addTitleLine(
363 $pdf,
364 $curY,
365 $nexY,
366 $default_font_size,
367 'piece_num',
368 $langs->transnoentities('AccountAccountingShort') . ' ' . length_accountg((string) $accountingAccount->ref) . ' - ' . $accountingAccount->label,
369 $tab_top_newpage
370 );
371
372 $account = $object->lines[$i]->numero_compte;
373 $accountDebit = $accountCredit = 0;
374 }
375 }
376
377 $accountDebit += $object->lines[$i]->debit;
378 $accountCredit += $object->lines[$i]->credit;
379 $totalDebit += $object->lines[$i]->debit;
380 $totalCredit += $object->lines[$i]->credit;
381
382 $curY = $nexY;
383 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
384 $pdf->SetTextColor(0, 0, 0);
385
386 $pdf->setTopMargin($tab_top_newpage);
387 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
388 $pageposbefore = $pdf->getPage();
389
390 $showpricebeforepagebreak = 1;
391 $heightforsignature = 0;
392
393 // Column used for testing page change
394 // No check on column status, this column is mandatory
395 $pdf->startTransaction();
396
397 $this->printStdColumnContent($pdf, $curY, 'label', $object->lines[$i]->label_operation);
398
399 $pageposafter = $pdf->getPage();
400 if ($pageposafter > $pageposbefore) { // There is a pagebreak
401 $pdf->rollbackTransaction(true);
402
403 $pdf->AddPage('', '', true);
404 $pdf->setPage($pageposafter);
405 $curY = $tab_top_newpage + $this->tabTitleHeight;
406 $this->printStdColumnContent($pdf, $curY, 'label', $object->lines[$i]->label_operation);
407
408 $pageposafter = $pdf->getPage();
409 $posyafter = $pdf->GetY();
410 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
411 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text
412 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
413 $pdf->AddPage('', '', true);
414 if (!empty($tplidx)) {
415 $pdf->useTemplate($tplidx);
416 }
417 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
418 $pdf->setPage($pageposafter + 1);
419 }
420 } else {
421 // We found a page break
422 // Allows data in the first page if description is long enough to break in multiples pages
423 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
424 $showpricebeforepagebreak = 1;
425 } else {
426 $showpricebeforepagebreak = 0;
427 }
428 }
429 } else { // No pagebreak
430 $pdf->commitTransaction();
431 }
432 $nexY = max($pdf->GetY(), $nexY);
433
434 $nexY = $pdf->GetY();
435 $pageposafter = $pdf->getPage();
436
437 $pdf->setPage($pageposbefore);
438 $pdf->setTopMargin($this->marge_haute);
439 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
440
441 // We suppose that a too long description is moved completely on next page
442 if ($pageposafter > $pageposbefore) {
443 $pdf->setPage($pageposafter);
444 $curY = $tab_top_newpage + $this->tabTitleHeight;
445 }
446
447 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
448
449 // # of line
450 if ($this->getColumnStatus('position')) {
451 $this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
452 }
453
454 if ($this->getColumnStatus('date')) {
455 $this->printStdColumnContent($pdf, $curY, 'date', dol_print_date($object->lines[$i]->doc_date, 'day'));
456 $nexY = max($pdf->GetY(), $nexY);
457 }
458
459 if ($this->getColumnStatus('journal')) {
460 $this->printStdColumnContent($pdf, $curY, 'journal', $object->lines[$i]->code_journal);
461 $nexY = max($pdf->GetY(), $nexY);
462 }
463
464 if ($this->getColumnStatus('piece_num')) {
465 $this->printStdColumnContent($pdf, $curY, 'piece_num', (string) $object->lines[$i]->piece_num);
466 $nexY = max($pdf->GetY(), $nexY);
467 }
468
469 if ($this->getColumnStatus('lettering_code')) {
470 $this->printStdColumnContent($pdf, $curY, 'lettering_code', $object->lines[$i]->lettering_code ?? '');
471 $nexY = max($pdf->GetY(), $nexY);
472 }
473
474 if ($this->getColumnStatus('debit')) {
475 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($object->lines[$i]->debit, 'MT')));
476 $nexY = max($pdf->GetY(), $nexY);
477 }
478
479 if ($this->getColumnStatus('credit')) {
480 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($object->lines[$i]->credit, 'MT')));
481 $nexY = max($pdf->GetY(), $nexY);
482 }
483
484 if ($this->getColumnStatus('balance')) {
485 // Running balance of the account, not of the single line: the screen ledger shows the
486 // accumulated balance per account, and the accumulators are already fed above (#40789).
487 $solde = $accountCredit - $accountDebit;
488 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' ' . $langs->trans('CreditShort') : ' ' . $langs->trans('DebitShort'));
489 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
490 $nexY = max($pdf->GetY(), $nexY);
491 }
492
493 $parameters = array(
494 'object' => $object,
495 'i' => $i,
496 'pdf' => & $pdf,
497 'curY' => & $curY,
498 'nexY' => & $nexY,
499 'outputlangs' => $outputlangs,
500 'hidedetails' => $hidedetails
501 );
502 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this);
503
504 // Add line
505 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
506 $this->addDashLine($pdf, $pageposafter, $nexY);
507 }
508
509 // Detect if some page were added automatically and output _tableau for past pages
510 while ($pagenb < $pageposafter) {
511 $pdf->setPage($pagenb);
512 if ($pagenb == $pageposbeforeprintlines) {
513 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
514 } else {
515 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
516 }
517 $this->_pagefoot($pdf, $object, $outputlangs, 1);
518 $pagenb++;
519 $pdf->setPage($pagenb);
520 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
521 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
522 $this->_pagehead($pdf, $object, 0, $outputlangs);
523 }
524 if (!empty($tplidx)) {
525 $pdf->useTemplate($tplidx);
526 }
527 }
528 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
529 if ($pagenb == 1) {
530 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
531 } else {
532 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
533 }
534 $this->_pagefoot($pdf, $object, $outputlangs, 1);
535 // New page
536 $pdf->AddPage();
537 if (!empty($tplidx)) {
538 $pdf->useTemplate($tplidx);
539 }
540 $pagenb++;
541 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
542 $this->_pagehead($pdf, $object, 0, $outputlangs);
543 }
544 }
545 }
546
547 // Add total line for last account
548 if (!empty($object->lines)) {
549 // Add line
550 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
551 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
552 }
553 $this->addTotalLine(
554 $pdf,
555 $curY,
556 $nexY,
557 $default_font_size,
558 $langs->transnoentities('Total'),
559 $tab_top_newpage,
560 $accountDebit,
561 $accountCredit
562 );
563 }
564
565 // Add grand total line
566 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
567 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
568 }
569 $this->addTotalLine(
570 $pdf,
571 $curY,
572 $nexY,
573 $default_font_size,
574 $langs->transnoentities('GrandTotals'),
575 $tab_top_newpage,
576 $totalDebit,
577 $totalCredit
578 );
579
580
581 // Show square
582 if ($pagenb == 1) {
583 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
584 } else {
585 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
586 }
587
588 // Pagefoot
589 $this->_pagefoot($pdf, $object, $outputlangs);
590 if (method_exists($pdf, 'AliasNbPages')) {
591 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
592 }
593
594 $pdf->Close();
595
596 $pdf->Output($file, $directDownload ? 'D' : 'F');
597
598 // Add pdfgeneration hook
599 $hookmanager->initHooks(array('pdfgeneration'));
600 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
601 global $action;
602 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
603 $this->warnings = $hookmanager->warnings;
604 if ($reshook < 0) {
605 $this->error = $hookmanager->error;
606 $this->errors = $hookmanager->errors;
607 dolChmod($file);
608 return -1;
609 }
610
611 dolChmod($file);
612
613 $this->result = array('fullpath' => $file);
614
615 return 1; // No error
616 }
617
618 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
633 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
634 {
635 global $conf;
636
637 // Force to disable hidetop and hidebottom
638 $hidebottom = 0;
639 if ($hidetop) {
640 $hidetop = -1;
641 }
642
643 $currency = !empty($currency) ? $currency : $conf->currency;
644 $default_font_size = pdf_getPDFFontSize($outputlangs);
645
646 // Amount in (at tab_top - 1)
647 $pdf->SetTextColor(0, 0, 0);
648 $pdf->SetFont('', '', $default_font_size - 2);
649
650 if (empty($hidetop)) {
651 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
652 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
653 }
654 }
655
656 $pdf->SetDrawColor(128, 128, 128);
657 $pdf->SetFont('', '', $default_font_size - 1);
658
659 // Output Rect
660 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
661
662 $pdf->SetFont('', 'B', $default_font_size - 1);
663 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
664 $pdf->SetFont('', '', $default_font_size - 1);
665
666
667 if (empty($hidetop)) {
668 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
669 }
670 }
671
672 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
682 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
683 {
684 global $conf, $langs;
685
686 $ltrdirection = 'L';
687 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
688
689 // Load traductions files required by page
690 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
691
692 $default_font_size = pdf_getPDFFontSize($outputlangs);
693
694 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
695
696
697 $pdf->SetTextColor(0, 0, 60);
698 $pdf->SetFont('', 'B', $default_font_size + 3);
699
700 $w = 110;
701 $posy = $this->marge_haute;
702 $posx = $this->marge_gauche;
703 $hautcadre = 20;
704 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
705 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
706
707 $posx = $this->page_largeur - $this->marge_droite - $w;
708 $nexY = $posy;
709
710 // Name of soc
711 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
712 $text = (string) $this->emetteur->name;
713 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset((string) $text), 0, $ltrdirection);
714 $nexY = max($pdf->GetY(), $nexY);
715
716 // Date of document
717 $pdf->SetFont('', '', $default_font_size - 2);
718 $pdf->SetXY($this->marge_gauche + 2, $nexY);
719 $pdf->SetTextColor(0, 0, 60);
720 $textDateNow = $outputlangs->transnoentities("PrintDate");
721 $pdf->MultiCell($w / 3, 3, $textDateNow . " : " . date('d/m/Y', dol_now()), '', 'L');
722 $nexY = max($pdf->GetY(), $nexY);
723
724 // Page title
725 $pdf->SetFont('', 'B', $default_font_size + 3);
726 $pdf->SetXY($posx - 2, $posy + 2);
727 $pdf->SetTextColor(0, 0, 120);
728 if ($this->ledgerType == "sub") {
729 $title = $outputlangs->transnoentities("BookkeepingSubAccount");
730 } else {
731 $title = $outputlangs->transnoentities("PdfLedgerTitle");
732 }
733 $pdf->MultiCell($w / 3, 3, $title, 0, 'C');
734 $nexY = max($pdf->GetY(), $nexY);
735
736 // Date From To
737 $pdf->SetFont('', 'B', $default_font_size);
738 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
739 $pdf->SetTextColor(0, 0, 60);
740
741 $fromDate = dol_print_date($this->fromDate, 'day');
742 $toDate = dol_print_date($this->toDate, 'day');
743 $textDate = $outputlangs->transnoentities("From") . " " . $fromDate . " " . $outputlangs->transnoentities("To") . " " . $toDate;
744 $pdf->MultiCell($w / 3, 4, $textDate, 0, 'R');
745 $nexY = max($pdf->GetY(), $nexY);
746
747 $pdf->SetTextColor(0, 0, 0);
748 return $nexY;
749 }
750
751 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
761 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
762 {
763 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
764 return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
765 }
766
777 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
778 {
779 global $conf, $hookmanager;
780
781 // Default field style for content
782 $this->defaultContentsFieldsStyle = array(
783 'align' => 'R', // R,C,L
784 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
785 );
786
787 // Default field style for content
788 $this->defaultTitlesFieldsStyle = array(
789 'align' => 'C', // R,C,L
790 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
791 );
792
793 $rank = 0; // do not use negative rank
794 $this->cols['position'] = [
795 'rank' => $rank,
796 'width' => 10.0,
797 'status' => (bool) getDolGlobalInt('PDF_ACCOUNTANCY_LEDGER_ADD_POSITION'),
798 'title' => [
799 'textkey' => '#', // use lang key is useful in some case with module
800 'align' => 'C',
801 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
802 // 'label' => ' ', // the final label
803 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
804 ],
805 'content' => [
806 'align' => 'C',
807 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
808 ],
809 ];
810
811 $rank += 10; // do not use negative rank
812 $this->cols['date'] = [
813 'rank' => $rank,
814 'width' => 18.0, // only for desc
815 'status' => true,
816 'title' => [
817 'textkey' => 'Date', // use lang key is useful in some case with module
818 'align' => 'C',
819 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
820 // 'label' => ' ', // the final label
821 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
822 ],
823 'content' => [
824 'align' => 'L',
825 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
826 ],
827 ];
828
829 $rank += 10;
830 $this->cols['journal'] = [
831 'rank' => $rank,
832 'width' => 15.0,
833 'status' => true,
834 'title' => [
835 'textkey' => 'Journal', // use lang key is useful in some case with module
836 'align' => 'C',
837 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
838 // 'label' => ' ', // the final label
839 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
840 ],
841 'content' => [
842 'align' => 'L',
843 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
844 ],
845 'border-left' => true, // add left line separator
846 ];
847
848 $rank += 10;
849 $this->cols['piece_num'] = [
850 'rank' => $rank,
851 'width' => 15.0,
852 'status' => true,
853 'title' => [
854 'textkey' => 'Piece', // use lang key is useful in some case with module
855 'align' => 'C',
856 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
857 // 'label' => ' ', // the final label
858 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
859 ],
860 'content' => [
861 'align' => 'L',
862 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
863 ],
864 'border-left' => true, // add left line separator
865 ];
866
867 $rank += 10;
868 $this->cols['label'] = [
869 'rank' => $rank,
870 'width' => false,
871 'status' => true,
872 'title' => [
873 'textkey' => 'Label', // use lang key is useful in some case with module
874 'align' => 'C',
875 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
876 // 'label' => ' ', // the final label
877 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
878 ],
879 'content' => [
880 'align' => 'L',
881 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
882 ],
883 'border-left' => true, // add left line separator
884 ];
885
886
887 $rank += 10;
888 $this->cols['lettering_code'] = [
889 'rank' => $rank,
890 'width' => 14.0,
891 'status' => true,
892 'title' => [
893 'textkey' => 'Lettering', // use lang key is useful in some case with module
894 'align' => 'C',
895 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
896 // 'label' => ' ', // the final label
897 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
898 ],
899 'content' => [
900 'align' => 'R',
901 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
902 ],
903 'border-left' => true, // add left line separator
904 ];
905
906 $rank += 10;
907 $this->cols['debit'] = [
908 'rank' => $rank,
909 'width' => 15.0,
910 'status' => true,
911 'title' => [
912 'textkey' => 'AccountingDebit', // use lang key is useful in some case with module
913 'align' => 'C',
914 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
915 // 'label' => ' ', // the final label
916 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
917 ],
918 'content' => [
919 'align' => 'R',
920 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
921 ],
922 'border-left' => true, // add left line separator
923 ];
924
925 $rank += 10;
926 $this->cols['credit'] = array(
927 'rank' => $rank,
928 'width' => 15.0,
929 'status' => true,
930 'title' => array(
931 'textkey' => 'AccountingCredit', // use lang key is useful in some case with module
932 'align' => 'C',
933 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
934 // 'label' => ' ', // the final label
935 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
936 ),
937 'content' => array(
938 'align' => 'R',
939 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
940 ),
941 'border-left' => true, // add left line separator
942 );
943
944 $rank += 10;
945 $this->cols['balance'] = [
946 'rank' => $rank,
947 'width' => 20.0,
948 'status' => true,
949 'title' => [
950 'textkey' => 'Balance', // use lang key is useful in some case with module
951 'align' => 'C',
952 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
953 // 'label' => ' ', // the final label
954 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
955 ],
956 'content' => [
957 'align' => 'R',
958 'padding' => [1.0, 0.5, 1.0, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
959 ],
960 'border-left' => true, // add left line separator
961 ];
962
963 // Add extrafields cols
964 if (!empty($object->lines)) {
965 $line = reset($object->lines);
966 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
967 }
968
969 $parameters = array(
970 'object' => $object,
971 'outputlangs' => $outputlangs,
972 'hidedetails' => $hidedetails,
973 'hidedesc' => $hidedesc,
974 'hideref' => $hideref
975 );
976
977 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
978 if ($reshook < 0) {
979 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
980 } elseif (empty($reshook)) {
981 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
982 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
983 } else {
984 $this->cols = $hookmanager->resArray;
985 }
986 }
987
1002 protected function addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase = true)
1003 {
1004 global $langs;
1005
1006 $curY = $nexY;
1007 $pageposbefore = $pdf->getPage();
1008 $pdf->SetFont('', 'B', $default_font_size - 1);
1009 $pdf->startTransaction();
1010
1011 if ($uppercase) {
1012 $label = mb_strtoupper($label);
1013 }
1014 $this->printStdColumnContent($pdf, $curY, 'label', $label);
1015
1016 $pageposafter = $pdf->getPage();
1017 if ($pageposafter > $pageposbefore) { // There is a pagebreak
1018 $pdf->rollbackTransaction(true);
1019
1020 $pdf->AddPage('', '', true);
1021 $pdf->setPage($pageposafter);
1022 $curY = $tab_top_newpage + $this->tabTitleHeight;
1023 $this->printStdColumnContent($pdf, $curY, 'label', $label);
1024 }
1025
1026 $nexY = $pdf->GetY();
1027
1028 if ($this->getColumnStatus('debit')) {
1029 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($debit, 'MT')));
1030 $nexY = max($pdf->GetY(), $nexY);
1031 }
1032
1033 if ($this->getColumnStatus('credit')) {
1034 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($credit, 'MT')));
1035 $nexY = max($pdf->GetY(), $nexY);
1036 }
1037
1038 if ($this->getColumnStatus('balance')) {
1039 $solde = $credit - $debit;
1040 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' ' . $langs->trans('CreditShort') : ' ' . $langs->trans('DebitShort'));
1041 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
1042 $nexY = max($pdf->GetY(), $nexY);
1043 }
1044
1045 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
1046 $this->addDashLine($pdf, $pageposafter, $nexY);
1047 }
1048 }
1049}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:280
Class to manage accounting accounts.
Class to manage Ledger (General Ledger and Subledger)
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage Dolibarr database access.
Class to manage hooks.
Parent class of accountancy models.
addTitleLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $columnKey, string $label, $tab_top_newpage, bool $uppercase=true)
Add the total accountancy group line to pdf.
addDashLine(TCPDF $pdf, int $page, $y)
Add dash line.
Class to manage translations.
Class to build sending documents with model Espadon.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file(BookKeeping $object, Translate $outputlangs, string $srctemplatepath='', bool $directDownload=true)
Function to build pdf onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase=true)
Add a total line to pdf.
__construct(DoliDB $db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:296
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:792
pdf_pagefoot($pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1466
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:275
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140