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;
161 $outputlangsbis->loadLangs(array(
"main",
"bills",
"orders",
"products",
"dict",
"companies",
"other",
"propal",
"deliveries",
"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";
177 $date = date(
'YmdHis',
dol_now());
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;
281 $fromYear = date(
'Y', $this->fromDate);
282 $fromMonth = date(
'm', $this->fromDate);
283 $toYear = date(
'Y', $this->toDate);
284 $toMonth = date(
'm', $this->toDate);
285 $nbMonths = (((int) $toYear - (
int) $fromYear) * 12) + ((int) $toMonth - (
int) $fromMonth) + 1;
286 $datePlusOneMonth = strtotime(
"-1 month", $this->fromDate);
288 for ($i = 0; $i < $nbMonths; $i++) {
289 $datePlusOneMonth = strtotime(
"+1 month", $datePlusOneMonth);
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->trans('Total')} {$journal}",
319 "{$langs->trans('Journal')} {$object->lines[$i]->code_journal}",
323 $journal =
$object->lines[$i]->code_journal;
324 $journalDebit = $journalCredit = 0;
327 $journalDebit +=
$object->lines[$i]->debit;
328 $journalCredit +=
$object->lines[$i]->credit;
329 $totalDebit +=
$object->lines[$i]->debit;
330 $totalCredit +=
$object->lines[$i]->credit;
333 $pdf->SetFont(
'',
'', $default_font_size - 1);
334 $pdf->SetTextColor(0, 0, 0);
336 $pdf->setTopMargin($tab_top_newpage);
337 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
338 $pageposbefore = $pdf->getPage();
340 $showpricebeforepagebreak = 1;
341 $heightforsignature = 0;
345 $pdf->startTransaction();
349 $pageposafter = $pdf->getPage();
350 if ($pageposafter > $pageposbefore) {
351 $pdf->rollbackTransaction(
true);
353 $pdf->AddPage(
'',
'',
true);
354 $pdf->setPage($pageposafter);
355 $curY = $tab_top_newpage + $this->tabTitleHeight;
358 $pageposafter = $pdf->getPage();
359 $posyafter = $pdf->GetY();
361 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
362 if ($i == ($nblines - 1)) {
363 $pdf->AddPage(
'',
'',
true);
364 if (!empty($tplidx)) {
365 $pdf->useTemplate($tplidx);
368 $pdf->setPage($pageposafter + 1);
374 $showpricebeforepagebreak = 1;
376 $showpricebeforepagebreak = 0;
380 $pdf->commitTransaction();
382 $nexY = max($pdf->GetY(), $nexY);
384 $nexY = $pdf->GetY();
385 $pageposafter = $pdf->getPage();
387 $pdf->setPage($pageposbefore);
388 $pdf->setTopMargin($this->marge_haute);
389 $pdf->setPageOrientation(
'',
true, 0);
392 if ($pageposafter > $pageposbefore) {
393 $pdf->setPage($pageposafter);
394 $curY = $tab_top_newpage + $this->tabTitleHeight;
397 $pdf->SetFont(
'',
'', $default_font_size - 1);
406 $nexY = max($pdf->GetY(), $nexY);
411 $nexY = max($pdf->GetY(), $nexY);
416 $nexY = max($pdf->GetY(), $nexY);
420 $nexY = max($pdf->GetY(), $nexY);
425 $nexY = max($pdf->GetY(), $nexY);
430 $nexY = max($pdf->GetY(), $nexY);
439 'outputlangs' => $outputlangs,
440 'hidedetails' => $hidedetails
442 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
450 while ($pagenb < $pageposafter) {
451 $pdf->setPage($pagenb);
452 if ($pagenb == $pageposbeforeprintlines) {
453 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
455 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
459 $pdf->setPage($pagenb);
460 $pdf->setPageOrientation(
'',
true, 0);
464 if (!empty($tplidx)) {
465 $pdf->useTemplate($tplidx);
468 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
470 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
472 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
477 if (!empty($tplidx)) {
478 $pdf->useTemplate($tplidx);
488 if (!empty($journal)) {
498 "{$langs->trans('Total')} {$journal}",
514 $langs->transnoentities(
'GrandTotals'),
524 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
526 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
531 if (method_exists($pdf,
'AliasNbPages')) {
532 $pdf->AliasNbPages();
537 $pdf->Output($file, $directDownload ?
'D' :
'F');
540 $hookmanager->initHooks(array(
'pdfgeneration'));
541 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
543 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
545 $this->error = $hookmanager->error;
546 $this->errors = $hookmanager->errors;
551 $this->result = array(
'fullpath' => $file);
571 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
581 $currency = !empty($currency) ? $currency :
$conf->currency;
585 $pdf->SetTextColor(0, 0, 0);
586 $pdf->SetFont(
'',
'', $default_font_size - 2);
588 if (empty($hidetop)) {
590 $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')));
594 $pdf->SetDrawColor(128, 128, 128);
595 $pdf->SetFont(
'',
'', $default_font_size - 1);
598 $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');
600 $pdf->SetFont(
'',
'B', $default_font_size - 1);
601 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
602 $pdf->SetFont(
'',
'', $default_font_size - 1);
605 if (empty($hidetop)) {
606 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
622 global
$conf, $langs;
625 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
628 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
635 $pdf->SetTextColor(0, 0, 60);
636 $pdf->SetFont(
'',
'B', $default_font_size + 3);
639 $posy = $this->marge_haute;
640 $posx = $this->marge_gauche;
642 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
643 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
645 $posx = $this->page_largeur - $this->marge_droite - $w;
649 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
650 $text = $this->emetteur->name;
651 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
652 $nexY = max($pdf->GetY(), $nexY);
655 $pdf->SetFont(
'',
'', $default_font_size - 2);
656 $pdf->SetXY($this->marge_gauche + 2, $nexY);
657 $pdf->SetTextColor(0, 0, 60);
658 $textDateNow = $outputlangs->transnoentities(
"PrintDate");
659 $pdf->MultiCell($w / 3, 3, $textDateNow .
" : " . date(
'd/m/Y',
dol_now()),
'',
'L');
660 $nexY = max($pdf->GetY(), $nexY);
663 $pdf->SetFont(
'',
'B', $default_font_size + 3);
664 $pdf->SetXY($posx - 2, $posy + 2);
665 $pdf->SetTextColor(0, 0, 60);
666 $title = $outputlangs->transnoentities(
"PdfBookkeepingTitle");
667 $pdf->MultiCell($w / 3, 3, $title, 0,
'C');
668 $nexY = max($pdf->GetY(), $nexY);
671 $pdf->SetFont(
'',
'B', $default_font_size);
672 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
673 $pdf->SetTextColor(0, 0, 60);
677 $textDate = $outputlangs->transnoentities(
"From") .
" " . $fromDate .
" " . $outputlangs->transnoentities(
"To") .
" " . $toDate;
678 $pdf->MultiCell($w / 3, 4, $textDate, 0,
'R');
679 $nexY = max($pdf->GetY(), $nexY);
681 $pdf->SetTextColor(0, 0, 0);
713 global
$conf, $hookmanager;
716 $this->defaultContentsFieldsStyle = array(
718 'padding' => array(1, 0.5, 1, 0.5),
722 $this->defaultTitlesFieldsStyle = array(
724 'padding' => array(0.5, 0, 0.5, 0),
728 $this->cols[
'position'] = [
731 'status' => (bool)
getDolGlobalInt(
'PDF_ACCOUNTANCY_LEDGER_ADD_POSITION'),
737 'padding' => [0.5, 0.5, 0.5, 0.5],
741 'padding' => [1, 0.5, 1, 1.5],
746 $this->cols[
'date'] = [
755 'padding' => [0.5, 0.5, 0.5, 0.5],
759 'padding' => [1, 0.5, 1, 1.5],
764 $this->cols[
'piece_num'] = [
769 'textkey' =>
'Piece',
773 'padding' => [0.5, 0.5, 0.5, 0.5],
777 'padding' => [1, 0.5, 1, 1.5],
779 'border-left' =>
true,
783 $this->cols[
'account'] = [
788 'textkey' =>
'Account',
792 'padding' => [0.5, 0.5, 0.5, 0.5],
796 'padding' => [1, 0.5, 1, 1.5],
798 'border-left' =>
true,
802 $this->cols[
'account_label'] = [
807 'textkey' =>
'LabelAccount',
811 'padding' => [0.5, 0.5, 0.5, 0.5],
815 'padding' => [1, 0.5, 1, 1.5],
817 'border-left' =>
true,
821 $this->cols[
'label'] = [
826 'textkey' =>
'Label',
830 'padding' => [0.5, 0.5, 0.5, 0.5],
834 'padding' => [1, 0.5, 1, 1.5],
836 'border-left' =>
true,
840 $this->cols[
'debit'] = [
845 'textkey' =>
'Debit',
849 'padding' => [0.5, 0.5, 0.5, 0.5],
853 'padding' => [1, 0.5, 1, 1.5],
855 'border-left' =>
true,
859 $this->cols[
'credit'] = array(
864 'textkey' =>
'Credit',
868 'padding' => array(0.5, 0.5, 0.5, 0.5),
872 'padding' => array(1, 0.5, 1, 1.5),
874 'border-left' =>
true,
885 'outputlangs' => $outputlangs,
886 'hidedetails' => $hidedetails,
887 'hidedesc' => $hidedesc,
888 'hideref' => $hideref
891 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
894 } elseif (empty($reshook)) {
896 $this->cols = array_replace($this->cols, $hookmanager->resArray);
898 $this->cols = $hookmanager->resArray;