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