133 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
138 if (!is_object($outputlangs)) {
139 $outputlangs = $langs;
143 $outputlangs->charset_output =
'ISO-8859-1';
147 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings"));
149 if (
$conf->expedition->dir_output) {
154 $dir =
$conf->expedition->dir_output.
"/receipt";
155 $file = $dir.
"/SPECIMEN.pdf";
158 $dir =
$conf->expedition->dir_output.
"/receipt/".$objectref;
159 $file = $dir.
"/".$objectref.
".pdf";
162 if (!file_exists($dir)) {
164 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
169 if (file_exists($dir)) {
171 if (!is_object($hookmanager)) {
172 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
175 $hookmanager->initHooks(array(
'pdfgeneration'));
176 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
178 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
180 $nblines = count(
$object->lines);
184 $realpatharray = array();
185 $this->atleastonephoto =
false;
187 $objphoto =
new Product($this->db);
189 for ($i = 0; $i < $nblines; $i++) {
190 if (empty(
$object->lines[$i]->fk_product)) {
194 $objphoto->fetch(
$object->lines[$i]->fk_product);
198 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
199 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
201 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
202 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
207 foreach ($pdir as $midir) {
209 $dir =
$conf->product->dir_output.
'/'.$midir;
211 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
213 if ($obj[
'photo_vignette']) {
214 $filename = $obj[
'photo_vignette'];
216 $filename = $obj[
'photo'];
219 $filename = $obj[
'photo'];
222 $realpath = $dir.$filename;
224 $this->atleastonephoto =
true;
229 if ($realpath && $arephoto) {
230 $realpatharray[$i] = $realpath;
239 $heightforinfotot = 30;
241 $heightforfooter = $this->marge_basse + 8;
243 $heightforfooter += 6;
245 $pdf->setAutoPageBreak(
true, 0);
247 if (class_exists(
'TCPDF')) {
248 $pdf->setPrintHeader(
false);
249 $pdf->setPrintFooter(
false);
254 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
255 $tplidx = $pdf->importPage(1);
260 $result = $expedition->fetch(
$object->origin_id);
262 $commande =
new Commande($this->db);
263 if ($expedition->origin ==
'commande') {
264 $commande->fetch($expedition->origin_id);
267 $object->commande->loadExpeditions();
272 $pdf->SetDrawColor(128, 128, 128);
274 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
275 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
276 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
277 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
278 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
280 $pdf->SetCompression(
false);
284 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
289 if (!empty($tplidx)) {
290 $pdf->useTemplate($tplidx);
294 $pdf->SetFont(
'',
'', $default_font_size - 1);
295 $pdf->MultiCell(0, 3,
'');
296 $pdf->SetTextColor(0, 0, 0);
299 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
301 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
303 $this->posxdesc = $this->marge_gauche + 1;
306 $height_incoterms = 0;
308 $desc_incoterms =
$object->getIncotermsForPDF();
309 if ($desc_incoterms) {
312 $pdf->SetFont(
'',
'', $default_font_size - 1);
313 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
314 $nexY = $pdf->GetY();
315 $height_incoterms = $nexY - $tab_top;
318 $pdf->SetDrawColor(192, 192, 192);
319 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
321 $tab_top = $nexY + 6;
322 $height_incoterms += 4;
327 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
330 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
331 if (!empty($extranote)) {
335 if (!empty($notetoshow)) {
336 $tab_top = 88 + $height_incoterms;
338 $pdf->SetFont(
'',
'', $default_font_size - 1);
339 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
340 $nexY = $pdf->GetY();
341 $height_note = $nexY - $tab_top;
344 $pdf->SetDrawColor(192, 192, 192);
345 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
347 $tab_height -= $height_note;
348 $tab_top = $nexY + 6;
357 $pdf->startTransaction();
358 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, 0);
359 $pdf->rollbackTransaction(
true);
361 $iniY = $tab_top + $this->tabTitleHeight + 2;
362 $curY = $tab_top + $this->tabTitleHeight + 2;
363 $nexY = $tab_top + $this->tabTitleHeight + 2;
366 for ($i = 0; $i < $nblines; $i++) {
368 if (empty(
$object->lines[$i]->array_options)) {
369 $object->lines[$i]->fetch_optionals();
373 $pdf->SetFont(
'',
'', $default_font_size - 1);
374 $pdf->SetTextColor(0, 0, 0);
377 $imglinesize = array();
378 if (!empty($realpatharray[$i])) {
383 $pdf->setTopMargin($tab_top_newpage);
384 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
385 $pageposbefore = $pdf->getPage();
388 $curX = $this->posxdesc - 1;
390 $showpricebeforepagebreak = 1;
393 $posYAfterDescription = 0;
396 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
397 $pdf->AddPage(
'',
'',
true);
398 if (!empty($tplidx)) {
399 $pdf->useTemplate($tplidx);
402 $pdf->setPage($pageposbefore + 1);
404 $curY = $tab_top_newpage;
408 $showpricebeforepagebreak = 1;
410 $showpricebeforepagebreak = 0;
415 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
416 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
418 $posYAfterImage = $curY + $imglinesize[
'height'];
425 $pdf->startTransaction();
427 $pageposafter = $pdf->getPage();
428 if ($pageposafter > $pageposbefore) {
429 $pdf->rollbackTransaction(
true);
430 $pageposafter = $pageposbefore;
432 $pdf->setPageOrientation(
'',
true, $heightforfooter);
434 $posyafter = $pdf->GetY();
435 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
436 if ($i == ($nblines - 1)) {
437 $pdf->AddPage(
'',
'',
true);
438 if (!empty($tplidx)) {
439 $pdf->useTemplate($tplidx);
444 $pdf->setPage($pageposafter + 1);
450 $showpricebeforepagebreak = 1;
452 $showpricebeforepagebreak = 0;
456 $pdf->commitTransaction();
459 $posYAfterDescription = $pdf->GetY();
462 $nexY = $pdf->GetY();
463 $pageposafter = $pdf->getPage();
464 $pdf->setPage($pageposbefore);
465 $pdf->setTopMargin($this->marge_haute);
466 $pdf->setPageOrientation(
'',
true, 0);
469 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
470 $pdf->setPage($pageposafter);
471 $curY = $tab_top_newpage;
474 $pdf->SetFont(
'',
'', $default_font_size - 1);
480 $nexY = max($pdf->GetY(), $nexY);
485 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
487 $nexY = max($pdf->GetY(), $nexY);
490 $nexY = max($nexY, $posYAfterImage);
493 if (!empty(
$object->lines[$i]->array_options)) {
494 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
498 $nexY = max($pdf->GetY(), $nexY);
505 $pdf->setPage($pageposafter);
506 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
508 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
509 $pdf->SetLineStyle(array(
'dash' => 0));
515 while ($pagenb < $pageposafter) {
516 $pdf->setPage($pagenb);
518 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
520 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
524 $pdf->setPage($pagenb);
525 $pdf->setPageOrientation(
'',
true, 0);
529 if (!empty($tplidx)) {
530 $pdf->useTemplate($tplidx);
533 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
535 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
537 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
542 if (!empty($tplidx)) {
543 $pdf->useTemplate($tplidx);
554 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
555 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
557 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
558 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
567 if (method_exists($pdf,
'AliasNbPages')) {
568 $pdf->AliasNbPages();
573 $pdf->Output($file,
'F');
576 if (!is_object($hookmanager)) {
577 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
580 $hookmanager->initHooks(array(
'pdfgeneration'));
581 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
583 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
584 $this->warnings = $hookmanager->warnings;
586 $this->error = $hookmanager->error;
587 $this->errors = $hookmanager->errors;
594 $this->result = array(
'fullpath' => $file);
598 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
603 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"LIVRAISON_OUTPUTDIR");
711 $pdf->SetTextColor(0, 0, 60);
712 $pdf->SetFont(
'',
'B', $default_font_size + 3);
714 $posy = $this->marge_haute;
715 $posx = $this->page_largeur - $this->marge_droite - 100;
717 $pdf->SetXY($this->marge_gauche, $posy);
720 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
721 if ($this->emetteur->logo) {
722 if (is_readable($logo)) {
724 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
726 $pdf->SetTextColor(200, 0, 0);
727 $pdf->SetFont(
'',
'B', $default_font_size - 2);
728 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
729 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
732 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
735 $pdf->SetFont(
'',
'B', $default_font_size + 2);
736 $pdf->SetXY($posx, $posy);
737 $pdf->SetTextColor(0, 0, 60);
738 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
740 $pdf->SetFont(
'',
'', $default_font_size + 2);
743 $pdf->SetXY($posx, $posy);
744 $pdf->SetTextColor(0, 0, 60);
746 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
748 $pdf->SetTextColor(255, 0, 0);
749 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
750 $pdf->SetTextColor(0, 0, 60);
753 if (
$object->thirdparty->code_client) {
755 $pdf->SetXY($posx, $posy);
756 $pdf->SetTextColor(0, 0, 60);
757 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
760 $pdf->SetTextColor(0, 0, 60);
773 $posx = $this->marge_gauche;
775 $posx = $this->page_largeur - $this->marge_droite - 80;
780 $pdf->SetTextColor(0, 0, 0);
781 $pdf->SetFont(
'',
'', $default_font_size - 2);
782 $pdf->SetXY($posx, $posy - 5);
783 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
784 $pdf->SetXY($posx, $posy);
785 $pdf->SetFillColor(230, 230, 230);
786 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
787 $pdf->SetTextColor(0, 0, 60);
790 $pdf->SetXY($posx + 2, $posy + 3);
791 $pdf->SetFont(
'',
'B', $default_font_size);
792 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
793 $posy = $pdf->getY();
796 $pdf->SetXY($posx + 2, $posy);
797 $pdf->SetFont(
'',
'', $default_font_size - 1);
798 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
804 $posx = $this->marge_gauche;
806 $pdf->SetTextColor(0, 0, 0);
807 $pdf->SetFont(
'',
'', $default_font_size - 2);
808 $pdf->SetXY($posx, $posy - 5);
809 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
813 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
814 if (count($arrayidcontact) > 0) {
816 $result =
$object->fetch_contact($arrayidcontact[0]);
820 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
821 $thirdparty =
$object->contact;
823 $thirdparty =
$object->thirdparty;
832 if ($this->page_largeur < 210) {
836 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
838 $posx = $this->marge_gauche;
842 $pdf->SetTextColor(0, 0, 0);
843 $pdf->SetFont(
'',
'', $default_font_size - 2);
844 $pdf->SetXY($posx + 2, $posy - 5);
846 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
849 $pdf->SetXY($posx + 2, $posy + 3);
850 $pdf->SetFont(
'',
'B', $default_font_size);
851 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
853 $posy = $pdf->getY();
856 $pdf->SetFont(
'',
'', $default_font_size - 1);
857 $pdf->SetXY($posx + 2, $posy);
858 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
861 $pdf->SetTextColor(0, 0, 60);