159 public function write_file(&$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
162 global $user, $conf, $langs, $mysoc, $hookmanager;
164 $object->fetch_thirdparty();
166 if (!is_object($outputlangs)) {
167 $outputlangs = $langs;
170 if (!empty($conf->global->MAIN_USE_FPDF)) {
171 $outputlangs->charset_output =
'ISO-8859-1';
175 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"deliveries",
"sendings",
"productbatch"));
177 if ($conf->expedition->dir_output) {
178 $object->fetch_thirdparty();
180 $origin = $object->origin;
183 $this->expediteur = $mysoc;
186 $idcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
187 $this->destinataire =
new Contact($this->db);
188 if (!empty($idcontact[0])) {
189 $this->destinataire->fetch($idcontact[0]);
193 $idcontact = $object->$origin->getIdContact(
'internal',
'LIVREUR');
194 $this->livreur =
new User($this->db);
195 if (!empty($idcontact[0])) {
196 $this->livreur->fetch($idcontact[0]);
200 if ($object->specimen) {
201 $dir = $conf->expedition->dir_output.
"/sending";
202 $file = $dir.
"/SPECIMEN.pdf";
205 $dir = $conf->expedition->dir_output.
"/sending/".$expref;
206 $file = $dir.
"/".$expref.
".pdf";
209 if (!file_exists($dir)) {
211 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
216 if (file_exists($dir)) {
218 if (!is_object($hookmanager)) {
219 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
222 $hookmanager->initHooks(array(
'pdfgeneration'));
223 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
225 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
227 $nblines = count($object->lines);
231 $heightforinfotot = 0;
232 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
233 $heightforfooter = $this->marge_basse + 8;
234 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
235 $heightforfooter += 6;
237 $pdf->SetAutoPageBreak(1, 0);
239 if (class_exists(
'TCPDF')) {
240 $pdf->setPrintHeader(
false);
241 $pdf->setPrintFooter(
false);
245 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
246 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
247 $tplidx = $pdf->importPage(1);
252 $pdf->SetDrawColor(128, 128, 128);
254 if (method_exists($pdf,
'AliasNbPages')) {
255 $pdf->AliasNbPages();
258 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
259 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
260 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
261 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
262 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
264 $pdf->SetCompression(
false);
267 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
272 $this->
_pagehead($pdf, $object, 1, $outputlangs);
273 $pdf->SetFont(
'',
'', $default_font_size - 3);
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 if (!empty($object->note_public)) {
284 $pdf->SetFont(
'',
'', $default_font_size - 1);
285 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top,
dol_htmlentitiesbr($object->note_public), 0, 1);
286 $nexY = $pdf->GetY();
287 $height_note = $nexY - $tab_top;
290 $pdf->SetDrawColor(192, 192, 192);
291 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
293 $tab_height = $tab_height - $height_note;
294 $tab_top = $nexY + 6;
300 $pdf->SetFillColor(240, 240, 240);
301 $pdf->SetTextColor(0, 0, 0);
302 $pdf->SetXY(10, $tab_top + 5);
304 $iniY = $tab_top + 7;
305 $curY = $tab_top + 7;
306 $nexY = $tab_top + 7;
308 $num = count($object->lines);
310 for ($i = 0; $i < $num; $i++) {
312 $pdf->SetFont(
'',
'', $default_font_size - 3);
313 $pdf->SetTextColor(0, 0, 0);
315 $pdf->setTopMargin($tab_top_newpage);
316 $pdf->setPageOrientation(
'', 1, $heightforfooter);
317 $pageposbefore = $pdf->getPage();
320 $libelleproduitservice =
pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 50, $curY, 0, 1);
322 $nexY = $pdf->GetY();
323 $pageposafter = $pdf->getPage();
324 $pdf->setPage($pageposbefore);
325 $pdf->setTopMargin($this->marge_haute);
326 $pdf->setPageOrientation(
'', 1, 0);
329 if ($pageposafter > $pageposbefore) {
330 $pdf->setPage($pageposafter);
331 $curY = $tab_top_newpage;
334 $pdf->SetFont(
'',
'', $default_font_size - 3);
337 $pdf->SetDrawColor(120, 120, 120);
338 $pdf->Rect(10 + 3, $curY, 3, 3);
339 $pdf->Rect(20 + 3, $curY, 3, 3);
342 $pdf->SetXY(30, $curY);
343 $pdf->SetFont(
'',
'B', $default_font_size - 3);
344 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0,
'L', 0);
346 $pdf->SetXY(140, $curY);
347 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0,
'C', 0);
349 $pdf->SetXY(170, $curY);
350 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0,
'C', 0);
353 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
354 $pdf->setPage($pageposafter);
355 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
357 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
358 $pdf->SetLineStyle(array(
'dash'=>0));
364 while ($pagenb < $pageposafter) {
365 $pdf->setPage($pagenb);
367 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
369 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
371 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
373 $pdf->setPage($pagenb);
374 $pdf->setPageOrientation(
'', 1, 0);
376 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
378 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
380 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
382 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
391 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
392 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
394 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
395 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
399 $this->
_pagefoot($pdf, $object, $outputlangs);
400 if (method_exists($pdf,
'AliasNbPages')) {
401 $pdf->AliasNbPages();
406 $pdf->Output($file,
'F');
409 if (!is_object($hookmanager)) {
410 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
413 $hookmanager->initHooks(array(
'pdfgeneration'));
414 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
416 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
418 $this->error = $hookmanager->error;
419 $this->errors = $hookmanager->errors;
424 $this->result = array(
'fullpath'=>$file);
428 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
432 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
517 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
519 global $conf, $langs, $hookmanager;
526 if ($object->statut == 0 && (!empty($conf->global->SENDING_DRAFT_WATERMARK))) {
527 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
530 $posy = $this->marge_haute;
531 $posx = $this->page_largeur - $this->marge_droite - 100;
543 if ($this->emetteur->logo) {
544 $logodir = $conf->mycompany->dir_output;
545 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
546 $logodir = $conf->mycompany->multidir_output[$object->entity];
549 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
551 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
553 if (is_readable($logo)) {
555 $pdf->Image($logo, 10, 5, 0, $height);
557 $pdf->SetTextColor(200, 0, 0);
558 $pdf->SetFont(
'',
'B', $default_font_size - 2);
559 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
560 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
563 $text = $this->emetteur->name;
564 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
569 $pdf->SetXY($Xoff, 7);
570 $pdf->SetFont(
'',
'B', $default_font_size + 2);
571 $pdf->SetTextColor(0, 0, 0);
572 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
577 $pdf->SetXY($Xoff, $Yoff);
578 $pdf->SetFont(
'',
'', $default_font_size - 2);
579 $pdf->SetTextColor(0, 0, 0);
580 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset($object->ref),
'',
'R');
583 $origin = $object->origin;
584 $origin_id = $object->origin_id;
587 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size - 1);
595 $blSocX2 = $blSocW + $blSocX;
598 $pdf->SetTextColor(0, 0, 0);
599 $pdf->SetFont(
'',
'B', $default_font_size - 3);
600 $pdf->SetXY($blSocX, $blSocY + 1);
601 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
602 $pdf->SetTextColor(0, 0, 0);
605 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
607 $pdf->SetFont(
'',
'', $default_font_size - 3);
608 $pdf->SetXY($blSocX, $blSocY + 4);
609 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
612 if ($object->thirdparty->code_client) {
615 $pdf->SetXY($Xoff, $posy);
616 $pdf->SetTextColor(0, 0, 0);
617 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
622 $pdf->SetXY($blSocX - 80, $blSocY + 17);
624 $pdf->SetFont(
'',
'B', $default_font_size - 3);
625 $pdf->SetTextColor(0, 0, 0);
626 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
628 $pdf->SetXY($blSocX - 80, $blSocY + 20);
629 $pdf->SetFont(
'',
'B', $default_font_size - 3);
630 $pdf->SetTextColor(0, 0, 0);
631 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".$object->tracking_number,
'',
'L');
634 $pdf->SetXY($blSocX - 80, $blSocY + 23);
635 $pdf->SetFont(
'',
'', $default_font_size - 3);
636 $pdf->SetTextColor(0, 0, 0);
638 if (!empty($object->tracking_number)) {
639 $object->getUrlTrackingStatus($object->tracking_number);
640 if (!empty($object->tracking_url)) {
641 if ($object->shipping_method_id > 0) {
643 $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
646 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
648 if ($object->tracking_url != $object->tracking_number) {
650 $label .= $object->tracking_url;
652 $pdf->SetFont(
'',
'B', $default_font_size - 3);
653 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
657 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
663 $blExpX = $Xoff - 20;
666 $pdf->Rect($blExpX, $Yoff, $blW, 26);
668 $object->fetch_thirdparty();
672 $arrayidcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
673 if (count($arrayidcontact) > 0) {
675 $result = $object->fetch_contact($arrayidcontact[0]);
679 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
680 $thirdparty = $object->contact;
682 $thirdparty = $object->thirdparty;
687 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'targetwithdetails', $object);
689 $blDestX = $blExpX + 55;
706 $pdf->SetFont(
'',
'B', $default_font_size - 3);
707 $pdf->SetXY($blDestX, $Yoff - 4);
708 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
709 $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
712 $pdf->SetFont(
'',
'B', $default_font_size - 3);
713 $pdf->SetXY($blDestX, $Yoff);
714 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
716 $posy = $pdf->getY();
719 $pdf->SetFont(
'',
'', $default_font_size - 3);
720 $pdf->SetXY($blDestX, $posy);
721 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');