29 require_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
30 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
58 public $update_main_doc_field;
69 public $phpmin = array(7, 0);
75 public $version =
'dolibarr';
100 public $marge_droite;
126 global $conf, $langs, $mysoc;
129 $this->
name =
"merou";
130 $this->
description = $langs->trans(
"DocumentModelMerou");
131 $this->update_main_doc_field = 1;
135 $this->page_largeur = $formatarray[
'width'];
136 $this->page_hauteur = round($formatarray[
'height'] / 2);
137 $this->format = array($this->page_largeur, $this->page_hauteur);
143 $this->option_logo = 1;
146 $this->emetteur = $mysoc;
147 if (!$this->emetteur->country_code) {
148 $this->emetteur->country_code = substr($langs->defaultlang, -2);
165 public function write_file(&$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
168 global $user, $conf, $langs, $mysoc, $hookmanager;
170 $object->fetch_thirdparty();
172 if (!is_object($outputlangs)) {
173 $outputlangs = $langs;
176 if (!empty($conf->global->MAIN_USE_FPDF)) {
177 $outputlangs->charset_output =
'ISO-8859-1';
181 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"deliveries",
"sendings",
"productbatch"));
183 if ($conf->expedition->dir_output) {
184 $object->fetch_thirdparty();
186 $origin = $object->origin;
189 $this->expediteur = $mysoc;
192 $idcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
193 $this->destinataire =
new Contact($this->
db);
194 if (!empty($idcontact[0])) {
195 $this->destinataire->fetch($idcontact[0]);
199 $idcontact = $object->$origin->getIdContact(
'internal',
'LIVREUR');
200 $this->livreur =
new User($this->
db);
201 if (!empty($idcontact[0])) {
202 $this->livreur->fetch($idcontact[0]);
206 if ($object->specimen) {
207 $dir = $conf->expedition->dir_output.
"/sending";
208 $file = $dir.
"/SPECIMEN.pdf";
211 $dir = $conf->expedition->dir_output.
"/sending/".$expref;
212 $file = $dir.
"/".$expref.
".pdf";
215 if (!file_exists($dir)) {
217 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
222 if (file_exists($dir)) {
224 if (!is_object($hookmanager)) {
225 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
228 $hookmanager->initHooks(array(
'pdfgeneration'));
229 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
231 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
233 $nblines = count($object->lines);
237 $heightforinfotot = 0;
238 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
239 $heightforfooter = $this->marge_basse + 8;
240 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
241 $heightforfooter += 6;
243 $pdf->SetAutoPageBreak(1, 0);
245 if (class_exists(
'TCPDF')) {
246 $pdf->setPrintHeader(
false);
247 $pdf->setPrintFooter(
false);
251 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
252 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
253 $tplidx = $pdf->importPage(1);
258 $pdf->SetDrawColor(128, 128, 128);
260 if (method_exists($pdf,
'AliasNbPages')) {
261 $pdf->AliasNbPages();
264 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
265 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
266 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
267 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
268 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
270 $pdf->SetCompression(
false);
273 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
278 $this->
_pagehead($pdf, $object, 1, $outputlangs);
279 $pdf->SetFont(
'',
'', $default_font_size - 3);
280 $pdf->MultiCell(0, 3,
'');
281 $pdf->SetTextColor(0, 0, 0);
284 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
286 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
289 if (!empty($object->note_public)) {
290 $pdf->SetFont(
'',
'', $default_font_size - 1);
291 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top,
dol_htmlentitiesbr($object->note_public), 0, 1);
292 $nexY = $pdf->GetY();
293 $height_note = $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_note + 1);
299 $tab_height = $tab_height - $height_note;
300 $tab_top = $nexY + 6;
306 $pdf->SetFillColor(240, 240, 240);
307 $pdf->SetTextColor(0, 0, 0);
308 $pdf->SetXY(10, $tab_top + 5);
310 $iniY = $tab_top + 7;
311 $curY = $tab_top + 7;
312 $nexY = $tab_top + 7;
314 $num = count($object->lines);
316 for ($i = 0; $i < $num; $i++) {
318 $pdf->SetFont(
'',
'', $default_font_size - 3);
319 $pdf->SetTextColor(0, 0, 0);
321 $pdf->setTopMargin($tab_top_newpage);
322 $pdf->setPageOrientation(
'', 1, $heightforfooter);
323 $pageposbefore = $pdf->getPage();
326 $libelleproduitservice =
pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 50, $curY, 0, 1);
328 $nexY = $pdf->GetY();
329 $pageposafter = $pdf->getPage();
330 $pdf->setPage($pageposbefore);
331 $pdf->setTopMargin($this->marge_haute);
332 $pdf->setPageOrientation(
'', 1, 0);
335 if ($pageposafter > $pageposbefore) {
336 $pdf->setPage($pageposafter);
337 $curY = $tab_top_newpage;
340 $pdf->SetFont(
'',
'', $default_font_size - 3);
343 $pdf->SetDrawColor(120, 120, 120);
344 $pdf->Rect(10 + 3, $curY, 3, 3);
345 $pdf->Rect(20 + 3, $curY, 3, 3);
348 $pdf->SetXY(30, $curY);
349 $pdf->SetFont(
'',
'B', $default_font_size - 3);
350 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0,
'L', 0);
352 $pdf->SetXY(140, $curY);
353 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0,
'C', 0);
355 $pdf->SetXY(170, $curY);
356 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0,
'C', 0);
359 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
360 $pdf->setPage($pageposafter);
361 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
363 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
364 $pdf->SetLineStyle(array(
'dash'=>0));
370 while ($pagenb < $pageposafter) {
371 $pdf->setPage($pagenb);
373 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
375 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
377 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
379 $pdf->setPage($pagenb);
380 $pdf->setPageOrientation(
'', 1, 0);
382 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
384 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
386 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
388 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
397 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
398 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
400 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
401 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
405 $this->
_pagefoot($pdf, $object, $outputlangs);
406 if (method_exists($pdf,
'AliasNbPages')) {
407 $pdf->AliasNbPages();
412 $pdf->Output($file,
'F');
415 if (!is_object($hookmanager)) {
416 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
419 $hookmanager->initHooks(array(
'pdfgeneration'));
420 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
422 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
424 $this->error = $hookmanager->error;
425 $this->errors = $hookmanager->errors;
430 $this->result = array(
'fullpath'=>$file);
434 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
438 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
456 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
462 $langs->loadLangs(array(
"main",
"bills",
"orders"));
464 if (empty($hidetop)) {
465 $pdf->SetFont(
'',
'B', $default_font_size - 2);
466 $pdf->SetXY(10, $tab_top);
467 $pdf->MultiCell(10, 5,
"LS", 0,
'C', 1);
468 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
469 $pdf->SetXY(20, $tab_top);
470 $pdf->MultiCell(10, 5,
"LR", 0,
'C', 1);
471 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
472 $pdf->SetXY(30, $tab_top);
473 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C', 1);
474 $pdf->SetXY(50, $tab_top);
475 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 1);
476 $pdf->SetXY(140, $tab_top);
477 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C', 1);
478 $pdf->SetXY(170, $tab_top);
479 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C', 1);
481 $pdf->Rect(10, $tab_top, 190, $tab_height);
494 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
497 $pdf->SetFont(
'',
'', $default_font_size - 2);
499 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"GoodStatusDeclaration"), 0,
'L');
501 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ToAndDate"), 0,
'C');
502 $pdf->SetXY(120, -23);
503 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"NameAndSignature"), 0,
'C');
523 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
525 global $conf, $langs, $hookmanager;
532 if ($object->statut == 0 && (!empty($conf->global->SENDING_DRAFT_WATERMARK))) {
533 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
536 $posy = $this->marge_haute;
537 $posx = $this->page_largeur - $this->marge_droite - 100;
549 if ($this->emetteur->logo) {
550 $logodir = $conf->mycompany->dir_output;
551 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
552 $logodir = $conf->mycompany->multidir_output[$object->entity];
555 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
557 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
559 if (is_readable($logo)) {
561 $pdf->Image($logo, 10, 5, 0, $height);
563 $pdf->SetTextColor(200, 0, 0);
564 $pdf->SetFont(
'',
'B', $default_font_size - 2);
565 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
566 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
569 $text = $this->emetteur->name;
570 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
575 $pdf->SetXY($Xoff, 7);
576 $pdf->SetFont(
'',
'B', $default_font_size + 2);
577 $pdf->SetTextColor(0, 0, 0);
578 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
583 $pdf->SetXY($Xoff, $Yoff);
584 $pdf->SetFont(
'',
'', $default_font_size - 2);
585 $pdf->SetTextColor(0, 0, 0);
586 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset($object->ref),
'',
'R');
589 $origin = $object->origin;
590 $origin_id = $object->origin_id;
593 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size - 1);
601 $blSocX2 = $blSocW + $blSocX;
604 $pdf->SetTextColor(0, 0, 0);
605 $pdf->SetFont(
'',
'B', $default_font_size - 3);
606 $pdf->SetXY($blSocX, $blSocY + 1);
607 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
608 $pdf->SetTextColor(0, 0, 0);
611 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
613 $pdf->SetFont(
'',
'', $default_font_size - 3);
614 $pdf->SetXY($blSocX, $blSocY + 4);
615 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
618 if ($object->thirdparty->code_client) {
621 $pdf->SetXY($Xoff, $posy);
622 $pdf->SetTextColor(0, 0, 0);
623 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
628 $pdf->SetXY($blSocX - 80, $blSocY + 17);
630 $pdf->SetFont(
'',
'B', $default_font_size - 3);
631 $pdf->SetTextColor(0, 0, 0);
632 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
634 $pdf->SetXY($blSocX - 80, $blSocY + 20);
635 $pdf->SetFont(
'',
'B', $default_font_size - 3);
636 $pdf->SetTextColor(0, 0, 0);
637 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".$object->tracking_number,
'',
'L');
640 $pdf->SetXY($blSocX - 80, $blSocY + 23);
641 $pdf->SetFont(
'',
'', $default_font_size - 3);
642 $pdf->SetTextColor(0, 0, 0);
644 if (!empty($object->tracking_number)) {
645 $object->getUrlTrackingStatus($object->tracking_number);
646 if (!empty($object->tracking_url)) {
647 if ($object->shipping_method_id > 0) {
649 $code = $outputlangs->getLabelFromKey($this->
db, $object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
652 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
654 if ($object->tracking_url != $object->tracking_number) {
656 $label .= $object->tracking_url;
658 $pdf->SetFont(
'',
'B', $default_font_size - 3);
659 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
663 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
669 $blExpX = $Xoff - 20;
672 $pdf->Rect($blExpX, $Yoff, $blW, 26);
674 $object->fetch_thirdparty();
678 $arrayidcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
679 if (count($arrayidcontact) > 0) {
681 $result = $object->fetch_contact($arrayidcontact[0]);
685 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)))) {
686 $thirdparty = $object->contact;
688 $thirdparty = $object->thirdparty;
693 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'targetwithdetails', $object);
695 $blDestX = $blExpX + 55;
712 $pdf->SetFont(
'',
'B', $default_font_size - 3);
713 $pdf->SetXY($blDestX, $Yoff - 4);
714 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
715 $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
718 $pdf->SetFont(
'',
'B', $default_font_size - 3);
719 $pdf->SetXY($blDestX, $Yoff);
720 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
722 $posy = $pdf->getY();
725 $pdf->SetFont(
'',
'', $default_font_size - 3);
726 $pdf->SetXY($blDestX, $posy);
727 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');