172 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
175 global $user, $langs, $conf, $mysoc, $hookmanager;
177 if (!is_object($outputlangs)) {
178 $outputlangs = $langs;
181 if (!empty($conf->global->MAIN_USE_FPDF)) {
182 $outputlangs->charset_output =
'ISO-8859-1';
186 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
188 if ($conf->expedition->dir_output) {
189 $object->fetch_thirdparty();
192 if ($object->specimen) {
193 $dir = $conf->expedition->dir_output.
"/receipt";
194 $file = $dir.
"/SPECIMEN.pdf";
197 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
198 $file = $dir.
"/".$objectref.
".pdf";
201 if (!file_exists($dir)) {
203 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
208 if (file_exists($dir)) {
210 if (!is_object($hookmanager)) {
211 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
214 $hookmanager->initHooks(array(
'pdfgeneration'));
215 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
217 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
219 $nblines = count($object->lines);
223 $realpatharray = array();
224 $this->atleastonephoto =
false;
225 if (!empty($conf->global->MAIN_GENERATE_DELIVERY_WITH_PICTURE)) {
226 $objphoto =
new Product($this->db);
228 for ($i = 0; $i < $nblines; $i++) {
229 if (empty($object->lines[$i]->fk_product)) {
233 $objphoto->fetch($object->lines[$i]->fk_product);
236 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
237 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
239 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
240 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
244 foreach ($pdir as $midir) {
246 $dir = $conf->product->dir_output.
'/'.$midir;
248 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
250 if ($obj[
'photo_vignette']) {
251 $filename = $obj[
'photo_vignette'];
253 $filename = $obj[
'photo'];
256 $filename = $obj[
'photo'];
259 $realpath = $dir.$filename;
261 $this->atleastonephoto =
true;
266 if ($realpath && $arephoto) {
267 $realpatharray[$i] = $realpath;
272 if (count($realpatharray) == 0) {
273 $this->posxpicture = $this->posxweightvol;
281 $heightforinfotot = 30;
282 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
283 $heightforfooter = $this->marge_basse + 8;
284 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
285 $heightforfooter += 6;
287 $pdf->SetAutoPageBreak(1, 0);
289 if (class_exists(
'TCPDF')) {
290 $pdf->setPrintHeader(
false);
291 $pdf->setPrintFooter(
false);
295 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
296 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
297 $tplidx = $pdf->importPage(1);
302 $result = $expedition->fetch($object->origin_id);
304 $commande =
new Commande($this->db);
305 if ($expedition->origin ==
'commande') {
306 $commande->fetch($expedition->origin_id);
308 $object->commande = $commande;
309 $object->commande->loadExpeditions();
314 $pdf->SetDrawColor(128, 128, 128);
316 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
317 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
318 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
319 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
320 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
322 $pdf->SetCompression(
false);
325 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
330 if (!empty($tplidx)) {
331 $pdf->useTemplate($tplidx);
334 $this->
_pagehead($pdf, $object, 1, $outputlangs);
335 $pdf->SetFont(
'',
'', $default_font_size - 1);
336 $pdf->MultiCell(0, 3,
'');
337 $pdf->SetTextColor(0, 0, 0);
340 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
342 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
344 $this->posxdesc = $this->marge_gauche + 1;
347 $height_incoterms = 0;
348 if (isModEnabled(
'incoterm')) {
349 $desc_incoterms = $object->getIncotermsForPDF();
350 if ($desc_incoterms) {
353 $pdf->SetFont(
'',
'', $default_font_size - 1);
354 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
355 $nexY = $pdf->GetY();
356 $height_incoterms = $nexY - $tab_top;
359 $pdf->SetDrawColor(192, 192, 192);
360 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
362 $tab_top = $nexY + 6;
363 $height_incoterms += 4;
368 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
371 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
372 if (!empty($extranote)) {
376 if (!empty($notetoshow)) {
377 $tab_top = 88 + $height_incoterms;
379 $pdf->SetFont(
'',
'', $default_font_size - 1);
380 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
381 $nexY = $pdf->GetY();
382 $height_note = $nexY - $tab_top;
385 $pdf->SetDrawColor(192, 192, 192);
386 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
388 $tab_height = $tab_height - $height_note;
389 $tab_top = $nexY + 6;
398 $pdf->startTransaction();
399 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, 0);
400 $pdf->rollbackTransaction(
true);
402 $iniY = $tab_top + $this->tabTitleHeight + 2;
403 $curY = $tab_top + $this->tabTitleHeight + 2;
404 $nexY = $tab_top + $this->tabTitleHeight + 2;
407 for ($i = 0; $i < $nblines; $i++) {
409 if (empty($object->lines[$i]->array_options)) {
410 $object->lines[$i]->fetch_optionals();
414 $pdf->SetFont(
'',
'', $default_font_size - 1);
415 $pdf->SetTextColor(0, 0, 0);
418 $imglinesize = array();
419 if (!empty($realpatharray[$i])) {
424 $pdf->setTopMargin($tab_top_newpage);
425 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
426 $pageposbefore = $pdf->getPage();
429 $curX = $this->posxdesc - 1;
431 $showpricebeforepagebreak = 1;
434 $posYAfterDescription = 0;
437 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
438 $pdf->AddPage(
'',
'',
true);
439 if (!empty($tplidx)) {
440 $pdf->useTemplate($tplidx);
443 $pdf->setPage($pageposbefore + 1);
445 $curY = $tab_top_newpage;
448 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
449 $showpricebeforepagebreak = 1;
451 $showpricebeforepagebreak = 0;
456 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
457 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
459 $posYAfterImage = $curY + $imglinesize[
'height'];
466 $pdf->startTransaction();
468 $pageposafter = $pdf->getPage();
469 if ($pageposafter > $pageposbefore) {
470 $pdf->rollbackTransaction(
true);
471 $pageposafter = $pageposbefore;
473 $pdf->setPageOrientation(
'', 1, $heightforfooter);
475 $posyafter = $pdf->GetY();
476 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
477 if ($i == ($nblines - 1)) {
478 $pdf->AddPage(
'',
'',
true);
479 if (!empty($tplidx)) {
480 $pdf->useTemplate($tplidx);
483 $this->
_pagehead($pdf, $object, 0, $outputlangs);
485 $pdf->setPage($pageposafter + 1);
490 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
491 $showpricebeforepagebreak = 1;
493 $showpricebeforepagebreak = 0;
498 $pdf->commitTransaction();
501 $posYAfterDescription = $pdf->GetY();
504 $nexY = $pdf->GetY();
505 $pageposafter = $pdf->getPage();
506 $pdf->setPage($pageposbefore);
507 $pdf->setTopMargin($this->marge_haute);
508 $pdf->setPageOrientation(
'', 1, 0);
511 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
512 $pdf->setPage($pageposafter);
513 $curY = $tab_top_newpage;
516 $pdf->SetFont(
'',
'', $default_font_size - 1);
522 $nexY = max($pdf->GetY(), $nexY);
527 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
529 $nexY = max($pdf->GetY(), $nexY);
532 $nexY = max($nexY, $posYAfterImage);
535 if (!empty($object->lines[$i]->array_options)) {
536 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
538 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
540 $nexY = max($pdf->GetY(), $nexY);
546 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
547 $pdf->setPage($pageposafter);
548 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
550 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
551 $pdf->SetLineStyle(array(
'dash'=>0));
557 while ($pagenb < $pageposafter) {
558 $pdf->setPage($pagenb);
560 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
562 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
564 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
566 $pdf->setPage($pagenb);
567 $pdf->setPageOrientation(
'', 1, 0);
569 $this->
_pagehead($pdf, $object, 0, $outputlangs);
571 if (!empty($tplidx)) {
572 $pdf->useTemplate($tplidx);
575 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
577 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
579 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
581 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
584 if (!empty($tplidx)) {
585 $pdf->useTemplate($tplidx);
589 $this->
_pagehead($pdf, $object, 0, $outputlangs);
596 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
597 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
599 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
600 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
604 $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
607 $this->
_pagefoot($pdf, $object, $outputlangs);
609 if (method_exists($pdf,
'AliasNbPages')) {
610 $pdf->AliasNbPages();
615 $pdf->Output($file,
'F');
618 if (!is_object($hookmanager)) {
619 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
622 $hookmanager->initHooks(array(
'pdfgeneration'));
623 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
625 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
627 $this->error = $hookmanager->error;
628 $this->errors = $hookmanager->errors;
633 $this->result = array(
'fullpath'=>$file);
637 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
642 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"LIVRAISON_OUTPUTDIR");
738 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
740 global $conf, $langs, $hookmanager;
751 $pdf->SetTextColor(0, 0, 60);
752 $pdf->SetFont(
'',
'B', $default_font_size + 3);
754 $posy = $this->marge_haute;
755 $posx = $this->page_largeur - $this->marge_droite - 100;
757 $pdf->SetXY($this->marge_gauche, $posy);
760 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
761 if ($this->emetteur->logo) {
762 if (is_readable($logo)) {
764 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
766 $pdf->SetTextColor(200, 0, 0);
767 $pdf->SetFont(
'',
'B', $default_font_size - 2);
768 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
769 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
772 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
775 $pdf->SetFont(
'',
'B', $default_font_size + 2);
776 $pdf->SetXY($posx, $posy);
777 $pdf->SetTextColor(0, 0, 60);
778 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
780 $pdf->SetFont(
'',
'', $default_font_size + 2);
783 $pdf->SetXY($posx, $posy);
784 $pdf->SetTextColor(0, 0, 60);
785 if ($object->date_valid) {
786 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
788 $pdf->SetTextColor(255, 0, 0);
789 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
790 $pdf->SetTextColor(0, 0, 60);
793 if ($object->thirdparty->code_client) {
795 $pdf->SetXY($posx, $posy);
796 $pdf->SetTextColor(0, 0, 60);
797 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
800 $pdf->SetTextColor(0, 0, 60);
805 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
809 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
813 $posx = $this->marge_gauche;
814 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
815 $posx = $this->page_largeur - $this->marge_droite - 80;
820 $pdf->SetTextColor(0, 0, 0);
821 $pdf->SetFont(
'',
'', $default_font_size - 2);
822 $pdf->SetXY($posx, $posy - 5);
823 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
824 $pdf->SetXY($posx, $posy);
825 $pdf->SetFillColor(230, 230, 230);
826 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
827 $pdf->SetTextColor(0, 0, 60);
830 $pdf->SetXY($posx + 2, $posy + 3);
831 $pdf->SetFont(
'',
'B', $default_font_size);
832 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
833 $posy = $pdf->getY();
836 $pdf->SetXY($posx + 2, $posy);
837 $pdf->SetFont(
'',
'', $default_font_size - 1);
838 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
843 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
844 $posx = $this->marge_gauche;
846 $pdf->SetTextColor(0, 0, 0);
847 $pdf->SetFont(
'',
'', $default_font_size - 2);
848 $pdf->SetXY($posx, $posy - 5);
849 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
853 $arrayidcontact = $object->commande->getIdContact(
'external',
'SHIPPING');
854 if (count($arrayidcontact) > 0) {
856 $result = $object->fetch_contact($arrayidcontact[0]);
860 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)))) {
861 $thirdparty = $object->contact;
863 $thirdparty = $object->thirdparty;
868 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
872 if ($this->page_largeur < 210) {
876 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
877 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
878 $posx = $this->marge_gauche;
882 $pdf->SetTextColor(0, 0, 0);
883 $pdf->SetFont(
'',
'', $default_font_size - 2);
884 $pdf->SetXY($posx + 2, $posy - 5);
886 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
889 $pdf->SetXY($posx + 2, $posy + 3);
890 $pdf->SetFont(
'',
'B', $default_font_size);
891 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
893 $posy = $pdf->getY();
896 $pdf->SetFont(
'',
'', $default_font_size - 1);
897 $pdf->SetXY($posx + 2, $posy);
898 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
901 $pdf->SetTextColor(0, 0, 60);