189 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
192 global $user, $langs, $conf, $mysoc, $hookmanager;
194 if (!is_object($outputlangs)) {
195 $outputlangs = $langs;
198 if (!empty($conf->global->MAIN_USE_FPDF)) {
199 $outputlangs->charset_output =
'ISO-8859-1';
203 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
205 if ($conf->expedition->dir_output) {
206 $object->fetch_thirdparty();
209 if ($object->specimen) {
210 $dir = $conf->expedition->dir_output.
"/receipt";
211 $file = $dir.
"/SPECIMEN.pdf";
214 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
215 $file = $dir.
"/".$objectref.
".pdf";
218 if (!file_exists($dir)) {
220 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
225 if (file_exists($dir)) {
227 if (!is_object($hookmanager)) {
228 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
231 $hookmanager->initHooks(array(
'pdfgeneration'));
232 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
234 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
236 $nblines = count($object->lines);
241 $heightforinfotot = 30;
242 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
243 $heightforfooter = $this->marge_basse + 8;
244 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
245 $heightforfooter += 6;
247 $pdf->SetAutoPageBreak(1, 0);
249 if (class_exists(
'TCPDF')) {
250 $pdf->setPrintHeader(
false);
251 $pdf->setPrintFooter(
false);
255 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
256 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
257 $tplidx = $pdf->importPage(1);
262 $result = $expedition->fetch($object->origin_id);
264 $commande =
new Commande($this->db);
265 if ($expedition->origin ==
'commande') {
266 $commande->fetch($expedition->origin_id);
268 $object->commande = $commande;
269 $object->commande->loadExpeditions();
274 $pdf->SetDrawColor(128, 128, 128);
276 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
277 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
278 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
279 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
280 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
282 $pdf->SetCompression(
false);
285 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
309 if (!empty($tplidx)) {
310 $pdf->useTemplate($tplidx);
313 $this->
_pagehead($pdf, $object, 1, $outputlangs);
314 $pdf->SetFont(
'',
'', $default_font_size - 1);
315 $pdf->MultiCell(0, 3,
'');
316 $pdf->SetTextColor(0, 0, 0);
319 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
321 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
324 $height_incoterms = 0;
325 if (isModEnabled(
'incoterm')) {
326 $desc_incoterms = $object->getIncotermsForPDF();
327 if ($desc_incoterms) {
330 $pdf->SetFont(
'',
'', $default_font_size - 1);
331 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
332 $nexY = $pdf->GetY();
333 $height_incoterms = $nexY - $tab_top;
336 $pdf->SetDrawColor(192, 192, 192);
337 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
339 $tab_top = $nexY + 6;
340 $height_incoterms += 4;
345 if (!empty($object->note_public)) {
346 $tab_top = 88 + $height_incoterms;
348 $pdf->SetFont(
'',
'', $default_font_size - 1);
349 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($object->note_public), 0, 1);
350 $nexY = $pdf->GetY();
351 $height_note = $nexY - $tab_top;
354 $pdf->SetDrawColor(192, 192, 192);
355 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
357 $tab_height = $tab_height - $height_note;
358 $tab_top = $nexY + 6;
363 $iniY = $tab_top + 11;
364 $curY = $tab_top + 11;
365 $nexY = $tab_top + 11;
368 for ($i = 0; $i < $nblines; $i++) {
370 $pdf->SetFont(
'',
'', $default_font_size - 1);
371 $pdf->SetTextColor(0, 0, 0);
373 $pdf->setTopMargin($tab_top_newpage);
374 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
375 $pageposbefore = $pdf->getPage();
378 $curX = $this->posxdesc - 1;
380 $showpricebeforepagebreak = 1;
382 $pdf->startTransaction();
383 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
384 $pageposafter = $pdf->getPage();
385 if ($pageposafter > $pageposbefore) {
386 $pdf->rollbackTransaction(
true);
387 $pageposafter = $pageposbefore;
389 $pdf->setPageOrientation(
'', 1, $heightforfooter);
390 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
391 $posyafter = $pdf->GetY();
392 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
393 if ($i == ($nblines - 1)) {
394 $pdf->AddPage(
'',
'',
true);
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
399 $this->
_pagehead($pdf, $object, 0, $outputlangs);
401 $pdf->setPage($pageposafter + 1);
406 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
407 $showpricebeforepagebreak = 1;
409 $showpricebeforepagebreak = 0;
414 $pdf->commitTransaction();
417 $nexY = $pdf->GetY();
418 $pageposafter = $pdf->getPage();
419 $pdf->setPage($pageposbefore);
420 $pdf->setTopMargin($this->marge_haute);
421 $pdf->setPageOrientation(
'', 1, 0);
424 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
425 $pdf->setPage($pageposafter);
426 $curY = $tab_top_newpage;
429 $pdf->SetFont(
'',
'', $default_font_size - 1);
442 $pdf->SetXY($this->posxqty, $curY);
443 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0,
'R');
446 $pdf->SetXY($this->posxremainingqty, $curY);
447 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
448 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0,
'R');
470 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
471 $pdf->setPage($pageposafter);
472 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
474 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
475 $pdf->SetLineStyle(array(
'dash'=>0));
481 while ($pagenb < $pageposafter) {
482 $pdf->setPage($pagenb);
484 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
486 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
488 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
490 $pdf->setPage($pagenb);
491 $pdf->setPageOrientation(
'', 1, 0);
493 $this->
_pagehead($pdf, $object, 0, $outputlangs);
495 if (!empty($tplidx)) {
496 $pdf->useTemplate($tplidx);
499 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
501 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
503 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
505 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
508 if (!empty($tplidx)) {
509 $pdf->useTemplate($tplidx);
513 $this->
_pagehead($pdf, $object, 0, $outputlangs);
520 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
521 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
523 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
524 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
528 $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
531 $this->
_pagefoot($pdf, $object, $outputlangs);
533 if (method_exists($pdf,
'AliasNbPages')) {
534 $pdf->AliasNbPages();
600 $pdf->Output($file,
'F');
603 if (!is_object($hookmanager)) {
604 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
607 $hookmanager->initHooks(array(
'pdfgeneration'));
608 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
610 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
612 $this->error = $hookmanager->error;
613 $this->errors = $hookmanager->errors;
618 $this->result = array(
'fullpath'=>$file);
622 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
627 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
674 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
676 global $conf, $mysoc;
687 $pdf->SetTextColor(0, 0, 0);
688 $pdf->SetFont(
'',
'', $default_font_size - 2);
691 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
693 if (empty($hidetop)) {
694 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
697 $pdf->SetDrawColor(128, 128, 128);
698 $pdf->SetFont(
'',
'', $default_font_size - 1);
700 if (empty($hidetop)) {
701 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
702 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
706 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
707 if (empty($hidetop)) {
708 $pdf->SetXY($this->posxcomm, $tab_top + 1);
709 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
713 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
714 if (empty($hidetop)) {
715 $pdf->SetXY($this->posxqty, $tab_top + 1);
716 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
720 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
721 if (empty($hidetop)) {
722 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
723 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
737 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
739 global $conf, $langs, $hookmanager;
750 $pdf->SetTextColor(0, 0, 60);
751 $pdf->SetFont(
'',
'B', $default_font_size + 3);
753 $posy = $this->marge_haute;
754 $posx = $this->page_largeur - $this->marge_droite - 100;
756 $pdf->SetXY($this->marge_gauche, $posy);
759 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
760 if ($this->emetteur->logo) {
761 if (is_readable($logo)) {
763 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
765 $pdf->SetTextColor(200, 0, 0);
766 $pdf->SetFont(
'',
'B', $default_font_size - 2);
767 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
768 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
771 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
774 $pdf->SetFont(
'',
'B', $default_font_size + 2);
775 $pdf->SetXY($posx, $posy);
776 $pdf->SetTextColor(0, 0, 60);
777 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
779 $pdf->SetFont(
'',
'', $default_font_size + 2);
782 $pdf->SetXY($posx, $posy);
783 $pdf->SetTextColor(0, 0, 60);
784 if ($object->date_valid) {
785 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
787 $pdf->SetTextColor(255, 0, 0);
788 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
789 $pdf->SetTextColor(0, 0, 60);
792 if ($object->thirdparty->code_client) {
794 $pdf->SetXY($posx, $posy);
795 $pdf->SetTextColor(0, 0, 60);
796 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
799 $pdf->SetTextColor(0, 0, 60);
804 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
808 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
812 $posx = $this->marge_gauche;
813 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
814 $posx = $this->page_largeur - $this->marge_droite - 80;
819 $pdf->SetTextColor(0, 0, 0);
820 $pdf->SetFont(
'',
'', $default_font_size - 2);
821 $pdf->SetXY($posx, $posy - 5);
822 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
823 $pdf->SetXY($posx, $posy);
824 $pdf->SetFillColor(230, 230, 230);
825 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
826 $pdf->SetTextColor(0, 0, 60);
829 $pdf->SetXY($posx + 2, $posy + 3);
830 $pdf->SetFont(
'',
'B', $default_font_size);
831 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
832 $posy = $pdf->getY();
835 $pdf->SetXY($posx + 2, $posy);
836 $pdf->SetFont(
'',
'', $default_font_size - 1);
837 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
842 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
843 $posx = $this->marge_gauche;
845 $pdf->SetTextColor(0, 0, 0);
846 $pdf->SetFont(
'',
'', $default_font_size - 2);
847 $pdf->SetXY($posx, $posy - 5);
848 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
852 $arrayidcontact = $object->commande->getIdContact(
'external',
'SHIPPING');
853 if ($arrayidcontact && count($arrayidcontact) > 0) {
855 $result = $object->fetch_contact($arrayidcontact[0]);
859 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)))) {
860 $thirdparty = $object->contact;
862 $thirdparty = $object->thirdparty;
867 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
871 if ($this->page_largeur < 210) {
875 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
876 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
877 $posx = $this->marge_gauche;
881 $pdf->SetTextColor(0, 0, 0);
882 $pdf->SetFont(
'',
'', $default_font_size - 2);
883 $pdf->SetXY($posx + 2, $posy - 5);
885 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
888 $pdf->SetXY($posx + 2, $posy + 3);
889 $pdf->SetFont(
'',
'B', $default_font_size);
890 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
892 $posy = $pdf->getY();
895 $pdf->SetFont(
'',
'', $default_font_size - 1);
896 $pdf->SetXY($posx + 2, $posy);
897 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
900 $pdf->SetTextColor(0, 0, 60);