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