154 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
157 global $user, $langs, $conf, $mysoc, $hookmanager;
159 if (!is_object($outputlangs)) {
160 $outputlangs = $langs;
164 $outputlangs->charset_output =
'ISO-8859-1';
168 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
170 if ($conf->expedition->dir_output) {
175 $dir = $conf->expedition->dir_output.
"/receipt";
176 $file = $dir.
"/SPECIMEN.pdf";
179 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
180 $file = $dir.
"/".$objectref.
".pdf";
183 if (!file_exists($dir)) {
185 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
190 if (file_exists($dir)) {
192 if (!is_object($hookmanager)) {
193 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
196 $hookmanager->initHooks(array(
'pdfgeneration'));
197 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
199 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
201 $nblines = count(
$object->lines);
206 $heightforinfotot = 30;
208 $heightforfooter = $this->marge_basse + 8;
210 $heightforfooter += 6;
212 $pdf->SetAutoPageBreak(1, 0);
214 if (class_exists(
'TCPDF')) {
215 $pdf->setPrintHeader(
false);
216 $pdf->setPrintFooter(
false);
221 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
222 $tplidx = $pdf->importPage(1);
227 $result = $expedition->fetch(
$object->origin_id);
229 $commande =
new Commande($this->db);
230 if ($expedition->origin ==
'commande') {
231 $commande->fetch($expedition->origin_id);
234 $object->commande->loadExpeditions();
239 $pdf->SetDrawColor(128, 128, 128);
241 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
242 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
243 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
244 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
245 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
247 $pdf->SetCompression(
false);
251 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
275 if (!empty($tplidx)) {
276 $pdf->useTemplate($tplidx);
280 $pdf->SetFont(
'',
'', $default_font_size - 1);
281 $pdf->MultiCell(0, 3,
'');
282 $pdf->SetTextColor(0, 0, 0);
285 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
287 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
290 $height_incoterms = 0;
291 if (isModEnabled(
'incoterm')) {
292 $desc_incoterms =
$object->getIncotermsForPDF();
293 if ($desc_incoterms) {
296 $pdf->SetFont(
'',
'', $default_font_size - 1);
297 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
298 $nexY = $pdf->GetY();
299 $height_incoterms = $nexY - $tab_top;
302 $pdf->SetDrawColor(192, 192, 192);
303 $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');
305 $tab_top = $nexY + 6;
306 $height_incoterms += 4;
311 if (!empty(
$object->note_public)) {
312 $tab_top = 88 + $height_incoterms;
314 $pdf->SetFont(
'',
'', $default_font_size - 1);
316 $nexY = $pdf->GetY();
317 $height_note = $nexY - $tab_top;
320 $pdf->SetDrawColor(192, 192, 192);
321 $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');
323 $tab_height -= $height_note;
324 $tab_top = $nexY + 6;
329 $iniY = $tab_top + 11;
330 $curY = $tab_top + 11;
331 $nexY = $tab_top + 11;
334 for ($i = 0; $i < $nblines; $i++) {
336 $pdf->SetFont(
'',
'', $default_font_size - 1);
337 $pdf->SetTextColor(0, 0, 0);
339 $pdf->setTopMargin($tab_top_newpage);
340 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
341 $pageposbefore = $pdf->getPage();
344 $curX = $this->posxdesc - 1;
346 $showpricebeforepagebreak = 1;
348 $pdf->startTransaction();
350 $pageposafter = $pdf->getPage();
351 if ($pageposafter > $pageposbefore) {
352 $pdf->rollbackTransaction(
true);
353 $pageposafter = $pageposbefore;
355 $pdf->setPageOrientation(
'', 1, $heightforfooter);
357 $posyafter = $pdf->GetY();
358 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
359 if ($i == ($nblines - 1)) {
360 $pdf->AddPage(
'',
'',
true);
361 if (!empty($tplidx)) {
362 $pdf->useTemplate($tplidx);
367 $pdf->setPage($pageposafter + 1);
373 $showpricebeforepagebreak = 1;
375 $showpricebeforepagebreak = 0;
379 $pdf->commitTransaction();
382 $nexY = $pdf->GetY();
383 $pageposafter = $pdf->getPage();
384 $pdf->setPage($pageposbefore);
385 $pdf->setTopMargin($this->marge_haute);
386 $pdf->setPageOrientation(
'', 1, 0);
389 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
390 $pdf->setPage($pageposafter);
391 $curY = $tab_top_newpage;
394 $pdf->SetFont(
'',
'', $default_font_size - 1);
407 $pdf->SetXY($this->posxqty, $curY);
408 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3,
$object->lines[$i]->qty_shipped, 0,
'R');
411 $pdf->SetXY($this->posxremainingqty, $curY);
412 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
413 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0,
'R');
436 $pdf->setPage($pageposafter);
437 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
439 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
440 $pdf->SetLineStyle(array(
'dash' => 0));
446 while ($pagenb < $pageposafter) {
447 $pdf->setPage($pagenb);
449 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
451 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
455 $pdf->setPage($pagenb);
456 $pdf->setPageOrientation(
'', 1, 0);
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
464 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
466 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
468 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
473 if (!empty($tplidx)) {
474 $pdf->useTemplate($tplidx);
485 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
486 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
488 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
489 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
498 if (method_exists($pdf,
'AliasNbPages')) {
499 $pdf->AliasNbPages();
565 $pdf->Output($file,
'F');
568 if (!is_object($hookmanager)) {
569 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
572 $hookmanager->initHooks(array(
'pdfgeneration'));
573 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
575 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
577 $this->error = $hookmanager->error;
578 $this->errors = $hookmanager->errors;
583 $this->result = array(
'fullpath' => $file);
587 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
592 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
639 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
641 global $conf, $mysoc;
652 $pdf->SetTextColor(0, 0, 0);
653 $pdf->SetFont(
'',
'', $default_font_size - 2);
656 $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');
658 if (empty($hidetop)) {
659 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
662 $pdf->SetDrawColor(128, 128, 128);
663 $pdf->SetFont(
'',
'', $default_font_size - 1);
665 if (empty($hidetop)) {
666 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
667 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
671 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
672 if (empty($hidetop)) {
673 $pdf->SetXY($this->posxcomm, $tab_top + 1);
674 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
678 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
679 if (empty($hidetop)) {
680 $pdf->SetXY($this->posxqty, $tab_top + 1);
681 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
685 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
686 if (empty($hidetop)) {
687 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
688 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
704 global $conf, $langs;
715 $pdf->SetTextColor(0, 0, 60);
716 $pdf->SetFont(
'',
'B', $default_font_size + 3);
718 $posy = $this->marge_haute;
719 $posx = $this->page_largeur - $this->marge_droite - 100;
721 $pdf->SetXY($this->marge_gauche, $posy);
724 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
725 if ($this->emetteur->logo) {
726 if (is_readable($logo)) {
728 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
730 $pdf->SetTextColor(200, 0, 0);
731 $pdf->SetFont(
'',
'B', $default_font_size - 2);
732 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
733 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
736 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
739 $pdf->SetFont(
'',
'B', $default_font_size + 2);
740 $pdf->SetXY($posx, $posy);
741 $pdf->SetTextColor(0, 0, 60);
742 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
744 $pdf->SetFont(
'',
'', $default_font_size + 2);
747 $pdf->SetXY($posx, $posy);
748 $pdf->SetTextColor(0, 0, 60);
750 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
752 $pdf->SetTextColor(255, 0, 0);
753 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
754 $pdf->SetTextColor(0, 0, 60);
757 if (
$object->thirdparty->code_client) {
759 $pdf->SetXY($posx, $posy);
760 $pdf->SetTextColor(0, 0, 60);
761 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
764 $pdf->SetTextColor(0, 0, 60);
777 $posx = $this->marge_gauche;
779 $posx = $this->page_largeur - $this->marge_droite - 80;
784 $pdf->SetTextColor(0, 0, 0);
785 $pdf->SetFont(
'',
'', $default_font_size - 2);
786 $pdf->SetXY($posx, $posy - 5);
787 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
788 $pdf->SetXY($posx, $posy);
789 $pdf->SetFillColor(230, 230, 230);
790 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'D');
791 $pdf->SetTextColor(0, 0, 60);
794 $pdf->SetXY($posx + 2, $posy + 3);
795 $pdf->SetFont(
'',
'B', $default_font_size);
796 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
797 $posy = $pdf->getY();
800 $pdf->SetXY($posx + 2, $posy);
801 $pdf->SetFont(
'',
'', $default_font_size - 1);
802 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
808 $posx = $this->marge_gauche;
810 $pdf->SetTextColor(0, 0, 0);
811 $pdf->SetFont(
'',
'', $default_font_size - 2);
812 $pdf->SetXY($posx, $posy - 5);
813 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
817 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
818 if ($arrayidcontact && count($arrayidcontact) > 0) {
820 $result =
$object->fetch_contact($arrayidcontact[0]);
824 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
825 $thirdparty =
$object->contact;
827 $thirdparty =
$object->thirdparty;
836 if ($this->page_largeur < 210) {
840 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
842 $posx = $this->marge_gauche;
846 $pdf->SetTextColor(0, 0, 0);
847 $pdf->SetFont(
'',
'', $default_font_size - 2);
848 $pdf->SetXY($posx + 2, $posy - 5);
850 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
853 $pdf->SetXY($posx + 2, $posy + 3);
854 $pdf->SetFont(
'',
'B', $default_font_size);
855 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
857 $posy = $pdf->getY();
860 $pdf->SetFont(
'',
'', $default_font_size - 1);
861 $pdf->SetXY($posx + 2, $posy);
862 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
865 $pdf->SetTextColor(0, 0, 60);