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);
486 $soldeText =
price(
price2num(abs($solde),
'MT')) . ($solde >= 0 ?
' ' . $langs->trans(
'CreditShort') :
' ' . $langs->trans(
'DebitShort'));
488 $nexY = max($pdf->GetY(), $nexY);
497 'outputlangs' => $outputlangs,
498 'hidedetails' => $hidedetails
500 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
508 while ($pagenb < $pageposafter) {
509 $pdf->setPage($pagenb);
510 if ($pagenb == $pageposbeforeprintlines) {
511 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
513 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
517 $pdf->setPage($pagenb);
518 $pdf->setPageOrientation(
'',
true, 0);
522 if (!empty($tplidx)) {
523 $pdf->useTemplate($tplidx);
526 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
528 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
530 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
535 if (!empty($tplidx)) {
536 $pdf->useTemplate($tplidx);
556 $langs->transnoentities(
'Total'),
572 $langs->transnoentities(
'GrandTotals'),
581 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
583 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
588 if (method_exists($pdf,
'AliasNbPages')) {
589 $pdf->AliasNbPages();
594 $pdf->Output($file, $directDownload ?
'D' :
'F');
597 $hookmanager->initHooks(array(
'pdfgeneration'));
598 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
600 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
601 $this->warnings = $hookmanager->warnings;
603 $this->error = $hookmanager->error;
604 $this->errors = $hookmanager->errors;
611 $this->result = array(
'fullpath' => $file);
631 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
641 $currency = !empty($currency) ? $currency :
$conf->currency;
645 $pdf->SetTextColor(0, 0, 0);
646 $pdf->SetFont(
'',
'', $default_font_size - 2);
648 if (empty($hidetop)) {
650 $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')));
654 $pdf->SetDrawColor(128, 128, 128);
655 $pdf->SetFont(
'',
'', $default_font_size - 1);
658 $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');
660 $pdf->SetFont(
'',
'B', $default_font_size - 1);
661 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
662 $pdf->SetFont(
'',
'', $default_font_size - 1);
665 if (empty($hidetop)) {
666 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
682 global
$conf, $langs;
685 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
688 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
695 $pdf->SetTextColor(0, 0, 60);
696 $pdf->SetFont(
'',
'B', $default_font_size + 3);
699 $posy = $this->marge_haute;
700 $posx = $this->marge_gauche;
702 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
703 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
705 $posx = $this->page_largeur - $this->marge_droite - $w;
709 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
710 $text = (
string) $this->emetteur->name;
711 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset((
string) $text), 0, $ltrdirection);
712 $nexY = max($pdf->GetY(), $nexY);
715 $pdf->SetFont(
'',
'', $default_font_size - 2);
716 $pdf->SetXY($this->marge_gauche + 2, $nexY);
717 $pdf->SetTextColor(0, 0, 60);
718 $textDateNow = $outputlangs->transnoentities(
"PrintDate");
719 $pdf->MultiCell($w / 3, 3, $textDateNow .
" : " .
date(
'd/m/Y',
dol_now()),
'',
'L');
720 $nexY = max($pdf->GetY(), $nexY);
723 $pdf->SetFont(
'',
'B', $default_font_size + 3);
724 $pdf->SetXY($posx - 2, $posy + 2);
725 $pdf->SetTextColor(0, 0, 120);
726 if ($this->ledgerType ==
"sub") {
727 $title = $outputlangs->transnoentities(
"BookkeepingSubAccount");
729 $title = $outputlangs->transnoentities(
"PdfLedgerTitle");
731 $pdf->MultiCell($w / 3, 3, $title, 0,
'C');
732 $nexY = max($pdf->GetY(), $nexY);
735 $pdf->SetFont(
'',
'B', $default_font_size);
736 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
737 $pdf->SetTextColor(0, 0, 60);
741 $textDate = $outputlangs->transnoentities(
"From") .
" " . $fromDate .
" " . $outputlangs->transnoentities(
"To") .
" " . $toDate;
742 $pdf->MultiCell($w / 3, 4, $textDate, 0,
'R');
743 $nexY = max($pdf->GetY(), $nexY);
745 $pdf->SetTextColor(0, 0, 0);