148 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
151 global $user, $langs, $conf, $mysoc, $hookmanager;
153 if (!is_object($outputlangs)) {
154 $outputlangs = $langs;
158 $outputlangs->charset_output =
'ISO-8859-1';
162 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
164 if ($conf->expedition->dir_output) {
169 $dir = $conf->expedition->dir_output.
"/receipt";
170 $file = $dir.
"/SPECIMEN.pdf";
173 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
174 $file = $dir.
"/".$objectref.
".pdf";
177 if (!file_exists($dir)) {
179 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
184 if (file_exists($dir)) {
186 if (!is_object($hookmanager)) {
187 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
190 $hookmanager->initHooks(array(
'pdfgeneration'));
191 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
193 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
195 $nblines = count(
$object->lines);
200 $heightforinfotot = 30;
202 $heightforfooter = $this->marge_basse + 8;
204 $heightforfooter += 6;
206 $pdf->SetAutoPageBreak(1, 0);
208 if (class_exists(
'TCPDF')) {
209 $pdf->setPrintHeader(
false);
210 $pdf->setPrintFooter(
false);
215 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
216 $tplidx = $pdf->importPage(1);
221 $result = $expedition->fetch(
$object->origin_id);
223 $commande =
new Commande($this->db);
224 if ($expedition->origin ==
'commande') {
225 $commande->fetch($expedition->origin_id);
228 $object->commande->loadExpeditions();
233 $pdf->SetDrawColor(128, 128, 128);
235 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
236 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
237 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
238 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
239 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
241 $pdf->SetCompression(
false);
245 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
269 if (!empty($tplidx)) {
270 $pdf->useTemplate($tplidx);
274 $pdf->SetFont(
'',
'', $default_font_size - 1);
275 $pdf->MultiCell(0, 3,
'');
276 $pdf->SetTextColor(0, 0, 0);
279 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
281 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
284 $height_incoterms = 0;
285 if (isModEnabled(
'incoterm')) {
286 $desc_incoterms =
$object->getIncotermsForPDF();
287 if ($desc_incoterms) {
290 $pdf->SetFont(
'',
'', $default_font_size - 1);
291 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
292 $nexY = $pdf->GetY();
293 $height_incoterms = $nexY - $tab_top;
296 $pdf->SetDrawColor(192, 192, 192);
297 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
299 $tab_top = $nexY + 6;
300 $height_incoterms += 4;
305 if (!empty(
$object->note_public)) {
306 $tab_top = 88 + $height_incoterms;
308 $pdf->SetFont(
'',
'', $default_font_size - 1);
310 $nexY = $pdf->GetY();
311 $height_note = $nexY - $tab_top;
314 $pdf->SetDrawColor(192, 192, 192);
315 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
317 $tab_height -= $height_note;
318 $tab_top = $nexY + 6;
323 $iniY = $tab_top + 11;
324 $curY = $tab_top + 11;
325 $nexY = $tab_top + 11;
328 for ($i = 0; $i < $nblines; $i++) {
330 $pdf->SetFont(
'',
'', $default_font_size - 1);
331 $pdf->SetTextColor(0, 0, 0);
333 $pdf->setTopMargin($tab_top_newpage);
334 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
335 $pageposbefore = $pdf->getPage();
338 $curX = $this->posxdesc - 1;
340 $showpricebeforepagebreak = 1;
342 $pdf->startTransaction();
344 $pageposafter = $pdf->getPage();
345 if ($pageposafter > $pageposbefore) {
346 $pdf->rollbackTransaction(
true);
347 $pageposafter = $pageposbefore;
349 $pdf->setPageOrientation(
'', 1, $heightforfooter);
351 $posyafter = $pdf->GetY();
352 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
353 if ($i == ($nblines - 1)) {
354 $pdf->AddPage(
'',
'',
true);
355 if (!empty($tplidx)) {
356 $pdf->useTemplate($tplidx);
361 $pdf->setPage($pageposafter + 1);
367 $showpricebeforepagebreak = 1;
369 $showpricebeforepagebreak = 0;
373 $pdf->commitTransaction();
376 $nexY = $pdf->GetY();
377 $pageposafter = $pdf->getPage();
378 $pdf->setPage($pageposbefore);
379 $pdf->setTopMargin($this->marge_haute);
380 $pdf->setPageOrientation(
'', 1, 0);
383 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
384 $pdf->setPage($pageposafter);
385 $curY = $tab_top_newpage;
388 $pdf->SetFont(
'',
'', $default_font_size - 1);
401 $pdf->SetXY($this->posxqty, $curY);
402 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3,
$object->lines[$i]->qty_shipped, 0,
'R');
405 $pdf->SetXY($this->posxremainingqty, $curY);
406 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
407 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0,
'R');
430 $pdf->setPage($pageposafter);
431 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
433 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
434 $pdf->SetLineStyle(array(
'dash' => 0));
440 while ($pagenb < $pageposafter) {
441 $pdf->setPage($pagenb);
443 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
445 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
449 $pdf->setPage($pagenb);
450 $pdf->setPageOrientation(
'', 1, 0);
454 if (!empty($tplidx)) {
455 $pdf->useTemplate($tplidx);
458 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
460 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
462 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
467 if (!empty($tplidx)) {
468 $pdf->useTemplate($tplidx);
479 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
480 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
482 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
483 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
492 if (method_exists($pdf,
'AliasNbPages')) {
493 $pdf->AliasNbPages();
559 $pdf->Output($file,
'F');
562 if (!is_object($hookmanager)) {
563 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
566 $hookmanager->initHooks(array(
'pdfgeneration'));
567 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
569 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
571 $this->error = $hookmanager->error;
572 $this->errors = $hookmanager->errors;
577 $this->result = array(
'fullpath' => $file);
581 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
586 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
633 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
635 global $conf, $mysoc;
646 $pdf->SetTextColor(0, 0, 0);
647 $pdf->SetFont(
'',
'', $default_font_size - 2);
650 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
652 if (empty($hidetop)) {
653 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
656 $pdf->SetDrawColor(128, 128, 128);
657 $pdf->SetFont(
'',
'', $default_font_size - 1);
659 if (empty($hidetop)) {
660 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
661 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
665 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
666 if (empty($hidetop)) {
667 $pdf->SetXY($this->posxcomm, $tab_top + 1);
668 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
672 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
673 if (empty($hidetop)) {
674 $pdf->SetXY($this->posxqty, $tab_top + 1);
675 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
679 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
680 if (empty($hidetop)) {
681 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
682 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
698 global $conf, $langs;
709 $pdf->SetTextColor(0, 0, 60);
710 $pdf->SetFont(
'',
'B', $default_font_size + 3);
712 $posy = $this->marge_haute;
713 $posx = $this->page_largeur - $this->marge_droite - 100;
715 $pdf->SetXY($this->marge_gauche, $posy);
718 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
719 if ($this->emetteur->logo) {
720 if (is_readable($logo)) {
722 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
724 $pdf->SetTextColor(200, 0, 0);
725 $pdf->SetFont(
'',
'B', $default_font_size - 2);
726 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
727 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
730 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
733 $pdf->SetFont(
'',
'B', $default_font_size + 2);
734 $pdf->SetXY($posx, $posy);
735 $pdf->SetTextColor(0, 0, 60);
736 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
738 $pdf->SetFont(
'',
'', $default_font_size + 2);
741 $pdf->SetXY($posx, $posy);
742 $pdf->SetTextColor(0, 0, 60);
744 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
746 $pdf->SetTextColor(255, 0, 0);
747 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
748 $pdf->SetTextColor(0, 0, 60);
751 if (
$object->thirdparty->code_client) {
753 $pdf->SetXY($posx, $posy);
754 $pdf->SetTextColor(0, 0, 60);
755 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
758 $pdf->SetTextColor(0, 0, 60);
771 $posx = $this->marge_gauche;
773 $posx = $this->page_largeur - $this->marge_droite - 80;
778 $pdf->SetTextColor(0, 0, 0);
779 $pdf->SetFont(
'',
'', $default_font_size - 2);
780 $pdf->SetXY($posx, $posy - 5);
781 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
782 $pdf->SetXY($posx, $posy);
783 $pdf->SetFillColor(230, 230, 230);
784 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
785 $pdf->SetTextColor(0, 0, 60);
788 $pdf->SetXY($posx + 2, $posy + 3);
789 $pdf->SetFont(
'',
'B', $default_font_size);
790 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
791 $posy = $pdf->getY();
794 $pdf->SetXY($posx + 2, $posy);
795 $pdf->SetFont(
'',
'', $default_font_size - 1);
796 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
802 $posx = $this->marge_gauche;
804 $pdf->SetTextColor(0, 0, 0);
805 $pdf->SetFont(
'',
'', $default_font_size - 2);
806 $pdf->SetXY($posx, $posy - 5);
807 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
811 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
812 if ($arrayidcontact && count($arrayidcontact) > 0) {
814 $result =
$object->fetch_contact($arrayidcontact[0]);
818 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
819 $thirdparty =
$object->contact;
821 $thirdparty =
$object->thirdparty;
830 if ($this->page_largeur < 210) {
834 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
836 $posx = $this->marge_gauche;
840 $pdf->SetTextColor(0, 0, 0);
841 $pdf->SetFont(
'',
'', $default_font_size - 2);
842 $pdf->SetXY($posx + 2, $posy - 5);
844 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
847 $pdf->SetXY($posx + 2, $posy + 3);
848 $pdf->SetFont(
'',
'B', $default_font_size);
849 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
851 $posy = $pdf->getY();
854 $pdf->SetFont(
'',
'', $default_font_size - 1);
855 $pdf->SetXY($posx + 2, $posy);
856 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
859 $pdf->SetTextColor(0, 0, 60);