147 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
150 global $user, $langs, $conf, $mysoc, $hookmanager;
152 if (!is_object($outputlangs)) {
153 $outputlangs = $langs;
157 $outputlangs->charset_output =
'ISO-8859-1';
161 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"sendings",
"deliveries"));
163 if ($conf->expedition->dir_output) {
168 $dir = $conf->expedition->dir_output.
"/receipt";
169 $file = $dir.
"/SPECIMEN.pdf";
172 $dir = $conf->expedition->dir_output.
"/receipt/".$objectref;
173 $file = $dir.
"/".$objectref.
".pdf";
176 if (!file_exists($dir)) {
178 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
183 if (file_exists($dir)) {
185 if (!is_object($hookmanager)) {
186 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
189 $hookmanager->initHooks(array(
'pdfgeneration'));
190 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
192 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
194 $nblines = count(
$object->lines);
199 $heightforinfotot = 30;
200 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
201 $heightforfooter = $this->marge_basse + 8;
203 $heightforfooter += 6;
205 $pdf->SetAutoPageBreak(1, 0);
207 if (class_exists(
'TCPDF')) {
208 $pdf->setPrintHeader(
false);
209 $pdf->setPrintFooter(
false);
214 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
215 $tplidx = $pdf->importPage(1);
220 $result = $expedition->fetch(
$object->origin_id);
222 $commande =
new Commande($this->db);
223 if ($expedition->origin ==
'commande') {
224 $commande->fetch($expedition->origin_id);
227 $object->commande->loadExpeditions();
232 $pdf->SetDrawColor(128, 128, 128);
234 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
235 $pdf->SetSubject($outputlangs->transnoentities(
"DeliveryOrder"));
236 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
237 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
238 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"DeliveryOrder"));
240 $pdf->SetCompression(
false);
244 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
268 if (!empty($tplidx)) {
269 $pdf->useTemplate($tplidx);
273 $pdf->SetFont(
'',
'', $default_font_size - 1);
274 $pdf->MultiCell(0, 3,
'');
275 $pdf->SetTextColor(0, 0, 0);
278 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
280 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
283 $height_incoterms = 0;
284 if (isModEnabled(
'incoterm')) {
285 $desc_incoterms =
$object->getIncotermsForPDF();
286 if ($desc_incoterms) {
289 $pdf->SetFont(
'',
'', $default_font_size - 1);
290 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
291 $nexY = $pdf->GetY();
292 $height_incoterms = $nexY - $tab_top;
295 $pdf->SetDrawColor(192, 192, 192);
296 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
298 $tab_top = $nexY + 6;
299 $height_incoterms += 4;
304 if (!empty(
$object->note_public)) {
305 $tab_top = 88 + $height_incoterms;
307 $pdf->SetFont(
'',
'', $default_font_size - 1);
309 $nexY = $pdf->GetY();
310 $height_note = $nexY - $tab_top;
313 $pdf->SetDrawColor(192, 192, 192);
314 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
316 $tab_height = $tab_height - $height_note;
317 $tab_top = $nexY + 6;
322 $iniY = $tab_top + 11;
323 $curY = $tab_top + 11;
324 $nexY = $tab_top + 11;
327 for ($i = 0; $i < $nblines; $i++) {
329 $pdf->SetFont(
'',
'', $default_font_size - 1);
330 $pdf->SetTextColor(0, 0, 0);
332 $pdf->setTopMargin($tab_top_newpage);
333 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
334 $pageposbefore = $pdf->getPage();
337 $curX = $this->posxdesc - 1;
339 $showpricebeforepagebreak = 1;
341 $pdf->startTransaction();
343 $pageposafter = $pdf->getPage();
344 if ($pageposafter > $pageposbefore) {
345 $pdf->rollbackTransaction(
true);
346 $pageposafter = $pageposbefore;
348 $pdf->setPageOrientation(
'', 1, $heightforfooter);
350 $posyafter = $pdf->GetY();
351 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
352 if ($i == ($nblines - 1)) {
353 $pdf->AddPage(
'',
'',
true);
354 if (!empty($tplidx)) {
355 $pdf->useTemplate($tplidx);
360 $pdf->setPage($pageposafter + 1);
366 $showpricebeforepagebreak = 1;
368 $showpricebeforepagebreak = 0;
372 $pdf->commitTransaction();
375 $nexY = $pdf->GetY();
376 $pageposafter = $pdf->getPage();
377 $pdf->setPage($pageposbefore);
378 $pdf->setTopMargin($this->marge_haute);
379 $pdf->setPageOrientation(
'', 1, 0);
382 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
383 $pdf->setPage($pageposafter);
384 $curY = $tab_top_newpage;
387 $pdf->SetFont(
'',
'', $default_font_size - 1);
400 $pdf->SetXY($this->posxqty, $curY);
401 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3,
$object->lines[$i]->qty_shipped, 0,
'R');
404 $pdf->SetXY($this->posxremainingqty, $curY);
405 $qtyRemaining =
$object->lines[$i]->qty_asked -
$object->commande->expeditions[
$object->lines[$i]->fk_origin_line];
406 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0,
'R');
429 $pdf->setPage($pageposafter);
430 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
432 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
433 $pdf->SetLineStyle(array(
'dash' => 0));
439 while ($pagenb < $pageposafter) {
440 $pdf->setPage($pagenb);
442 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
444 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
448 $pdf->setPage($pagenb);
449 $pdf->setPageOrientation(
'', 1, 0);
453 if (!empty($tplidx)) {
454 $pdf->useTemplate($tplidx);
457 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
459 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
461 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
466 if (!empty($tplidx)) {
467 $pdf->useTemplate($tplidx);
478 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
479 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
481 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
482 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
491 if (method_exists($pdf,
'AliasNbPages')) {
492 $pdf->AliasNbPages();
558 $pdf->Output($file,
'F');
561 if (!is_object($hookmanager)) {
562 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
565 $hookmanager->initHooks(array(
'pdfgeneration'));
566 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
568 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
570 $this->error = $hookmanager->error;
571 $this->errors = $hookmanager->errors;
576 $this->result = array(
'fullpath' => $file);
580 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
585 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DELIVERY_OUTPUTDIR");
632 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
634 global $conf, $mysoc;
645 $pdf->SetTextColor(0, 0, 0);
646 $pdf->SetFont(
'',
'', $default_font_size - 2);
649 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
651 if (empty($hidetop)) {
652 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
655 $pdf->SetDrawColor(128, 128, 128);
656 $pdf->SetFont(
'',
'', $default_font_size - 1);
658 if (empty($hidetop)) {
659 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
660 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
664 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
665 if (empty($hidetop)) {
666 $pdf->SetXY($this->posxcomm, $tab_top + 1);
667 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities(
"Comments"),
'',
'L');
671 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
672 if (empty($hidetop)) {
673 $pdf->SetXY($this->posxqty, $tab_top + 1);
674 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities(
"QtyShippedShort"),
'',
'R');
678 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
679 if (empty($hidetop)) {
680 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
681 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities(
"KeepToShipShort"),
'',
'R');
697 global $conf, $langs;
708 $pdf->SetTextColor(0, 0, 60);
709 $pdf->SetFont(
'',
'B', $default_font_size + 3);
711 $posy = $this->marge_haute;
712 $posx = $this->page_largeur - $this->marge_droite - 100;
714 $pdf->SetXY($this->marge_gauche, $posy);
717 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
718 if ($this->emetteur->logo) {
719 if (is_readable($logo)) {
721 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
723 $pdf->SetTextColor(200, 0, 0);
724 $pdf->SetFont(
'',
'B', $default_font_size - 2);
725 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
726 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
729 $pdf->MultiCell(100, 4, $this->emetteur->name, 0,
'L');
732 $pdf->SetFont(
'',
'B', $default_font_size + 2);
733 $pdf->SetXY($posx, $posy);
734 $pdf->SetTextColor(0, 0, 60);
735 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"DeliveryOrder").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
737 $pdf->SetFont(
'',
'', $default_font_size + 2);
740 $pdf->SetXY($posx, $posy);
741 $pdf->SetTextColor(0, 0, 60);
743 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_delivery,
"%d %b %Y",
false, $outputlangs,
true),
'',
'R');
745 $pdf->SetTextColor(255, 0, 0);
746 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DeliveryNotValidated"),
'',
'R');
747 $pdf->SetTextColor(0, 0, 60);
750 if (
$object->thirdparty->code_client) {
752 $pdf->SetXY($posx, $posy);
753 $pdf->SetTextColor(0, 0, 60);
754 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
757 $pdf->SetTextColor(0, 0, 60);
770 $posx = $this->marge_gauche;
772 $posx = $this->page_largeur - $this->marge_droite - 80;
777 $pdf->SetTextColor(0, 0, 0);
778 $pdf->SetFont(
'',
'', $default_font_size - 2);
779 $pdf->SetXY($posx, $posy - 5);
780 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
781 $pdf->SetXY($posx, $posy);
782 $pdf->SetFillColor(230, 230, 230);
783 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
784 $pdf->SetTextColor(0, 0, 60);
787 $pdf->SetXY($posx + 2, $posy + 3);
788 $pdf->SetFont(
'',
'B', $default_font_size);
789 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
790 $posy = $pdf->getY();
793 $pdf->SetXY($posx + 2, $posy);
794 $pdf->SetFont(
'',
'', $default_font_size - 1);
795 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
801 $posx = $this->marge_gauche;
803 $pdf->SetTextColor(0, 0, 0);
804 $pdf->SetFont(
'',
'', $default_font_size - 2);
805 $pdf->SetXY($posx, $posy - 5);
806 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"DeliveryAddress"), 0,
'L');
810 $arrayidcontact =
$object->commande->getIdContact(
'external',
'SHIPPING');
811 if ($arrayidcontact && count($arrayidcontact) > 0) {
813 $result =
$object->fetch_contact($arrayidcontact[0]);
817 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
818 $thirdparty =
$object->contact;
820 $thirdparty =
$object->thirdparty;
829 if ($this->page_largeur < 210) {
833 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
835 $posx = $this->marge_gauche;
839 $pdf->SetTextColor(0, 0, 0);
840 $pdf->SetFont(
'',
'', $default_font_size - 2);
841 $pdf->SetXY($posx + 2, $posy - 5);
843 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
846 $pdf->SetXY($posx + 2, $posy + 3);
847 $pdf->SetFont(
'',
'B', $default_font_size);
848 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
850 $posy = $pdf->getY();
853 $pdf->SetFont(
'',
'', $default_font_size - 1);
854 $pdf->SetXY($posx + 2, $posy);
855 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
858 $pdf->SetTextColor(0, 0, 60);