125 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
128 global $user, $langs, $conf, $mysoc, $hookmanager;
130 if (!is_object($outputlangs)) {
131 $outputlangs = $langs;
135 $outputlangs->charset_output =
'ISO-8859-1';
139 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
141 if ($conf->expedition->dir_output) {
142 $object->fetch_thirdparty();
145 if ($object->specimen) {
146 $dir = $conf->expedition->dir_output.
"/receipt";
147 $file = $dir.
"/SPECIMEN.pdf";
150 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
151 $file = $dir.
"/".$objectref.
".pdf";
154 if (!file_exists($dir)) {
156 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
161 if (file_exists($dir)) {
163 if (!is_object($hookmanager)) {
164 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
167 $hookmanager->initHooks(array(
'pdfgeneration'));
168 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
170 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
172 $nblines = count($object->lines);
176 $realpatharray = array();
177 $this->atleastonephoto =
false;
179 $objphoto =
new Product($this->db);
181 for ($i = 0; $i < $nblines; $i++) {
182 if (empty($object->lines[$i]->fk_product)) {
186 $objphoto->fetch($object->lines[$i]->fk_product);
189 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
190 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
192 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
193 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
197 foreach ($pdir as $midir) {
199 $dir = $conf->product->dir_output.
'/'.$midir;
201 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
203 if ($obj[
'photo_vignette']) {
204 $filename = $obj[
'photo_vignette'];
206 $filename = $obj[
'photo'];
209 $filename = $obj[
'photo'];
212 $realpath = $dir.$filename;
214 $this->atleastonephoto =
true;
219 if ($realpath && $arephoto) {
220 $realpatharray[$i] = $realpath;
229 $heightforinfotot = 30;
230 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
231 $heightforfooter = $this->marge_basse + 8;
233 $heightforfooter += 6;
235 $pdf->SetAutoPageBreak(1, 0);
237 if (class_exists(
'TCPDF')) {
238 $pdf->setPrintHeader(
false);
239 $pdf->setPrintFooter(
false);
244 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
245 $tplidx = $pdf->importPage(1);
250 $result = $expedition->fetch($object->origin_id);
252 $commande =
new Commande($this->db);
253 if ($expedition->origin ==
'commande') {
254 $commande->fetch($expedition->origin_id);
256 $object->commande = $commande;
257 $object->commande->loadExpeditions();
262 $pdf->SetDrawColor(128, 128, 128);
264 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
265 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
266 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
267 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
268 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
270 $pdf->SetCompression(
false);
273 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
278 if (!empty($tplidx)) {
279 $pdf->useTemplate($tplidx);
282 $this->
_pagehead($pdf, $object, 1, $outputlangs);
283 $pdf->SetFont(
'',
'', $default_font_size - 1);
284 $pdf->MultiCell(0, 3,
'');
285 $pdf->SetTextColor(0, 0, 0);
288 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
290 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
292 $this->posxdesc = $this->marge_gauche + 1;
295 $height_incoterms = 0;
296 if (isModEnabled(
'incoterm')) {
297 $desc_incoterms = $object->getIncotermsForPDF();
298 if ($desc_incoterms) {
301 $pdf->SetFont(
'',
'', $default_font_size - 1);
302 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
303 $nexY = $pdf->GetY();
304 $height_incoterms = $nexY - $tab_top;
307 $pdf->SetDrawColor(192, 192, 192);
308 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
310 $tab_top = $nexY + 6;
311 $height_incoterms += 4;
316 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
319 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
320 if (!empty($extranote)) {
324 if (!empty($notetoshow)) {
325 $tab_top = 88 + $height_incoterms;
327 $pdf->SetFont(
'',
'', $default_font_size - 1);
328 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
329 $nexY = $pdf->GetY();
330 $height_note = $nexY - $tab_top;
333 $pdf->SetDrawColor(192, 192, 192);
334 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
336 $tab_height = $tab_height - $height_note;
337 $tab_top = $nexY + 6;
346 $pdf->startTransaction();
347 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, 0);
348 $pdf->rollbackTransaction(
true);
350 $iniY = $tab_top + $this->tabTitleHeight + 2;
351 $curY = $tab_top + $this->tabTitleHeight + 2;
352 $nexY = $tab_top + $this->tabTitleHeight + 2;
355 for ($i = 0; $i < $nblines; $i++) {
357 if (empty($object->lines[$i]->array_options)) {
358 $object->lines[$i]->fetch_optionals();
362 $pdf->SetFont(
'',
'', $default_font_size - 1);
363 $pdf->SetTextColor(0, 0, 0);
366 $imglinesize = array();
367 if (!empty($realpatharray[$i])) {
372 $pdf->setTopMargin($tab_top_newpage);
373 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
374 $pageposbefore = $pdf->getPage();
377 $curX = $this->posxdesc - 1;
379 $showpricebeforepagebreak = 1;
382 $posYAfterDescription = 0;
385 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
386 $pdf->AddPage(
'',
'',
true);
387 if (!empty($tplidx)) {
388 $pdf->useTemplate($tplidx);
391 $pdf->setPage($pageposbefore + 1);
393 $curY = $tab_top_newpage;
397 $showpricebeforepagebreak = 1;
399 $showpricebeforepagebreak = 0;
404 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
405 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
407 $posYAfterImage = $curY + $imglinesize[
'height'];
414 $pdf->startTransaction();
416 $pageposafter = $pdf->getPage();
417 if ($pageposafter > $pageposbefore) {
418 $pdf->rollbackTransaction(
true);
419 $pageposafter = $pageposbefore;
421 $pdf->setPageOrientation(
'', 1, $heightforfooter);
423 $posyafter = $pdf->GetY();
424 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
425 if ($i == ($nblines - 1)) {
426 $pdf->AddPage(
'',
'',
true);
427 if (!empty($tplidx)) {
428 $pdf->useTemplate($tplidx);
431 $this->
_pagehead($pdf, $object, 0, $outputlangs);
433 $pdf->setPage($pageposafter + 1);
439 $showpricebeforepagebreak = 1;
441 $showpricebeforepagebreak = 0;
445 $pdf->commitTransaction();
448 $posYAfterDescription = $pdf->GetY();
451 $nexY = $pdf->GetY();
452 $pageposafter = $pdf->getPage();
453 $pdf->setPage($pageposbefore);
454 $pdf->setTopMargin($this->marge_haute);
455 $pdf->setPageOrientation(
'', 1, 0);
458 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
459 $pdf->setPage($pageposafter);
460 $curY = $tab_top_newpage;
463 $pdf->SetFont(
'',
'', $default_font_size - 1);
469 $nexY = max($pdf->GetY(), $nexY);
474 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
476 $nexY = max($pdf->GetY(), $nexY);
479 $nexY = max($nexY, $posYAfterImage);
482 if (!empty($object->lines[$i]->array_options)) {
483 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
485 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
487 $nexY = max($pdf->GetY(), $nexY);
494 $pdf->setPage($pageposafter);
495 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
497 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
498 $pdf->SetLineStyle(array(
'dash'=>0));
504 while ($pagenb < $pageposafter) {
505 $pdf->setPage($pagenb);
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);
513 $pdf->setPage($pagenb);
514 $pdf->setPageOrientation(
'', 1, 0);
516 $this->
_pagehead($pdf, $object, 0, $outputlangs);
518 if (!empty($tplidx)) {
519 $pdf->useTemplate($tplidx);
522 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
524 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
526 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
528 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
531 if (!empty($tplidx)) {
532 $pdf->useTemplate($tplidx);
536 $this->
_pagehead($pdf, $object, 0, $outputlangs);
543 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
544 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
546 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
547 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
551 $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
554 $this->
_pagefoot($pdf, $object, $outputlangs);
556 if (method_exists($pdf,
'AliasNbPages')) {
557 $pdf->AliasNbPages();
562 $pdf->Output($file,
'F');
565 if (!is_object($hookmanager)) {
566 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
569 $hookmanager->initHooks(array(
'pdfgeneration'));
570 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
572 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
574 $this->error = $hookmanager->error;
575 $this->errors = $hookmanager->errors;
580 $this->result = array(
'fullpath'=>$file);
584 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
589 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"LIVRAISON_OUTPUTDIR");
684 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
686 global $conf, $langs, $hookmanager;
697 $pdf->SetTextColor(0, 0, 60);
698 $pdf->SetFont(
'',
'B', $default_font_size + 3);
700 $posy = $this->marge_haute;
701 $posx = $this->page_largeur - $this->marge_droite - 100;
703 $pdf->SetXY($this->marge_gauche, $posy);
706 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
707 if ($this->emetteur->logo) {
708 if (is_readable($logo)) {
710 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
712 $pdf->SetTextColor(200, 0, 0);
713 $pdf->SetFont(
'',
'B', $default_font_size - 2);
714 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
715 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
718 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
721 $pdf->SetFont(
'',
'B', $default_font_size + 2);
722 $pdf->SetXY($posx, $posy);
723 $pdf->SetTextColor(0, 0, 60);
724 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
726 $pdf->SetFont(
'',
'', $default_font_size + 2);
729 $pdf->SetXY($posx, $posy);
730 $pdf->SetTextColor(0, 0, 60);
731 if ($object->date_valid) {
732 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
734 $pdf->SetTextColor(255, 0, 0);
735 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
736 $pdf->SetTextColor(0, 0, 60);
739 if ($object->thirdparty->code_client) {
741 $pdf->SetXY($posx, $posy);
742 $pdf->SetTextColor(0, 0, 60);
743 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
746 $pdf->SetTextColor(0, 0, 60);
751 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
755 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
759 $posx = $this->marge_gauche;
761 $posx = $this->page_largeur - $this->marge_droite - 80;
766 $pdf->SetTextColor(0, 0, 0);
767 $pdf->SetFont(
'',
'', $default_font_size - 2);
768 $pdf->SetXY($posx, $posy - 5);
769 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
770 $pdf->SetXY($posx, $posy);
771 $pdf->SetFillColor(230, 230, 230);
772 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
773 $pdf->SetTextColor(0, 0, 60);
776 $pdf->SetXY($posx + 2, $posy + 3);
777 $pdf->SetFont(
'',
'B', $default_font_size);
778 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
779 $posy = $pdf->getY();
782 $pdf->SetXY($posx + 2, $posy);
783 $pdf->SetFont(
'',
'', $default_font_size - 1);
784 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
790 $posx = $this->marge_gauche;
792 $pdf->SetTextColor(0, 0, 0);
793 $pdf->SetFont(
'',
'', $default_font_size - 2);
794 $pdf->SetXY($posx, $posy - 5);
795 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
799 $arrayidcontact = $object->commande->getIdContact(
'external',
'SHIPPING');
800 if (count($arrayidcontact) > 0) {
802 $result = $object->fetch_contact($arrayidcontact[0]);
806 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
807 $thirdparty = $object->contact;
809 $thirdparty = $object->thirdparty;
814 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
818 if ($this->page_largeur < 210) {
822 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
824 $posx = $this->marge_gauche;
828 $pdf->SetTextColor(0, 0, 0);
829 $pdf->SetFont(
'',
'', $default_font_size - 2);
830 $pdf->SetXY($posx + 2, $posy - 5);
832 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
835 $pdf->SetXY($posx + 2, $posy + 3);
836 $pdf->SetFont(
'',
'B', $default_font_size);
837 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
839 $posy = $pdf->getY();
842 $pdf->SetFont(
'',
'', $default_font_size - 1);
843 $pdf->SetXY($posx + 2, $posy);
844 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
847 $pdf->SetTextColor(0, 0, 60);