dolibarr 23.0.3
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->getFullName($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($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 $solde = $object->lines[$i]->credit - $object->lines[$i]->debit;
486 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' ' . $langs->trans('CreditShort') : ' ' . $langs->trans('DebitShort'));
487 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
488 $nexY = max($pdf->GetY(), $nexY);
489 }
490
491 $parameters = array(
492 'object' => $object,
493 'i' => $i,
494 'pdf' => & $pdf,
495 'curY' => & $curY,
496 'nexY' => & $nexY,
497 'outputlangs' => $outputlangs,
498 'hidedetails' => $hidedetails
499 );
500 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this);
501
502 // Add line
503 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
504 $this->addDashLine($pdf, $pageposafter, $nexY);
505 }
506
507 // Detect if some page were added automatically and output _tableau for past pages
508 while ($pagenb < $pageposafter) {
509 $pdf->setPage($pagenb);
510 if ($pagenb == $pageposbeforeprintlines) {
511 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
512 } else {
513 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
514 }
515 $this->_pagefoot($pdf, $object, $outputlangs, 1);
516 $pagenb++;
517 $pdf->setPage($pagenb);
518 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
519 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
520 $this->_pagehead($pdf, $object, 0, $outputlangs);
521 }
522 if (!empty($tplidx)) {
523 $pdf->useTemplate($tplidx);
524 }
525 }
526 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
527 if ($pagenb == 1) {
528 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
529 } else {
530 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
531 }
532 $this->_pagefoot($pdf, $object, $outputlangs, 1);
533 // New page
534 $pdf->AddPage();
535 if (!empty($tplidx)) {
536 $pdf->useTemplate($tplidx);
537 }
538 $pagenb++;
539 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
540 $this->_pagehead($pdf, $object, 0, $outputlangs);
541 }
542 }
543 }
544
545 // Add total line for last account
546 if (!empty($object->lines)) {
547 // Add line
548 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
549 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
550 }
551 $this->addTotalLine(
552 $pdf,
553 $curY,
554 $nexY,
555 $default_font_size,
556 $langs->transnoentities('Total'),
557 $tab_top_newpage,
558 $accountDebit,
559 $accountCredit
560 );
561 }
562
563 // Add grand total line
564 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
565 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
566 }
567 $this->addTotalLine(
568 $pdf,
569 $curY,
570 $nexY,
571 $default_font_size,
572 $langs->transnoentities('GrandTotals'),
573 $tab_top_newpage,
574 $totalDebit,
575 $totalCredit
576 );
577
578
579 // Show square
580 if ($pagenb == 1) {
581 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
582 } else {
583 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
584 }
585
586 // Pagefoot
587 $this->_pagefoot($pdf, $object, $outputlangs);
588 if (method_exists($pdf, 'AliasNbPages')) {
589 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
590 }
591
592 $pdf->Close();
593
594 $pdf->Output($file, $directDownload ? 'D' : 'F');
595
596 // Add pdfgeneration hook
597 $hookmanager->initHooks(array('pdfgeneration'));
598 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
599 global $action;
600 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
601 $this->warnings = $hookmanager->warnings;
602 if ($reshook < 0) {
603 $this->error = $hookmanager->error;
604 $this->errors = $hookmanager->errors;
605 dolChmod($file);
606 return -1;
607 }
608
609 dolChmod($file);
610
611 $this->result = array('fullpath' => $file);
612
613 return 1; // No error
614 }
615
616 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
631 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
632 {
633 global $conf;
634
635 // Force to disable hidetop and hidebottom
636 $hidebottom = 0;
637 if ($hidetop) {
638 $hidetop = -1;
639 }
640
641 $currency = !empty($currency) ? $currency : $conf->currency;
642 $default_font_size = pdf_getPDFFontSize($outputlangs);
643
644 // Amount in (at tab_top - 1)
645 $pdf->SetTextColor(0, 0, 0);
646 $pdf->SetFont('', '', $default_font_size - 2);
647
648 if (empty($hidetop)) {
649 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
650 $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')));
651 }
652 }
653
654 $pdf->SetDrawColor(128, 128, 128);
655 $pdf->SetFont('', '', $default_font_size - 1);
656
657 // Output Rect
658 $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
659
660 $pdf->SetFont('', 'B', $default_font_size - 1);
661 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
662 $pdf->SetFont('', '', $default_font_size - 1);
663
664
665 if (empty($hidetop)) {
666 $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
667 }
668 }
669
670 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
680 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
681 {
682 global $conf, $langs;
683
684 $ltrdirection = 'L';
685 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
686
687 // Load traductions files required by page
688 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
689
690 $default_font_size = pdf_getPDFFontSize($outputlangs);
691
692 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
693
694
695 $pdf->SetTextColor(0, 0, 60);
696 $pdf->SetFont('', 'B', $default_font_size + 3);
697
698 $w = 110;
699 $posy = $this->marge_haute;
700 $posx = $this->marge_gauche;
701 $hautcadre = 20;
702 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
703 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
704
705 $posx = $this->page_largeur - $this->marge_droite - $w;
706 $nexY = $posy;
707
708 // Name of soc
709 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
710 $text = $this->emetteur->name;
711 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
712 $nexY = max($pdf->GetY(), $nexY);
713
714 // Date of document
715 $pdf->SetFont('', '', $default_font_size - 2);
716 $pdf->SetXY($this->marge_gauche + 2, $nexY);
717 $pdf->SetTextColor(0, 0, 60);
718 $textDateNow = $outputlangs->transnoentities("PrintDate");
719 $pdf->MultiCell($w / 3, 3, $textDateNow . " : " . date('d/m/Y', dol_now()), '', 'L');
720 $nexY = max($pdf->GetY(), $nexY);
721
722 // Page title
723 $pdf->SetFont('', 'B', $default_font_size + 3);
724 $pdf->SetXY($posx - 2, $posy + 2);
725 $pdf->SetTextColor(0, 0, 120);
726 if ($this->ledgerType == "sub") {
727 $title = $outputlangs->transnoentities("BookkeepingSubAccount");
728 } else {
729 $title = $outputlangs->transnoentities("PdfLedgerTitle");
730 }
731 $pdf->MultiCell($w / 3, 3, $title, 0, 'C');
732 $nexY = max($pdf->GetY(), $nexY);
733
734 // Date From To
735 $pdf->SetFont('', 'B', $default_font_size);
736 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
737 $pdf->SetTextColor(0, 0, 60);
738
739 $fromDate = dol_print_date($this->fromDate, 'day');
740 $toDate = dol_print_date($this->toDate, 'day');
741 $textDate = $outputlangs->transnoentities("From") . " " . $fromDate . " " . $outputlangs->transnoentities("To") . " " . $toDate;
742 $pdf->MultiCell($w / 3, 4, $textDate, 0, 'R');
743 $nexY = max($pdf->GetY(), $nexY);
744
745 $pdf->SetTextColor(0, 0, 0);
746 return $nexY;
747 }
748
749 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
759 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
760 {
761 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
762 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);
763 }
764
775 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
776 {
777 global $conf, $hookmanager;
778
779 // Default field style for content
780 $this->defaultContentsFieldsStyle = array(
781 'align' => 'R', // R,C,L
782 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
783 );
784
785 // Default field style for content
786 $this->defaultTitlesFieldsStyle = array(
787 'align' => 'C', // R,C,L
788 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
789 );
790
791 $rank = 0; // do not use negative rank
792 $this->cols['position'] = [
793 'rank' => $rank,
794 'width' => 10,
795 'status' => (bool) getDolGlobalInt('PDF_ACCOUNTANCY_LEDGER_ADD_POSITION'),
796 'title' => [
797 'textkey' => '#', // use lang key is useful in some case with module
798 'align' => 'C',
799 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
800 // 'label' => ' ', // the final label
801 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
802 ],
803 'content' => [
804 'align' => 'C',
805 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
806 ],
807 ];
808
809 $rank += 10; // do not use negative rank
810 $this->cols['date'] = [
811 'rank' => $rank,
812 'width' => 18, // only for desc
813 'status' => true,
814 'title' => [
815 'textkey' => 'Date', // use lang key is useful in some case with module
816 'align' => 'C',
817 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
818 // 'label' => ' ', // the final label
819 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
820 ],
821 'content' => [
822 'align' => 'L',
823 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
824 ],
825 ];
826
827 $rank += 10;
828 $this->cols['journal'] = [
829 'rank' => $rank,
830 'width' => 15,
831 'status' => true,
832 'title' => [
833 'textkey' => 'Journal', // use lang key is useful in some case with module
834 'align' => 'C',
835 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
836 // 'label' => ' ', // the final label
837 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
838 ],
839 'content' => [
840 'align' => 'L',
841 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
842 ],
843 'border-left' => true, // add left line separator
844 ];
845
846 $rank += 10;
847 $this->cols['piece_num'] = [
848 'rank' => $rank,
849 'width' => 15,
850 'status' => true,
851 'title' => [
852 'textkey' => 'Piece', // use lang key is useful in some case with module
853 'align' => 'C',
854 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
855 // 'label' => ' ', // the final label
856 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
857 ],
858 'content' => [
859 'align' => 'L',
860 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
861 ],
862 'border-left' => true, // add left line separator
863 ];
864
865 $rank += 10;
866 $this->cols['label'] = [
867 'rank' => $rank,
868 'width' => false,
869 'status' => true,
870 'title' => [
871 'textkey' => 'Label', // use lang key is useful in some case with module
872 'align' => 'C',
873 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
874 // 'label' => ' ', // the final label
875 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
876 ],
877 'content' => [
878 'align' => 'L',
879 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
880 ],
881 'border-left' => true, // add left line separator
882 ];
883
884
885 $rank += 10;
886 $this->cols['lettering_code'] = [
887 'rank' => $rank,
888 'width' => 14,
889 'status' => true,
890 'title' => [
891 'textkey' => 'Lettering', // use lang key is useful in some case with module
892 'align' => 'C',
893 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
894 // 'label' => ' ', // the final label
895 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
896 ],
897 'content' => [
898 'align' => 'R',
899 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
900 ],
901 'border-left' => true, // add left line separator
902 ];
903
904 $rank += 10;
905 $this->cols['debit'] = [
906 'rank' => $rank,
907 'width' => 15,
908 'status' => true,
909 'title' => [
910 'textkey' => 'AccountingDebit', // use lang key is useful in some case with module
911 'align' => 'C',
912 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
913 // 'label' => ' ', // the final label
914 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
915 ],
916 'content' => [
917 'align' => 'R',
918 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
919 ],
920 'border-left' => true, // add left line separator
921 ];
922
923 $rank += 10;
924 $this->cols['credit'] = array(
925 'rank' => $rank,
926 'width' => 15,
927 'status' => true,
928 'title' => array(
929 'textkey' => 'AccountingCredit', // use lang key is useful in some case with module
930 'align' => 'C',
931 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
932 // 'label' => ' ', // the final label
933 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
934 ),
935 'content' => array(
936 'align' => 'R',
937 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
938 ),
939 'border-left' => true, // add left line separator
940 );
941
942 $rank += 10;
943 $this->cols['balance'] = [
944 'rank' => $rank,
945 'width' => 20,
946 'status' => true,
947 'title' => [
948 'textkey' => 'Balance', // use lang key is useful in some case with module
949 'align' => 'C',
950 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
951 // 'label' => ' ', // the final label
952 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
953 ],
954 'content' => [
955 'align' => 'R',
956 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
957 ],
958 'border-left' => true, // add left line separator
959 ];
960
961 // Add extrafields cols
962 if (!empty($object->lines)) {
963 $line = reset($object->lines);
964 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
965 }
966
967 $parameters = array(
968 'object' => $object,
969 'outputlangs' => $outputlangs,
970 'hidedetails' => $hidedetails,
971 'hidedesc' => $hidedesc,
972 'hideref' => $hideref
973 );
974
975 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
976 if ($reshook < 0) {
977 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
978 } elseif (empty($reshook)) {
979 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
980 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
981 } else {
982 $this->cols = $hookmanager->resArray;
983 }
984 }
985
1000 protected function addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase = true)
1001 {
1002 global $langs;
1003
1004 $curY = $nexY;
1005 $pageposbefore = $pdf->getPage();
1006 $pdf->SetFont('', 'B', $default_font_size - 1);
1007 $pdf->startTransaction();
1008
1009 if ($uppercase) {
1010 $label = mb_strtoupper($label);
1011 }
1012 $this->printStdColumnContent($pdf, $curY, 'label', $label);
1013
1014 $pageposafter = $pdf->getPage();
1015 if ($pageposafter > $pageposbefore) { // There is a pagebreak
1016 $pdf->rollbackTransaction(true);
1017
1018 $pdf->AddPage('', '', true);
1019 $pdf->setPage($pageposafter);
1020 $curY = $tab_top_newpage + $this->tabTitleHeight;
1021 $this->printStdColumnContent($pdf, $curY, 'label', $label);
1022 }
1023
1024 $nexY = $pdf->GetY();
1025
1026 if ($this->getColumnStatus('debit')) {
1027 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($debit, 'MT')));
1028 $nexY = max($pdf->GetY(), $nexY);
1029 }
1030
1031 if ($this->getColumnStatus('credit')) {
1032 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($credit, 'MT')));
1033 $nexY = max($pdf->GetY(), $nexY);
1034 }
1035
1036 if ($this->getColumnStatus('balance')) {
1037 $solde = $credit - $debit;
1038 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' ' . $langs->trans('CreditShort') : ' ' . $langs->trans('DebitShort'));
1039 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
1040 $nexY = max($pdf->GetY(), $nexY);
1041 }
1042
1043 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
1044 $this->addDashLine($pdf, $pageposafter, $nexY);
1045 }
1046 }
1047}
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.
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.
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
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.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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:289
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:1110
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:742
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:268
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:464
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128