142 global $user, $conf, $langs, $hookmanager;
144 $hidedesc = $hidedetails = $hideref = 0;
150 $outputlangs->charset_output =
'ISO-8859-1';
154 $outputlangs->loadLangs(array(
"main",
"bills",
"orders",
"companies",
"other",
"accountancy",
"compta"));
156 global $outputlangsbis;
157 $outputlangsbis =
null;
159 $outputlangsbis =
new Translate(
'', $conf);
161 $outputlangsbis->loadLangs(array(
"main",
"bills",
"orders",
"products",
"dict",
"companies",
"other",
"propal",
"sendings",
"productbatch",
"compta"));
164 $nblines = count(
$object->lines);
166 if (!$conf->accounting->multidir_output[$conf->entity]) {
167 $this->error = $langs->transnoentities(
"ErrorAccountancyDirectoryNotDefined");
172 $dir = $conf->accounting->multidir_output[$conf->entity].
"/export";
174 $file =
"{$dir}/SPECIMEN_{$this->name}.pdf";
178 $file =
"{$dir}/{$this->name}_{$date}.pdf";
181 if (!file_exists($dir)) {
183 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
189 if (!is_object($hookmanager)) {
190 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
193 $hookmanager->initHooks(array(
'pdfgeneration'));
194 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
196 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
203 $heightforinfotot = 8;
205 $heightforfooter = $this->marge_basse + 14;
207 $heightforfooter += 6;
209 $pdf->setAutoPageBreak(
true, 0);
211 if (class_exists(
'TCPDF')) {
212 $pdf->setPrintHeader(
false);
213 $pdf->setPrintFooter(
false);
218 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
219 $tplidx = $pdf->importPage(1);
224 $pdf->SetDrawColor(128, 128, 128);
226 if (method_exists($pdf,
'AliasNbPages')) {
227 $pdf->AliasNbPages();
230 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
231 $pdf->SetSubject($outputlangs->transnoentities(
"AccountancyBookkeeping"));
232 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
233 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
234 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"AccountancyBookkeeping"));
236 $pdf->SetCompression(
false);
240 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
244 if (!empty($tplidx)) {
245 $pdf->useTemplate($tplidx);
249 $pdf->SetFont(
'',
'', $default_font_size - 1);
250 $pdf->MultiCell(0, 3,
'');
251 $pdf->SetTextColor(0, 0, 0);
254 $tab_top_newpage = (
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 10 : $tab_top);
256 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
258 $this->posxdesc = $this->marge_gauche + 1;
261 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
267 $pdf->startTransaction();
268 $pdf->SetFont(
'',
'B', $default_font_size - 1);
269 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
270 $pdf->SetFont(
'',
'', $default_font_size - 1);
271 $pdf->rollbackTransaction(
true);
274 $curY = $nexY = $tab_top + $this->tabTitleHeight;
277 $pageposbeforeprintlines = $pdf->getPage();
278 $pagenb = $pageposbeforeprintlines;
285 $nbMonths = (((int) $toYear - (
int) $fromYear) * 12) + ((int) $toMonth - (
int) $fromMonth) + 1;
288 for ($i = 0; $i < $nbMonths; $i++) {
290 $dates[$datePlusOneMonth] =
dol_print_date($datePlusOneMonth,
"%B %Y");
294 $journalDebit = $journalCredit = $totalDebit = $totalCredit = 0;
295 for ($i = 0; $i < $nblines; $i++) {
297 if (empty($journal) || $journal !=
$object->lines[$i]->code_journal) {
299 if (!empty($journal)) {
305 "{$langs->transnoentities('Total')} {$journal}",
322 "{$langs->transnoentities('Journal')} {$object->lines[$i]->code_journal}",
326 $journal =
$object->lines[$i]->code_journal;
327 $journalDebit = $journalCredit = 0;
330 $journalDebit +=
$object->lines[$i]->debit;
331 $journalCredit +=
$object->lines[$i]->credit;
332 $totalDebit +=
$object->lines[$i]->debit;
333 $totalCredit +=
$object->lines[$i]->credit;
336 $pdf->SetFont(
'',
'', $default_font_size - 1);
337 $pdf->SetTextColor(0, 0, 0);
339 $pdf->setTopMargin($tab_top_newpage);
340 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
341 $pageposbefore = $pdf->getPage();
343 $showpricebeforepagebreak = 1;
344 $heightforsignature = 0;
348 $pdf->startTransaction();
352 $pageposafter = $pdf->getPage();
353 if ($pageposafter > $pageposbefore) {
354 $pdf->rollbackTransaction(
true);
356 $pdf->AddPage(
'',
'',
true);
357 $pdf->setPage($pageposafter);
358 $curY = $tab_top_newpage + $this->tabTitleHeight;
361 $pageposafter = $pdf->getPage();
362 $posyafter = $pdf->GetY();
364 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
365 if ($i == ($nblines - 1)) {
366 $pdf->AddPage(
'',
'',
true);
367 if (!empty($tplidx)) {
368 $pdf->useTemplate($tplidx);
371 $pdf->setPage($pageposafter + 1);
377 $showpricebeforepagebreak = 1;
379 $showpricebeforepagebreak = 0;
383 $pdf->commitTransaction();
385 $nexY = max($pdf->GetY(), $nexY);
387 $nexY = $pdf->GetY();
388 $pageposafter = $pdf->getPage();
390 $pdf->setPage($pageposbefore);
391 $pdf->setTopMargin($this->marge_haute);
392 $pdf->setPageOrientation(
'',
true, 0);
395 if ($pageposafter > $pageposbefore) {
396 $pdf->setPage($pageposafter);
397 $curY = $tab_top_newpage + $this->tabTitleHeight;
400 $pdf->SetFont(
'',
'', $default_font_size - 1);
409 $nexY = max($pdf->GetY(), $nexY);
414 $nexY = max($pdf->GetY(), $nexY);
419 $nexY = max($pdf->GetY(), $nexY);
423 $nexY = max($pdf->GetY(), $nexY);
428 $nexY = max($pdf->GetY(), $nexY);
433 $nexY = max($pdf->GetY(), $nexY);
442 'outputlangs' => $outputlangs,
443 'hidedetails' => $hidedetails
445 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
453 while ($pagenb < $pageposafter) {
454 $pdf->setPage($pagenb);
455 if ($pagenb == $pageposbeforeprintlines) {
456 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
458 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
462 $pdf->setPage($pagenb);
463 $pdf->setPageOrientation(
'',
true, 0);
467 if (!empty($tplidx)) {
468 $pdf->useTemplate($tplidx);
471 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
473 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
475 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
480 if (!empty($tplidx)) {
481 $pdf->useTemplate($tplidx);
491 if (!empty($journal)) {
501 "{$langs->transnoentities('Total')} {$journal}",
517 $langs->transnoentities(
'GrandTotals'),
527 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
529 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
534 if (method_exists($pdf,
'AliasNbPages')) {
535 $pdf->AliasNbPages();
540 $pdf->Output($file, $directDownload ?
'D' :
'F');
543 $hookmanager->initHooks(array(
'pdfgeneration'));
544 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
546 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
547 $this->warnings = $hookmanager->warnings;
549 $this->error = $hookmanager->error;
550 $this->errors = $hookmanager->errors;
557 $this->result = array(
'fullpath' => $file);
577 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
587 $currency = !empty($currency) ? $currency : $conf->currency;
591 $pdf->SetTextColor(0, 0, 0);
592 $pdf->SetFont(
'',
'', $default_font_size - 2);
594 if (empty($hidetop)) {
596 $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')));
600 $pdf->SetDrawColor(128, 128, 128);
601 $pdf->SetFont(
'',
'', $default_font_size - 1);
604 $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');
606 $pdf->SetFont(
'',
'B', $default_font_size - 1);
607 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
608 $pdf->SetFont(
'',
'', $default_font_size - 1);
611 if (empty($hidetop)) {
612 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
628 global $conf, $langs;
631 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
634 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
641 $pdf->SetTextColor(0, 0, 60);
642 $pdf->SetFont(
'',
'B', $default_font_size + 3);
645 $posy = $this->marge_haute;
646 $posx = $this->marge_gauche;
648 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
649 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
651 $posx = $this->page_largeur - $this->marge_droite - $w;
655 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
656 $text = $this->emetteur->name;
657 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
658 $nexY = max($pdf->GetY(), $nexY);
661 $pdf->SetFont(
'',
'', $default_font_size - 2);
662 $pdf->SetXY($this->marge_gauche + 2, $nexY);
663 $pdf->SetTextColor(0, 0, 60);
664 $textDateNow = $outputlangs->transnoentities(
"PrintDate");
665 $pdf->MultiCell($w / 3, 3, $textDateNow .
" : " .
date(
'd/m/Y',
dol_now()),
'',
'L');
666 $nexY = max($pdf->GetY(), $nexY);
669 $pdf->SetFont(
'',
'B', $default_font_size + 3);
670 $pdf->SetXY($posx - 2, $posy + 2);
671 $pdf->SetTextColor(0, 0, 60);
672 $title = $outputlangs->transnoentities(
"PdfBookkeepingTitle");
673 $pdf->MultiCell($w / 3, 3, $title, 0,
'C');
674 $nexY = max($pdf->GetY(), $nexY);
677 $pdf->SetFont(
'',
'B', $default_font_size);
678 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
679 $pdf->SetTextColor(0, 0, 60);
683 $textDate = $outputlangs->transnoentities(
"From") .
" " . $fromDate .
" " . $outputlangs->transnoentities(
"To") .
" " . $toDate;
684 $pdf->MultiCell($w / 3, 4, $textDate, 0,
'R');
685 $nexY = max($pdf->GetY(), $nexY);
687 $pdf->SetTextColor(0, 0, 0);
719 global $conf, $hookmanager;
722 $this->defaultContentsFieldsStyle = array(
724 'padding' => array(1, 0.5, 1, 0.5),
728 $this->defaultTitlesFieldsStyle = array(
730 'padding' => array(0.5, 0, 0.5, 0),
734 $this->cols[
'position'] = [
737 'status' => (bool)
getDolGlobalInt(
'PDF_ACCOUNTANCY_LEDGER_ADD_POSITION'),
743 'padding' => [0.5, 0.5, 0.5, 0.5],
747 'padding' => [1, 0.5, 1, 1.5],
752 $this->cols[
'date'] = [
761 'padding' => [0.5, 0.5, 0.5, 0.5],
765 'padding' => [1, 0.5, 1, 1.5],
770 $this->cols[
'piece_num'] = [
775 'textkey' =>
'Piece',
779 'padding' => [0.5, 0.5, 0.5, 0.5],
783 'padding' => [1, 0.5, 1, 1.5],
785 'border-left' =>
true,
789 $this->cols[
'account'] = [
794 'textkey' =>
'Account',
798 'padding' => [0.5, 0.5, 0.5, 0.5],
802 'padding' => [1, 0.5, 1, 1.5],
804 'border-left' =>
true,
808 $this->cols[
'account_label'] = [
813 'textkey' =>
'LabelAccount',
817 'padding' => [0.5, 0.5, 0.5, 0.5],
821 'padding' => [1, 0.5, 1, 1.5],
823 'border-left' =>
true,
827 $this->cols[
'label'] = [
832 'textkey' =>
'Label',
836 'padding' => [0.5, 0.5, 0.5, 0.5],
840 'padding' => [1, 0.5, 1, 1.5],
842 'border-left' =>
true,
846 $this->cols[
'debit'] = [
851 'textkey' =>
'Debit',
855 'padding' => [0.5, 0.5, 0.5, 0.5],
859 'padding' => [1, 0.5, 1, 1.5],
861 'border-left' =>
true,
865 $this->cols[
'credit'] = array(
870 'textkey' =>
'Credit',
874 'padding' => array(0.5, 0.5, 0.5, 0.5),
878 'padding' => array(1, 0.5, 1, 1.5),
880 'border-left' =>
true,
891 'outputlangs' => $outputlangs,
892 'hidedetails' => $hidedetails,
893 'hidedesc' => $hidedesc,
894 'hideref' => $hideref
897 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
900 } elseif (empty($reshook)) {
902 $this->cols = array_replace($this->cols, $hookmanager->resArray);
904 $this->cols = $hookmanager->resArray;