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;
428 if (!empty($conf->global->MAIN_UMASK)) {
429 @chmod($file, octdec($conf->global->MAIN_UMASK));
432 $this->result = array(
'fullpath'=>$file);
436 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
440 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
458 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
464 $langs->loadLangs(array(
"main",
"bills",
"orders"));
466 if (empty($hidetop)) {
467 $pdf->SetFont(
'',
'B', $default_font_size - 2);
468 $pdf->SetXY(10, $tab_top);
469 $pdf->MultiCell(10, 5,
"LS", 0,
'C', 1);
470 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
471 $pdf->SetXY(20, $tab_top);
472 $pdf->MultiCell(10, 5,
"LR", 0,
'C', 1);
473 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
474 $pdf->SetXY(30, $tab_top);
475 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C', 1);
476 $pdf->SetXY(50, $tab_top);
477 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 1);
478 $pdf->SetXY(140, $tab_top);
479 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C', 1);
480 $pdf->SetXY(170, $tab_top);
481 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C', 1);
483 $pdf->Rect(10, $tab_top, 190, $tab_height);
496 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
499 $pdf->SetFont(
'',
'', $default_font_size - 2);
501 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"GoodStatusDeclaration"), 0,
'L');
503 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ToAndDate"), 0,
'C');
504 $pdf->SetXY(120, -23);
505 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"NameAndSignature"), 0,
'C');
525 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
527 global $conf, $langs, $hookmanager;
534 if ($object->statut == 0 && (!empty($conf->global->SENDING_DRAFT_WATERMARK))) {
535 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
538 $posy = $this->marge_haute;
539 $posx = $this->page_largeur - $this->marge_droite - 100;
551 if ($this->emetteur->logo) {
552 $logodir = $conf->mycompany->dir_output;
553 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
554 $logodir = $conf->mycompany->multidir_output[$object->entity];
557 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
559 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
561 if (is_readable($logo)) {
563 $pdf->Image($logo, 10, 5, 0, $height);
565 $pdf->SetTextColor(200, 0, 0);
566 $pdf->SetFont(
'',
'B', $default_font_size - 2);
567 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
568 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
571 $text = $this->emetteur->name;
572 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
577 $pdf->SetXY($Xoff, 7);
578 $pdf->SetFont(
'',
'B', $default_font_size + 2);
579 $pdf->SetTextColor(0, 0, 0);
580 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
585 $pdf->SetXY($Xoff, $Yoff);
586 $pdf->SetFont(
'',
'', $default_font_size - 2);
587 $pdf->SetTextColor(0, 0, 0);
588 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset($object->ref),
'',
'R');
591 $origin = $object->origin;
592 $origin_id = $object->origin_id;
595 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size - 1);
603 $blSocX2 = $blSocW + $blSocX;
606 $pdf->SetTextColor(0, 0, 0);
607 $pdf->SetFont(
'',
'B', $default_font_size - 3);
608 $pdf->SetXY($blSocX, $blSocY + 1);
609 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
610 $pdf->SetTextColor(0, 0, 0);
613 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
615 $pdf->SetFont(
'',
'', $default_font_size - 3);
616 $pdf->SetXY($blSocX, $blSocY + 4);
617 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
620 if ($object->thirdparty->code_client) {
623 $pdf->SetXY($Xoff, $posy);
624 $pdf->SetTextColor(0, 0, 0);
625 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
630 $pdf->SetXY($blSocX - 80, $blSocY + 17);
632 $pdf->SetFont(
'',
'B', $default_font_size - 3);
633 $pdf->SetTextColor(0, 0, 0);
634 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
636 $pdf->SetXY($blSocX - 80, $blSocY + 20);
637 $pdf->SetFont(
'',
'B', $default_font_size - 3);
638 $pdf->SetTextColor(0, 0, 0);
639 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".$object->tracking_number,
'',
'L');
642 $pdf->SetXY($blSocX - 80, $blSocY + 23);
643 $pdf->SetFont(
'',
'', $default_font_size - 3);
644 $pdf->SetTextColor(0, 0, 0);
646 if (!empty($object->tracking_number)) {
647 $object->getUrlTrackingStatus($object->tracking_number);
648 if (!empty($object->tracking_url)) {
649 if ($object->shipping_method_id > 0) {
651 $code = $outputlangs->getLabelFromKey($this->
db, $object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
654 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
656 if ($object->tracking_url != $object->tracking_number) {
658 $label .= $object->tracking_url;
660 $pdf->SetFont(
'',
'B', $default_font_size - 3);
661 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
665 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
671 $blExpX = $Xoff - 20;
674 $pdf->Rect($blExpX, $Yoff, $blW, 26);
676 $object->fetch_thirdparty();
680 $arrayidcontact = $object->$origin->getIdContact(
'external',
'SHIPPING');
681 if (count($arrayidcontact) > 0) {
683 $result = $object->fetch_contact($arrayidcontact[0]);
687 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)))) {
688 $thirdparty = $object->contact;
690 $thirdparty = $object->thirdparty;
695 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'targetwithdetails', $object);
697 $blDestX = $blExpX + 55;
714 $pdf->SetFont(
'',
'B', $default_font_size - 3);
715 $pdf->SetXY($blDestX, $Yoff - 4);
716 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
717 $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
720 $pdf->SetFont(
'',
'B', $default_font_size - 3);
721 $pdf->SetXY($blDestX, $Yoff);
722 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
724 $posy = $pdf->getY();
727 $pdf->SetFont(
'',
'', $default_font_size - 3);
728 $pdf->SetXY($blDestX, $posy);
729 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
Class to manage Dolibarr database access.
Parent class of sending receipts models.
Class to manage Dolibarr users.
Class to build sending documents with model Merou.
__construct(DoliDB $db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file(&$object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.