138 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
143 if (!is_object($outputlangs)) {
144 $outputlangs = $langs;
148 $outputlangs->charset_output =
'ISO-8859-1';
152 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings"));
154 if (
$conf->expedition->dir_output) {
159 $dir =
$conf->expedition->dir_output.
"/receipt";
160 $file = $dir.
"/SPECIMEN.pdf";
163 $dir =
$conf->expedition->dir_output.
"/receipt/".$objectref;
164 $file = $dir.
"/".$objectref.
".pdf";
167 if (!file_exists($dir)) {
169 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
174 if (file_exists($dir)) {
176 if (!is_object($hookmanager)) {
177 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
180 $hookmanager->initHooks(array(
'pdfgeneration'));
181 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
183 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
185 $nblines = count(
$object->lines);
189 $realpatharray = array();
190 $this->atleastonephoto =
false;
192 $objphoto =
new Product($this->db);
194 for ($i = 0; $i < $nblines; $i++) {
195 if (empty(
$object->lines[$i]->fk_product)) {
199 $objphoto->fetch(
$object->lines[$i]->fk_product);
203 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
204 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
206 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
207 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
212 foreach ($pdir as $midir) {
214 $dir =
$conf->product->dir_output.
'/'.$midir;
216 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
218 if ($obj[
'photo_vignette']) {
219 $filename = $obj[
'photo_vignette'];
221 $filename = $obj[
'photo'];
224 $filename = $obj[
'photo'];
227 $realpath = $dir.$filename;
229 $this->atleastonephoto =
true;
234 if ($realpath && $arephoto) {
235 $realpatharray[$i] = $realpath;
244 $heightforinfotot = 30;
246 $heightforfooter = $this->marge_basse + 8;
248 $heightforfooter += 6;
250 $pdf->setAutoPageBreak(
true, 0);
252 if (class_exists(
'TCPDF')) {
253 $pdf->setPrintHeader(
false);
254 $pdf->setPrintFooter(
false);
259 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
260 $tplidx = $pdf->importPage(1);
265 $result = $expedition->fetch(
$object->origin_id);
267 $commande =
new Commande($this->db);
268 if ($expedition->origin ==
'commande') {
269 $commande->fetch($expedition->origin_id);
272 $object->commande->loadExpeditions();
277 $pdf->SetDrawColor(128, 128, 128);
279 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
280 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
281 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
282 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
283 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
285 $pdf->SetCompression(
false);
289 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
294 if (!empty($tplidx)) {
295 $pdf->useTemplate($tplidx);
299 $pdf->SetFont(
'',
'', $default_font_size - 1);
300 $pdf->MultiCell(0, 3,
'');
301 $pdf->SetTextColor(0, 0, 0);
304 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
306 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
308 $this->posxdesc = $this->marge_gauche + 1;
311 $height_incoterms = 0;
313 $desc_incoterms =
$object->getIncotermsForPDF();
314 if ($desc_incoterms) {
317 $pdf->SetFont(
'',
'', $default_font_size - 1);
318 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
319 $nexY = $pdf->GetY();
320 $height_incoterms = $nexY - $tab_top;
323 $pdf->SetDrawColor(192, 192, 192);
324 $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');
326 $tab_top = $nexY + 6;
327 $height_incoterms += 4;
332 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
335 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
336 if (!empty($extranote)) {
340 if (!empty($notetoshow)) {
341 $tab_top = 88 + $height_incoterms;
343 $pdf->SetFont(
'',
'', $default_font_size - 1);
344 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
345 $nexY = $pdf->GetY();
346 $height_note = $nexY - $tab_top;
349 $pdf->SetDrawColor(192, 192, 192);
350 $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');
352 $tab_height -= $height_note;
353 $tab_top = $nexY + 6;
362 $pdf->startTransaction();
363 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, 0);
364 $pdf->rollbackTransaction(
true);
366 $iniY = $tab_top + $this->tabTitleHeight + 2;
367 $curY = $tab_top + $this->tabTitleHeight + 2;
368 $nexY = $tab_top + $this->tabTitleHeight + 2;
371 for ($i = 0; $i < $nblines; $i++) {
373 if (empty(
$object->lines[$i]->array_options)) {
374 $object->lines[$i]->fetch_optionals();
378 $pdf->SetFont(
'',
'', $default_font_size - 1);
379 $pdf->SetTextColor(0, 0, 0);
382 $imglinesize = array();
383 if (!empty($realpatharray[$i])) {
388 $pdf->setTopMargin($tab_top_newpage);
389 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
390 $pageposbefore = $pdf->getPage();
393 $curX = $this->posxdesc - 1;
395 $showpricebeforepagebreak = 1;
398 $posYAfterDescription = 0;
401 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
402 $pdf->AddPage(
'',
'',
true);
403 if (!empty($tplidx)) {
404 $pdf->useTemplate($tplidx);
407 $pdf->setPage($pageposbefore + 1);
409 $curY = $tab_top_newpage;
413 $showpricebeforepagebreak = 1;
415 $showpricebeforepagebreak = 0;
420 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
421 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
423 $posYAfterImage = $curY + $imglinesize[
'height'];
430 $pdf->startTransaction();
432 $pageposafter = $pdf->getPage();
433 if ($pageposafter > $pageposbefore) {
434 $pdf->rollbackTransaction(
true);
435 $pageposafter = $pageposbefore;
437 $pdf->setPageOrientation(
'',
true, $heightforfooter);
439 $posyafter = $pdf->GetY();
440 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
441 if ($i == ($nblines - 1)) {
442 $pdf->AddPage(
'',
'',
true);
443 if (!empty($tplidx)) {
444 $pdf->useTemplate($tplidx);
449 $pdf->setPage($pageposafter + 1);
455 $showpricebeforepagebreak = 1;
457 $showpricebeforepagebreak = 0;
461 $pdf->commitTransaction();
464 $posYAfterDescription = $pdf->GetY();
467 $nexY = $pdf->GetY();
468 $pageposafter = $pdf->getPage();
469 $pdf->setPage($pageposbefore);
470 $pdf->setTopMargin($this->marge_haute);
471 $pdf->setPageOrientation(
'',
true, 0);
474 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
475 $pdf->setPage($pageposafter);
476 $curY = $tab_top_newpage;
479 $pdf->SetFont(
'',
'', $default_font_size - 1);
485 $nexY = max($pdf->GetY(), $nexY);
490 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
492 $nexY = max($pdf->GetY(), $nexY);
495 $nexY = max($nexY, $posYAfterImage);
498 if (!empty(
$object->lines[$i]->array_options)) {
499 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
503 $nexY = max($pdf->GetY(), $nexY);
510 $pdf->setPage($pageposafter);
511 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
513 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
514 $pdf->SetLineStyle(array(
'dash' => 0));
520 while ($pagenb < $pageposafter) {
521 $pdf->setPage($pagenb);
523 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
525 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
529 $pdf->setPage($pagenb);
530 $pdf->setPageOrientation(
'',
true, 0);
534 if (!empty($tplidx)) {
535 $pdf->useTemplate($tplidx);
538 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
540 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
542 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
547 if (!empty($tplidx)) {
548 $pdf->useTemplate($tplidx);
559 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
560 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
562 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
563 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
572 if (method_exists($pdf,
'AliasNbPages')) {
573 $pdf->AliasNbPages();
578 $pdf->Output($file,
'F');
581 if (!is_object($hookmanager)) {
582 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
585 $hookmanager->initHooks(array(
'pdfgeneration'));
586 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
588 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
589 $this->warnings = $hookmanager->warnings;
591 $this->error = $hookmanager->error;
592 $this->errors = $hookmanager->errors;
599 $this->result = array(
'fullpath' => $file);
603 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
608 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"LIVRAISON_OUTPUTDIR");
716 $pdf->SetTextColor(0, 0, 60);
717 $pdf->SetFont(
'',
'B', $default_font_size + 3);
719 $posy = $this->marge_haute;
720 $posx = $this->page_largeur - $this->marge_droite - 100;
722 $pdf->SetXY($this->marge_gauche, $posy);
725 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
726 if ($this->emetteur->logo) {
727 if (is_readable($logo)) {
729 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
731 $pdf->SetTextColor(200, 0, 0);
732 $pdf->SetFont(
'',
'B', $default_font_size - 2);
733 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
734 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
737 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
740 $pdf->SetFont(
'',
'B', $default_font_size + 2);
741 $pdf->SetXY($posx, $posy);
742 $pdf->SetTextColor(0, 0, 60);
743 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
745 $pdf->SetFont(
'',
'', $default_font_size + 2);
748 $pdf->SetXY($posx, $posy);
749 $pdf->SetTextColor(0, 0, 60);
751 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
753 $pdf->SetTextColor(255, 0, 0);
754 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
755 $pdf->SetTextColor(0, 0, 60);
758 if (
$object->thirdparty->code_client) {
760 $pdf->SetXY($posx, $posy);
761 $pdf->SetTextColor(0, 0, 60);
762 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
765 $pdf->SetTextColor(0, 0, 60);
778 $posx = $this->marge_gauche;
780 $posx = $this->page_largeur - $this->marge_droite - 80;
785 $pdf->SetTextColor(0, 0, 0);
786 $pdf->SetFont(
'',
'', $default_font_size - 2);
787 $pdf->SetXY($posx, $posy - 5);
788 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
789 $pdf->SetXY($posx, $posy);
790 $pdf->SetFillColor(230, 230, 230);
791 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
792 $pdf->SetTextColor(0, 0, 60);
795 $pdf->SetXY($posx + 2, $posy + 3);
796 $pdf->SetFont(
'',
'B', $default_font_size);
797 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
798 $posy = $pdf->getY();
801 $pdf->SetXY($posx + 2, $posy);
802 $pdf->SetFont(
'',
'', $default_font_size - 1);
803 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
809 $posx = $this->marge_gauche;
811 $pdf->SetTextColor(0, 0, 0);
812 $pdf->SetFont(
'',
'', $default_font_size - 2);
813 $pdf->SetXY($posx, $posy - 5);
814 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
818 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
819 if (count($arrayidcontact) > 0) {
821 $result =
$object->fetch_contact($arrayidcontact[0]);
825 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
826 $thirdparty =
$object->contact;
828 $thirdparty =
$object->thirdparty;
837 if ($this->page_largeur < 210) {
841 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
843 $posx = $this->marge_gauche;
847 $pdf->SetTextColor(0, 0, 0);
848 $pdf->SetFont(
'',
'', $default_font_size - 2);
849 $pdf->SetXY($posx + 2, $posy - 5);
851 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
854 $pdf->SetXY($posx + 2, $posy + 3);
855 $pdf->SetFont(
'',
'B', $default_font_size);
856 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
858 $posy = $pdf->getY();
861 $pdf->SetFont(
'',
'', $default_font_size - 1);
862 $pdf->SetXY($posx + 2, $posy);
863 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
866 $pdf->SetTextColor(0, 0, 60);