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",
"deliveries"));
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;
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->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);
586 $this->error = $hookmanager->error;
587 $this->errors = $hookmanager->errors;
592 $this->result = array(
'fullpath' => $file);
596 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
601 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
648 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
650 global
$conf, $mysoc;
661 $pdf->SetTextColor(0, 0, 0);
662 $pdf->SetFont(
'',
'', $default_font_size - 2);
665 $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');
667 if (empty($hidetop)) {
668 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
671 $pdf->SetDrawColor(128, 128, 128);
672 $pdf->SetFont(
'',
'', $default_font_size - 1);
674 if (empty($hidetop)) {
675 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
676 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
680 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
681 if (empty($hidetop)) {
682 $pdf->SetXY($this->posxcomm, $tab_top + 1);
683 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
687 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
688 if (empty($hidetop)) {
689 $pdf->SetXY($this->posxqty, $tab_top + 1);
690 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
694 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
695 if (empty($hidetop)) {
696 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
697 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
713 global
$conf, $langs;
724 $pdf->SetTextColor(0, 0, 60);
725 $pdf->SetFont(
'',
'B', $default_font_size + 3);
727 $posy = $this->marge_haute;
728 $posx = $this->page_largeur - $this->marge_droite - 100;
730 $pdf->SetXY($this->marge_gauche, $posy);
733 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
734 if ($this->emetteur->logo) {
735 if (is_readable($logo)) {
737 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
739 $pdf->SetTextColor(200, 0, 0);
740 $pdf->SetFont(
'',
'B', $default_font_size - 2);
741 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
742 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
745 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
748 $pdf->SetFont(
'',
'B', $default_font_size + 2);
749 $pdf->SetXY($posx, $posy);
750 $pdf->SetTextColor(0, 0, 60);
751 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
753 $pdf->SetFont(
'',
'', $default_font_size + 2);
756 $pdf->SetXY($posx, $posy);
757 $pdf->SetTextColor(0, 0, 60);
759 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
761 $pdf->SetTextColor(255, 0, 0);
762 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
763 $pdf->SetTextColor(0, 0, 60);
766 if (
$object->thirdparty->code_client) {
768 $pdf->SetXY($posx, $posy);
769 $pdf->SetTextColor(0, 0, 60);
770 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
773 $pdf->SetTextColor(0, 0, 60);
786 $posx = $this->marge_gauche;
788 $posx = $this->page_largeur - $this->marge_droite - 80;
793 $pdf->SetTextColor(0, 0, 0);
794 $pdf->SetFont(
'',
'', $default_font_size - 2);
795 $pdf->SetXY($posx, $posy - 5);
796 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
797 $pdf->SetXY($posx, $posy);
798 $pdf->SetFillColor(230, 230, 230);
799 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'D');
800 $pdf->SetTextColor(0, 0, 60);
803 $pdf->SetXY($posx + 2, $posy + 3);
804 $pdf->SetFont(
'',
'B', $default_font_size);
805 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
806 $posy = $pdf->getY();
809 $pdf->SetXY($posx + 2, $posy);
810 $pdf->SetFont(
'',
'', $default_font_size - 1);
811 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
817 $posx = $this->marge_gauche;
819 $pdf->SetTextColor(0, 0, 0);
820 $pdf->SetFont(
'',
'', $default_font_size - 2);
821 $pdf->SetXY($posx, $posy - 5);
822 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
826 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
827 if ($arrayidcontact && count($arrayidcontact) > 0) {
829 $result =
$object->fetch_contact($arrayidcontact[0]);
833 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
834 $thirdparty =
$object->contact;
836 $thirdparty =
$object->thirdparty;
845 if ($this->page_largeur < 210) {
849 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
851 $posx = $this->marge_gauche;
855 $pdf->SetTextColor(0, 0, 0);
856 $pdf->SetFont(
'',
'', $default_font_size - 2);
857 $pdf->SetXY($posx + 2, $posy - 5);
859 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
862 $pdf->SetXY($posx + 2, $posy + 3);
863 $pdf->SetFont(
'',
'B', $default_font_size);
864 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
866 $posy = $pdf->getY();
869 $pdf->SetFont(
'',
'', $default_font_size - 1);
870 $pdf->SetXY($posx + 2, $posy);
871 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
874 $pdf->SetTextColor(0, 0, 60);