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"));
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));
237 if ($this->balanceType ==
"sub") {
238 $pdf->SetSubject($outputlangs->transnoentities(
"AccountBalanceSubAccount"));
240 $pdf->SetSubject($outputlangs->transnoentities(
"AccountancyBalance"));
242 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
243 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
244 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"AccountancyBalance"));
246 $pdf->SetCompression(
false);
250 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
254 if (!empty($tplidx)) {
255 $pdf->useTemplate($tplidx);
259 $pdf->SetFont(
'',
'', $default_font_size - 1);
260 $pdf->MultiCell(0, 3,
'');
261 $pdf->SetTextColor(0, 0, 0);
264 $tab_top_newpage = (
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 10 : $tab_top);
266 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
268 $this->posxdesc = $this->marge_gauche + 1;
271 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
277 $pdf->startTransaction();
278 $pdf->SetFont(
'',
'B', $default_font_size - 1);
279 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
280 $pdf->SetFont(
'',
'', $default_font_size - 1);
281 $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 $groupDebit = $groupCredit = $totalDebit = $totalCredit = 0;
304 for ($i = 0; $i < $nblines; $i++) {
306 $accountingAccount->fetch(0,
$object->lines[$i]->numero_compte,
true);
309 if (empty($accountGroup)) {
310 $accountGroup = $accountingAccount->pcg_type;
314 if ($accountGroup != $accountingAccount->pcg_type) {
320 $langs->transnoentitiesnoconv(
'Total') .
' ' . $langs->transnoentitiesnoconv(
'AccountancyGroup' . $accountGroup),
325 $accountGroup = $accountingAccount->pcg_type;
326 $groupDebit = $groupCredit = 0;
329 $groupDebit +=
$object->lines[$i]->debit;
330 $groupCredit +=
$object->lines[$i]->credit;
331 $totalDebit +=
$object->lines[$i]->debit;
332 $totalCredit +=
$object->lines[$i]->credit;
335 $pdf->SetFont(
'',
'', $default_font_size - 1);
336 $pdf->SetTextColor(0, 0, 0);
338 $pdf->setTopMargin($tab_top_newpage);
339 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
340 $pageposbefore = $pdf->getPage();
342 $showpricebeforepagebreak = 1;
343 $heightforsignature = 0;
347 $pdf->startTransaction();
349 if ($this->balanceType ==
"sub") {
355 $pageposafter = $pdf->getPage();
356 if ($pageposafter > $pageposbefore) {
357 $pdf->rollbackTransaction(
true);
359 $pdf->AddPage(
'',
'',
true);
360 $pdf->setPage($pageposafter);
361 $curY = $tab_top_newpage + $this->tabTitleHeight;
362 if ($this->balanceType ==
"sub") {
368 $pageposafter = $pdf->getPage();
369 $posyafter = $pdf->GetY();
371 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
372 if ($i == ($nblines - 1)) {
373 $pdf->AddPage(
'',
'',
true);
374 if (!empty($tplidx)) {
375 $pdf->useTemplate($tplidx);
378 $pdf->setPage($pageposafter + 1);
384 $showpricebeforepagebreak = 1;
386 $showpricebeforepagebreak = 0;
390 $pdf->commitTransaction();
392 $nexY = max($pdf->GetY(), $nexY);
394 $nexY = $pdf->GetY();
395 $pageposafter = $pdf->getPage();
397 $pdf->setPage($pageposbefore);
398 $pdf->setTopMargin($this->marge_haute);
399 $pdf->setPageOrientation(
'',
true, 0);
402 if ($pageposafter > $pageposbefore) {
403 $pdf->setPage($pageposafter);
404 $curY = $tab_top_newpage + $this->tabTitleHeight;
407 $pdf->SetFont(
'',
'', $default_font_size - 1);
414 if ($this->balanceType ==
'sub' && $this->
getColumnStatus(
'account_number')) {
417 $nexY = max($pdf->GetY(), $nexY);
421 $nexY = max($pdf->GetY(), $nexY);
426 $nexY = max($pdf->GetY(), $nexY);
431 $nexY = max($pdf->GetY(), $nexY);
436 $soldeText =
price(
price2num(abs($solde),
'MT')) . ($solde >= 0 ?
' ' . $langs->trans(
'CreditShort') :
' ' . $langs->trans(
'DebitShort'));
438 $nexY = max($pdf->GetY(), $nexY);
447 'outputlangs' => $outputlangs,
448 'hidedetails' => $hidedetails
450 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
458 while ($pagenb < $pageposafter) {
459 $pdf->setPage($pagenb);
460 if ($pagenb == $pageposbeforeprintlines) {
461 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
463 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
467 $pdf->setPage($pagenb);
468 $pdf->setPageOrientation(
'',
true, 0);
472 if (!empty($tplidx)) {
473 $pdf->useTemplate($tplidx);
476 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
478 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
480 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 0, 1);
485 if (!empty($tplidx)) {
486 $pdf->useTemplate($tplidx);
496 if (!empty($accountingAccount->pcg_type)) {
502 $translationKey =
'AccountancyGroup' . $accountingAccount->pcg_type;
503 $translation = $langs->transnoentitiesnoconv($translationKey);
504 if ($translation !== $translationKey) {
505 $output = $langs->transnoentitiesnoconv(
'Total') .
' ' . $translation;
507 $output = $langs->transnoentitiesnoconv(
'Total') .
' ' . $langs->transnoentitiesnoconv(
'AccountancyGroup') .
' ' . $accountingAccount->pcg_type;
514 $langs->transnoentitiesnoconv(
'Total') .
' ' . $langs->transnoentitiesnoconv(
'AccountancyGroup' . $accountingAccount->pcg_type),
530 $langs->transnoentities(
'GrandTotals'),
539 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
540 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
542 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
543 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
548 if (method_exists($pdf,
'AliasNbPages')) {
549 $pdf->AliasNbPages();
554 $pdf->Output($file, $directDownload ?
'D' :
'F');
557 $hookmanager->initHooks(array(
'pdfgeneration'));
558 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
560 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
561 $this->warnings = $hookmanager->warnings;
563 $this->error = $hookmanager->error;
564 $this->errors = $hookmanager->errors;
571 $this->result = array(
'fullpath' => $file);
642 global
$conf, $langs;
645 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
648 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
655 $pdf->SetTextColor(0, 0, 60);
656 $pdf->SetFont(
'',
'B', $default_font_size + 3);
659 $posy = $this->marge_haute;
660 $posx = $this->marge_gauche;
662 $widthrecbox = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
663 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
665 $posx = $this->page_largeur - $this->marge_droite - $w;
669 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
670 $text = (
string) $this->emetteur->name;
671 $pdf->MultiCell($w / 3, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
672 $nexY = max($pdf->GetY(), $nexY);
675 $pdf->SetFont(
'',
'', $default_font_size - 2);
676 $pdf->SetXY($this->marge_gauche + 2, $nexY);
677 $pdf->SetTextColor(0, 0, 60);
678 $textDateNow = $outputlangs->transnoentities(
"PrintDate");
679 $pdf->MultiCell($w / 3, 3, $textDateNow .
" : " .
date(
'd/m/Y',
dol_now()),
'',
'L');
680 $nexY = max($pdf->GetY(), $nexY);
683 $pdf->SetFont(
'',
'B', $default_font_size + 3);
684 $pdf->SetXY($posx - 2, $posy + 2);
685 $pdf->SetTextColor(0, 0, 120);
686 if ($this->balanceType ==
"sub") {
687 $title = $outputlangs->transnoentities(
"AccountBalanceSubAccount");
689 $title = $outputlangs->transnoentities(
"PdfBalanceTitle");
691 $pdf->MultiCell($w / 3, 3, $title, 0,
'C');
692 $nexY = max($pdf->GetY(), $nexY);
695 $pdf->SetFont(
'',
'B', $default_font_size);
696 $pdf->SetXY(($posx + ($w / 3) * 2) - 2, $posy + 2);
697 $pdf->SetTextColor(0, 0, 60);
701 $textDate = $outputlangs->transnoentities(
"From") .
" " . $fromDate .
" " . $outputlangs->transnoentities(
"To") .
" " . $toDate;
702 $pdf->MultiCell($w / 3, 4, $textDate, 0,
'R');
703 $nexY = max($pdf->GetY(), $nexY);
705 $pdf->SetTextColor(0, 0, 0);