139 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
142 global $user, $conf, $langs,
$mysoc, $hookmanager;
146 if (!is_object($outputlangs)) {
147 $outputlangs = $langs;
151 $outputlangs->charset_output =
'ISO-8859-1';
155 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"sendings",
"productbatch"));
157 if ($conf->expedition->dir_output) {
165 $this->expediteur =
$mysoc;
168 $idcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
169 $this->destinataire =
new Contact($this->db);
170 if (!empty($idcontact[0])) {
171 $this->destinataire->fetch($idcontact[0]);
175 $idcontact =
$object->origin_object->getIdContact(
'internal',
'LIVREUR');
176 $this->livreur =
new User($this->db);
177 if (!empty($idcontact[0])) {
178 $this->livreur->fetch($idcontact[0]);
183 $dir = $conf->expedition->dir_output.
"/sending";
184 $file = $dir.
"/SPECIMEN.pdf";
187 $dir = $conf->expedition->dir_output.
"/sending/".$expref;
188 $file = $dir.
"/".$expref.
".pdf";
191 if (!file_exists($dir)) {
193 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
198 if (file_exists($dir)) {
200 if (!is_object($hookmanager)) {
201 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
204 $hookmanager->initHooks(array(
'pdfgeneration'));
205 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
207 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
209 $nblines = count(
$object->lines);
213 $heightforinfotot = 0;
215 $heightforfooter = $this->marge_basse + 8;
217 $heightforfooter += 6;
219 $pdf->setAutoPageBreak(
true, 0);
221 if (class_exists(
'TCPDF')) {
222 $pdf->setPrintHeader(
false);
223 $pdf->setPrintFooter(
false);
228 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
229 $tplidx = $pdf->importPage(1);
234 $pdf->SetDrawColor(128, 128, 128);
236 if (method_exists($pdf,
'AliasNbPages')) {
237 $pdf->AliasNbPages();
240 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
241 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
242 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
243 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
244 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
246 $pdf->SetCompression(
false);
250 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
256 $pdf->SetFont(
'',
'', $default_font_size - 3);
257 $pdf->MultiCell(0, 3,
'');
258 $pdf->SetTextColor(0, 0, 0);
261 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
263 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
266 if (!empty(
$object->note_public)) {
267 $pdf->SetFont(
'',
'', $default_font_size - 1);
269 $nexY = $pdf->GetY();
270 $height_note = $nexY - $tab_top;
273 $pdf->SetDrawColor(192, 192, 192);
274 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
276 $tab_height -= $height_note;
277 $tab_top = $nexY + 6;
283 $pdf->SetFillColor(240, 240, 240);
284 $pdf->SetTextColor(0, 0, 0);
285 $pdf->SetXY(10, $tab_top + 5);
287 $iniY = $tab_top + 7;
288 $curY = $tab_top + 7;
289 $nexY = $tab_top + 7;
293 for ($i = 0; $i < $num; $i++) {
295 $pdf->SetFont(
'',
'', $default_font_size - 3);
296 $pdf->SetTextColor(0, 0, 0);
298 $pdf->setTopMargin($tab_top_newpage);
299 $pdf->setPageOrientation(
'',
true, $heightforfooter);
300 $pageposbefore = $pdf->getPage();
305 $nexY = $pdf->GetY();
306 $pageposafter = $pdf->getPage();
307 $pdf->setPage($pageposbefore);
308 $pdf->setTopMargin($this->marge_haute);
309 $pdf->setPageOrientation(
'',
true, 0);
312 if ($pageposafter > $pageposbefore) {
313 $pdf->setPage($pageposafter);
314 $curY = $tab_top_newpage;
317 $pdf->SetFont(
'',
'', $default_font_size - 3);
320 $pdf->SetDrawColor(120, 120, 120);
321 $pdf->Rect(10 + 3, $curY, 3, 3);
322 $pdf->Rect(20 + 3, $curY, 3, 3);
325 $pdf->SetXY(30, $curY);
326 $pdf->SetFont(
'',
'B', $default_font_size - 3);
327 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset(
$object->lines[$i]->ref), 0,
'L',
false);
330 $pdf->SetXY(140, $curY);
331 $pdf->MultiCell(30, 3, (
string)
$object->lines[$i]->qty_asked, 0,
'C',
false);
335 $pdf->SetXY(170, $curY);
336 $pdf->MultiCell(30, 3, (
string)
$object->lines[$i]->qty_shipped, 0,
'C',
false);
341 $pdf->setPage($pageposafter);
342 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
344 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
345 $pdf->SetLineStyle(array(
'dash' => 0));
351 while ($pagenb < $pageposafter) {
352 $pdf->setPage($pagenb);
354 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
356 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
360 $pdf->setPage($pagenb);
361 $pdf->setPageOrientation(
'',
true, 0);
363 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
365 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
367 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
378 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
379 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
381 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
382 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
387 if (method_exists($pdf,
'AliasNbPages')) {
388 $pdf->AliasNbPages();
393 $pdf->Output($file,
'F');
396 if (!is_object($hookmanager)) {
397 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
400 $hookmanager->initHooks(array(
'pdfgeneration'));
401 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
403 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
404 $this->warnings = $hookmanager->warnings;
406 $this->error = $hookmanager->error;
407 $this->errors = $hookmanager->errors;
414 $this->result = array(
'fullpath' => $file);
418 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
422 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
440 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
446 $langs->loadLangs(array(
"main",
"bills",
"orders"));
448 if (empty($hidetop)) {
449 $pdf->SetFont(
'',
'B', $default_font_size - 2);
450 $pdf->SetXY(10, $tab_top);
451 $pdf->MultiCell(10, 5,
"LS", 0,
'C',
true);
452 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
453 $pdf->SetXY(20, $tab_top);
454 $pdf->MultiCell(10, 5,
"LR", 0,
'C',
true);
455 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
456 $pdf->SetXY(30, $tab_top);
457 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C',
true);
458 $pdf->SetXY(50, $tab_top);
459 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L',
true);
461 $pdf->SetXY(140, $tab_top);
462 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C',
true);
465 $pdf->SetXY(170, $tab_top);
466 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C',
true);
469 $pdf->RoundedRect(10, $tab_top, 190, $tab_height, $this->corner_radius,
'1234',
'D');
513 global $conf, $langs, $hookmanager;
521 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
524 $posy = $this->marge_haute;
525 $posx = $this->page_largeur - $this->marge_droite - 100;
537 if ($this->emetteur->logo) {
538 $logodir = $conf->mycompany->dir_output;
539 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
540 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
543 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
545 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
547 if (is_readable($logo)) {
549 $pdf->Image($logo, 10, 5, 0, $height);
551 $pdf->SetTextColor(200, 0, 0);
552 $pdf->SetFont(
'',
'B', $default_font_size - 2);
553 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
554 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
557 $text = $this->emetteur->name;
558 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
563 $pdf->SetXY($Xoff, 7);
564 $pdf->SetFont(
'',
'B', $default_font_size + 2);
565 $pdf->SetTextColor(0, 0, 0);
566 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
571 $pdf->SetXY($Xoff, $Yoff);
572 $pdf->SetFont(
'',
'', $default_font_size - 2);
573 $pdf->SetTextColor(0, 0, 0);
574 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
578 $origin_id =
$object->origin_id;
589 $blSocX2 = $blSocW + $blSocX;
592 $pdf->SetTextColor(0, 0, 0);
593 $pdf->SetFont(
'',
'B', $default_font_size - 3);
594 $pdf->SetXY($blSocX, $blSocY + 1);
595 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
596 $pdf->SetTextColor(0, 0, 0);
601 $pdf->SetFont(
'',
'', $default_font_size - 3);
602 $pdf->SetXY($blSocX, $blSocY + 4);
603 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
606 if (
$object->thirdparty->code_client) {
609 $pdf->SetXY($Xoff, $posy);
610 $pdf->SetTextColor(0, 0, 0);
611 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
616 $pdf->SetXY($blSocX - 80, $blSocY + 17);
618 $pdf->SetFont(
'',
'B', $default_font_size - 3);
619 $pdf->SetTextColor(0, 0, 0);
620 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date(
$object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
622 $pdf->SetXY($blSocX - 80, $blSocY + 20);
623 $pdf->SetFont(
'',
'B', $default_font_size - 3);
624 $pdf->SetTextColor(0, 0, 0);
625 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".
$object->tracking_number,
'',
'L');
628 $pdf->SetXY($blSocX - 80, $blSocY + 23);
629 $pdf->SetFont(
'',
'', $default_font_size - 3);
630 $pdf->SetTextColor(0, 0, 0);
632 if (!empty(
$object->tracking_number)) {
634 if (!empty(
$object->tracking_url)) {
635 if (
$object->shipping_method_id > 0) {
637 $code = $outputlangs->getLabelFromKey($this->db, (
string)
$object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
640 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
644 $label .=
$object->tracking_url;
646 $pdf->SetFont(
'',
'B', $default_font_size - 3);
647 $pdf->writeHTMLCell(50, 8,
null,
null, $label, 0, 1,
false,
true,
'L');
651 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
657 $blExpX = $Xoff - 20;
660 $pdf->RoundedRect($blExpX, $Yoff, $blW, 26, $this->corner_radius,
'1234',
'D');
666 $arrayidcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
667 if (count($arrayidcontact) > 0) {
669 $result =
$object->fetch_contact($arrayidcontact[0]);
673 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
674 $thirdparty =
$object->contact;
676 $thirdparty =
$object->thirdparty;
683 $blDestX = $blExpX + 55;
700 $pdf->SetFont(
'',
'B', $default_font_size - 3);
701 $pdf->SetXY($blDestX, $Yoff - 4);
702 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
703 $pdf->RoundedRect($blDestX, $Yoff - 1, $blW, 26, $this->corner_radius,
'1234',
'D');
706 $pdf->SetFont(
'',
'B', $default_font_size - 3);
707 $pdf->SetXY($blDestX, $Yoff);
708 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
710 $posy = $pdf->getY();
713 $pdf->SetFont(
'',
'', $default_font_size - 3);
714 $pdf->SetXY($blDestX, $posy);
715 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');