dolibarr 22.0.5
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", "deliveries", "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 = date('Y', $this->fromDate);
282 $fromMonth = date('m', $this->fromDate);
283 $toYear = date('Y', $this->toDate);
284 $toMonth = date('m', $this->toDate);
285 $nbMonths = (((int) $toYear - (int) $fromYear) * 12) + ((int) $toMonth - (int) $fromMonth) + 1;
286 $datePlusOneMonth = strtotime("-1 month", $this->fromDate);
287 $dates = [];
288 for ($i = 0; $i < $nbMonths; $i++) {
289 $datePlusOneMonth = strtotime("+1 month", $datePlusOneMonth);
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->trans('Total')} {$journal}",
306 $tab_top_newpage,
307 $journalDebit,
308 $journalCredit
309 );
310 }
311
312 // Add the title line
313 $this->addTitleLine(
314 $pdf,
315 $curY,
316 $nexY,
317 $default_font_size,
318 'piece_num',
319 "{$langs->trans('Journal')} {$object->lines[$i]->code_journal}",
320 $tab_top_newpage
321 );
322
323 $journal = $object->lines[$i]->code_journal;
324 $journalDebit = $journalCredit = 0;
325 }
326
327 $journalDebit += $object->lines[$i]->debit;
328 $journalCredit += $object->lines[$i]->credit;
329 $totalDebit += $object->lines[$i]->debit;
330 $totalCredit += $object->lines[$i]->credit;
331
332 $curY = $nexY;
333 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
334 $pdf->SetTextColor(0, 0, 0);
335
336 $pdf->setTopMargin($tab_top_newpage);
337 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
338 $pageposbefore = $pdf->getPage();
339
340 $showpricebeforepagebreak = 1;
341 $heightforsignature = 0;
342
343 // Column used for testing page change
344 // No check on column status, this column is mandatory
345 $pdf->startTransaction();
346
347 $this->printStdColumnContent($pdf, $curY, 'label', $object->lines[$i]->label_operation);
348
349 $pageposafter = $pdf->getPage();
350 if ($pageposafter > $pageposbefore) { // There is a pagebreak
351 $pdf->rollbackTransaction(true);
352
353 $pdf->AddPage('', '', true);
354 $pdf->setPage($pageposafter);
355 $curY = $tab_top_newpage + $this->tabTitleHeight;
356 $this->printStdColumnContent($pdf, $curY, 'label', $object->lines[$i]->label_operation);
357
358 $pageposafter = $pdf->getPage();
359 $posyafter = $pdf->GetY();
360 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
361 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text
362 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
363 $pdf->AddPage('', '', true);
364 if (!empty($tplidx)) {
365 $pdf->useTemplate($tplidx);
366 }
367 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
368 $pdf->setPage($pageposafter + 1);
369 }
370 } else {
371 // We found a page break
372 // Allows data in the first page if description is long enough to break in multiples pages
373 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
374 $showpricebeforepagebreak = 1;
375 } else {
376 $showpricebeforepagebreak = 0;
377 }
378 }
379 } else { // No pagebreak
380 $pdf->commitTransaction();
381 }
382 $nexY = max($pdf->GetY(), $nexY);
383
384 $nexY = $pdf->GetY();
385 $pageposafter = $pdf->getPage();
386
387 $pdf->setPage($pageposbefore);
388 $pdf->setTopMargin($this->marge_haute);
389 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
390
391 // We suppose that a too long description is moved completely on next page
392 if ($pageposafter > $pageposbefore) {
393 $pdf->setPage($pageposafter);
394 $curY = $tab_top_newpage + $this->tabTitleHeight;
395 }
396
397 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
398
399 // # of line
400 if ($this->getColumnStatus('position')) {
401 $this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
402 }
403
404 if ($this->getColumnStatus('date')) {
405 $this->printStdColumnContent($pdf, $curY, 'date', dol_print_date($object->lines[$i]->doc_date, 'day'));
406 $nexY = max($pdf->GetY(), $nexY);
407 }
408
409 if ($this->getColumnStatus('piece_num')) {
410 $this->printStdColumnContent($pdf, $curY, 'piece_num', (string) $object->lines[$i]->piece_num);
411 $nexY = max($pdf->GetY(), $nexY);
412 }
413
414 if ($this->getColumnStatus('account')) {
415 $this->printStdColumnContent($pdf, $curY, 'account', length_accountg($object->lines[$i]->numero_compte));
416 $nexY = max($pdf->GetY(), $nexY);
417 }
418 if ($this->getColumnStatus('account_label')) {
419 $this->printStdColumnContent($pdf, $curY, 'account_label', $object->lines[$i]->label_compte);
420 $nexY = max($pdf->GetY(), $nexY);
421 }
422
423 if ($this->getColumnStatus('debit')) {
424 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($object->lines[$i]->debit, 'MT')));
425 $nexY = max($pdf->GetY(), $nexY);
426 }
427
428 if ($this->getColumnStatus('credit')) {
429 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($object->lines[$i]->credit, 'MT')));
430 $nexY = max($pdf->GetY(), $nexY);
431 }
432
433 $parameters = array(
434 'object' => $object,
435 'i' => $i,
436 'pdf' => & $pdf,
437 'curY' => & $curY,
438 'nexY' => & $nexY,
439 'outputlangs' => $outputlangs,
440 'hidedetails' => $hidedetails
441 );
442 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this);
443
444 // Add line
445 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
446 $this->addDashLine($pdf, $pageposafter, $nexY);
447 }
448
449 // Detect if some page were added automatically and output _tableau for past pages
450 while ($pagenb < $pageposafter) {
451 $pdf->setPage($pagenb);
452 if ($pagenb == $pageposbeforeprintlines) {
453 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
454 } else {
455 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
456 }
457 $this->_pagefoot($pdf, $object, $outputlangs, 1);
458 $pagenb++;
459 $pdf->setPage($pagenb);
460 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
461 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
462 $this->_pagehead($pdf, $object, 0, $outputlangs);
463 }
464 if (!empty($tplidx)) {
465 $pdf->useTemplate($tplidx);
466 }
467 }
468 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
469 if ($pagenb == 1) {
470 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
471 } else {
472 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
473 }
474 $this->_pagefoot($pdf, $object, $outputlangs, 1);
475 // New page
476 $pdf->AddPage();
477 if (!empty($tplidx)) {
478 $pdf->useTemplate($tplidx);
479 }
480 $pagenb++;
481 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
482 $this->_pagehead($pdf, $object, 0, $outputlangs);
483 }
484 }
485 }
486
487 // Add total line for last group
488 if (!empty($journal)) {
489 // Add line
490 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
491 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
492 }
493 $this->addTotalLine(
494 $pdf,
495 $curY,
496 $nexY,
497 $default_font_size,
498 "{$langs->trans('Total')} {$journal}",
499 $tab_top_newpage,
500 $journalDebit,
501 $journalCredit
502 );
503 }
504
505 // Add grand total line
506 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
507 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
508 }
509 $this->addTotalLine(
510 $pdf,
511 $curY,
512 $nexY,
513 $default_font_size,
514 $langs->transnoentities('GrandTotals'),
515 $tab_top_newpage,
516 $totalDebit,
517 $totalCredit,
518 );
519
520
521
522 // Show square
523 if ($pagenb == 1) {
524 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
525 } else {
526 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
527 }
528
529 // Pagefoot
530 $this->_pagefoot($pdf, $object, $outputlangs);
531 if (method_exists($pdf, 'AliasNbPages')) {
532 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
533 }
534
535 $pdf->Close();
536
537 $pdf->Output($file, $directDownload ? 'D' : 'F');
538
539 // Add pdfgeneration hook
540 $hookmanager->initHooks(array('pdfgeneration'));
541 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
542 global $action;
543 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
544 if ($reshook < 0) {
545 $this->error = $hookmanager->error;
546 $this->errors = $hookmanager->errors;
547 }
548
549 dolChmod($file);
550
551 $this->result = array('fullpath' => $file);
552
553 return 1; // No error
554 }
555
556 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
571 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
572 {
573 global $conf;
574
575 // Force to disable hidetop and hidebottom
576 $hidebottom = 0;
577 if ($hidetop) {
578 $hidetop = -1;
579 }
580
581 $currency = !empty($currency) ? $currency : $conf->currency;
582 $default_font_size = pdf_getPDFFontSize($outputlangs);
583
584 // Amount in (at tab_top - 1)
585 $pdf->SetTextColor(0, 0, 0);
586 $pdf->SetFont('', '', $default_font_size - 2);
587
588 if (empty($hidetop)) {
589 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
590 $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')));
591 }
592 }
593
594 $pdf->SetDrawColor(128, 128, 128);
595 $pdf->SetFont('', '', $default_font_size - 1);
596
597 // Output Rect
598 $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
599
600 $pdf->SetFont('', 'B', $default_font_size - 1);
601 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
602 $pdf->SetFont('', '', $default_font_size - 1);
603
604
605 if (empty($hidetop)) {
606 $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
607 }
608 }
609
610 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
620 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
621 {
622 global $conf, $langs;
623
624 $ltrdirection = 'L';
625 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
626
627 // Load traductions files required by page
628 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
629
630 $default_font_size = pdf_getPDFFontSize($outputlangs);
631
632 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
633
634
635 $pdf->SetTextColor(0, 0, 60);
636 $pdf->SetFont('', 'B', $default_font_size + 3);
637
638 $w = 110;
639 $posy = $this->marge_haute;
640 $posx = $this->marge_gauche;
641 $hautcadre = 20;
642 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
643 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
644
645 $posx = $this->page_largeur - $this->marge_droite - $w;
646 $nexY = $posy;
647
648 // Name of soc
649 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
650 $text = $this->emetteur->name;
651 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
652 $nexY = max($pdf->GetY(), $nexY);
653
654 // Date of document
655 $pdf->SetFont('', '', $default_font_size - 2);
656 $pdf->SetXY($this->marge_gauche + 2, $nexY);
657 $pdf->SetTextColor(0, 0, 60);
658 $textDateNow = $outputlangs->transnoentities("PrintDate");
659 $pdf->MultiCell($w / 3, 3, $textDateNow . " : " . date('d/m/Y', dol_now()), '', 'L');
660 $nexY = max($pdf->GetY(), $nexY);
661
662 // Page title
663 $pdf->SetFont('', 'B', $default_font_size + 3);
664 $pdf->SetXY($posx - 2, $posy + 2);
665 $pdf->SetTextColor(0, 0, 60);
666 $title = $outputlangs->transnoentities("PdfBookkeepingTitle");
667 $pdf->MultiCell($w / 3, 3, $title, 0, 'C');
668 $nexY = max($pdf->GetY(), $nexY);
669
670 // Date From To
671 $pdf->SetFont('', 'B', $default_font_size);
672 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
673 $pdf->SetTextColor(0, 0, 60);
674
675 $fromDate = dol_print_date($this->fromDate, 'day');
676 $toDate = dol_print_date($this->toDate, 'day');
677 $textDate = $outputlangs->transnoentities("From") . " " . $fromDate . " " . $outputlangs->transnoentities("To") . " " . $toDate;
678 $pdf->MultiCell($w / 3, 4, $textDate, 0, 'R');
679 $nexY = max($pdf->GetY(), $nexY);
680
681 $pdf->SetTextColor(0, 0, 0);
682 return $nexY;
683 }
684
685 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
695 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
696 {
697 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
698 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);
699 }
700
711 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
712 {
713 global $conf, $hookmanager;
714
715 // Default field style for content
716 $this->defaultContentsFieldsStyle = array(
717 'align' => 'R', // R,C,L
718 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
719 );
720
721 // Default field style for content
722 $this->defaultTitlesFieldsStyle = array(
723 'align' => 'C', // R,C,L
724 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
725 );
726
727 $rank = 0; // do not use negative rank
728 $this->cols['position'] = [
729 'rank' => $rank,
730 'width' => 10,
731 'status' => (bool) getDolGlobalInt('PDF_ACCOUNTANCY_LEDGER_ADD_POSITION'),
732 'title' => [
733 'textkey' => '#', // use lang key is useful in somme case with module
734 'align' => 'C',
735 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
736 // 'label' => ' ', // the final label
737 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
738 ],
739 'content' => [
740 'align' => 'C',
741 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
742 ],
743 ];
744
745 $rank += 10; // do not use negative rank
746 $this->cols['date'] = [
747 'rank' => $rank,
748 'width' => 18, // only for desc
749 'status' => true,
750 'title' => [
751 'textkey' => 'Date', // use lang key is useful in somme case with module
752 'align' => 'C',
753 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
754 // 'label' => ' ', // the final label
755 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
756 ],
757 'content' => [
758 'align' => 'L',
759 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
760 ],
761 ];
762
763 $rank += 10;
764 $this->cols['piece_num'] = [
765 'rank' => $rank,
766 'width' => 14,
767 'status' => true,
768 'title' => [
769 'textkey' => 'Piece', // use lang key is useful in somme case with module
770 'align' => 'C',
771 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
772 // 'label' => ' ', // the final label
773 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
774 ],
775 'content' => [
776 'align' => 'L',
777 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
778 ],
779 'border-left' => true, // add left line separator
780 ];
781
782 $rank += 10;
783 $this->cols['account'] = [
784 'rank' => $rank,
785 'width' => 15,
786 'status' => true,
787 'title' => [
788 'textkey' => 'Account', // use lang key is useful in somme case with module
789 'align' => 'C',
790 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
791 // 'label' => ' ', // the final label
792 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
793 ],
794 'content' => [
795 'align' => 'L',
796 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
797 ],
798 'border-left' => true, // add left line separator
799 ];
800
801 $rank += 10;
802 $this->cols['account_label'] = [
803 'rank' => $rank,
804 'width' => 30,
805 'status' => true,
806 'title' => [
807 'textkey' => 'LabelAccount', // use lang key is useful in somme case with module
808 'align' => 'C',
809 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
810 // 'label' => ' ', // the final label
811 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
812 ],
813 'content' => [
814 'align' => 'L',
815 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
816 ],
817 'border-left' => true, // add left line separator
818 ];
819
820 $rank += 10;
821 $this->cols['label'] = [
822 'rank' => $rank,
823 'width' => false,
824 'status' => true,
825 'title' => [
826 'textkey' => 'Label', // use lang key is useful in somme case with module
827 'align' => 'C',
828 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
829 // 'label' => ' ', // the final label
830 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
831 ],
832 'content' => [
833 'align' => 'L',
834 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
835 ],
836 'border-left' => true, // add left line separator
837 ];
838
839 $rank += 10;
840 $this->cols['debit'] = [
841 'rank' => $rank,
842 'width' => 15,
843 'status' => true,
844 'title' => [
845 'textkey' => 'Debit', // use lang key is useful in somme case with module
846 'align' => 'C',
847 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
848 // 'label' => ' ', // the final label
849 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
850 ],
851 'content' => [
852 'align' => 'R',
853 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
854 ],
855 'border-left' => true, // add left line separator
856 ];
857
858 $rank += 10;
859 $this->cols['credit'] = array(
860 'rank' => $rank,
861 'width' => 15,
862 'status' => true,
863 'title' => array(
864 'textkey' => 'Credit', // use lang key is useful in somme case with module
865 'align' => 'C',
866 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
867 // 'label' => ' ', // the final label
868 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
869 ),
870 'content' => array(
871 'align' => 'R',
872 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
873 ),
874 'border-left' => true, // add left line separator
875 );
876
877 // Add extrafields cols
878 if (!empty($object->lines)) {
879 $line = reset($object->lines);
880 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
881 }
882
883 $parameters = array(
884 'object' => $object,
885 'outputlangs' => $outputlangs,
886 'hidedetails' => $hidedetails,
887 'hidedesc' => $hidedesc,
888 'hideref' => $hideref
889 );
890
891 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
892 if ($reshook < 0) {
893 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
894 } elseif (empty($reshook)) {
895 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
896 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
897 } else {
898 $this->cols = $hookmanager->resArray;
899 }
900 }
901
916 protected function addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase = true)
917 {
918 $curY = $nexY;
919 $pageposbefore = $pdf->getPage();
920 $pdf->SetFont('', 'B', $default_font_size - 1);
921 $pdf->startTransaction();
922
923 if ($uppercase) {
924 $label = mb_strtoupper($label);
925 }
926 $this->printStdColumnContent($pdf, $curY, 'label', $label);
927
928 $pageposafter = $pdf->getPage();
929 if ($pageposafter > $pageposbefore) { // There is a pagebreak
930 $pdf->rollbackTransaction(true);
931
932 $pdf->AddPage('', '', true);
933 $pdf->setPage($pageposafter);
934 $curY = $tab_top_newpage + $this->tabTitleHeight;
935 $this->printStdColumnContent($pdf, $curY, 'label', $label);
936 }
937
938 $nexY = $pdf->GetY();
939
940 if ($this->getColumnStatus('debit')) {
941 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($debit, 'MT')));
942 $nexY = max($pdf->GetY(), $nexY);
943 }
944
945 if ($this->getColumnStatus('credit')) {
946 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($credit, 'MT')));
947 $nexY = max($pdf->GetY(), $nexY);
948 }
949
950 if ($this->getColumnStatus('balance')) {
951 $solde = $credit - $debit;
952 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' C' : ' D');
953 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
954 $nexY = max($pdf->GetY(), $nexY);
955 }
956
957 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
958 $this->addDashLine($pdf, $pageposafter, $nexY);
959 }
960 }
961}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
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.
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.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:1047
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:266
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161