133 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
136 global $user, $langs, $conf, $mysoc, $hookmanager;
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",
"deliveries"));
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/";
206 foreach ($pdir as $midir) {
208 $dir = $conf->product->dir_output.
'/'.$midir;
210 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
212 if ($obj[
'photo_vignette']) {
213 $filename = $obj[
'photo_vignette'];
215 $filename = $obj[
'photo'];
218 $filename = $obj[
'photo'];
221 $realpath = $dir.$filename;
223 $this->atleastonephoto =
true;
228 if ($realpath && $arephoto) {
229 $realpatharray[$i] = $realpath;
238 $heightforinfotot = 30;
240 $heightforfooter = $this->marge_basse + 8;
242 $heightforfooter += 6;
244 $pdf->SetAutoPageBreak(1, 0);
246 if (class_exists(
'TCPDF')) {
247 $pdf->setPrintHeader(
false);
248 $pdf->setPrintFooter(
false);
253 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
254 $tplidx = $pdf->importPage(1);
259 $result = $expedition->fetch(
$object->origin_id);
261 $commande =
new Commande($this->db);
262 if ($expedition->origin ==
'commande') {
263 $commande->fetch($expedition->origin_id);
266 $object->commande->loadExpeditions();
271 $pdf->SetDrawColor(128, 128, 128);
273 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
274 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
275 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
276 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
277 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
279 $pdf->SetCompression(
false);
283 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
288 if (!empty($tplidx)) {
289 $pdf->useTemplate($tplidx);
293 $pdf->SetFont(
'',
'', $default_font_size - 1);
294 $pdf->MultiCell(0, 3,
'');
295 $pdf->SetTextColor(0, 0, 0);
298 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
300 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
302 $this->posxdesc = $this->marge_gauche + 1;
305 $height_incoterms = 0;
306 if (isModEnabled(
'incoterm')) {
307 $desc_incoterms =
$object->getIncotermsForPDF();
308 if ($desc_incoterms) {
311 $pdf->SetFont(
'',
'', $default_font_size - 1);
312 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
313 $nexY = $pdf->GetY();
314 $height_incoterms = $nexY - $tab_top;
317 $pdf->SetDrawColor(192, 192, 192);
318 $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');
320 $tab_top = $nexY + 6;
321 $height_incoterms += 4;
326 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
329 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
330 if (!empty($extranote)) {
334 if (!empty($notetoshow)) {
335 $tab_top = 88 + $height_incoterms;
337 $pdf->SetFont(
'',
'', $default_font_size - 1);
338 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
339 $nexY = $pdf->GetY();
340 $height_note = $nexY - $tab_top;
343 $pdf->SetDrawColor(192, 192, 192);
344 $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');
346 $tab_height -= $height_note;
347 $tab_top = $nexY + 6;
356 $pdf->startTransaction();
357 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, 0);
358 $pdf->rollbackTransaction(
true);
360 $iniY = $tab_top + $this->tabTitleHeight + 2;
361 $curY = $tab_top + $this->tabTitleHeight + 2;
362 $nexY = $tab_top + $this->tabTitleHeight + 2;
365 for ($i = 0; $i < $nblines; $i++) {
367 if (empty(
$object->lines[$i]->array_options)) {
368 $object->lines[$i]->fetch_optionals();
372 $pdf->SetFont(
'',
'', $default_font_size - 1);
373 $pdf->SetTextColor(0, 0, 0);
376 $imglinesize = array();
377 if (!empty($realpatharray[$i])) {
382 $pdf->setTopMargin($tab_top_newpage);
383 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
384 $pageposbefore = $pdf->getPage();
387 $curX = $this->posxdesc - 1;
389 $showpricebeforepagebreak = 1;
392 $posYAfterDescription = 0;
395 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
396 $pdf->AddPage(
'',
'',
true);
397 if (!empty($tplidx)) {
398 $pdf->useTemplate($tplidx);
401 $pdf->setPage($pageposbefore + 1);
403 $curY = $tab_top_newpage;
407 $showpricebeforepagebreak = 1;
409 $showpricebeforepagebreak = 0;
414 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
415 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
417 $posYAfterImage = $curY + $imglinesize[
'height'];
424 $pdf->startTransaction();
426 $pageposafter = $pdf->getPage();
427 if ($pageposafter > $pageposbefore) {
428 $pdf->rollbackTransaction(
true);
429 $pageposafter = $pageposbefore;
431 $pdf->setPageOrientation(
'', 1, $heightforfooter);
433 $posyafter = $pdf->GetY();
434 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
435 if ($i == ($nblines - 1)) {
436 $pdf->AddPage(
'',
'',
true);
437 if (!empty($tplidx)) {
438 $pdf->useTemplate($tplidx);
443 $pdf->setPage($pageposafter + 1);
449 $showpricebeforepagebreak = 1;
451 $showpricebeforepagebreak = 0;
455 $pdf->commitTransaction();
458 $posYAfterDescription = $pdf->GetY();
461 $nexY = $pdf->GetY();
462 $pageposafter = $pdf->getPage();
463 $pdf->setPage($pageposbefore);
464 $pdf->setTopMargin($this->marge_haute);
465 $pdf->setPageOrientation(
'', 1, 0);
468 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
469 $pdf->setPage($pageposafter);
470 $curY = $tab_top_newpage;
473 $pdf->SetFont(
'',
'', $default_font_size - 1);
479 $nexY = max($pdf->GetY(), $nexY);
484 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
486 $nexY = max($pdf->GetY(), $nexY);
489 $nexY = max($nexY, $posYAfterImage);
492 if (!empty(
$object->lines[$i]->array_options)) {
493 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
497 $nexY = max($pdf->GetY(), $nexY);
504 $pdf->setPage($pageposafter);
505 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
507 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
508 $pdf->SetLineStyle(array(
'dash' => 0));
514 while ($pagenb < $pageposafter) {
515 $pdf->setPage($pagenb);
517 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
519 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
523 $pdf->setPage($pagenb);
524 $pdf->setPageOrientation(
'', 1, 0);
528 if (!empty($tplidx)) {
529 $pdf->useTemplate($tplidx);
532 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
534 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
536 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
541 if (!empty($tplidx)) {
542 $pdf->useTemplate($tplidx);
553 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
554 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
556 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
557 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
566 if (method_exists($pdf,
'AliasNbPages')) {
567 $pdf->AliasNbPages();
572 $pdf->Output($file,
'F');
575 if (!is_object($hookmanager)) {
576 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
579 $hookmanager->initHooks(array(
'pdfgeneration'));
580 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
582 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
584 $this->error = $hookmanager->error;
585 $this->errors = $hookmanager->errors;
590 $this->result = array(
'fullpath' => $file);
594 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
599 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"LIVRAISON_OUTPUTDIR");
696 global $conf, $langs;
707 $pdf->SetTextColor(0, 0, 60);
708 $pdf->SetFont(
'',
'B', $default_font_size + 3);
710 $posy = $this->marge_haute;
711 $posx = $this->page_largeur - $this->marge_droite - 100;
713 $pdf->SetXY($this->marge_gauche, $posy);
716 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
717 if ($this->emetteur->logo) {
718 if (is_readable($logo)) {
720 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
722 $pdf->SetTextColor(200, 0, 0);
723 $pdf->SetFont(
'',
'B', $default_font_size - 2);
724 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
725 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
728 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
731 $pdf->SetFont(
'',
'B', $default_font_size + 2);
732 $pdf->SetXY($posx, $posy);
733 $pdf->SetTextColor(0, 0, 60);
734 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
736 $pdf->SetFont(
'',
'', $default_font_size + 2);
739 $pdf->SetXY($posx, $posy);
740 $pdf->SetTextColor(0, 0, 60);
742 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
744 $pdf->SetTextColor(255, 0, 0);
745 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
746 $pdf->SetTextColor(0, 0, 60);
749 if (
$object->thirdparty->code_client) {
751 $pdf->SetXY($posx, $posy);
752 $pdf->SetTextColor(0, 0, 60);
753 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
756 $pdf->SetTextColor(0, 0, 60);
769 $posx = $this->marge_gauche;
771 $posx = $this->page_largeur - $this->marge_droite - 80;
776 $pdf->SetTextColor(0, 0, 0);
777 $pdf->SetFont(
'',
'', $default_font_size - 2);
778 $pdf->SetXY($posx, $posy - 5);
779 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
780 $pdf->SetXY($posx, $posy);
781 $pdf->SetFillColor(230, 230, 230);
782 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
783 $pdf->SetTextColor(0, 0, 60);
786 $pdf->SetXY($posx + 2, $posy + 3);
787 $pdf->SetFont(
'',
'B', $default_font_size);
788 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
789 $posy = $pdf->getY();
792 $pdf->SetXY($posx + 2, $posy);
793 $pdf->SetFont(
'',
'', $default_font_size - 1);
794 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
800 $posx = $this->marge_gauche;
802 $pdf->SetTextColor(0, 0, 0);
803 $pdf->SetFont(
'',
'', $default_font_size - 2);
804 $pdf->SetXY($posx, $posy - 5);
805 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
809 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
810 if (count($arrayidcontact) > 0) {
812 $result =
$object->fetch_contact($arrayidcontact[0]);
816 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
817 $thirdparty =
$object->contact;
819 $thirdparty =
$object->thirdparty;
828 if ($this->page_largeur < 210) {
832 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
834 $posx = $this->marge_gauche;
838 $pdf->SetTextColor(0, 0, 0);
839 $pdf->SetFont(
'',
'', $default_font_size - 2);
840 $pdf->SetXY($posx + 2, $posy - 5);
842 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
845 $pdf->SetXY($posx + 2, $posy + 3);
846 $pdf->SetFont(
'',
'B', $default_font_size);
847 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
849 $posy = $pdf->getY();
852 $pdf->SetFont(
'',
'', $default_font_size - 1);
853 $pdf->SetXY($posx + 2, $posy);
854 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
857 $pdf->SetTextColor(0, 0, 60);