127 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
130 global $user, $langs, $conf, $mysoc, $hookmanager;
132 if (!is_object($outputlangs)) {
133 $outputlangs = $langs;
137 $outputlangs->charset_output =
'ISO-8859-1';
141 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
143 if ($conf->expedition->dir_output) {
148 $dir = $conf->expedition->dir_output.
"/receipt";
149 $file = $dir.
"/SPECIMEN.pdf";
152 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
153 $file = $dir.
"/".$objectref.
".pdf";
156 if (!file_exists($dir)) {
158 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
163 if (file_exists($dir)) {
165 if (!is_object($hookmanager)) {
166 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
169 $hookmanager->initHooks(array(
'pdfgeneration'));
170 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
172 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
174 $nblines = count(
$object->lines);
178 $realpatharray = array();
179 $this->atleastonephoto =
false;
181 $objphoto =
new Product($this->db);
183 for ($i = 0; $i < $nblines; $i++) {
184 if (empty(
$object->lines[$i]->fk_product)) {
188 $objphoto->fetch(
$object->lines[$i]->fk_product);
192 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
193 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
195 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
196 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
200 foreach ($pdir as $midir) {
202 $dir = $conf->product->dir_output.
'/'.$midir;
204 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
206 if ($obj[
'photo_vignette']) {
207 $filename = $obj[
'photo_vignette'];
209 $filename = $obj[
'photo'];
212 $filename = $obj[
'photo'];
215 $realpath = $dir.$filename;
217 $this->atleastonephoto =
true;
222 if ($realpath && $arephoto) {
223 $realpatharray[$i] = $realpath;
232 $heightforinfotot = 30;
233 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
234 $heightforfooter = $this->marge_basse + 8;
236 $heightforfooter += 6;
238 $pdf->SetAutoPageBreak(1, 0);
240 if (class_exists(
'TCPDF')) {
241 $pdf->setPrintHeader(
false);
242 $pdf->setPrintFooter(
false);
247 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
248 $tplidx = $pdf->importPage(1);
253 $result = $expedition->fetch(
$object->origin_id);
255 $commande =
new Commande($this->db);
256 if ($expedition->origin ==
'commande') {
257 $commande->fetch($expedition->origin_id);
260 $object->commande->loadExpeditions();
265 $pdf->SetDrawColor(128, 128, 128);
267 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
268 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
269 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
270 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
271 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
273 $pdf->SetCompression(
false);
277 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
282 if (!empty($tplidx)) {
283 $pdf->useTemplate($tplidx);
287 $pdf->SetFont(
'',
'', $default_font_size - 1);
288 $pdf->MultiCell(0, 3,
'');
289 $pdf->SetTextColor(0, 0, 0);
292 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
294 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
296 $this->posxdesc = $this->marge_gauche + 1;
299 $height_incoterms = 0;
300 if (isModEnabled(
'incoterm')) {
301 $desc_incoterms =
$object->getIncotermsForPDF();
302 if ($desc_incoterms) {
305 $pdf->SetFont(
'',
'', $default_font_size - 1);
306 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
307 $nexY = $pdf->GetY();
308 $height_incoterms = $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_incoterms + 1);
314 $tab_top = $nexY + 6;
315 $height_incoterms += 4;
320 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
323 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
324 if (!empty($extranote)) {
328 if (!empty($notetoshow)) {
329 $tab_top = 88 + $height_incoterms;
331 $pdf->SetFont(
'',
'', $default_font_size - 1);
332 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
333 $nexY = $pdf->GetY();
334 $height_note = $nexY - $tab_top;
337 $pdf->SetDrawColor(192, 192, 192);
338 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
340 $tab_height = $tab_height - $height_note;
341 $tab_top = $nexY + 6;
350 $pdf->startTransaction();
351 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, 0);
352 $pdf->rollbackTransaction(
true);
354 $iniY = $tab_top + $this->tabTitleHeight + 2;
355 $curY = $tab_top + $this->tabTitleHeight + 2;
356 $nexY = $tab_top + $this->tabTitleHeight + 2;
359 for ($i = 0; $i < $nblines; $i++) {
361 if (empty(
$object->lines[$i]->array_options)) {
362 $object->lines[$i]->fetch_optionals();
366 $pdf->SetFont(
'',
'', $default_font_size - 1);
367 $pdf->SetTextColor(0, 0, 0);
370 $imglinesize = array();
371 if (!empty($realpatharray[$i])) {
376 $pdf->setTopMargin($tab_top_newpage);
377 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
378 $pageposbefore = $pdf->getPage();
381 $curX = $this->posxdesc - 1;
383 $showpricebeforepagebreak = 1;
386 $posYAfterDescription = 0;
389 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
390 $pdf->AddPage(
'',
'',
true);
391 if (!empty($tplidx)) {
392 $pdf->useTemplate($tplidx);
395 $pdf->setPage($pageposbefore + 1);
397 $curY = $tab_top_newpage;
401 $showpricebeforepagebreak = 1;
403 $showpricebeforepagebreak = 0;
408 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
409 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
411 $posYAfterImage = $curY + $imglinesize[
'height'];
418 $pdf->startTransaction();
420 $pageposafter = $pdf->getPage();
421 if ($pageposafter > $pageposbefore) {
422 $pdf->rollbackTransaction(
true);
423 $pageposafter = $pageposbefore;
425 $pdf->setPageOrientation(
'', 1, $heightforfooter);
427 $posyafter = $pdf->GetY();
428 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
429 if ($i == ($nblines - 1)) {
430 $pdf->AddPage(
'',
'',
true);
431 if (!empty($tplidx)) {
432 $pdf->useTemplate($tplidx);
437 $pdf->setPage($pageposafter + 1);
443 $showpricebeforepagebreak = 1;
445 $showpricebeforepagebreak = 0;
449 $pdf->commitTransaction();
452 $posYAfterDescription = $pdf->GetY();
455 $nexY = $pdf->GetY();
456 $pageposafter = $pdf->getPage();
457 $pdf->setPage($pageposbefore);
458 $pdf->setTopMargin($this->marge_haute);
459 $pdf->setPageOrientation(
'', 1, 0);
462 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
463 $pdf->setPage($pageposafter);
464 $curY = $tab_top_newpage;
467 $pdf->SetFont(
'',
'', $default_font_size - 1);
473 $nexY = max($pdf->GetY(), $nexY);
478 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
480 $nexY = max($pdf->GetY(), $nexY);
483 $nexY = max($nexY, $posYAfterImage);
486 if (!empty(
$object->lines[$i]->array_options)) {
487 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
491 $nexY = max($pdf->GetY(), $nexY);
498 $pdf->setPage($pageposafter);
499 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
501 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
502 $pdf->SetLineStyle(array(
'dash' => 0));
508 while ($pagenb < $pageposafter) {
509 $pdf->setPage($pagenb);
511 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
513 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
517 $pdf->setPage($pagenb);
518 $pdf->setPageOrientation(
'', 1, 0);
522 if (!empty($tplidx)) {
523 $pdf->useTemplate($tplidx);
526 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
528 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
530 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
535 if (!empty($tplidx)) {
536 $pdf->useTemplate($tplidx);
547 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
548 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
550 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
551 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
560 if (method_exists($pdf,
'AliasNbPages')) {
561 $pdf->AliasNbPages();
566 $pdf->Output($file,
'F');
569 if (!is_object($hookmanager)) {
570 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
573 $hookmanager->initHooks(array(
'pdfgeneration'));
574 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
576 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
578 $this->error = $hookmanager->error;
579 $this->errors = $hookmanager->errors;
584 $this->result = array(
'fullpath' => $file);
588 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
593 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"LIVRAISON_OUTPUTDIR");
690 global $conf, $langs;
701 $pdf->SetTextColor(0, 0, 60);
702 $pdf->SetFont(
'',
'B', $default_font_size + 3);
704 $posy = $this->marge_haute;
705 $posx = $this->page_largeur - $this->marge_droite - 100;
707 $pdf->SetXY($this->marge_gauche, $posy);
710 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
711 if ($this->emetteur->logo) {
712 if (is_readable($logo)) {
714 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
716 $pdf->SetTextColor(200, 0, 0);
717 $pdf->SetFont(
'',
'B', $default_font_size - 2);
718 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
719 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
722 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
725 $pdf->SetFont(
'',
'B', $default_font_size + 2);
726 $pdf->SetXY($posx, $posy);
727 $pdf->SetTextColor(0, 0, 60);
728 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
730 $pdf->SetFont(
'',
'', $default_font_size + 2);
733 $pdf->SetXY($posx, $posy);
734 $pdf->SetTextColor(0, 0, 60);
736 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
738 $pdf->SetTextColor(255, 0, 0);
739 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
740 $pdf->SetTextColor(0, 0, 60);
743 if (
$object->thirdparty->code_client) {
745 $pdf->SetXY($posx, $posy);
746 $pdf->SetTextColor(0, 0, 60);
747 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
750 $pdf->SetTextColor(0, 0, 60);
763 $posx = $this->marge_gauche;
765 $posx = $this->page_largeur - $this->marge_droite - 80;
770 $pdf->SetTextColor(0, 0, 0);
771 $pdf->SetFont(
'',
'', $default_font_size - 2);
772 $pdf->SetXY($posx, $posy - 5);
773 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
774 $pdf->SetXY($posx, $posy);
775 $pdf->SetFillColor(230, 230, 230);
776 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
777 $pdf->SetTextColor(0, 0, 60);
780 $pdf->SetXY($posx + 2, $posy + 3);
781 $pdf->SetFont(
'',
'B', $default_font_size);
782 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
783 $posy = $pdf->getY();
786 $pdf->SetXY($posx + 2, $posy);
787 $pdf->SetFont(
'',
'', $default_font_size - 1);
788 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
794 $posx = $this->marge_gauche;
796 $pdf->SetTextColor(0, 0, 0);
797 $pdf->SetFont(
'',
'', $default_font_size - 2);
798 $pdf->SetXY($posx, $posy - 5);
799 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
803 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
804 if (count($arrayidcontact) > 0) {
806 $result =
$object->fetch_contact($arrayidcontact[0]);
810 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
811 $thirdparty =
$object->contact;
813 $thirdparty =
$object->thirdparty;
822 if ($this->page_largeur < 210) {
826 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
828 $posx = $this->marge_gauche;
832 $pdf->SetTextColor(0, 0, 0);
833 $pdf->SetFont(
'',
'', $default_font_size - 2);
834 $pdf->SetXY($posx + 2, $posy - 5);
836 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
839 $pdf->SetXY($posx + 2, $posy + 3);
840 $pdf->SetFont(
'',
'B', $default_font_size);
841 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
843 $posy = $pdf->getY();
846 $pdf->SetFont(
'',
'', $default_font_size - 1);
847 $pdf->SetXY($posx + 2, $posy);
848 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
851 $pdf->SetTextColor(0, 0, 60);