130 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
133 global $user,
$conf, $langs, $mysoc, $hookmanager;
137 if (!is_object($outputlangs)) {
138 $outputlangs = $langs;
142 $outputlangs->charset_output =
'ISO-8859-1';
146 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"deliveries",
"sendings",
"productbatch"));
148 if (
$conf->expedition->dir_output) {
156 $this->expediteur = $mysoc;
159 $idcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
160 $this->destinataire =
new Contact($this->db);
161 if (!empty($idcontact[0])) {
162 $this->destinataire->fetch($idcontact[0]);
166 $idcontact =
$object->origin_object->getIdContact(
'internal',
'LIVREUR');
167 $this->livreur =
new User($this->db);
168 if (!empty($idcontact[0])) {
169 $this->livreur->fetch($idcontact[0]);
174 $dir =
$conf->expedition->dir_output.
"/sending";
175 $file = $dir.
"/SPECIMEN.pdf";
178 $dir =
$conf->expedition->dir_output.
"/sending/".$expref;
179 $file = $dir.
"/".$expref.
".pdf";
182 if (!file_exists($dir)) {
184 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
189 if (file_exists($dir)) {
191 if (!is_object($hookmanager)) {
192 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
195 $hookmanager->initHooks(array(
'pdfgeneration'));
196 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
198 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
200 $nblines = count(
$object->lines);
204 $heightforinfotot = 0;
206 $heightforfooter = $this->marge_basse + 8;
208 $heightforfooter += 6;
210 $pdf->SetAutoPageBreak(1, 0);
212 if (class_exists(
'TCPDF')) {
213 $pdf->setPrintHeader(
false);
214 $pdf->setPrintFooter(
false);
219 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
220 $tplidx = $pdf->importPage(1);
225 $pdf->SetDrawColor(128, 128, 128);
227 if (method_exists($pdf,
'AliasNbPages')) {
228 $pdf->AliasNbPages();
231 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
232 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
233 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
234 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
235 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
237 $pdf->SetCompression(
false);
241 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
247 $pdf->SetFont(
'',
'', $default_font_size - 3);
248 $pdf->MultiCell(0, 3,
'');
249 $pdf->SetTextColor(0, 0, 0);
252 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
254 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
257 if (!empty(
$object->note_public)) {
258 $pdf->SetFont(
'',
'', $default_font_size - 1);
260 $nexY = $pdf->GetY();
261 $height_note = $nexY - $tab_top;
264 $pdf->SetDrawColor(192, 192, 192);
265 $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');
267 $tab_height -= $height_note;
268 $tab_top = $nexY + 6;
274 $pdf->SetFillColor(240, 240, 240);
275 $pdf->SetTextColor(0, 0, 0);
276 $pdf->SetXY(10, $tab_top + 5);
278 $iniY = $tab_top + 7;
279 $curY = $tab_top + 7;
280 $nexY = $tab_top + 7;
284 for ($i = 0; $i < $num; $i++) {
286 $pdf->SetFont(
'',
'', $default_font_size - 3);
287 $pdf->SetTextColor(0, 0, 0);
289 $pdf->setTopMargin($tab_top_newpage);
290 $pdf->setPageOrientation(
'', 1, $heightforfooter);
291 $pageposbefore = $pdf->getPage();
296 $nexY = $pdf->GetY();
297 $pageposafter = $pdf->getPage();
298 $pdf->setPage($pageposbefore);
299 $pdf->setTopMargin($this->marge_haute);
300 $pdf->setPageOrientation(
'', 1, 0);
303 if ($pageposafter > $pageposbefore) {
304 $pdf->setPage($pageposafter);
305 $curY = $tab_top_newpage;
308 $pdf->SetFont(
'',
'', $default_font_size - 3);
311 $pdf->SetDrawColor(120, 120, 120);
312 $pdf->Rect(10 + 3, $curY, 3, 3);
313 $pdf->Rect(20 + 3, $curY, 3, 3);
316 $pdf->SetXY(30, $curY);
317 $pdf->SetFont(
'',
'B', $default_font_size - 3);
318 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset(
$object->lines[$i]->ref), 0,
'L', 0);
320 $pdf->SetXY(140, $curY);
321 $pdf->MultiCell(30, 3,
$object->lines[$i]->qty_asked, 0,
'C', 0);
323 $pdf->SetXY(170, $curY);
324 $pdf->MultiCell(30, 3,
$object->lines[$i]->qty_shipped, 0,
'C', 0);
328 $pdf->setPage($pageposafter);
329 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
331 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
332 $pdf->SetLineStyle(array(
'dash' => 0));
338 while ($pagenb < $pageposafter) {
339 $pdf->setPage($pagenb);
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);
347 $pdf->setPage($pagenb);
348 $pdf->setPageOrientation(
'', 1, 0);
350 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
352 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
354 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
365 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
366 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
368 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
369 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
374 if (method_exists($pdf,
'AliasNbPages')) {
375 $pdf->AliasNbPages();
380 $pdf->Output($file,
'F');
383 if (!is_object($hookmanager)) {
384 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
387 $hookmanager->initHooks(array(
'pdfgeneration'));
388 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
390 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
392 $this->error = $hookmanager->error;
393 $this->errors = $hookmanager->errors;
398 $this->result = array(
'fullpath' => $file);
402 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
406 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
424 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
430 $langs->loadLangs(array(
"main",
"bills",
"orders"));
432 if (empty($hidetop)) {
433 $pdf->SetFont(
'',
'B', $default_font_size - 2);
434 $pdf->SetXY(10, $tab_top);
435 $pdf->MultiCell(10, 5,
"LS", 0,
'C', 1);
436 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
437 $pdf->SetXY(20, $tab_top);
438 $pdf->MultiCell(10, 5,
"LR", 0,
'C', 1);
439 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
440 $pdf->SetXY(30, $tab_top);
441 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C', 1);
442 $pdf->SetXY(50, $tab_top);
443 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 1);
444 $pdf->SetXY(140, $tab_top);
445 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C', 1);
446 $pdf->SetXY(170, $tab_top);
447 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C', 1);
449 $pdf->RoundedRect(10, $tab_top, 190, $tab_height, $this->corner_radius,
'1234',
'D');
493 global
$conf, $langs, $hookmanager;
501 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
$conf->global->SENDING_DRAFT_WATERMARK);
504 $posy = $this->marge_haute;
505 $posx = $this->page_largeur - $this->marge_droite - 100;
517 if ($this->emetteur->logo) {
518 $logodir =
$conf->mycompany->dir_output;
519 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
520 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
523 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
525 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
527 if (is_readable($logo)) {
529 $pdf->Image($logo, 10, 5, 0, $height);
531 $pdf->SetTextColor(200, 0, 0);
532 $pdf->SetFont(
'',
'B', $default_font_size - 2);
533 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
534 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
537 $text = $this->emetteur->name;
538 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
543 $pdf->SetXY($Xoff, 7);
544 $pdf->SetFont(
'',
'B', $default_font_size + 2);
545 $pdf->SetTextColor(0, 0, 0);
546 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
551 $pdf->SetXY($Xoff, $Yoff);
552 $pdf->SetFont(
'',
'', $default_font_size - 2);
553 $pdf->SetTextColor(0, 0, 0);
554 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
558 $origin_id =
$object->origin_id;
569 $blSocX2 = $blSocW + $blSocX;
572 $pdf->SetTextColor(0, 0, 0);
573 $pdf->SetFont(
'',
'B', $default_font_size - 3);
574 $pdf->SetXY($blSocX, $blSocY + 1);
575 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
576 $pdf->SetTextColor(0, 0, 0);
581 $pdf->SetFont(
'',
'', $default_font_size - 3);
582 $pdf->SetXY($blSocX, $blSocY + 4);
583 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
586 if (
$object->thirdparty->code_client) {
589 $pdf->SetXY($Xoff, $posy);
590 $pdf->SetTextColor(0, 0, 0);
591 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
596 $pdf->SetXY($blSocX - 80, $blSocY + 17);
598 $pdf->SetFont(
'',
'B', $default_font_size - 3);
599 $pdf->SetTextColor(0, 0, 0);
600 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date(
$object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
602 $pdf->SetXY($blSocX - 80, $blSocY + 20);
603 $pdf->SetFont(
'',
'B', $default_font_size - 3);
604 $pdf->SetTextColor(0, 0, 0);
605 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".
$object->tracking_number,
'',
'L');
608 $pdf->SetXY($blSocX - 80, $blSocY + 23);
609 $pdf->SetFont(
'',
'', $default_font_size - 3);
610 $pdf->SetTextColor(0, 0, 0);
612 if (!empty(
$object->tracking_number)) {
614 if (!empty(
$object->tracking_url)) {
615 if (
$object->shipping_method_id > 0) {
617 $code = $outputlangs->getLabelFromKey($this->db,
$object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
620 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
624 $label .=
$object->tracking_url;
626 $pdf->SetFont(
'',
'B', $default_font_size - 3);
627 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
631 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
637 $blExpX = $Xoff - 20;
640 $pdf->RoundedRect($blExpX, $Yoff, $blW, 26, $this->corner_radius,
'1234',
'D');
646 $arrayidcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
647 if (count($arrayidcontact) > 0) {
649 $result =
$object->fetch_contact($arrayidcontact[0]);
653 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
654 $thirdparty =
$object->contact;
656 $thirdparty =
$object->thirdparty;
663 $blDestX = $blExpX + 55;
680 $pdf->SetFont(
'',
'B', $default_font_size - 3);
681 $pdf->SetXY($blDestX, $Yoff - 4);
682 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
683 $pdf->RoundedRect($blDestX, $Yoff - 1, $blW, 26, $this->corner_radius,
'1234',
'D');
686 $pdf->SetFont(
'',
'B', $default_font_size - 3);
687 $pdf->SetXY($blDestX, $Yoff);
688 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
690 $posy = $pdf->getY();
693 $pdf->SetFont(
'',
'', $default_font_size - 3);
694 $pdf->SetXY($blDestX, $posy);
695 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');