dolibarr 24.0.0-beta
modules_accountancy.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
7 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2025 Jean-Rémi TAPONIER <jean-remi@netlogic.fr>
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
34require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php';
36
37
42{
46 public $fromDate;
47
51 public $toDate;
52
57 public $verticalLinesSpacesCoordinates = [];
58
59 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
67 public static function liste_modeles($db, $maxfilenamelength = 0)
68 {
69 // phpcs:enable
70 $type = 'accountancy';
71 $list = array();
72
73 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
74 $list = getListOfModels($db, $type, $maxfilenamelength);
75
76 return $list;
77 }
78
79
80 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
90 abstract public function write_file(BookKeeping $object, Translate $outputlangs, string $srctemplatepath = '', bool $directDownload = true);
91 // phpcs:enable
92
101 protected function addDashLine(TCPDF $pdf, int $page, $y)
102 {
103 // Add line
104 $pdf->setPage($page);
105 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
106 //$pdf->SetDrawColor(190,190,200);
107 $pdf->line($this->marge_gauche, $y, $this->page_largeur - $this->marge_droite, $y);
108 $pdf->SetLineStyle(array('dash' => 0));
109 }
110
125 abstract protected function addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase = true);
126
140 protected function addTitleLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $columnKey, string $label, $tab_top_newpage, bool $uppercase = true)
141 {
142 $curY = $nexY;
143 $pageposbefore = $pdf->getPage();
144 $pdf->SetFont('', 'B', $default_font_size);
145 $pdf->startTransaction();
146
147 if ($uppercase) {
148 $label = mb_strtoupper($label);
149 }
150 $this->printTitleContent($pdf, $curY, $columnKey, $label);
151
152 $pageposafter = $pdf->getPage();
153 if ($pageposafter > $pageposbefore) { // There is a pagebreak
154 $pdf->rollbackTransaction(true);
155
156 $pdf->AddPage('', '', true);
157 $pdf->setPage($pageposafter);
158 $curY = $tab_top_newpage + $this->tabTitleHeight;
159 $this->printTitleContent($pdf, $curY, $columnKey, $label);
160 }
161
162 $nexY = $pdf->GetY();
163
164 $this->verticalLinesSpacesCoordinates[$pdf->getPage()][] = ['start' => $curY, 'end' => $nexY];
165 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES')) {
166 $this->addDashLine($pdf, $pageposafter, $nexY);
167 }
168 }
169
179 protected function printTitleContent($pdf, $curY, $colKey, $columnText)
180 {
181 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
182 $colDef = $this->cols[$colKey];
183 // save current cell padding
184 $curentCellPaddinds = $pdf->getCellPaddings();
185 // set cell padding with column content definition
186 $pdf->setCellPaddings(isset($colDef['content']['padding'][3]) ? $colDef['content']['padding'][3] : 0, isset($colDef['content']['padding'][0]) ? $colDef['content']['padding'][0] : 0, isset($colDef['content']['padding'][1]) ? $colDef['content']['padding'][1] : 0, isset($colDef['content']['padding'][2]) ? $colDef['content']['padding'][2] : 0);
187 $pdf->writeHTMLCell($this->page_largeur - $this->marge_droite, 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, false, true, $colDef['content']['align']);
188 $this->setAfterColsLinePositionsData($colKey, $pdf->GetY(), $pdf->getPage());
189
190 // restore cell padding
191 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
192 }
193
204 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
205 {
206 global $hookmanager, $conf;
207
208 foreach ($this->cols as $colKey => $colDef) {
209 $parameters = array(
210 'colKey' => $colKey,
211 'pdf' => $pdf,
212 'outputlangs' => $outputlangs,
213 'tab_top' => $tab_top,
214 'tab_height' => $tab_height,
215 'hidetop' => $hidetop
216 );
217
218 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
219 if ($reshook < 0) {
220 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
221 } elseif (empty($reshook)) {
222 if (!$this->getColumnStatus($colKey)) {
223 continue;
224 }
225
226 // get title label
227 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
228
229 // Add column separator
230 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
231 // Use title coordinates if exists
232 if (!empty($this->verticalLinesSpacesCoordinates[$pdf->getPage()])) {
233 $coordinates = $this->verticalLinesSpacesCoordinates[$pdf->getPage()];
234 array_unshift($coordinates, ['start' => null, 'end' => $tab_top]);
235 $coordinates[] = ['start' => $tab_top + $tab_height, 'end' => null];
236
237 foreach ($coordinates as $key => $yCoordinates) {
238 if (!isset($coordinates[$key-1]['end'])) {
239 continue;
240 }
241 $pdf->line($colDef['xStartPos'], $coordinates[$key-1]['end'], $colDef['xStartPos'], $yCoordinates['start']);
242 }
243 } else {
244 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
245 }
246 }
247
248 if (empty($hidetop)) {
249 // save current cell padding
250 $curentCellPaddinds = $pdf->getCellPaddings();
251
252 // Add space for lines (more if we need to show a second alternative language)
253 global $outputlangsbis;
254 if (is_object($outputlangsbis)) {
255 // set cell padding with column title definition
256 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
257 } else {
258 // set cell padding with column title definition
259 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
260 }
261 if (isset($colDef['title']['align'])) {
262 $align = $colDef['title']['align'];
263 } else {
264 $align = '';
265 }
266 $pdf->SetXY($colDef['xStartPos'], $tab_top);
267 $textWidth = $colDef['width'];
268 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
269
270 // Add variant of translation if $outputlangsbis is an object
271 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
272 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
273 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
274 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
275 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
276 }
277
278 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
279
280 // restore cell padding
281 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
282 }
283 }
284 }
285
286 return $this->tabTitleHeight;
287 }
288}
289
294{
301 abstract public function getNextValue(BookKeeping $object);
302
303
309 abstract public function getExample();
310}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage Ledger (General Ledger and Subledger)
Parent class for documents (PDF, ODT, ...) generators.
getColumnStatus($colKey)
get column status from column key
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
Used for to set afterColsLinePositions var in a pdf draw line loop.
Parent class for number ref generators.
Parent class to manage numbering of Sale Orders.
getNextValue(BookKeeping $object)
Return next free value.
getExample()
Return an example of numbering.
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.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
addDashLine(TCPDF $pdf, int $page, $y)
Add dash line.
write_file(BookKeeping $object, Translate $outputlangs, string $srctemplatepath='', bool $directDownload=true)
Function to build pdf onto disk.
printTitleContent($pdf, $curY, $colKey, $columnText)
Print a title using the colKey start position, and the end of table as end position.
addTotalLine(TCPDF $pdf, &$curY, &$nexY, $default_font_size, string $label, $tab_top_newpage, $debit, $credit, bool $uppercase=true)
Add a total line to pdf.
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
Class to manage translations.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getListOfModels($db, $type, $maxfilenamelength=0, $showempty=0)
Return list of activated modules usable for document generation.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.