30 require_once DOL_DOCUMENT_ROOT.
'/core/modules/delivery/modules_delivery.php';
31 require_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
59 public $update_main_doc_field;
70 public $phpmin = array(7, 0);
76 public $version =
'dolibarr';
101 public $marge_droite;
126 global $conf, $langs, $mysoc;
129 $langs->loadLangs(array(
"main",
"bills",
"sendings",
"companies"));
132 $this->
name =
"Typhon";
133 $this->
description = $langs->trans(
"DocumentModelTyphon");
134 $this->update_main_doc_field = 1;
139 $this->page_largeur = $formatarray[
'width'];
140 $this->page_hauteur = $formatarray[
'height'];
141 $this->format = array($this->page_largeur, $this->page_hauteur);
147 $this->option_logo = 1;
148 $this->option_tva = 1;
151 $this->emetteur = $mysoc;
152 if (empty($this->emetteur->country_code)) {
153 $this->emetteur->country_code = substr($langs->defaultlang, -2);
157 $this->posxdesc = $this->marge_gauche + 1;
158 $this->posxcomm = 112;
161 $this->posxqty = 165;
162 $this->posxremainingqty = 185;
165 if ($this->page_largeur < 210) {
166 $this->posxcomm -= 20;
169 $this->posxqty -= 20;
174 $this->tva = array();
175 $this->tva_array = array();
176 $this->localtax1 = array();
177 $this->localtax2 = array();
178 $this->atleastoneratenotnull = 0;
179 $this->atleastonediscount = 0;
195 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
198 global $user, $langs, $conf, $mysoc, $hookmanager;
200 if (!is_object($outputlangs)) {
201 $outputlangs = $langs;
204 if (!empty($conf->global->MAIN_USE_FPDF)) {
205 $outputlangs->charset_output =
'ISO-8859-1';
209 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
211 if ($conf->expedition->dir_output) {
212 $object->fetch_thirdparty();
215 if ($object->specimen) {
216 $dir = $conf->expedition->dir_output.
"/receipt";
217 $file = $dir.
"/SPECIMEN.pdf";
220 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
221 $file = $dir.
"/".$objectref.
".pdf";
224 if (!file_exists($dir)) {
226 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
231 if (file_exists($dir)) {
233 if (!is_object($hookmanager)) {
234 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
237 $hookmanager->initHooks(array(
'pdfgeneration'));
238 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
240 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
242 $nblines = count($object->lines);
247 $heightforinfotot = 30;
248 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
249 $heightforfooter = $this->marge_basse + 8;
250 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
251 $heightforfooter += 6;
253 $pdf->SetAutoPageBreak(1, 0);
255 if (class_exists(
'TCPDF')) {
256 $pdf->setPrintHeader(
false);
257 $pdf->setPrintFooter(
false);
261 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
262 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
263 $tplidx = $pdf->importPage(1);
268 $result = $expedition->fetch($object->origin_id);
271 if ($expedition->origin ==
'commande') {
272 $commande->fetch($expedition->origin_id);
274 $object->commande = $commande;
275 $object->commande->loadExpeditions();
280 $pdf->SetDrawColor(128, 128, 128);
282 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
283 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
284 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
285 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
286 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
288 $pdf->SetCompression(
false);
291 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
315 if (!empty($tplidx)) {
316 $pdf->useTemplate($tplidx);
319 $this->
_pagehead($pdf, $object, 1, $outputlangs);
320 $pdf->SetFont(
'',
'', $default_font_size - 1);
321 $pdf->MultiCell(0, 3,
'');
322 $pdf->SetTextColor(0, 0, 0);
325 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
327 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
330 $height_incoterms = 0;
332 $desc_incoterms = $object->getIncotermsForPDF();
333 if ($desc_incoterms) {
336 $pdf->SetFont(
'',
'', $default_font_size - 1);
337 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
338 $nexY = $pdf->GetY();
339 $height_incoterms = $nexY - $tab_top;
342 $pdf->SetDrawColor(192, 192, 192);
343 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
345 $tab_top = $nexY + 6;
346 $height_incoterms += 4;
351 if (!empty($object->note_public)) {
352 $tab_top = 88 + $height_incoterms;
354 $pdf->SetFont(
'',
'', $default_font_size - 1);
355 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($object->note_public), 0, 1);
356 $nexY = $pdf->GetY();
357 $height_note = $nexY - $tab_top;
360 $pdf->SetDrawColor(192, 192, 192);
361 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
363 $tab_height = $tab_height - $height_note;
364 $tab_top = $nexY + 6;
369 $iniY = $tab_top + 11;
370 $curY = $tab_top + 11;
371 $nexY = $tab_top + 11;
374 for ($i = 0; $i < $nblines; $i++) {
376 $pdf->SetFont(
'',
'', $default_font_size - 1);
377 $pdf->SetTextColor(0, 0, 0);
379 $pdf->setTopMargin($tab_top_newpage);
380 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
381 $pageposbefore = $pdf->getPage();
384 $curX = $this->posxdesc - 1;
386 $showpricebeforepagebreak = 1;
388 $pdf->startTransaction();
389 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
390 $pageposafter = $pdf->getPage();
391 if ($pageposafter > $pageposbefore) {
392 $pdf->rollbackTransaction(
true);
393 $pageposafter = $pageposbefore;
395 $pdf->setPageOrientation(
'', 1, $heightforfooter);
396 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
397 $posyafter = $pdf->GetY();
398 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
399 if ($i == ($nblines - 1)) {
400 $pdf->AddPage(
'',
'',
true);
401 if (!empty($tplidx)) {
402 $pdf->useTemplate($tplidx);
405 $this->
_pagehead($pdf, $object, 0, $outputlangs);
407 $pdf->setPage($pageposafter + 1);
412 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
413 $showpricebeforepagebreak = 1;
415 $showpricebeforepagebreak = 0;
420 $pdf->commitTransaction();
423 $nexY = $pdf->GetY();
424 $pageposafter = $pdf->getPage();
425 $pdf->setPage($pageposbefore);
426 $pdf->setTopMargin($this->marge_haute);
427 $pdf->setPageOrientation(
'', 1, 0);
430 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
431 $pdf->setPage($pageposafter);
432 $curY = $tab_top_newpage;
435 $pdf->SetFont(
'',
'', $default_font_size - 1);
448 $pdf->SetXY($this->posxqty, $curY);
449 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0,
'R');
452 $pdf->SetXY($this->posxremainingqty, $curY);
453 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
454 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0,
'R');
476 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
477 $pdf->setPage($pageposafter);
478 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
480 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
481 $pdf->SetLineStyle(array(
'dash'=>0));
487 while ($pagenb < $pageposafter) {
488 $pdf->setPage($pagenb);
490 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
492 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
494 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
496 $pdf->setPage($pagenb);
497 $pdf->setPageOrientation(
'', 1, 0);
499 $this->
_pagehead($pdf, $object, 0, $outputlangs);
501 if (!empty($tplidx)) {
502 $pdf->useTemplate($tplidx);
505 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
507 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
509 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
511 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
514 if (!empty($tplidx)) {
515 $pdf->useTemplate($tplidx);
519 $this->
_pagehead($pdf, $object, 0, $outputlangs);
526 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
527 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
529 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
530 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
534 $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
537 $this->
_pagefoot($pdf, $object, $outputlangs);
539 if (method_exists($pdf,
'AliasNbPages')) {
540 $pdf->AliasNbPages();
606 $pdf->Output($file,
'F');
609 if (!is_object($hookmanager)) {
610 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
613 $hookmanager->initHooks(array(
'pdfgeneration'));
614 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
616 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
618 $this->error = $hookmanager->error;
619 $this->errors = $hookmanager->errors;
624 $this->result = array(
'fullpath'=>$file);
628 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
633 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
651 global $conf, $mysoc;
654 $pdf->SetFont(
'',
'', $default_font_size);
655 $pdf->SetXY($this->marge_gauche, $posy);
657 $larg_sign = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 3;
658 $pdf->Rect($this->marge_gauche, $posy + 1, $larg_sign, 25);
659 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
660 $pdf->MultiCell($larg_sign, 2, $outputlangs->trans(
"For").
' '.$outputlangs->convToOutputCharset($mysoc->name).
":",
'',
'L');
662 $pdf->Rect(2 * $larg_sign + $this->marge_gauche, $posy + 1, $larg_sign, 25);
663 $pdf->SetXY(2 * $larg_sign + $this->marge_gauche + 2, $posy + 2);
664 $pdf->MultiCell($larg_sign, 2, $outputlangs->trans(
"ForCustomer").
':',
'',
'L');
680 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
682 global $conf, $mysoc;
693 $pdf->SetTextColor(0, 0, 0);
694 $pdf->SetFont(
'',
'', $default_font_size - 2);
697 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
699 if (empty($hidetop)) {
700 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
703 $pdf->SetDrawColor(128, 128, 128);
704 $pdf->SetFont(
'',
'', $default_font_size - 1);
706 if (empty($hidetop)) {
707 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
708 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
712 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
713 if (empty($hidetop)) {
714 $pdf->SetXY($this->posxcomm, $tab_top + 1);
715 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
719 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
720 if (empty($hidetop)) {
721 $pdf->SetXY($this->posxqty, $tab_top + 1);
722 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
726 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
727 if (empty($hidetop)) {
728 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
729 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
743 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
745 global $conf, $langs, $hookmanager;
756 $pdf->SetTextColor(0, 0, 60);
757 $pdf->SetFont(
'',
'B', $default_font_size + 3);
759 $posy = $this->marge_haute;
760 $posx = $this->page_largeur - $this->marge_droite - 100;
762 $pdf->SetXY($this->marge_gauche, $posy);
765 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
766 if ($this->emetteur->logo) {
767 if (is_readable($logo)) {
769 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
771 $pdf->SetTextColor(200, 0, 0);
772 $pdf->SetFont(
'',
'B', $default_font_size - 2);
773 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
774 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
777 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
780 $pdf->SetFont(
'',
'B', $default_font_size + 2);
781 $pdf->SetXY($posx, $posy);
782 $pdf->SetTextColor(0, 0, 60);
783 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
785 $pdf->SetFont(
'',
'', $default_font_size + 2);
788 $pdf->SetXY($posx, $posy);
789 $pdf->SetTextColor(0, 0, 60);
790 if ($object->date_valid) {
791 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
793 $pdf->SetTextColor(255, 0, 0);
794 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
795 $pdf->SetTextColor(0, 0, 60);
798 if ($object->thirdparty->code_client) {
800 $pdf->SetXY($posx, $posy);
801 $pdf->SetTextColor(0, 0, 60);
802 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
805 $pdf->SetTextColor(0, 0, 60);
810 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
814 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
818 $posx = $this->marge_gauche;
819 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
820 $posx = $this->page_largeur - $this->marge_droite - 80;
825 $pdf->SetTextColor(0, 0, 0);
826 $pdf->SetFont(
'',
'', $default_font_size - 2);
827 $pdf->SetXY($posx, $posy - 5);
828 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
829 $pdf->SetXY($posx, $posy);
830 $pdf->SetFillColor(230, 230, 230);
831 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
832 $pdf->SetTextColor(0, 0, 60);
835 $pdf->SetXY($posx + 2, $posy + 3);
836 $pdf->SetFont(
'',
'B', $default_font_size);
837 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
838 $posy = $pdf->getY();
841 $pdf->SetXY($posx + 2, $posy);
842 $pdf->SetFont(
'',
'', $default_font_size - 1);
843 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
848 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
849 $posx = $this->marge_gauche;
851 $pdf->SetTextColor(0, 0, 0);
852 $pdf->SetFont(
'',
'', $default_font_size - 2);
853 $pdf->SetXY($posx, $posy - 5);
854 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
858 $arrayidcontact = $object->commande->getIdContact(
'external',
'SHIPPING');
859 if ($arrayidcontact && count($arrayidcontact) > 0) {
861 $result = $object->fetch_contact($arrayidcontact[0]);
865 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
866 $thirdparty = $object->contact;
868 $thirdparty = $object->thirdparty;
873 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
877 if ($this->page_largeur < 210) {
881 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
882 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
883 $posx = $this->marge_gauche;
887 $pdf->SetTextColor(0, 0, 0);
888 $pdf->SetFont(
'',
'', $default_font_size - 2);
889 $pdf->SetXY($posx + 2, $posy - 5);
891 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
894 $pdf->SetXY($posx + 2, $posy + 3);
895 $pdf->SetFont(
'',
'B', $default_font_size);
896 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
898 $posy = $pdf->getY();
901 $pdf->SetFont(
'',
'', $default_font_size - 1);
902 $pdf->SetXY($posx + 2, $posy);
903 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
906 $pdf->SetTextColor(0, 0, 60);
919 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
921 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
922 return pdf_pagefoot($pdf, $outputlangs,
'DELIVERY_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);