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",
"deliveries",
"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);
405 $this->error = $hookmanager->error;
406 $this->errors = $hookmanager->errors;
411 $this->result = array(
'fullpath' => $file);
415 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
419 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
437 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
443 $langs->loadLangs(array(
"main",
"bills",
"orders"));
445 if (empty($hidetop)) {
446 $pdf->SetFont(
'',
'B', $default_font_size - 2);
447 $pdf->SetXY(10, $tab_top);
448 $pdf->MultiCell(10, 5,
"LS", 0,
'C',
true);
449 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
450 $pdf->SetXY(20, $tab_top);
451 $pdf->MultiCell(10, 5,
"LR", 0,
'C',
true);
452 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
453 $pdf->SetXY(30, $tab_top);
454 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C',
true);
455 $pdf->SetXY(50, $tab_top);
456 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L',
true);
458 $pdf->SetXY(140, $tab_top);
459 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C',
true);
462 $pdf->SetXY(170, $tab_top);
463 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C',
true);
466 $pdf->RoundedRect(10, $tab_top, 190, $tab_height, $this->corner_radius,
'1234',
'D');
510 global
$conf, $langs, $hookmanager;
518 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
$conf->global->SENDING_DRAFT_WATERMARK);
521 $posy = $this->marge_haute;
522 $posx = $this->page_largeur - $this->marge_droite - 100;
534 if ($this->emetteur->logo) {
535 $logodir =
$conf->mycompany->dir_output;
536 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
537 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
540 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
542 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
544 if (is_readable($logo)) {
546 $pdf->Image($logo, 10, 5, 0, $height);
548 $pdf->SetTextColor(200, 0, 0);
549 $pdf->SetFont(
'',
'B', $default_font_size - 2);
550 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
551 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
554 $text = $this->emetteur->name;
555 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
560 $pdf->SetXY($Xoff, 7);
561 $pdf->SetFont(
'',
'B', $default_font_size + 2);
562 $pdf->SetTextColor(0, 0, 0);
563 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
568 $pdf->SetXY($Xoff, $Yoff);
569 $pdf->SetFont(
'',
'', $default_font_size - 2);
570 $pdf->SetTextColor(0, 0, 0);
571 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
575 $origin_id =
$object->origin_id;
586 $blSocX2 = $blSocW + $blSocX;
589 $pdf->SetTextColor(0, 0, 0);
590 $pdf->SetFont(
'',
'B', $default_font_size - 3);
591 $pdf->SetXY($blSocX, $blSocY + 1);
592 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
593 $pdf->SetTextColor(0, 0, 0);
598 $pdf->SetFont(
'',
'', $default_font_size - 3);
599 $pdf->SetXY($blSocX, $blSocY + 4);
600 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
603 if (
$object->thirdparty->code_client) {
606 $pdf->SetXY($Xoff, $posy);
607 $pdf->SetTextColor(0, 0, 0);
608 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
613 $pdf->SetXY($blSocX - 80, $blSocY + 17);
615 $pdf->SetFont(
'',
'B', $default_font_size - 3);
616 $pdf->SetTextColor(0, 0, 0);
617 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date(
$object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
619 $pdf->SetXY($blSocX - 80, $blSocY + 20);
620 $pdf->SetFont(
'',
'B', $default_font_size - 3);
621 $pdf->SetTextColor(0, 0, 0);
622 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".
$object->tracking_number,
'',
'L');
625 $pdf->SetXY($blSocX - 80, $blSocY + 23);
626 $pdf->SetFont(
'',
'', $default_font_size - 3);
627 $pdf->SetTextColor(0, 0, 0);
629 if (!empty(
$object->tracking_number)) {
631 if (!empty(
$object->tracking_url)) {
632 if (
$object->shipping_method_id > 0) {
634 $code = $outputlangs->getLabelFromKey($this->db, (
string)
$object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
637 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
641 $label .=
$object->tracking_url;
643 $pdf->SetFont(
'',
'B', $default_font_size - 3);
644 $pdf->writeHTMLCell(50, 8,
null,
null, $label, 0, 1,
false,
true,
'L');
648 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
654 $blExpX = $Xoff - 20;
657 $pdf->RoundedRect($blExpX, $Yoff, $blW, 26, $this->corner_radius,
'1234',
'D');
663 $arrayidcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
664 if (count($arrayidcontact) > 0) {
666 $result =
$object->fetch_contact($arrayidcontact[0]);
670 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
671 $thirdparty =
$object->contact;
673 $thirdparty =
$object->thirdparty;
680 $blDestX = $blExpX + 55;
697 $pdf->SetFont(
'',
'B', $default_font_size - 3);
698 $pdf->SetXY($blDestX, $Yoff - 4);
699 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
700 $pdf->RoundedRect($blDestX, $Yoff - 1, $blW, 26, $this->corner_radius,
'1234',
'D');
703 $pdf->SetFont(
'',
'B', $default_font_size - 3);
704 $pdf->SetXY($blDestX, $Yoff);
705 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
707 $posy = $pdf->getY();
710 $pdf->SetFont(
'',
'', $default_font_size - 3);
711 $pdf->SetXY($blDestX, $posy);
712 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');