122 public function write_file(&$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
125 global $user, $conf, $langs, $mysoc, $hookmanager;
127 $object->fetch_thirdparty();
129 if (!is_object($outputlangs)) {
130 $outputlangs = $langs;
134 $outputlangs->charset_output =
'ISO-8859-1';
138 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"deliveries",
"sendings",
"productbatch"));
140 if ($conf->expedition->dir_output) {
141 $object->fetch_thirdparty();
143 $origin = $object->origin;
146 $this->expediteur = $mysoc;
149 $idcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
150 $this->destinataire =
new Contact($this->db);
151 if (!empty($idcontact[0])) {
152 $this->destinataire->fetch($idcontact[0]);
156 $idcontact = $object->$origin->getIdContact(
'internal',
'LIVREUR');
157 $this->livreur =
new User($this->db);
158 if (!empty($idcontact[0])) {
159 $this->livreur->fetch($idcontact[0]);
163 if ($object->specimen) {
164 $dir = $conf->expedition->dir_output.
"/sending";
165 $file = $dir.
"/SPECIMEN.pdf";
168 $dir = $conf->expedition->dir_output.
"/sending/".$expref;
169 $file = $dir.
"/".$expref.
".pdf";
172 if (!file_exists($dir)) {
174 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
179 if (file_exists($dir)) {
181 if (!is_object($hookmanager)) {
182 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
185 $hookmanager->initHooks(array(
'pdfgeneration'));
186 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
188 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
190 $nblines = count($object->lines);
194 $heightforinfotot = 0;
195 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
196 $heightforfooter = $this->marge_basse + 8;
198 $heightforfooter += 6;
200 $pdf->SetAutoPageBreak(1, 0);
202 if (class_exists(
'TCPDF')) {
203 $pdf->setPrintHeader(
false);
204 $pdf->setPrintFooter(
false);
209 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
210 $tplidx = $pdf->importPage(1);
215 $pdf->SetDrawColor(128, 128, 128);
217 if (method_exists($pdf,
'AliasNbPages')) {
218 $pdf->AliasNbPages();
221 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
222 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
223 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
224 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
225 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
227 $pdf->SetCompression(
false);
230 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
235 $this->
_pagehead($pdf, $object, 1, $outputlangs);
236 $pdf->SetFont(
'',
'', $default_font_size - 3);
237 $pdf->MultiCell(0, 3,
'');
238 $pdf->SetTextColor(0, 0, 0);
241 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
243 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
246 if (!empty($object->note_public)) {
247 $pdf->SetFont(
'',
'', $default_font_size - 1);
248 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top,
dol_htmlentitiesbr($object->note_public), 0, 1);
249 $nexY = $pdf->GetY();
250 $height_note = $nexY - $tab_top;
253 $pdf->SetDrawColor(192, 192, 192);
254 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
256 $tab_height = $tab_height - $height_note;
257 $tab_top = $nexY + 6;
263 $pdf->SetFillColor(240, 240, 240);
264 $pdf->SetTextColor(0, 0, 0);
265 $pdf->SetXY(10, $tab_top + 5);
267 $iniY = $tab_top + 7;
268 $curY = $tab_top + 7;
269 $nexY = $tab_top + 7;
271 $num = count($object->lines);
273 for ($i = 0; $i < $num; $i++) {
275 $pdf->SetFont(
'',
'', $default_font_size - 3);
276 $pdf->SetTextColor(0, 0, 0);
278 $pdf->setTopMargin($tab_top_newpage);
279 $pdf->setPageOrientation(
'', 1, $heightforfooter);
280 $pageposbefore = $pdf->getPage();
283 $libelleproduitservice =
pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 50, $curY, 0, 1);
285 $nexY = $pdf->GetY();
286 $pageposafter = $pdf->getPage();
287 $pdf->setPage($pageposbefore);
288 $pdf->setTopMargin($this->marge_haute);
289 $pdf->setPageOrientation(
'', 1, 0);
292 if ($pageposafter > $pageposbefore) {
293 $pdf->setPage($pageposafter);
294 $curY = $tab_top_newpage;
297 $pdf->SetFont(
'',
'', $default_font_size - 3);
300 $pdf->SetDrawColor(120, 120, 120);
301 $pdf->Rect(10 + 3, $curY, 3, 3);
302 $pdf->Rect(20 + 3, $curY, 3, 3);
305 $pdf->SetXY(30, $curY);
306 $pdf->SetFont(
'',
'B', $default_font_size - 3);
307 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0,
'L', 0);
309 $pdf->SetXY(140, $curY);
310 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0,
'C', 0);
312 $pdf->SetXY(170, $curY);
313 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0,
'C', 0);
317 $pdf->setPage($pageposafter);
318 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
320 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
321 $pdf->SetLineStyle(array(
'dash'=>0));
327 while ($pagenb < $pageposafter) {
328 $pdf->setPage($pagenb);
330 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
332 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
334 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
336 $pdf->setPage($pagenb);
337 $pdf->setPageOrientation(
'', 1, 0);
339 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
341 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
343 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
345 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
354 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
355 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
357 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
358 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
362 $this->
_pagefoot($pdf, $object, $outputlangs);
363 if (method_exists($pdf,
'AliasNbPages')) {
364 $pdf->AliasNbPages();
369 $pdf->Output($file,
'F');
372 if (!is_object($hookmanager)) {
373 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
376 $hookmanager->initHooks(array(
'pdfgeneration'));
377 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
379 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
381 $this->error = $hookmanager->error;
382 $this->errors = $hookmanager->errors;
387 $this->result = array(
'fullpath'=>$file);
391 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
395 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
480 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
482 global $conf, $langs, $hookmanager;
490 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
493 $posy = $this->marge_haute;
494 $posx = $this->page_largeur - $this->marge_droite - 100;
506 if ($this->emetteur->logo) {
507 $logodir = $conf->mycompany->dir_output;
508 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
509 $logodir = $conf->mycompany->multidir_output[$object->entity];
512 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
514 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
516 if (is_readable($logo)) {
518 $pdf->Image($logo, 10, 5, 0, $height);
520 $pdf->SetTextColor(200, 0, 0);
521 $pdf->SetFont(
'',
'B', $default_font_size - 2);
522 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
523 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
526 $text = $this->emetteur->name;
527 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
532 $pdf->SetXY($Xoff, 7);
533 $pdf->SetFont(
'',
'B', $default_font_size + 2);
534 $pdf->SetTextColor(0, 0, 0);
535 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
540 $pdf->SetXY($Xoff, $Yoff);
541 $pdf->SetFont(
'',
'', $default_font_size - 2);
542 $pdf->SetTextColor(0, 0, 0);
543 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset($object->ref),
'',
'R');
546 $origin = $object->origin;
547 $origin_id = $object->origin_id;
550 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size - 1);
558 $blSocX2 = $blSocW + $blSocX;
561 $pdf->SetTextColor(0, 0, 0);
562 $pdf->SetFont(
'',
'B', $default_font_size - 3);
563 $pdf->SetXY($blSocX, $blSocY + 1);
564 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
565 $pdf->SetTextColor(0, 0, 0);
568 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
570 $pdf->SetFont(
'',
'', $default_font_size - 3);
571 $pdf->SetXY($blSocX, $blSocY + 4);
572 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
575 if ($object->thirdparty->code_client) {
578 $pdf->SetXY($Xoff, $posy);
579 $pdf->SetTextColor(0, 0, 0);
580 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
585 $pdf->SetXY($blSocX - 80, $blSocY + 17);
587 $pdf->SetFont(
'',
'B', $default_font_size - 3);
588 $pdf->SetTextColor(0, 0, 0);
589 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
591 $pdf->SetXY($blSocX - 80, $blSocY + 20);
592 $pdf->SetFont(
'',
'B', $default_font_size - 3);
593 $pdf->SetTextColor(0, 0, 0);
594 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".$object->tracking_number,
'',
'L');
597 $pdf->SetXY($blSocX - 80, $blSocY + 23);
598 $pdf->SetFont(
'',
'', $default_font_size - 3);
599 $pdf->SetTextColor(0, 0, 0);
601 if (!empty($object->tracking_number)) {
602 $object->getUrlTrackingStatus($object->tracking_number);
603 if (!empty($object->tracking_url)) {
604 if ($object->shipping_method_id > 0) {
606 $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
609 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
611 if ($object->tracking_url != $object->tracking_number) {
613 $label .= $object->tracking_url;
615 $pdf->SetFont(
'',
'B', $default_font_size - 3);
616 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
620 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
626 $blExpX = $Xoff - 20;
629 $pdf->Rect($blExpX, $Yoff, $blW, 26);
631 $object->fetch_thirdparty();
635 $arrayidcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
636 if (count($arrayidcontact) > 0) {
638 $result = $object->fetch_contact($arrayidcontact[0]);
642 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
643 $thirdparty = $object->contact;
645 $thirdparty = $object->thirdparty;
650 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'targetwithdetails', $object);
652 $blDestX = $blExpX + 55;
669 $pdf->SetFont(
'',
'B', $default_font_size - 3);
670 $pdf->SetXY($blDestX, $Yoff - 4);
671 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
672 $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
675 $pdf->SetFont(
'',
'B', $default_font_size - 3);
676 $pdf->SetXY($blDestX, $Yoff);
677 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
679 $posy = $pdf->getY();
682 $pdf->SetFont(
'',
'', $default_font_size - 3);
683 $pdf->SetXY($blDestX, $posy);
684 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');