163 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
166 global $user, $langs, $conf,
$mysoc, $hookmanager;
168 if (!is_object($outputlangs)) {
169 $outputlangs = $langs;
173 $outputlangs->charset_output =
'ISO-8859-1';
177 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings"));
179 if ($conf->expedition->dir_output) {
184 $dir = $conf->expedition->dir_output.
"/receipt";
185 $file = $dir.
"/SPECIMEN.pdf";
188 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
189 $file = $dir.
"/".$objectref.
".pdf";
192 if (!file_exists($dir)) {
194 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
199 if (file_exists($dir)) {
201 if (!is_object($hookmanager)) {
202 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
205 $hookmanager->initHooks(array(
'pdfgeneration'));
206 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
208 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
210 $nblines = count(
$object->lines);
215 $heightforinfotot = 30;
217 $heightforfooter = $this->marge_basse + 8;
219 $heightforfooter += 6;
221 $pdf->setAutoPageBreak(
true, 0);
223 if (class_exists(
'TCPDF')) {
224 $pdf->setPrintHeader(
false);
225 $pdf->setPrintFooter(
false);
230 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
231 $tplidx = $pdf->importPage(1);
236 $result = $expedition->fetch(
$object->origin_id);
238 $commande =
new Commande($this->db);
239 if ($expedition->origin ==
'commande') {
240 $commande->fetch($expedition->origin_id);
243 $object->commande->loadExpeditions();
248 $pdf->SetDrawColor(128, 128, 128);
250 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
251 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
252 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
253 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
254 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
256 $pdf->SetCompression(
false);
260 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
284 if (!empty($tplidx)) {
285 $pdf->useTemplate($tplidx);
289 $pdf->SetFont(
'',
'', $default_font_size - 1);
290 $pdf->MultiCell(0, 3,
'');
291 $pdf->SetTextColor(0, 0, 0);
294 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
296 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
299 $height_incoterms = 0;
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->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
314 $tab_top = $nexY + 6;
315 $height_incoterms += 4;
320 if (!empty(
$object->note_public)) {
321 $tab_top = 88 + $height_incoterms;
323 $pdf->SetFont(
'',
'', $default_font_size - 1);
325 $nexY = $pdf->GetY();
326 $height_note = $nexY - $tab_top;
329 $pdf->SetDrawColor(192, 192, 192);
330 $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');
332 $tab_height -= $height_note;
333 $tab_top = $nexY + 6;
338 $iniY = $tab_top + 11;
339 $curY = $tab_top + 11;
340 $nexY = $tab_top + 11;
343 for ($i = 0; $i < $nblines; $i++) {
345 $pdf->SetFont(
'',
'', $default_font_size - 1);
346 $pdf->SetTextColor(0, 0, 0);
348 $pdf->setTopMargin($tab_top_newpage);
349 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
350 $pageposbefore = $pdf->getPage();
353 $curX = $this->posxdesc - 1;
355 $showpricebeforepagebreak = 1;
357 $pdf->startTransaction();
359 $pageposafter = $pdf->getPage();
360 if ($pageposafter > $pageposbefore) {
361 $pdf->rollbackTransaction(
true);
362 $pageposafter = $pageposbefore;
364 $pdf->setPageOrientation(
'',
true, $heightforfooter);
366 $posyafter = $pdf->GetY();
367 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
368 if ($i == ($nblines - 1)) {
369 $pdf->AddPage(
'',
'',
true);
370 if (!empty($tplidx)) {
371 $pdf->useTemplate($tplidx);
376 $pdf->setPage($pageposafter + 1);
382 $showpricebeforepagebreak = 1;
384 $showpricebeforepagebreak = 0;
388 $pdf->commitTransaction();
391 $nexY = $pdf->GetY();
392 $pageposafter = $pdf->getPage();
393 $pdf->setPage($pageposbefore);
394 $pdf->setTopMargin($this->marge_haute);
395 $pdf->setPageOrientation(
'',
true, 0);
398 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
399 $pdf->setPage($pageposafter);
400 $curY = $tab_top_newpage;
403 $pdf->SetFont(
'',
'', $default_font_size - 1);
416 $pdf->SetXY($this->posxqty, $curY);
417 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, (
string)
$object->lines[$i]->qty_shipped, 0,
'R');
420 $pdf->SetXY($this->posxremainingqty, $curY);
421 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
422 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, (
string) $qtyRemaining, 0,
'R');
445 $pdf->setPage($pageposafter);
446 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
448 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
449 $pdf->SetLineStyle(array(
'dash' => 0));
455 while ($pagenb < $pageposafter) {
456 $pdf->setPage($pagenb);
458 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
460 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
464 $pdf->setPage($pagenb);
465 $pdf->setPageOrientation(
'',
true, 0);
469 if (!empty($tplidx)) {
470 $pdf->useTemplate($tplidx);
473 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
475 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
477 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
482 if (!empty($tplidx)) {
483 $pdf->useTemplate($tplidx);
494 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
495 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
497 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
498 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
507 if (method_exists($pdf,
'AliasNbPages')) {
508 $pdf->AliasNbPages();
574 $pdf->Output($file,
'F');
577 if (!is_object($hookmanager)) {
578 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
581 $hookmanager->initHooks(array(
'pdfgeneration'));
582 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
584 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
585 $this->warnings = $hookmanager->warnings;
587 $this->error = $hookmanager->error;
588 $this->errors = $hookmanager->errors;
595 $this->result = array(
'fullpath' => $file);
599 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
604 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
651 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
664 $pdf->SetTextColor(0, 0, 0);
665 $pdf->SetFont(
'',
'', $default_font_size - 2);
668 $this->
printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
670 if (empty($hidetop)) {
671 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
674 $pdf->SetDrawColor(128, 128, 128);
675 $pdf->SetFont(
'',
'', $default_font_size - 1);
677 if (empty($hidetop)) {
678 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
679 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
683 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
684 if (empty($hidetop)) {
685 $pdf->SetXY($this->posxcomm, $tab_top + 1);
686 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
690 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
691 if (empty($hidetop)) {
692 $pdf->SetXY($this->posxqty, $tab_top + 1);
693 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
697 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
698 if (empty($hidetop)) {
699 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
700 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
716 global $conf, $langs;
727 $pdf->SetTextColor(0, 0, 60);
728 $pdf->SetFont(
'',
'B', $default_font_size + 3);
730 $posy = $this->marge_haute;
731 $posx = $this->page_largeur - $this->marge_droite - 100;
733 $pdf->SetXY($this->marge_gauche, $posy);
736 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
737 if ($this->emetteur->logo) {
738 if (is_readable($logo)) {
740 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
742 $pdf->SetTextColor(200, 0, 0);
743 $pdf->SetFont(
'',
'B', $default_font_size - 2);
744 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
745 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
748 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
751 $pdf->SetFont(
'',
'B', $default_font_size + 2);
752 $pdf->SetXY($posx, $posy);
753 $pdf->SetTextColor(0, 0, 60);
754 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
756 $pdf->SetFont(
'',
'', $default_font_size + 2);
759 $pdf->SetXY($posx, $posy);
760 $pdf->SetTextColor(0, 0, 60);
762 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
764 $pdf->SetTextColor(255, 0, 0);
765 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
766 $pdf->SetTextColor(0, 0, 60);
769 if (
$object->thirdparty->code_client) {
771 $pdf->SetXY($posx, $posy);
772 $pdf->SetTextColor(0, 0, 60);
773 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
776 $pdf->SetTextColor(0, 0, 60);
789 $posx = $this->marge_gauche;
791 $posx = $this->page_largeur - $this->marge_droite - 80;
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(
"BillFrom"), 0,
'L');
800 $pdf->SetXY($posx, $posy);
801 $pdf->SetFillColor(230, 230, 230);
802 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'D');
803 $pdf->SetTextColor(0, 0, 60);
806 $pdf->SetXY($posx + 2, $posy + 3);
807 $pdf->SetFont(
'',
'B', $default_font_size);
808 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
809 $posy = $pdf->getY();
812 $pdf->SetXY($posx + 2, $posy);
813 $pdf->SetFont(
'',
'', $default_font_size - 1);
814 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
820 $posx = $this->marge_gauche;
822 $pdf->SetTextColor(0, 0, 0);
823 $pdf->SetFont(
'',
'', $default_font_size - 2);
824 $pdf->SetXY($posx, $posy - 5);
825 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
829 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
830 if ($arrayidcontact && count($arrayidcontact) > 0) {
832 $result =
$object->fetch_contact($arrayidcontact[0]);
836 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
837 $thirdparty =
$object->contact;
839 $thirdparty =
$object->thirdparty;
848 if ($this->page_largeur < 210) {
852 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
854 $posx = $this->marge_gauche;
858 $pdf->SetTextColor(0, 0, 0);
859 $pdf->SetFont(
'',
'', $default_font_size - 2);
860 $pdf->SetXY($posx + 2, $posy - 5);
862 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
865 $pdf->SetXY($posx + 2, $posy + 3);
866 $pdf->SetFont(
'',
'B', $default_font_size);
867 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
869 $posy = $pdf->getY();
872 $pdf->SetFont(
'',
'', $default_font_size - 1);
873 $pdf->SetXY($posx + 2, $posy);
874 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
877 $pdf->SetTextColor(0, 0, 60);