124 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
127 global $user, $conf, $langs, $mysoc, $hookmanager;
131 if (!is_object($outputlangs)) {
132 $outputlangs = $langs;
136 $outputlangs->charset_output =
'ISO-8859-1';
140 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"deliveries",
"sendings",
"productbatch"));
142 if ($conf->expedition->dir_output) {
150 $this->expediteur = $mysoc;
153 $idcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
154 $this->destinataire =
new Contact($this->db);
155 if (!empty($idcontact[0])) {
156 $this->destinataire->fetch($idcontact[0]);
160 $idcontact =
$object->origin_object->getIdContact(
'internal',
'LIVREUR');
161 $this->livreur =
new User($this->db);
162 if (!empty($idcontact[0])) {
163 $this->livreur->fetch($idcontact[0]);
168 $dir = $conf->expedition->dir_output.
"/sending";
169 $file = $dir.
"/SPECIMEN.pdf";
172 $dir = $conf->expedition->dir_output.
"/sending/".$expref;
173 $file = $dir.
"/".$expref.
".pdf";
176 if (!file_exists($dir)) {
178 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
183 if (file_exists($dir)) {
185 if (!is_object($hookmanager)) {
186 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
189 $hookmanager->initHooks(array(
'pdfgeneration'));
190 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
192 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
194 $nblines = count(
$object->lines);
198 $heightforinfotot = 0;
200 $heightforfooter = $this->marge_basse + 8;
202 $heightforfooter += 6;
204 $pdf->SetAutoPageBreak(1, 0);
206 if (class_exists(
'TCPDF')) {
207 $pdf->setPrintHeader(
false);
208 $pdf->setPrintFooter(
false);
213 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
214 $tplidx = $pdf->importPage(1);
219 $pdf->SetDrawColor(128, 128, 128);
221 if (method_exists($pdf,
'AliasNbPages')) {
222 $pdf->AliasNbPages();
225 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
226 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
227 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
228 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
229 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
231 $pdf->SetCompression(
false);
235 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
241 $pdf->SetFont(
'',
'', $default_font_size - 3);
242 $pdf->MultiCell(0, 3,
'');
243 $pdf->SetTextColor(0, 0, 0);
246 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
248 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
251 if (!empty(
$object->note_public)) {
252 $pdf->SetFont(
'',
'', $default_font_size - 1);
254 $nexY = $pdf->GetY();
255 $height_note = $nexY - $tab_top;
258 $pdf->SetDrawColor(192, 192, 192);
259 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
261 $tab_height -= $height_note;
262 $tab_top = $nexY + 6;
268 $pdf->SetFillColor(240, 240, 240);
269 $pdf->SetTextColor(0, 0, 0);
270 $pdf->SetXY(10, $tab_top + 5);
272 $iniY = $tab_top + 7;
273 $curY = $tab_top + 7;
274 $nexY = $tab_top + 7;
278 for ($i = 0; $i < $num; $i++) {
280 $pdf->SetFont(
'',
'', $default_font_size - 3);
281 $pdf->SetTextColor(0, 0, 0);
283 $pdf->setTopMargin($tab_top_newpage);
284 $pdf->setPageOrientation(
'', 1, $heightforfooter);
285 $pageposbefore = $pdf->getPage();
290 $nexY = $pdf->GetY();
291 $pageposafter = $pdf->getPage();
292 $pdf->setPage($pageposbefore);
293 $pdf->setTopMargin($this->marge_haute);
294 $pdf->setPageOrientation(
'', 1, 0);
297 if ($pageposafter > $pageposbefore) {
298 $pdf->setPage($pageposafter);
299 $curY = $tab_top_newpage;
302 $pdf->SetFont(
'',
'', $default_font_size - 3);
305 $pdf->SetDrawColor(120, 120, 120);
306 $pdf->Rect(10 + 3, $curY, 3, 3);
307 $pdf->Rect(20 + 3, $curY, 3, 3);
310 $pdf->SetXY(30, $curY);
311 $pdf->SetFont(
'',
'B', $default_font_size - 3);
312 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset(
$object->lines[$i]->ref), 0,
'L', 0);
314 $pdf->SetXY(140, $curY);
315 $pdf->MultiCell(30, 3,
$object->lines[$i]->qty_asked, 0,
'C', 0);
317 $pdf->SetXY(170, $curY);
318 $pdf->MultiCell(30, 3,
$object->lines[$i]->qty_shipped, 0,
'C', 0);
322 $pdf->setPage($pageposafter);
323 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
325 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
326 $pdf->SetLineStyle(array(
'dash' => 0));
332 while ($pagenb < $pageposafter) {
333 $pdf->setPage($pagenb);
335 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
337 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
341 $pdf->setPage($pagenb);
342 $pdf->setPageOrientation(
'', 1, 0);
344 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
346 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
348 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
359 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
360 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
362 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
363 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
368 if (method_exists($pdf,
'AliasNbPages')) {
369 $pdf->AliasNbPages();
374 $pdf->Output($file,
'F');
377 if (!is_object($hookmanager)) {
378 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
381 $hookmanager->initHooks(array(
'pdfgeneration'));
382 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
384 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
386 $this->error = $hookmanager->error;
387 $this->errors = $hookmanager->errors;
392 $this->result = array(
'fullpath' => $file);
396 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
400 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
418 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
424 $langs->loadLangs(array(
"main",
"bills",
"orders"));
426 if (empty($hidetop)) {
427 $pdf->SetFont(
'',
'B', $default_font_size - 2);
428 $pdf->SetXY(10, $tab_top);
429 $pdf->MultiCell(10, 5,
"LS", 0,
'C', 1);
430 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
431 $pdf->SetXY(20, $tab_top);
432 $pdf->MultiCell(10, 5,
"LR", 0,
'C', 1);
433 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
434 $pdf->SetXY(30, $tab_top);
435 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C', 1);
436 $pdf->SetXY(50, $tab_top);
437 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 1);
438 $pdf->SetXY(140, $tab_top);
439 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C', 1);
440 $pdf->SetXY(170, $tab_top);
441 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C', 1);
443 $pdf->Rect(10, $tab_top, 190, $tab_height);
487 global $conf, $langs, $hookmanager;
495 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
498 $posy = $this->marge_haute;
499 $posx = $this->page_largeur - $this->marge_droite - 100;
511 if ($this->emetteur->logo) {
512 $logodir = $conf->mycompany->dir_output;
513 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
514 $logodir = $conf->mycompany->multidir_output[
$object->entity];
517 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
519 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
521 if (is_readable($logo)) {
523 $pdf->Image($logo, 10, 5, 0, $height);
525 $pdf->SetTextColor(200, 0, 0);
526 $pdf->SetFont(
'',
'B', $default_font_size - 2);
527 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
528 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
531 $text = $this->emetteur->name;
532 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
537 $pdf->SetXY($Xoff, 7);
538 $pdf->SetFont(
'',
'B', $default_font_size + 2);
539 $pdf->SetTextColor(0, 0, 0);
540 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
545 $pdf->SetXY($Xoff, $Yoff);
546 $pdf->SetFont(
'',
'', $default_font_size - 2);
547 $pdf->SetTextColor(0, 0, 0);
548 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
552 $origin_id =
$object->origin_id;
563 $blSocX2 = $blSocW + $blSocX;
566 $pdf->SetTextColor(0, 0, 0);
567 $pdf->SetFont(
'',
'B', $default_font_size - 3);
568 $pdf->SetXY($blSocX, $blSocY + 1);
569 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
570 $pdf->SetTextColor(0, 0, 0);
575 $pdf->SetFont(
'',
'', $default_font_size - 3);
576 $pdf->SetXY($blSocX, $blSocY + 4);
577 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
580 if (
$object->thirdparty->code_client) {
583 $pdf->SetXY($Xoff, $posy);
584 $pdf->SetTextColor(0, 0, 0);
585 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
590 $pdf->SetXY($blSocX - 80, $blSocY + 17);
592 $pdf->SetFont(
'',
'B', $default_font_size - 3);
593 $pdf->SetTextColor(0, 0, 0);
594 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date(
$object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
596 $pdf->SetXY($blSocX - 80, $blSocY + 20);
597 $pdf->SetFont(
'',
'B', $default_font_size - 3);
598 $pdf->SetTextColor(0, 0, 0);
599 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".
$object->tracking_number,
'',
'L');
602 $pdf->SetXY($blSocX - 80, $blSocY + 23);
603 $pdf->SetFont(
'',
'', $default_font_size - 3);
604 $pdf->SetTextColor(0, 0, 0);
606 if (!empty(
$object->tracking_number)) {
608 if (!empty(
$object->tracking_url)) {
609 if (
$object->shipping_method_id > 0) {
611 $code = $outputlangs->getLabelFromKey($this->db,
$object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
614 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
618 $label .=
$object->tracking_url;
620 $pdf->SetFont(
'',
'B', $default_font_size - 3);
621 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
625 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
631 $blExpX = $Xoff - 20;
634 $pdf->Rect($blExpX, $Yoff, $blW, 26);
640 $arrayidcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
641 if (count($arrayidcontact) > 0) {
643 $result =
$object->fetch_contact($arrayidcontact[0]);
647 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
648 $thirdparty =
$object->contact;
650 $thirdparty =
$object->thirdparty;
657 $blDestX = $blExpX + 55;
674 $pdf->SetFont(
'',
'B', $default_font_size - 3);
675 $pdf->SetXY($blDestX, $Yoff - 4);
676 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
677 $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
680 $pdf->SetFont(
'',
'B', $default_font_size - 3);
681 $pdf->SetXY($blDestX, $Yoff);
682 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
684 $posy = $pdf->getY();
687 $pdf->SetFont(
'',
'', $default_font_size - 3);
688 $pdf->SetXY($blDestX, $posy);
689 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');