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",
"deliveries",
"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";
182 $date = date(
'YmdHis',
dol_now());
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->getFullName($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'),
329 $langs->trans(
'SubledgerAccount') .
' ' .
length_accounta(
$object->lines[$i]->subledger_account) .
' - ' .
$object->lines[$i]->subledger_label,
333 $account =
$object->lines[$i]->subledger_account;
334 $accountDebit = $accountCredit = 0;
337 if (empty($account) || $account !=
$object->lines[$i]->numero_compte) {
339 $accountingAccount->fetch(0,
$object->lines[$i]->numero_compte,
true);
342 if (!empty($account)) {
348 $langs->trans(
'Total'),
362 $langs->trans(
'AccountAccountingShort') .
' ' .
length_accountg($accountingAccount->ref) .
' - ' . $accountingAccount->label,
366 $account =
$object->lines[$i]->numero_compte;
367 $accountDebit = $accountCredit = 0;
371 $accountDebit +=
$object->lines[$i]->debit;
372 $accountCredit +=
$object->lines[$i]->credit;
373 $totalDebit +=
$object->lines[$i]->debit;
374 $totalCredit +=
$object->lines[$i]->credit;
377 $pdf->SetFont(
'',
'', $default_font_size - 1);
378 $pdf->SetTextColor(0, 0, 0);
380 $pdf->setTopMargin($tab_top_newpage);
381 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
382 $pageposbefore = $pdf->getPage();
384 $showpricebeforepagebreak = 1;
385 $heightforsignature = 0;
389 $pdf->startTransaction();
393 $pageposafter = $pdf->getPage();
394 if ($pageposafter > $pageposbefore) {
395 $pdf->rollbackTransaction(
true);
397 $pdf->AddPage(
'',
'',
true);
398 $pdf->setPage($pageposafter);
399 $curY = $tab_top_newpage + $this->tabTitleHeight;
402 $pageposafter = $pdf->getPage();
403 $posyafter = $pdf->GetY();
405 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
406 if ($i == ($nblines - 1)) {
407 $pdf->AddPage(
'',
'',
true);
408 if (!empty($tplidx)) {
409 $pdf->useTemplate($tplidx);
412 $pdf->setPage($pageposafter + 1);
418 $showpricebeforepagebreak = 1;
420 $showpricebeforepagebreak = 0;
424 $pdf->commitTransaction();
426 $nexY = max($pdf->GetY(), $nexY);
428 $nexY = $pdf->GetY();
429 $pageposafter = $pdf->getPage();
431 $pdf->setPage($pageposbefore);
432 $pdf->setTopMargin($this->marge_haute);
433 $pdf->setPageOrientation(
'',
true, 0);
436 if ($pageposafter > $pageposbefore) {
437 $pdf->setPage($pageposafter);
438 $curY = $tab_top_newpage + $this->tabTitleHeight;
441 $pdf->SetFont(
'',
'', $default_font_size - 1);
450 $nexY = max($pdf->GetY(), $nexY);
455 $nexY = max($pdf->GetY(), $nexY);
460 $nexY = max($pdf->GetY(), $nexY);
465 $nexY = max($pdf->GetY(), $nexY);
470 $nexY = max($pdf->GetY(), $nexY);
475 $nexY = max($pdf->GetY(), $nexY);
480 $soldeText =
price(
price2num(abs($solde),
'MT')) . ($solde >= 0 ?
' C' :
' D');
482 $nexY = max($pdf->GetY(), $nexY);
491 'outputlangs' => $outputlangs,
492 'hidedetails' => $hidedetails
494 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
502 while ($pagenb < $pageposafter) {
503 $pdf->setPage($pagenb);
504 if ($pagenb == $pageposbeforeprintlines) {
505 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
507 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
511 $pdf->setPage($pagenb);
512 $pdf->setPageOrientation(
'',
true, 0);
516 if (!empty($tplidx)) {
517 $pdf->useTemplate($tplidx);
520 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
522 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
524 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
529 if (!empty($tplidx)) {
530 $pdf->useTemplate($tplidx);
550 $langs->trans(
'Total'),
566 $langs->transnoentities(
'GrandTotals'),
576 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
578 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
583 if (method_exists($pdf,
'AliasNbPages')) {
584 $pdf->AliasNbPages();
589 $pdf->Output($file, $directDownload ?
'D' :
'F');
592 $hookmanager->initHooks(array(
'pdfgeneration'));
593 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
595 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
597 $this->error = $hookmanager->error;
598 $this->errors = $hookmanager->errors;
603 $this->result = array(
'fullpath' => $file);
623 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
633 $currency = !empty($currency) ? $currency :
$conf->currency;
637 $pdf->SetTextColor(0, 0, 0);
638 $pdf->SetFont(
'',
'', $default_font_size - 2);
640 if (empty($hidetop)) {
642 $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')));
646 $pdf->SetDrawColor(128, 128, 128);
647 $pdf->SetFont(
'',
'', $default_font_size - 1);
650 $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');
652 $pdf->SetFont(
'',
'B', $default_font_size - 1);
653 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
654 $pdf->SetFont(
'',
'', $default_font_size - 1);
657 if (empty($hidetop)) {
658 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
674 global
$conf, $langs;
677 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
680 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
687 $pdf->SetTextColor(0, 0, 60);
688 $pdf->SetFont(
'',
'B', $default_font_size + 3);
691 $posy = $this->marge_haute;
692 $posx = $this->marge_gauche;
694 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
695 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
697 $posx = $this->page_largeur - $this->marge_droite - $w;
701 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
702 $text = $this->emetteur->name;
703 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
704 $nexY = max($pdf->GetY(), $nexY);
707 $pdf->SetFont(
'',
'', $default_font_size - 2);
708 $pdf->SetXY($this->marge_gauche + 2, $nexY);
709 $pdf->SetTextColor(0, 0, 60);
710 $textDateNow = $outputlangs->transnoentities(
"PrintDate");
711 $pdf->MultiCell($w / 3, 3, $textDateNow .
" : " . date(
'd/m/Y',
dol_now()),
'',
'L');
712 $nexY = max($pdf->GetY(), $nexY);
715 $pdf->SetFont(
'',
'B', $default_font_size + 3);
716 $pdf->SetXY($posx - 2, $posy + 2);
717 $pdf->SetTextColor(0, 0, 120);
718 if ($this->ledgerType ==
"sub") {
719 $title = $outputlangs->transnoentities(
"BookkeepingSubAccount");
721 $title = $outputlangs->transnoentities(
"PdfLedgerTitle");
723 $pdf->MultiCell($w / 3, 3, $title, 0,
'C');
724 $nexY = max($pdf->GetY(), $nexY);
727 $pdf->SetFont(
'',
'B', $default_font_size);
728 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
729 $pdf->SetTextColor(0, 0, 60);
733 $textDate = $outputlangs->transnoentities(
"From") .
" " . $fromDate .
" " . $outputlangs->transnoentities(
"To") .
" " . $toDate;
734 $pdf->MultiCell($w / 3, 4, $textDate, 0,
'R');
735 $nexY = max($pdf->GetY(), $nexY);
737 $pdf->SetTextColor(0, 0, 0);