123 public function write_file(&
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
126 global $user, $conf, $langs, $mysoc, $hookmanager;
130 if (!is_object($outputlangs)) {
131 $outputlangs = $langs;
135 $outputlangs->charset_output =
'ISO-8859-1';
139 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"propal",
"deliveries",
"sendings",
"productbatch"));
141 if ($conf->expedition->dir_output) {
149 $this->expediteur = $mysoc;
152 $idcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
153 $this->destinataire =
new Contact($this->db);
154 if (!empty($idcontact[0])) {
155 $this->destinataire->fetch($idcontact[0]);
159 $idcontact =
$object->origin_object->getIdContact(
'internal',
'LIVREUR');
160 $this->livreur =
new User($this->db);
161 if (!empty($idcontact[0])) {
162 $this->livreur->fetch($idcontact[0]);
167 $dir = $conf->expedition->dir_output.
"/sending";
168 $file = $dir.
"/SPECIMEN.pdf";
171 $dir = $conf->expedition->dir_output.
"/sending/".$expref;
172 $file = $dir.
"/".$expref.
".pdf";
175 if (!file_exists($dir)) {
177 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
182 if (file_exists($dir)) {
184 if (!is_object($hookmanager)) {
185 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
188 $hookmanager->initHooks(array(
'pdfgeneration'));
189 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
191 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
193 $nblines = count(
$object->lines);
197 $heightforinfotot = 0;
198 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
199 $heightforfooter = $this->marge_basse + 8;
201 $heightforfooter += 6;
203 $pdf->SetAutoPageBreak(1, 0);
205 if (class_exists(
'TCPDF')) {
206 $pdf->setPrintHeader(
false);
207 $pdf->setPrintFooter(
false);
212 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
213 $tplidx = $pdf->importPage(1);
218 $pdf->SetDrawColor(128, 128, 128);
220 if (method_exists($pdf,
'AliasNbPages')) {
221 $pdf->AliasNbPages();
224 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
225 $pdf->SetSubject($outputlangs->transnoentities(
"Shipment"));
226 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
227 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
228 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Shipment"));
230 $pdf->SetCompression(
false);
234 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
240 $pdf->SetFont(
'',
'', $default_font_size - 3);
241 $pdf->MultiCell(0, 3,
'');
242 $pdf->SetTextColor(0, 0, 0);
245 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
247 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
250 if (!empty(
$object->note_public)) {
251 $pdf->SetFont(
'',
'', $default_font_size - 1);
253 $nexY = $pdf->GetY();
254 $height_note = $nexY - $tab_top;
257 $pdf->SetDrawColor(192, 192, 192);
258 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
260 $tab_height = $tab_height - $height_note;
261 $tab_top = $nexY + 6;
267 $pdf->SetFillColor(240, 240, 240);
268 $pdf->SetTextColor(0, 0, 0);
269 $pdf->SetXY(10, $tab_top + 5);
271 $iniY = $tab_top + 7;
272 $curY = $tab_top + 7;
273 $nexY = $tab_top + 7;
277 for ($i = 0; $i < $num; $i++) {
279 $pdf->SetFont(
'',
'', $default_font_size - 3);
280 $pdf->SetTextColor(0, 0, 0);
282 $pdf->setTopMargin($tab_top_newpage);
283 $pdf->setPageOrientation(
'', 1, $heightforfooter);
284 $pageposbefore = $pdf->getPage();
289 $nexY = $pdf->GetY();
290 $pageposafter = $pdf->getPage();
291 $pdf->setPage($pageposbefore);
292 $pdf->setTopMargin($this->marge_haute);
293 $pdf->setPageOrientation(
'', 1, 0);
296 if ($pageposafter > $pageposbefore) {
297 $pdf->setPage($pageposafter);
298 $curY = $tab_top_newpage;
301 $pdf->SetFont(
'',
'', $default_font_size - 3);
304 $pdf->SetDrawColor(120, 120, 120);
305 $pdf->Rect(10 + 3, $curY, 3, 3);
306 $pdf->Rect(20 + 3, $curY, 3, 3);
309 $pdf->SetXY(30, $curY);
310 $pdf->SetFont(
'',
'B', $default_font_size - 3);
311 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset(
$object->lines[$i]->ref), 0,
'L', 0);
313 $pdf->SetXY(140, $curY);
314 $pdf->MultiCell(30, 3,
$object->lines[$i]->qty_asked, 0,
'C', 0);
316 $pdf->SetXY(170, $curY);
317 $pdf->MultiCell(30, 3,
$object->lines[$i]->qty_shipped, 0,
'C', 0);
321 $pdf->setPage($pageposafter);
322 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
324 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
325 $pdf->SetLineStyle(array(
'dash' => 0));
331 while ($pagenb < $pageposafter) {
332 $pdf->setPage($pagenb);
334 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
336 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
340 $pdf->setPage($pagenb);
341 $pdf->setPageOrientation(
'', 1, 0);
343 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
345 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
347 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
358 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
359 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
361 $this->
_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
362 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
367 if (method_exists($pdf,
'AliasNbPages')) {
368 $pdf->AliasNbPages();
373 $pdf->Output($file,
'F');
376 if (!is_object($hookmanager)) {
377 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
380 $hookmanager->initHooks(array(
'pdfgeneration'));
381 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
383 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
385 $this->error = $hookmanager->error;
386 $this->errors = $hookmanager->errors;
391 $this->result = array(
'fullpath' => $file);
395 $this->error = $outputlangs->transnoentities(
"ErrorCanNotCreateDir", $dir);
399 $this->error = $outputlangs->transnoentities(
"ErrorConstantNotDefined",
"EXP_OUTPUTDIR");
417 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
423 $langs->loadLangs(array(
"main",
"bills",
"orders"));
425 if (empty($hidetop)) {
426 $pdf->SetFont(
'',
'B', $default_font_size - 2);
427 $pdf->SetXY(10, $tab_top);
428 $pdf->MultiCell(10, 5,
"LS", 0,
'C', 1);
429 $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
430 $pdf->SetXY(20, $tab_top);
431 $pdf->MultiCell(10, 5,
"LR", 0,
'C', 1);
432 $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
433 $pdf->SetXY(30, $tab_top);
434 $pdf->MultiCell(20, 5, $outputlangs->transnoentities(
"Ref"), 0,
'C', 1);
435 $pdf->SetXY(50, $tab_top);
436 $pdf->MultiCell(90, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 1);
437 $pdf->SetXY(140, $tab_top);
438 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyOrdered"), 0,
'C', 1);
439 $pdf->SetXY(170, $tab_top);
440 $pdf->MultiCell(30, 5, $outputlangs->transnoentities(
"QtyToShip"), 0,
'C', 1);
442 $pdf->Rect(10, $tab_top, 190, $tab_height);
486 global $conf, $langs, $hookmanager;
494 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->SENDING_DRAFT_WATERMARK);
497 $posy = $this->marge_haute;
498 $posx = $this->page_largeur - $this->marge_droite - 100;
510 if ($this->emetteur->logo) {
511 $logodir = $conf->mycompany->dir_output;
512 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
513 $logodir = $conf->mycompany->multidir_output[
$object->entity];
516 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
518 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
520 if (is_readable($logo)) {
522 $pdf->Image($logo, 10, 5, 0, $height);
524 $pdf->SetTextColor(200, 0, 0);
525 $pdf->SetFont(
'',
'B', $default_font_size - 2);
526 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
527 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
530 $text = $this->emetteur->name;
531 $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0,
'L');
536 $pdf->SetXY($Xoff, 7);
537 $pdf->SetFont(
'',
'B', $default_font_size + 2);
538 $pdf->SetTextColor(0, 0, 0);
539 $pdf->MultiCell(0, 3, $outputlangs->transnoentities(
"SendingSheet"),
'',
'L');
544 $pdf->SetXY($Xoff, $Yoff);
545 $pdf->SetFont(
'',
'', $default_font_size - 2);
546 $pdf->SetTextColor(0, 0, 0);
547 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"RefSending").
': '.$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
551 $origin_id =
$object->origin_id;
562 $blSocX2 = $blSocW + $blSocX;
565 $pdf->SetTextColor(0, 0, 0);
566 $pdf->SetFont(
'',
'B', $default_font_size - 3);
567 $pdf->SetXY($blSocX, $blSocY + 1);
568 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
569 $pdf->SetTextColor(0, 0, 0);
574 $pdf->SetFont(
'',
'', $default_font_size - 3);
575 $pdf->SetXY($blSocX, $blSocY + 4);
576 $pdf->MultiCell(80, 2, $carac_emetteur, 0,
'L');
579 if (
$object->thirdparty->code_client) {
582 $pdf->SetXY($Xoff, $posy);
583 $pdf->SetTextColor(0, 0, 0);
584 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
589 $pdf->SetXY($blSocX - 80, $blSocY + 17);
591 $pdf->SetFont(
'',
'B', $default_font_size - 3);
592 $pdf->SetTextColor(0, 0, 0);
593 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date(
$object->date_delivery,
'day',
false, $outputlangs,
true),
'',
'L');
595 $pdf->SetXY($blSocX - 80, $blSocY + 20);
596 $pdf->SetFont(
'',
'B', $default_font_size - 3);
597 $pdf->SetTextColor(0, 0, 0);
598 $pdf->MultiCell(70, 8, $outputlangs->transnoentities(
"TrackingNumber").
" : ".
$object->tracking_number,
'',
'L');
601 $pdf->SetXY($blSocX - 80, $blSocY + 23);
602 $pdf->SetFont(
'',
'', $default_font_size - 3);
603 $pdf->SetTextColor(0, 0, 0);
605 if (!empty(
$object->tracking_number)) {
607 if (!empty(
$object->tracking_url)) {
608 if (
$object->shipping_method_id > 0) {
610 $code = $outputlangs->getLabelFromKey($this->db,
$object->shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
613 $label .= $outputlangs->trans(
"SendingMethod").
": ".$outputlangs->trans(
"SendingMethod".strtoupper($code));
617 $label .=
$object->tracking_url;
619 $pdf->SetFont(
'',
'B', $default_font_size - 3);
620 $pdf->writeHTMLCell(50, 8,
'',
'', $label,
'',
'L');
624 $pdf->MultiCell(50, 8, $outputlangs->transnoentities(
"Deliverer").
" ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)),
'',
'L');
630 $blExpX = $Xoff - 20;
633 $pdf->Rect($blExpX, $Yoff, $blW, 26);
639 $arrayidcontact =
$object->origin_object->getIdContact(
'external',
'SHIPPING');
640 if (count($arrayidcontact) > 0) {
642 $result =
$object->fetch_contact($arrayidcontact[0]);
646 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
647 $thirdparty =
$object->contact;
649 $thirdparty =
$object->thirdparty;
656 $blDestX = $blExpX + 55;
673 $pdf->SetFont(
'',
'B', $default_font_size - 3);
674 $pdf->SetXY($blDestX, $Yoff - 4);
675 $pdf->MultiCell($blW, 3, $outputlangs->transnoentities(
"Recipient"), 0,
'L');
676 $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
679 $pdf->SetFont(
'',
'B', $default_font_size - 3);
680 $pdf->SetXY($blDestX, $Yoff);
681 $pdf->MultiCell($blW, 3, $carac_client_name, 0,
'L');
683 $posy = $pdf->getY();
686 $pdf->SetFont(
'',
'', $default_font_size - 3);
687 $pdf->SetXY($blDestX, $posy);
688 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');