147 global $user,
$conf, $langs, $hookmanager;
149 $hidedesc = $hidedetails = $hideref = 0;
155 $outputlangs->charset_output =
'ISO-8859-1';
159 $outputlangs->loadLangs(array(
"main",
"bills",
"orders",
"companies",
"other",
"accountancy",
"compta"));
161 global $outputlangsbis;
162 $outputlangsbis =
null;
166 $outputlangsbis->loadLangs(array(
"main",
"bills",
"orders",
"products",
"dict",
"companies",
"other",
"propal",
"sendings",
"productbatch",
"compta"));
169 $nblines = count(
$object->lines);
171 if (!
$conf->accounting->multidir_output[
$conf->entity]) {
172 $this->error = $langs->transnoentities(
"ErrorAccountancyDirectoryNotDefined");
177 $dir =
$conf->accounting->multidir_output[
$conf->entity].
"/export";
179 $file =
"{$dir}/SPECIMEN_{$this->name}.pdf";
183 $file =
"{$dir}/{$this->name}_{$date}.pdf";
186 if (!file_exists($dir)) {
188 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
194 if (!is_object($hookmanager)) {
195 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
198 $hookmanager->initHooks(array(
'pdfgeneration'));
199 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
201 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
208 $heightforinfotot = 8;
210 $heightforfooter = $this->marge_basse + 14;
212 $heightforfooter += 6;
214 $pdf->setAutoPageBreak(
true, 0);
216 if (class_exists(
'TCPDF')) {
217 $pdf->setPrintHeader(
false);
218 $pdf->setPrintFooter(
false);
223 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
224 $tplidx = $pdf->importPage(1);
229 $pdf->SetDrawColor(128, 128, 128);
231 if (method_exists($pdf,
'AliasNbPages')) {
232 $pdf->AliasNbPages();
235 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
236 if ($this->ledgerType ==
"sub") {
237 $pdf->SetSubject($outputlangs->transnoentities(
"BookkeepingSubAccount"));
239 $pdf->SetSubject($outputlangs->transnoentities(
"AccountancyLedger"));
241 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
242 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
243 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"AccountancyLedger"));
245 $pdf->SetCompression(
false);
249 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
253 if (!empty($tplidx)) {
254 $pdf->useTemplate($tplidx);
258 $pdf->SetFont(
'',
'', $default_font_size - 1);
259 $pdf->MultiCell(0, 3,
'');
260 $pdf->SetTextColor(0, 0, 0);
263 $tab_top_newpage = (
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 10 : $tab_top);
265 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
267 $this->posxdesc = $this->marge_gauche + 1;
270 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
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);
283 $curY = $nexY = $tab_top + $this->tabTitleHeight;
286 $pageposbeforeprintlines = $pdf->getPage();
287 $pagenb = $pageposbeforeprintlines;
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);
297 for ($i = 0; $i < $nbMonths; $i++) {
298 $datePlusOneMonth = strtotime(
"+1 month", $datePlusOneMonth);
299 $dates[$datePlusOneMonth] =
dol_print_date($datePlusOneMonth,
"%B %Y");
303 $accountDebit = $accountCredit = $totalDebit = $totalCredit = 0;
304 for ($i = 0; $i < $nblines; $i++) {
306 if ($this->ledgerType ==
"sub") {
307 if (empty($account) || $account !=
$object->lines[$i]->subledger_account) {
309 if (!empty($account)) {
315 $langs->trans(
'Total'),
332 $langs->trans(
'SubledgerAccount') .
' ' .
length_accounta(
$object->lines[$i]->subledger_account) .
' - ' .
$object->lines[$i]->subledger_label,
336 $account =
$object->lines[$i]->subledger_account;
337 $accountDebit = $accountCredit = 0;
340 if (empty($account) || $account !=
$object->lines[$i]->numero_compte) {
342 $accountingAccount->fetch(0,
$object->lines[$i]->numero_compte,
true);
345 if (!empty($account)) {
351 $langs->transnoentities(
'Total'),
368 $langs->transnoentities(
'AccountAccountingShort') .
' ' .
length_accountg((
string) $accountingAccount->ref) .
' - ' . $accountingAccount->label,
372 $account =
$object->lines[$i]->numero_compte;
373 $accountDebit = $accountCredit = 0;
377 $accountDebit +=
$object->lines[$i]->debit;
378 $accountCredit +=
$object->lines[$i]->credit;
379 $totalDebit +=
$object->lines[$i]->debit;
380 $totalCredit +=
$object->lines[$i]->credit;
383 $pdf->SetFont(
'',
'', $default_font_size - 1);
384 $pdf->SetTextColor(0, 0, 0);
386 $pdf->setTopMargin($tab_top_newpage);
387 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
388 $pageposbefore = $pdf->getPage();
390 $showpricebeforepagebreak = 1;
391 $heightforsignature = 0;
395 $pdf->startTransaction();
399 $pageposafter = $pdf->getPage();
400 if ($pageposafter > $pageposbefore) {
401 $pdf->rollbackTransaction(
true);
403 $pdf->AddPage(
'',
'',
true);
404 $pdf->setPage($pageposafter);
405 $curY = $tab_top_newpage + $this->tabTitleHeight;
408 $pageposafter = $pdf->getPage();
409 $posyafter = $pdf->GetY();
411 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
412 if ($i == ($nblines - 1)) {
413 $pdf->AddPage(
'',
'',
true);
414 if (!empty($tplidx)) {
415 $pdf->useTemplate($tplidx);
418 $pdf->setPage($pageposafter + 1);
424 $showpricebeforepagebreak = 1;
426 $showpricebeforepagebreak = 0;
430 $pdf->commitTransaction();
432 $nexY = max($pdf->GetY(), $nexY);
434 $nexY = $pdf->GetY();
435 $pageposafter = $pdf->getPage();
437 $pdf->setPage($pageposbefore);
438 $pdf->setTopMargin($this->marge_haute);
439 $pdf->setPageOrientation(
'',
true, 0);
442 if ($pageposafter > $pageposbefore) {
443 $pdf->setPage($pageposafter);
444 $curY = $tab_top_newpage + $this->tabTitleHeight;
447 $pdf->SetFont(
'',
'', $default_font_size - 1);
456 $nexY = max($pdf->GetY(), $nexY);
461 $nexY = max($pdf->GetY(), $nexY);
466 $nexY = max($pdf->GetY(), $nexY);
471 $nexY = max($pdf->GetY(), $nexY);
476 $nexY = max($pdf->GetY(), $nexY);
481 $nexY = max($pdf->GetY(), $nexY);
487 $solde = $accountCredit - $accountDebit;
488 $soldeText =
price(
price2num(abs($solde),
'MT')) . ($solde >= 0 ?
' ' . $langs->trans(
'CreditShort') :
' ' . $langs->trans(
'DebitShort'));
490 $nexY = max($pdf->GetY(), $nexY);
499 'outputlangs' => $outputlangs,
500 'hidedetails' => $hidedetails
502 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
510 while ($pagenb < $pageposafter) {
511 $pdf->setPage($pagenb);
512 if ($pagenb == $pageposbeforeprintlines) {
513 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
515 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
519 $pdf->setPage($pagenb);
520 $pdf->setPageOrientation(
'',
true, 0);
524 if (!empty($tplidx)) {
525 $pdf->useTemplate($tplidx);
528 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
530 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
532 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
537 if (!empty($tplidx)) {
538 $pdf->useTemplate($tplidx);
558 $langs->transnoentities(
'Total'),
574 $langs->transnoentities(
'GrandTotals'),
583 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
585 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
590 if (method_exists($pdf,
'AliasNbPages')) {
591 $pdf->AliasNbPages();
596 $pdf->Output($file, $directDownload ?
'D' :
'F');
599 $hookmanager->initHooks(array(
'pdfgeneration'));
600 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
602 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
603 $this->warnings = $hookmanager->warnings;
605 $this->error = $hookmanager->error;
606 $this->errors = $hookmanager->errors;
613 $this->result = array(
'fullpath' => $file);
633 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
643 $currency = !empty($currency) ? $currency :
$conf->currency;
647 $pdf->SetTextColor(0, 0, 0);
648 $pdf->SetFont(
'',
'', $default_font_size - 2);
650 if (empty($hidetop)) {
652 $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')));
656 $pdf->SetDrawColor(128, 128, 128);
657 $pdf->SetFont(
'',
'', $default_font_size - 1);
660 $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');
662 $pdf->SetFont(
'',
'B', $default_font_size - 1);
663 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
664 $pdf->SetFont(
'',
'', $default_font_size - 1);
667 if (empty($hidetop)) {
668 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
684 global
$conf, $langs;
687 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
690 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
697 $pdf->SetTextColor(0, 0, 60);
698 $pdf->SetFont(
'',
'B', $default_font_size + 3);
701 $posy = $this->marge_haute;
702 $posx = $this->marge_gauche;
704 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
705 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
707 $posx = $this->page_largeur - $this->marge_droite - $w;
711 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
712 $text = (string) $this->emetteur->name;
713 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset((
string) $text), 0, $ltrdirection);
714 $nexY = max($pdf->GetY(), $nexY);
717 $pdf->SetFont(
'',
'', $default_font_size - 2);
718 $pdf->SetXY($this->marge_gauche + 2, $nexY);
719 $pdf->SetTextColor(0, 0, 60);
720 $textDateNow = $outputlangs->transnoentities(
"PrintDate");
721 $pdf->MultiCell($w / 3, 3, $textDateNow .
" : " .
date(
'd/m/Y',
dol_now()),
'',
'L');
722 $nexY = max($pdf->GetY(), $nexY);
725 $pdf->SetFont(
'',
'B', $default_font_size + 3);
726 $pdf->SetXY($posx - 2, $posy + 2);
727 $pdf->SetTextColor(0, 0, 120);
728 if ($this->ledgerType ==
"sub") {
729 $title = $outputlangs->transnoentities(
"BookkeepingSubAccount");
731 $title = $outputlangs->transnoentities(
"PdfLedgerTitle");
733 $pdf->MultiCell($w / 3, 3, $title, 0,
'C');
734 $nexY = max($pdf->GetY(), $nexY);
737 $pdf->SetFont(
'',
'B', $default_font_size);
738 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
739 $pdf->SetTextColor(0, 0, 60);
743 $textDate = $outputlangs->transnoentities(
"From") .
" " . $fromDate .
" " . $outputlangs->transnoentities(
"To") .
" " . $toDate;
744 $pdf->MultiCell($w / 3, 4, $textDate, 0,
'R');
745 $nexY = max($pdf->GetY(), $nexY);
747 $pdf->SetTextColor(0, 0, 0);