dolibarr 22.0.5
pdf_balance.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 $balanceType;
89
95 public function __construct(DoliDB $db)
96 {
97 global $langs, $mysoc;
98
99 $this->name = "balance";
100 $this->description = $langs->trans("PDFAccountancyBalanceDescription");
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"));
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", "deliveries", "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);
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
237 if ($this->balanceType == "sub") {
238 $pdf->SetSubject($outputlangs->transnoentities("AccountBalanceSubAccount"));
239 } else {
240 $pdf->SetSubject($outputlangs->transnoentities("AccountancyBalance"));
241 }
242 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
243 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
244 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("AccountancyBalance"));
245 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
246 $pdf->SetCompression(false);
247 }
248
249 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
250 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
251
252 // New page
253 $pdf->AddPage();
254 if (!empty($tplidx)) {
255 $pdf->useTemplate($tplidx);
256 }
257 $pagenb++;
258 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
259 $pdf->SetFont('', '', $default_font_size - 1);
260 $pdf->MultiCell(0, 3, ''); // Set interline to 3
261 $pdf->SetTextColor(0, 0, 0);
262
263 $tab_top = 40; // position of top tab
264 $tab_top_newpage = (getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 10 : $tab_top);
265
266 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
267
268 $this->posxdesc = $this->marge_gauche + 1;
269
270 // Displays notes. Here we are still on code executed only for the first page.
271 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
272
273 // Use new auto column system
274 $this->prepareArrayColumnField($object, $outputlangs);
275
276 // Table simulation to know the height of the title line
277 $pdf->startTransaction();
278 $pdf->SetFont('', 'B', $default_font_size - 1);
279 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
280 $pdf->SetFont('', '', $default_font_size - 1);
281 $pdf->rollbackTransaction(true);
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 $accountGroup = '';
303 $groupDebit = $groupCredit = $totalDebit = $totalCredit = 0;
304 for ($i = 0; $i < $nblines; $i++) {
305 $accountingAccount = new AccountingAccount($this->db);
306 $accountingAccount->fetch(0, $object->lines[$i]->numero_compte, true);
307
308 // Init the first account group
309 if (empty($accountGroup)) {
310 $accountGroup = $accountingAccount->pcg_type;
311 }
312
313 // If account group has changed, display the group summary line
314 if ($accountGroup != $accountingAccount->pcg_type) {
315 $this->addTotalLine(
316 $pdf,
317 $curY,
318 $nexY,
319 $default_font_size,
320 $langs->transnoentitiesnoconv('Total') . ' ' . $langs->transnoentitiesnoconv('AccountancyGroup' . $accountGroup),
321 $tab_top_newpage,
322 $groupDebit,
323 $groupCredit
324 );
325 $accountGroup = $accountingAccount->pcg_type;
326 $groupDebit = $groupCredit = 0;
327 }
328
329 $groupDebit += $object->lines[$i]->debit;
330 $groupCredit += $object->lines[$i]->credit;
331 $totalDebit += $object->lines[$i]->debit;
332 $totalCredit += $object->lines[$i]->credit;
333
334 $curY = $nexY;
335 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
336 $pdf->SetTextColor(0, 0, 0);
337
338 $pdf->setTopMargin($tab_top_newpage);
339 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
340 $pageposbefore = $pdf->getPage();
341
342 $showpricebeforepagebreak = 1;
343 $heightforsignature = 0;
344
345 // Column used for testing page change
346 // No check on column status, this column is mandatory
347 $pdf->startTransaction();
348
349 if ($this->balanceType == "sub") {
350 $this->printStdColumnContent($pdf, $curY, 'account_label', $object->lines[$i]->subledger_label);
351 } else {
352 $this->printStdColumnContent($pdf, $curY, 'account_label', $accountingAccount->label);
353 }
354
355 $pageposafter = $pdf->getPage();
356 if ($pageposafter > $pageposbefore) { // There is a pagebreak
357 $pdf->rollbackTransaction(true);
358
359 $pdf->AddPage('', '', true);
360 $pdf->setPage($pageposafter);
361 $curY = $tab_top_newpage + $this->tabTitleHeight;
362 if ($this->balanceType == "sub") {
363 $this->printStdColumnContent($pdf, $curY, 'account_label', $object->lines[$i]->subledger_label);
364 } else {
365 $this->printStdColumnContent($pdf, $curY, 'account_label', $accountingAccount->label);
366 }
367
368 $pageposafter = $pdf->getPage();
369 $posyafter = $pdf->GetY();
370 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
371 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text
372 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
373 $pdf->AddPage('', '', true);
374 if (!empty($tplidx)) {
375 $pdf->useTemplate($tplidx);
376 }
377 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
378 $pdf->setPage($pageposafter + 1);
379 }
380 } else {
381 // We found a page break
382 // Allows data in the first page if description is long enough to break in multiples pages
383 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
384 $showpricebeforepagebreak = 1;
385 } else {
386 $showpricebeforepagebreak = 0;
387 }
388 }
389 } else { // No pagebreak
390 $pdf->commitTransaction();
391 }
392 $nexY = max($pdf->GetY(), $nexY);
393
394 $nexY = $pdf->GetY();
395 $pageposafter = $pdf->getPage();
396
397 $pdf->setPage($pageposbefore);
398 $pdf->setTopMargin($this->marge_haute);
399 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
400
401 // We suppose that a too long description is moved completely on next page
402 if ($pageposafter > $pageposbefore) {
403 $pdf->setPage($pageposafter);
404 $curY = $tab_top_newpage + $this->tabTitleHeight;
405 }
406
407 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
408
409 // # of line
410 if ($this->getColumnStatus('position')) {
411 $this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
412 }
413
414 if ($this->balanceType == 'sub' && $this->getColumnStatus('account_number')) {
415 $text = length_accounta($object->lines[$i]->subledger_account);
416 $this->printStdColumnContent($pdf, $curY, 'account_number', $text);
417 $nexY = max($pdf->GetY(), $nexY);
418 } elseif ($this->getColumnStatus('account_number')) {
419 $text = length_accountg($object->lines[$i]->numero_compte);
420 $this->printStdColumnContent($pdf, $curY, 'account_number', $text);
421 $nexY = max($pdf->GetY(), $nexY);
422 }
423
424 if ($this->getColumnStatus('debit')) {
425 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($object->lines[$i]->debit, 'MT')));
426 $nexY = max($pdf->GetY(), $nexY);
427 }
428
429 if ($this->getColumnStatus('credit')) {
430 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($object->lines[$i]->credit, 'MT')));
431 $nexY = max($pdf->GetY(), $nexY);
432 }
433
434 if ($this->getColumnStatus('balance')) {
435 $solde = $object->lines[$i]->credit - $object->lines[$i]->debit;
436 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' C' : ' D');
437 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
438 $nexY = max($pdf->GetY(), $nexY);
439 }
440
441 $parameters = array(
442 'object' => $object,
443 'i' => $i,
444 'pdf' => & $pdf,
445 'curY' => & $curY,
446 'nexY' => & $nexY,
447 'outputlangs' => $outputlangs,
448 'hidedetails' => $hidedetails
449 );
450 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this);
451
452 // Add line
453 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
454 $this->addDashLine($pdf, $pageposafter, $nexY);
455 }
456
457 // Detect if some page were added automatically and output _tableau for past pages
458 while ($pagenb < $pageposafter) {
459 $pdf->setPage($pagenb);
460 if ($pagenb == $pageposbeforeprintlines) {
461 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
462 } else {
463 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
464 }
465 $this->_pagefoot($pdf, $object, $outputlangs, 1);
466 $pagenb++;
467 $pdf->setPage($pagenb);
468 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
469 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
470 $this->_pagehead($pdf, $object, 0, $outputlangs);
471 }
472 if (!empty($tplidx)) {
473 $pdf->useTemplate($tplidx);
474 }
475 }
476 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
477 if ($pagenb == 1) {
478 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
479 } else {
480 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
481 }
482 $this->_pagefoot($pdf, $object, $outputlangs, 1);
483 // New page
484 $pdf->AddPage();
485 if (!empty($tplidx)) {
486 $pdf->useTemplate($tplidx);
487 }
488 $pagenb++;
489 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
490 $this->_pagehead($pdf, $object, 0, $outputlangs);
491 }
492 }
493 }
494
495 // Add total line for last group
496 if (!empty($accountingAccount->pcg_type)) {
497 // Add line
498 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
499 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
500 }
501 $this->addTotalLine(
502 $pdf,
503 $curY,
504 $nexY,
505 $default_font_size,
506 $langs->transnoentitiesnoconv('Total') . ' ' . $langs->transnoentitiesnoconv('AccountancyGroup' . $accountingAccount->pcg_type),
507 $tab_top_newpage,
508 $groupDebit,
509 $groupCredit
510 );
511 }
512
513 // Add grand total line
514 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
515 $this->addDashLine($pdf, $pdf->getPage(), $nexY);
516 }
517 $this->addTotalLine(
518 $pdf,
519 $curY,
520 $nexY,
521 $default_font_size,
522 $langs->transnoentities('GrandTotals'),
523 $tab_top_newpage,
524 $totalDebit,
525 $totalCredit,
526 );
527
528
529
530 // Show square
531 if ($pagenb == 1) {
532 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
533 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
534 } else {
535 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
536 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
537 }
538
539 // Pagefoot
540 $this->_pagefoot($pdf, $object, $outputlangs);
541 if (method_exists($pdf, 'AliasNbPages')) {
542 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
543 }
544
545 $pdf->Close();
546
547 $pdf->Output($file, $directDownload ? 'D' : 'F');
548
549 // Add pdfgeneration hook
550 $hookmanager->initHooks(array('pdfgeneration'));
551 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
552 global $action;
553 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
554 if ($reshook < 0) {
555 $this->error = $hookmanager->error;
556 $this->errors = $hookmanager->errors;
557 }
558
559 dolChmod($file);
560
561 $this->result = array('fullpath' => $file);
562
563 return 1; // No error
564 }
565
566 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
581 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
582 {
583 global $conf;
584
585 // Force to disable hidetop and hidebottom
586 $hidebottom = 0;
587 if ($hidetop) {
588 $hidetop = -1;
589 }
590
591 $currency = !empty($currency) ? $currency : $conf->currency;
592 $default_font_size = pdf_getPDFFontSize($outputlangs);
593
594 // Amount in (at tab_top - 1)
595 $pdf->SetTextColor(0, 0, 0);
596 $pdf->SetFont('', '', $default_font_size - 2);
597
598 if (empty($hidetop)) {
599 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
600 $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')));
601 }
602 }
603
604 $pdf->SetDrawColor(128, 128, 128);
605 $pdf->SetFont('', '', $default_font_size - 1);
606
607 // Output Rect
608 $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
609
610 $pdf->SetFont('', 'B', $default_font_size - 1);
611 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
612 $pdf->SetFont('', '', $default_font_size - 1);
613
614
615 if (empty($hidetop)) {
616 $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
617 }
618 }
619
620 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
630 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
631 {
632 global $conf, $langs;
633
634 $ltrdirection = 'L';
635 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
636
637 // Load traductions files required by page
638 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
639
640 $default_font_size = pdf_getPDFFontSize($outputlangs);
641
642 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
643
644
645 $pdf->SetTextColor(0, 0, 60);
646 $pdf->SetFont('', 'B', $default_font_size + 3);
647
648 $w = 110;
649 $posy = $this->marge_haute;
650 $posx = $this->marge_gauche;
651 $hautcadre = 20;
652 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
653 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
654
655 $posx = $this->page_largeur - $this->marge_droite - $w;
656 $nexY = $posy;
657
658 // Name of soc
659 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
660 $text = $this->emetteur->name;
661 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
662 $nexY = max($pdf->GetY(), $nexY);
663
664 // Date of document
665 $pdf->SetFont('', '', $default_font_size - 2);
666 $pdf->SetXY($this->marge_gauche + 2, $nexY);
667 $pdf->SetTextColor(0, 0, 60);
668 $textDateNow = $outputlangs->transnoentities("PrintDate");
669 $pdf->MultiCell($w / 3, 3, $textDateNow . " : " . date('d/m/Y', dol_now()), '', 'L');
670 $nexY = max($pdf->GetY(), $nexY);
671
672 // Page title
673 $pdf->SetFont('', 'B', $default_font_size + 3);
674 $pdf->SetXY($posx - 2, $posy + 2);
675 $pdf->SetTextColor(0, 0, 120);
676 if ($this->balanceType == "sub") {
677 $title = $outputlangs->transnoentities("AccountBalanceSubAccount");
678 } else {
679 $title = $outputlangs->transnoentities("PdfBalanceTitle");
680 }
681 $pdf->MultiCell($w / 3, 3, $title, 0, 'C');
682 $nexY = max($pdf->GetY(), $nexY);
683
684 // Date From To
685 $pdf->SetFont('', 'B', $default_font_size);
686 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
687 $pdf->SetTextColor(0, 0, 60);
688
689 $fromDate = dol_print_date($this->fromDate, 'day');
690 $toDate = dol_print_date($this->toDate, 'day');
691 $textDate = $outputlangs->transnoentities("From") . " " . $fromDate . " " . $outputlangs->transnoentities("To") . " " . $toDate;
692 $pdf->MultiCell($w / 3, 4, $textDate, 0, 'R');
693 $nexY = max($pdf->GetY(), $nexY);
694
695 $pdf->SetTextColor(0, 0, 0);
696 return $nexY;
697 }
698
699 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
709 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
710 {
711 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
712 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);
713 }
714
725 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
726 {
727 global $conf, $hookmanager;
728
729 // Default field style for content
730 $this->defaultContentsFieldsStyle = array(
731 'align' => 'R', // R,C,L
732 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
733 );
734
735 // Default field style for content
736 $this->defaultTitlesFieldsStyle = array(
737 'align' => 'C', // R,C,L
738 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
739 );
740
741 $rank = 0; // do not use negative rank
742 $this->cols['position'] = [
743 'rank' => $rank,
744 'width' => 10,
745 'status' => (bool) getDolGlobalInt('PDF_ACCOUNTANCY_BALANCE_ADD_POSITION'),
746 'title' => [
747 'textkey' => '#', // use lang key is useful in some case with module
748 'align' => 'C',
749 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
750 // 'label' => ' ', // the final label
751 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
752 ],
753 'content' => [
754 'align' => 'C',
755 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
756 ],
757 ];
758
759 $rank += 10; // do not use negative rank
760 $this->cols['account_number'] = [
761 'rank' => $rank,
762 'width' => 20, // only for desc
763 'status' => true,
764 'title' => [
765 'textkey' => 'AccountNumber', // use lang key is useful in some case with module
766 'align' => 'C',
767 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
768 // 'label' => ' ', // the final label
769 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
770 ],
771 'content' => [
772 'align' => 'L',
773 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
774 ],
775 ];
776
777 $rank += 10;
778 $this->cols['account_label'] = [
779 'rank' => $rank,
780 'width' => false,
781 'status' => true,
782 'title' => [
783 'textkey' => 'Label', // use lang key is useful in some case with module
784 'align' => 'C',
785 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
786 // 'label' => ' ', // the final label
787 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
788 ],
789 'content' => [
790 'align' => 'L',
791 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
792 ],
793 'border-left' => true, // add left line separator
794 ];
795
796
797 $rank += 10;
798 $this->cols['debit'] = [
799 'rank' => $rank,
800 'width' => 30,
801 'status' => true,
802 'title' => [
803 'textkey' => 'AccountingDebit', // use lang key is useful in some case with module
804 'align' => 'C',
805 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
806 // 'label' => ' ', // the final label
807 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
808 ],
809 'content' => [
810 'align' => 'R',
811 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
812 ],
813 'border-left' => true, // add left line separator
814 ];
815
816 $rank += 10;
817 $this->cols['credit'] = array(
818 'rank' => $rank,
819 'width' => 30,
820 'status' => true,
821 'title' => array(
822 'textkey' => 'AccountingCredit', // use lang key is useful in some case with module
823 'align' => 'C',
824 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
825 // 'label' => ' ', // the final label
826 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
827 ),
828 'content' => array(
829 'align' => 'R',
830 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
831 ),
832 'border-left' => true, // add left line separator
833 );
834
835 $rank += 10;
836 $this->cols['balance'] = [
837 'rank' => $rank,
838 'width' => 32,
839 'status' => true,
840 'title' => [
841 'textkey' => 'Balance', // use lang key is useful in some case with module
842 'align' => 'C',
843 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
844 // 'label' => ' ', // the final label
845 'padding' => [0.5, 0.5, 0.5, 0.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
846 ],
847 'content' => [
848 'align' => 'R',
849 'padding' => [1, 0.5, 1, 1.5], // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
850 ],
851 'border-left' => true, // add left line separator
852 ];
853
854 // Add extrafields cols
855 if (!empty($object->lines)) {
856 $line = reset($object->lines);
857 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
858 }
859
860 $parameters = array(
861 'object' => $object,
862 'outputlangs' => $outputlangs,
863 'hidedetails' => $hidedetails,
864 'hidedesc' => $hidedesc,
865 'hideref' => $hideref
866 );
867
868 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
869 if ($reshook < 0) {
870 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
871 } elseif (empty($reshook)) {
872 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
873 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
874 } else {
875 $this->cols = $hookmanager->resArray;
876 }
877 }
878
893 protected function addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase = true)
894 {
895 $curY = $nexY;
896 $pageposbefore = $pdf->getPage();
897 $pdf->SetFont('', 'B', $default_font_size - 1);
898 $pdf->startTransaction();
899
900 if ($uppercase) {
901 $label = mb_strtoupper($label);
902 }
903 $this->printStdColumnContent($pdf, $curY, 'account_label', $label);
904
905 $pageposafter = $pdf->getPage();
906 if ($pageposafter > $pageposbefore) { // There is a pagebreak
907 $pdf->rollbackTransaction(true);
908
909 $pdf->AddPage('', '', true);
910 $pdf->setPage($pageposafter);
911 $curY = $tab_top_newpage + $this->tabTitleHeight;
912 $this->printStdColumnContent($pdf, $curY, 'account_label', $label);
913 }
914
915 $nexY = $pdf->GetY();
916
917 if ($this->getColumnStatus('debit')) {
918 $this->printStdColumnContent($pdf, $curY, 'debit', price(price2num($debit, 'MT')));
919 $nexY = max($pdf->GetY(), $nexY);
920 }
921
922 if ($this->getColumnStatus('credit')) {
923 $this->printStdColumnContent($pdf, $curY, 'credit', price(price2num($credit, 'MT')));
924 $nexY = max($pdf->GetY(), $nexY);
925 }
926
927 if ($this->getColumnStatus('balance')) {
928 $solde = $credit - $debit;
929 $soldeText = price(price2num(abs($solde), 'MT')) . ($solde >= 0 ? ' C' : ' D');
930 $this->printStdColumnContent($pdf, $curY, 'balance', $soldeText);
931 $nexY = max($pdf->GetY(), $nexY);
932 }
933
934 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
935 $this->addDashLine($pdf, $pageposafter, $nexY);
936 }
937 }
938}
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)
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.
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.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
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.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
__construct(DoliDB $db)
Constructor.
write_file(BookKeeping $object, Translate $outputlangs, string $srctemplatepath='', bool $directDownload=true)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
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