146 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
149 global $user, $langs, $conf, $mysoc, $hookmanager;
151 if (!is_object($outputlangs)) {
152 $outputlangs = $langs;
156 $outputlangs->charset_output =
'ISO-8859-1';
160 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
162 if ($conf->expedition->dir_output) {
163 $object->fetch_thirdparty();
166 if ($object->specimen) {
167 $dir = $conf->expedition->dir_output.
"/receipt";
168 $file = $dir.
"/SPECIMEN.pdf";
171 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
172 $file = $dir.
"/".$objectref.
".pdf";
175 if (!file_exists($dir)) {
177 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
182 if (file_exists($dir)) {
184 if (!is_object($hookmanager)) {
185 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
188 $hookmanager->initHooks(array(
'pdfgeneration'));
189 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
191 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
193 $nblines = count($object->lines);
198 $heightforinfotot = 30;
199 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
200 $heightforfooter = $this->marge_basse + 8;
202 $heightforfooter += 6;
204 $pdf->SetAutoPageBreak(1, 0);
206 if (class_exists(
'TCPDF')) {
207 $pdf->setPrintHeader(
false);
208 $pdf->setPrintFooter(
false);
213 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
214 $tplidx = $pdf->importPage(1);
219 $result = $expedition->fetch($object->origin_id);
221 $commande =
new Commande($this->db);
222 if ($expedition->origin ==
'commande') {
223 $commande->fetch($expedition->origin_id);
225 $object->commande = $commande;
226 $object->commande->loadExpeditions();
231 $pdf->SetDrawColor(128, 128, 128);
233 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
234 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
235 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
236 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
237 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
239 $pdf->SetCompression(
false);
242 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
266 if (!empty($tplidx)) {
267 $pdf->useTemplate($tplidx);
270 $this->
_pagehead($pdf, $object, 1, $outputlangs);
271 $pdf->SetFont(
'',
'', $default_font_size - 1);
272 $pdf->MultiCell(0, 3,
'');
273 $pdf->SetTextColor(0, 0, 0);
276 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
278 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
281 $height_incoterms = 0;
282 if (isModEnabled(
'incoterm')) {
283 $desc_incoterms = $object->getIncotermsForPDF();
284 if ($desc_incoterms) {
287 $pdf->SetFont(
'',
'', $default_font_size - 1);
288 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
289 $nexY = $pdf->GetY();
290 $height_incoterms = $nexY - $tab_top;
293 $pdf->SetDrawColor(192, 192, 192);
294 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
296 $tab_top = $nexY + 6;
297 $height_incoterms += 4;
302 if (!empty($object->note_public)) {
303 $tab_top = 88 + $height_incoterms;
305 $pdf->SetFont(
'',
'', $default_font_size - 1);
306 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($object->note_public), 0, 1);
307 $nexY = $pdf->GetY();
308 $height_note = $nexY - $tab_top;
311 $pdf->SetDrawColor(192, 192, 192);
312 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
314 $tab_height = $tab_height - $height_note;
315 $tab_top = $nexY + 6;
320 $iniY = $tab_top + 11;
321 $curY = $tab_top + 11;
322 $nexY = $tab_top + 11;
325 for ($i = 0; $i < $nblines; $i++) {
327 $pdf->SetFont(
'',
'', $default_font_size - 1);
328 $pdf->SetTextColor(0, 0, 0);
330 $pdf->setTopMargin($tab_top_newpage);
331 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
332 $pageposbefore = $pdf->getPage();
335 $curX = $this->posxdesc - 1;
337 $showpricebeforepagebreak = 1;
339 $pdf->startTransaction();
340 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
341 $pageposafter = $pdf->getPage();
342 if ($pageposafter > $pageposbefore) {
343 $pdf->rollbackTransaction(
true);
344 $pageposafter = $pageposbefore;
346 $pdf->setPageOrientation(
'', 1, $heightforfooter);
347 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
348 $posyafter = $pdf->GetY();
349 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
350 if ($i == ($nblines - 1)) {
351 $pdf->AddPage(
'',
'',
true);
352 if (!empty($tplidx)) {
353 $pdf->useTemplate($tplidx);
356 $this->
_pagehead($pdf, $object, 0, $outputlangs);
358 $pdf->setPage($pageposafter + 1);
364 $showpricebeforepagebreak = 1;
366 $showpricebeforepagebreak = 0;
370 $pdf->commitTransaction();
373 $nexY = $pdf->GetY();
374 $pageposafter = $pdf->getPage();
375 $pdf->setPage($pageposbefore);
376 $pdf->setTopMargin($this->marge_haute);
377 $pdf->setPageOrientation(
'', 1, 0);
380 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
381 $pdf->setPage($pageposafter);
382 $curY = $tab_top_newpage;
385 $pdf->SetFont(
'',
'', $default_font_size - 1);
398 $pdf->SetXY($this->posxqty, $curY);
399 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0,
'R');
402 $pdf->SetXY($this->posxremainingqty, $curY);
403 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
404 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0,
'R');
427 $pdf->setPage($pageposafter);
428 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
430 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
431 $pdf->SetLineStyle(array(
'dash'=>0));
437 while ($pagenb < $pageposafter) {
438 $pdf->setPage($pagenb);
440 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
442 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
444 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
446 $pdf->setPage($pagenb);
447 $pdf->setPageOrientation(
'', 1, 0);
449 $this->
_pagehead($pdf, $object, 0, $outputlangs);
451 if (!empty($tplidx)) {
452 $pdf->useTemplate($tplidx);
455 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
457 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
459 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
461 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
464 if (!empty($tplidx)) {
465 $pdf->useTemplate($tplidx);
469 $this->
_pagehead($pdf, $object, 0, $outputlangs);
476 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
477 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
479 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
480 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
484 $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
487 $this->
_pagefoot($pdf, $object, $outputlangs);
489 if (method_exists($pdf,
'AliasNbPages')) {
490 $pdf->AliasNbPages();
556 $pdf->Output($file,
'F');
559 if (!is_object($hookmanager)) {
560 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
563 $hookmanager->initHooks(array(
'pdfgeneration'));
564 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
566 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
568 $this->error = $hookmanager->error;
569 $this->errors = $hookmanager->errors;
574 $this->result = array(
'fullpath'=>$file);
578 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
583 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
630 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
632 global $conf, $mysoc;
643 $pdf->SetTextColor(0, 0, 0);
644 $pdf->SetFont(
'',
'', $default_font_size - 2);
647 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
649 if (empty($hidetop)) {
650 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
653 $pdf->SetDrawColor(128, 128, 128);
654 $pdf->SetFont(
'',
'', $default_font_size - 1);
656 if (empty($hidetop)) {
657 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
658 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
662 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
663 if (empty($hidetop)) {
664 $pdf->SetXY($this->posxcomm, $tab_top + 1);
665 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
669 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
670 if (empty($hidetop)) {
671 $pdf->SetXY($this->posxqty, $tab_top + 1);
672 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
676 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
677 if (empty($hidetop)) {
678 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
679 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
693 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
695 global $conf, $langs, $hookmanager;
706 $pdf->SetTextColor(0, 0, 60);
707 $pdf->SetFont(
'',
'B', $default_font_size + 3);
709 $posy = $this->marge_haute;
710 $posx = $this->page_largeur - $this->marge_droite - 100;
712 $pdf->SetXY($this->marge_gauche, $posy);
715 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
716 if ($this->emetteur->logo) {
717 if (is_readable($logo)) {
719 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
721 $pdf->SetTextColor(200, 0, 0);
722 $pdf->SetFont(
'',
'B', $default_font_size - 2);
723 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
724 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
727 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
730 $pdf->SetFont(
'',
'B', $default_font_size + 2);
731 $pdf->SetXY($posx, $posy);
732 $pdf->SetTextColor(0, 0, 60);
733 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
735 $pdf->SetFont(
'',
'', $default_font_size + 2);
738 $pdf->SetXY($posx, $posy);
739 $pdf->SetTextColor(0, 0, 60);
740 if ($object->date_valid) {
741 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
743 $pdf->SetTextColor(255, 0, 0);
744 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
745 $pdf->SetTextColor(0, 0, 60);
748 if ($object->thirdparty->code_client) {
750 $pdf->SetXY($posx, $posy);
751 $pdf->SetTextColor(0, 0, 60);
752 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
755 $pdf->SetTextColor(0, 0, 60);
760 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
764 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
768 $posx = $this->marge_gauche;
770 $posx = $this->page_largeur - $this->marge_droite - 80;
775 $pdf->SetTextColor(0, 0, 0);
776 $pdf->SetFont(
'',
'', $default_font_size - 2);
777 $pdf->SetXY($posx, $posy - 5);
778 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
779 $pdf->SetXY($posx, $posy);
780 $pdf->SetFillColor(230, 230, 230);
781 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
782 $pdf->SetTextColor(0, 0, 60);
785 $pdf->SetXY($posx + 2, $posy + 3);
786 $pdf->SetFont(
'',
'B', $default_font_size);
787 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
788 $posy = $pdf->getY();
791 $pdf->SetXY($posx + 2, $posy);
792 $pdf->SetFont(
'',
'', $default_font_size - 1);
793 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
799 $posx = $this->marge_gauche;
801 $pdf->SetTextColor(0, 0, 0);
802 $pdf->SetFont(
'',
'', $default_font_size - 2);
803 $pdf->SetXY($posx, $posy - 5);
804 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
808 $arrayidcontact = $object->commande->getIdContact(
'external',
'SHIPPING');
809 if ($arrayidcontact && count($arrayidcontact) > 0) {
811 $result = $object->fetch_contact($arrayidcontact[0]);
815 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
816 $thirdparty = $object->contact;
818 $thirdparty = $object->thirdparty;
823 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
827 if ($this->page_largeur < 210) {
831 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
833 $posx = $this->marge_gauche;
837 $pdf->SetTextColor(0, 0, 0);
838 $pdf->SetFont(
'',
'', $default_font_size - 2);
839 $pdf->SetXY($posx + 2, $posy - 5);
841 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
844 $pdf->SetXY($posx + 2, $posy + 3);
845 $pdf->SetFont(
'',
'B', $default_font_size);
846 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
848 $posy = $pdf->getY();
851 $pdf->SetFont(
'',
'', $default_font_size - 1);
852 $pdf->SetXY($posx + 2, $posy);
853 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
856 $pdf->SetTextColor(0, 0, 60);