dolibarr 23.0.3
pdf_bookkeeping.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 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
90 public function __construct(DoliDB $db)
91 {
92 global $langs, $mysoc;
93
94 $this->name = "bookkeeping";
95 $this->description = $langs->trans("PDFAccountancyBookkeepingDescription");
96 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
97
98 // Dimension page
99 $this->type = 'pdf';
100 $formatarray = pdf_getFormat();
101 $this->page_largeur = $formatarray['width'];
102 $this->page_hauteur = $formatarray['height'];
103 $this->format = array($this->page_largeur, $this->page_hauteur);
104 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
105 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
106 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
107 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
108 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
109 $this->option_logo = 1; // Display logo
110 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
111 $this->watermark = '';
112
113 if ($mysoc === null) {
114 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
115 return;
116 }
117
118 // Get source company
119 $this->emetteur = $mysoc;
120 if (empty($this->emetteur->country_code)) {
121 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
122 }
123
124 $this->tabTitleHeight = 5; // default height
125
126 parent::__construct($db);
127 }
128
129 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
139 public function write_file(BookKeeping $object, Translate $outputlangs, string $srctemplatepath = '', bool $directDownload = true)
140 {
141 // phpcs:enable
142 global $user, $conf, $langs, $hookmanager;
143
144 $hidedesc = $hidedetails = $hideref = 0;
145
146 $object->fetch_thirdparty();
147
148 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
149 if (getDolGlobalString('MAIN_USE_FPDF')) {
150 $outputlangs->charset_output = 'ISO-8859-1';
151 }
152
153 // Load traductions files required by page
154 $outputlangs->loadLangs(array("main", "bills", "orders", "companies", "other", "accountancy", "compta"));
155
156 global $outputlangsbis;
157 $outputlangsbis = null;
158 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
159 $outputlangsbis = new Translate('', $conf);
160 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
161 $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "other", "propal", "sendings", "productbatch", "compta"));
162 }
163
164 $nblines = count($object->lines);
165
166 if (!$conf->accounting->multidir_output[$conf->entity]) {
167 $this->error = $langs->transnoentities("ErrorAccountancyDirectoryNotDefined");
168 return 0;
169 }
170
171 // Definition of $dir and $file
172 $dir = $conf->accounting->multidir_output[$conf->entity]."/export";
173 if ($object->specimen) {
174 $file = "{$dir}/SPECIMEN_{$this->name}.pdf";
175 } else {
176 $expref = dol_sanitizeFileName($object->ref);
177 $date = date('YmdHis', dol_now());
178 $file = "{$dir}/{$this->name}_{$date}.pdf";
179 }
180
181 if (!file_exists($dir)) {
182 if (dol_mkdir($dir) < 0) {
183 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
184 return 0;
185 }
186 }
187
188 // Add pdfgeneration hook
189 if (!is_object($hookmanager)) {
190 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
191 $hookmanager = new HookManager($this->db);
192 }
193 $hookmanager->initHooks(array('pdfgeneration'));
194 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
195 global $action;
196 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
197
198 // Set nblines with the new facture lines content after hook
199 $nblines = is_array($object->lines) ? count($object->lines) : 0;
200
201 $pdf = pdf_getInstance($this->format);
202 $default_font_size = pdf_getPDFFontSize($outputlangs) - 2;
203 $heightforinfotot = 8; // Height reserved to output the info and total part
204 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
205 $heightforfooter = $this->marge_basse + 14; // Height reserved to output the footer (value include bottom margin)
206 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
207 $heightforfooter += 6;
208 }
209 $pdf->setAutoPageBreak(true, 0);
210
211 if (class_exists('TCPDF')) {
212 $pdf->setPrintHeader(false);
213 $pdf->setPrintFooter(false);
214 }
215 $pdf->SetFont(pdf_getPDFFont($outputlangs));
216 // Set path to the background PDF File
217 if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
218 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
219 $tplidx = $pdf->importPage(1);
220 }
221
222 $pdf->Open();
223 $pagenb = 0;
224 $pdf->SetDrawColor(128, 128, 128);
225
226 if (method_exists($pdf, 'AliasNbPages')) {
227 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
228 }
229
230 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
231 $pdf->SetSubject($outputlangs->transnoentities("AccountancyBookkeeping"));
232 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
233 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
234 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("AccountancyBookkeeping"));
235 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
236 $pdf->SetCompression(false);
237 }
238
239 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
240 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
241
242 // New page
243 $pdf->AddPage();
244 if (!empty($tplidx)) {
245 $pdf->useTemplate($tplidx);
246 }
247 $pagenb++;
248 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
249 $pdf->SetFont('', '', $default_font_size - 1);
250 $pdf->MultiCell(0, 3, ''); // Set interline to 3
251 $pdf->SetTextColor(0, 0, 0);
252
253 $tab_top = 40; // position of top tab
254 $tab_top_newpage = (getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 10 : $tab_top);
255
256 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
257
258 $this->posxdesc = $this->marge_gauche + 1;
259
260 // Displays notes. Here we are still on code executed only for the first page.
261 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
262
263 // Use new auto column system
264 $this->prepareArrayColumnField($object, $outputlangs);
265
266 // Table simulation to know the height of the title line
267 $pdf->startTransaction();
268 $pdf->SetFont('', 'B', $default_font_size - 1);
269 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
270 $pdf->SetFont('', '', $default_font_size - 1);
271 $pdf->rollbackTransaction(true);
272
273
274 $curY = $nexY = $tab_top + $this->tabTitleHeight;
275
276 // Loop on each lines
277 $pageposbeforeprintlines = $pdf->getPage();
278 $pagenb = $pageposbeforeprintlines;
279
280 // Knowing how many month our period covers
281 $fromYear = dol_print_date($this->fromDate, "%Y");
282 $fromMonth = dol_print_date($this->fromDate, "%m");
283 $toYear = dol_print_date($this->toDate, "%Y");
284 $toMonth = dol_print_date($this->toDate, "%m");
285 $nbMonths = (((int) $toYear - (int) $fromYear) * 12) + ((int) $toMonth - (int) $fromMonth) + 1;
286 $datePlusOneMonth = dol_time_plus_duree($this->fromDate, -1, 'm');
287 $dates = [];
288 for ($i = 0; $i < $nbMonths; $i++) {
289 $datePlusOneMonth = dol_time_plus_duree($datePlusOneMonth, 1, "m");
290 $dates[$datePlusOneMonth] = dol_print_date($datePlusOneMonth, "%B %Y");
291 }
292
293 $journal = '';
294 $journalDebit = $journalCredit = $totalDebit = $totalCredit = 0;
295 for ($i = 0; $i < $nblines; $i++) {
296 // Show total line / title line when account has changed
297 if (empty($journal) || $journal != $object->lines[$i]->code_journal) {
298 // Add the subtotal line
299 if (!empty($journal)) {
300 $this->addTotalLine(
301 $pdf,
302 $curY,
303 $nexY,
304 $default_font_size,
305 "{$langs->transnoentities('Total')} {$journal}",
306 $tab_top_newpage,
307 $journalDebit,
308 $journalCredit
309 );
310 }
311
312 // Add the title line
313 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
314 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
315 }
316 $this->addTitleLine(
317 $pdf,
318 $curY,
319 $nexY,
320 $default_font_size,
321 'piece_num',
322 "{$langs->transnoentities('Journal')} {$object->lines[$i]->code_journal}",
323 $tab_top_newpage
324 );
325
326 $journal = $object->lines[$i]->code_journal;
327 $journalDebit = $journalCredit = 0;
328 }
329
330 $journalDebit += $object->lines[$i]->debit;
331 $journalCredit += $object->lines[$i]->credit;
332 $totalDebit += $object->lines[$i]->debit;
333 $totalCredit += $object->lines[$i]->credit;
334
335 $curY = $nexY;
336 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
337 $pdf->SetTextColor(0, 0, 0);
338
339 $pdf->setTopMargin($tab_top_newpage);
340 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
341 $pageposbefore = $pdf->getPage();
342
343 $showpricebeforepagebreak = 1;
344 $heightforsignature = 0;
345
346 // Column used for testing page change
347 // No check on column status, this column is mandatory
348 $pdf->startTransaction();
349
350 $this->printStdColumnContent($pdf, $curY, 'label', $object->lines[$i]->label_operation);
351
352 $pageposafter = $pdf->getPage();
353 if ($pageposafter > $pageposbefore) { // There is a pagebreak
354 $pdf->rollbackTransaction(true);
355
356 $pdf->AddPage('', '', true);
357 $pdf->setPage($pageposafter);
358 $curY = $tab_top_newpage + $this->tabTitleHeight;
359 $this->printStdColumnContent($pdf, $curY, 'label', $object->lines[$i]->label_operation);
360
361 $pageposafter = $pdf->getPage();
362 $posyafter = $pdf->GetY();
363 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
364 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text
365 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
366 $pdf->AddPage('', '', true);
367 if (!empty($tplidx)) {
368 $pdf->useTemplate($tplidx);
369 }
370 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
371 $pdf->setPage($pageposafter + 1);
372 }
373 } else {
374 // We found a page break
375 // Allows data in the first page if description is long enough to break in multiples pages
376 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
377 $showpricebeforepagebreak = 1;
378 } else {
379 $showpricebeforepagebreak = 0;
380 }
381 }
382 } else { // No pagebreak
383 $pdf->commitTransaction();
384 }
385 $nexY = max($pdf->GetY(), $nexY);
386
387 $nexY = $pdf->GetY();
388 $pageposafter = $pdf->getPage();
389
390 $pdf->setPage($pageposbefore);
391 $pdf->setTopMargin($this->marge_haute);
392 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
393
394 // We suppose that a too long description is moved completely on next page
395 if ($pageposafter > $pageposbefore) {
396 $pdf->setPage($pageposafter);
397 $curY = $tab_top_newpage + $this->tabTitleHeight;
398 }
399
400 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
401
402 // # of line
403 if ($this->getColumnStatus('position')) {
404 $this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
405 }
406
407 if ($this->getColumnStatus('date')) {
408 $this->printStdColumnContent($pdf, $curY, 'date', dol_print_date($object->lines[$i]->doc_date, 'day'));
409 $nexY = max($pdf->GetY(), $nexY);
410 }
411
412 if ($this->getColumnStatus('piece_num')) {
413 $this->printStdColumnContent($pdf, $curY, 'piece_num', (string) $object->lines[$i]->piece_num);
414 $nexY = max($pdf->GetY(), $nexY);
415 }
416
417 if ($this->getColumnStatus('account')) {
418 $this->printStdColumnContent($pdf, $curY, 'account', length_accountg($object->lines[$i]->numero_compte));
419 $nexY = max($pdf->GetY(), $nexY);
420 }
421 if ($this->getColumnStatus('account_label')) {
422 $this->printStdColumnContent($pdf, $curY, 'account_label', $object->lines[$i]->label_compte);
423 $nexY = max($pdf->GetY(), $nexY);
424 }
425
426 if ($this->getColumnStatus('debit')) {
427 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($object->lines[$i]->debit, 'MT')));
428 $nexY = max($pdf->GetY(), $nexY);
429 }
430
431 if ($this->getColumnStatus('credit')) {
432 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($object->lines[$i]->credit, 'MT')));
433 $nexY = max($pdf->GetY(), $nexY);
434 }
435
436 $parameters = array(
437 'object' => $object,
438 'i' => $i,
439 'pdf' => & $pdf,
440 'curY' => & $curY,
441 'nexY' => & $nexY,
442 'outputlangs' => $outputlangs,
443 'hidedetails' => $hidedetails
444 );
445 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this);
446
447 // Add line
448 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
449 $this->addDashLine($pdf, $pageposafter, $nexY);
450 }
451
452 // Detect if some page were added automatically and output _tableau for past pages
453 while ($pagenb < $pageposafter) {
454 $pdf->setPage($pagenb);
455 if ($pagenb == $pageposbeforeprintlines) {
456 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
457 } else {
458 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
459 }
460 $this->_pagefoot($pdf, $object, $outputlangs, 1);
461 $pagenb++;
462 $pdf->setPage($pagenb);
463 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
464 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
465 $this->_pagehead($pdf, $object, 0, $outputlangs);
466 }
467 if (!empty($tplidx)) {
468 $pdf->useTemplate($tplidx);
469 }
470 }
471 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
472 if ($pagenb == 1) {
473 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
474 } else {
475 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
476 }
477 $this->_pagefoot($pdf, $object, $outputlangs, 1);
478 // New page
479 $pdf->AddPage();
480 if (!empty($tplidx)) {
481 $pdf->useTemplate($tplidx);
482 }
483 $pagenb++;
484 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
485 $this->_pagehead($pdf, $object, 0, $outputlangs);
486 }
487 }
488 }
489
490 // Add total line for last group
491 if (!empty($journal)) {
492 // Add line
493 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
494 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
495 }
496 $this->addTotalLine(
497 $pdf,
498 $curY,
499 $nexY,
500 $default_font_size,
501 "{$langs->transnoentities('Total')} {$journal}",
502 $tab_top_newpage,
503 $journalDebit,
504 $journalCredit
505 );
506 }
507
508 // Add grand total line
509 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
510 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
511 }
512 $this->addTotalLine(
513 $pdf,
514 $curY,
515 $nexY,
516 $default_font_size,
517 $langs->transnoentities('GrandTotals'),
518 $tab_top_newpage,
519 $totalDebit,
520 $totalCredit,
521 true
522 );
523
524
525 // Show square
526 if ($pagenb == 1) {
527 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
528 } else {
529 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
530 }
531
532 // Pagefoot
533 $this->_pagefoot($pdf, $object, $outputlangs);
534 if (method_exists($pdf, 'AliasNbPages')) {
535 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
536 }
537
538 $pdf->Close();
539
540 $pdf->Output($file, $directDownload ? 'D' : 'F');
541
542 // Add pdfgeneration hook
543 $hookmanager->initHooks(array('pdfgeneration'));
544 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
545 global $action;
546 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
547 $this->warnings = $hookmanager->warnings;
548 if ($reshook < 0) {
549 $this->error = $hookmanager->error;
550 $this->errors = $hookmanager->errors;
551 dolChmod($file);
552 return -1;
553 }
554
555 dolChmod($file);
556
557 $this->result = array('fullpath' => $file);
558
559 return 1; // No error
560 }
561
562 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
577 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
578 {
579 global $conf;
580
581 // Force to disable hidetop and hidebottom
582 $hidebottom = 0;
583 if ($hidetop) {
584 $hidetop = -1;
585 }
586
587 $currency = !empty($currency) ? $currency : $conf->currency;
588 $default_font_size = pdf_getPDFFontSize($outputlangs);
589
590 // Amount in (at tab_top - 1)
591 $pdf->SetTextColor(0, 0, 0);
592 $pdf->SetFont('', '', $default_font_size - 2);
593
594 if (empty($hidetop)) {
595 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
596 $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')));
597 }
598 }
599
600 $pdf->SetDrawColor(128, 128, 128);
601 $pdf->SetFont('', '', $default_font_size - 1);
602
603 // Output Rect
604 $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
605
606 $pdf->SetFont('', 'B', $default_font_size - 1);
607 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
608 $pdf->SetFont('', '', $default_font_size - 1);
609
610
611 if (empty($hidetop)) {
612 $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
613 }
614 }
615
616 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
626 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
627 {
628 global $conf, $langs;
629
630 $ltrdirection = 'L';
631 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
632
633 // Load traductions files required by page
634 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
635
636 $default_font_size = pdf_getPDFFontSize($outputlangs);
637
638 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
639
640
641 $pdf->SetTextColor(0, 0, 60);
642 $pdf->SetFont('', 'B', $default_font_size + 3);
643
644 $w = 110;
645 $posy = $this->marge_haute;
646 $posx = $this->marge_gauche;
647 $hautcadre = 20;
648 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
649 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
650
651 $posx = $this->page_largeur - $this->marge_droite - $w;
652 $nexY = $posy;
653
654 // Name of soc
655 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
656 $text = $this->emetteur->name;
657 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
658 $nexY = max($pdf->GetY(), $nexY);
659
660 // Date of document
661 $pdf->SetFont('', '', $default_font_size - 2);
662 $pdf->SetXY($this->marge_gauche + 2, $nexY);
663 $pdf->SetTextColor(0, 0, 60);
664 $textDateNow = $outputlangs->transnoentities("PrintDate");
665 $pdf->MultiCell($w / 3, 3, $textDateNow . " : " . date('d/m/Y', dol_now()), '', 'L');
666 $nexY = max($pdf->GetY(), $nexY);
667
668 // Page title
669 $pdf->SetFont('', 'B', $default_font_size + 3);
670 $pdf->SetXY($posx - 2, $posy + 2);
671 $pdf->SetTextColor(0, 0, 60);
672 $title = $outputlangs->transnoentities("PdfBookkeepingTitle");
673 $pdf->MultiCell($w / 3, 3, $title, 0, 'C');
674 $nexY = max($pdf->GetY(), $nexY);
675
676 // Date From To
677 $pdf->SetFont('', 'B', $default_font_size);
678 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
679 $pdf->SetTextColor(0, 0, 60);
680
681 $fromDate = dol_print_date($this->fromDate, 'day');
682 $toDate = dol_print_date($this->toDate, 'day');
683 $textDate = $outputlangs->transnoentities("From") . " " . $fromDate . " " . $outputlangs->transnoentities("To") . " " . $toDate;
684 $pdf->MultiCell($w / 3, 4, $textDate, 0, 'R');
685 $nexY = max($pdf->GetY(), $nexY);
686
687 $pdf->SetTextColor(0, 0, 0);
688 return $nexY;
689 }
690
691 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
701 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
702 {
703 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
704 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);
705 }
706
717 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
718 {
719 global $conf, $hookmanager;
720
721 // Default field style for content
722 $this->defaultContentsFieldsStyle = array(
723 'align' => 'R', // R,C,L
724 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
725 );
726
727 // Default field style for content
728 $this->defaultTitlesFieldsStyle = array(
729 'align' => 'C', // R,C,L
730 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
731 );
732
733 $rank = 0; // do not use negative rank
734 $this->cols['position'] = [
735 'rank' => $rank,
736 'width' => 10,
737 'status' => (bool) getDolGlobalInt('PDF_ACCOUNTANCY_LEDGER_ADD_POSITION'),
738 'title' => [
739 'textkey' => '#', // use lang key is useful in some case with module
740 'align' => 'C',
741 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
742 // 'label' => ' ', // the final label
743 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
744 ],
745 'content' => [
746 'align' => 'C',
747 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
748 ],
749 ];
750
751 $rank += 10; // do not use negative rank
752 $this->cols['date'] = [
753 'rank' => $rank,
754 'width' => 18, // only for desc
755 'status' => true,
756 'title' => [
757 'textkey' => 'Date', // use lang key is useful in some case with module
758 'align' => 'C',
759 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
760 // 'label' => ' ', // the final label
761 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
762 ],
763 'content' => [
764 'align' => 'L',
765 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
766 ],
767 ];
768
769 $rank += 10;
770 $this->cols['piece_num'] = [
771 'rank' => $rank,
772 'width' => 14,
773 'status' => true,
774 'title' => [
775 'textkey' => 'Piece', // use lang key is useful in some case with module
776 'align' => 'C',
777 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
778 // 'label' => ' ', // the final label
779 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
780 ],
781 'content' => [
782 'align' => 'L',
783 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
784 ],
785 'border-left' => true, // add left line separator
786 ];
787
788 $rank += 10;
789 $this->cols['account'] = [
790 'rank' => $rank,
791 'width' => 15,
792 'status' => true,
793 'title' => [
794 'textkey' => 'Account', // use lang key is useful in some case with module
795 'align' => 'C',
796 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
797 // 'label' => ' ', // the final label
798 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
799 ],
800 'content' => [
801 'align' => 'L',
802 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
803 ],
804 'border-left' => true, // add left line separator
805 ];
806
807 $rank += 10;
808 $this->cols['account_label'] = [
809 'rank' => $rank,
810 'width' => 30,
811 'status' => true,
812 'title' => [
813 'textkey' => 'LabelAccount', // use lang key is useful in some case with module
814 'align' => 'C',
815 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
816 // 'label' => ' ', // the final label
817 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
818 ],
819 'content' => [
820 'align' => 'L',
821 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
822 ],
823 'border-left' => true, // add left line separator
824 ];
825
826 $rank += 10;
827 $this->cols['label'] = [
828 'rank' => $rank,
829 'width' => false,
830 'status' => true,
831 'title' => [
832 'textkey' => 'Label', // use lang key is useful in some case with module
833 'align' => 'C',
834 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
835 // 'label' => ' ', // the final label
836 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
837 ],
838 'content' => [
839 'align' => 'L',
840 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
841 ],
842 'border-left' => true, // add left line separator
843 ];
844
845 $rank += 10;
846 $this->cols['debit'] = [
847 'rank' => $rank,
848 'width' => 15,
849 'status' => true,
850 'title' => [
851 'textkey' => 'Debit', // use lang key is useful in some case with module
852 'align' => 'C',
853 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
854 // 'label' => ' ', // the final label
855 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
856 ],
857 'content' => [
858 'align' => 'R',
859 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
860 ],
861 'border-left' => true, // add left line separator
862 ];
863
864 $rank += 10;
865 $this->cols['credit'] = array(
866 'rank' => $rank,
867 'width' => 15,
868 'status' => true,
869 'title' => array(
870 'textkey' => 'Credit', // use lang key is useful in some case with module
871 'align' => 'C',
872 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
873 // 'label' => ' ', // the final label
874 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
875 ),
876 'content' => array(
877 'align' => 'R',
878 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
879 ),
880 'border-left' => true, // add left line separator
881 );
882
883 // Add extrafields cols
884 if (!empty($object->lines)) {
885 $line = reset($object->lines);
886 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
887 }
888
889 $parameters = array(
890 'object' => $object,
891 'outputlangs' => $outputlangs,
892 'hidedetails' => $hidedetails,
893 'hidedesc' => $hidedesc,
894 'hideref' => $hideref
895 );
896
897 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
898 if ($reshook < 0) {
899 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
900 } elseif (empty($reshook)) {
901 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
902 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
903 } else {
904 $this->cols = $hookmanager->resArray;
905 }
906 }
907
922 protected function addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase = true)
923 {
924 global $langs;
925
926 $curY = $nexY;
927 $pageposbefore = $pdf->getPage();
928 $pdf->SetFont('', 'B', $default_font_size - 1);
929 $pdf->startTransaction();
930
931 if ($uppercase) {
932 $label = mb_strtoupper($label);
933 }
934 $this->printStdColumnContent($pdf, $curY, 'label', $label);
935
936 $pageposafter = $pdf->getPage();
937 if ($pageposafter > $pageposbefore) { // There is a pagebreak
938 $pdf->rollbackTransaction(true);
939
940 $pdf->AddPage('', '', true);
941 $pdf->setPage($pageposafter);
942 $curY = $tab_top_newpage + $this->tabTitleHeight;
943 $this->printStdColumnContent($pdf, $curY, 'label', $label);
944 }
945
946 $nexY = $pdf->GetY();
947
948 if ($this->getColumnStatus('debit')) {
949 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($debit, 'MT')));
950 $nexY = max($pdf->GetY(), $nexY);
951 }
952
953 if ($this->getColumnStatus('credit')) {
954 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($credit, 'MT')));
955 $nexY = max($pdf->GetY(), $nexY);
956 }
957
958 if ($this->getColumnStatus('balance')) {
959 $solde = $credit - $debit;
960 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' ' . $langs->trans('CreditShort') : ' ' . $langs->trans('DebitShort'));
961 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
962 $nexY = max($pdf->GetY(), $nexY);
963 }
964
965 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
966 $this->addDashLine($pdf, $pageposafter, $nexY);
967 }
968 }
969}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
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.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase=true)
Add the total accountancy group line to pdf.
__construct(DoliDB $db)
Constructor.
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.
global $mysoc
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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