Merge pull request #17428 from FHenry/13_fix_expadon_withlongnote
FIX: Espadon PDF shippment model with long public note now working
This commit is contained in:
commit
09d56e4abe
@ -274,6 +274,15 @@ class pdf_espadon extends ModelePdfExpedition
|
||||
if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6;
|
||||
$pdf->SetAutoPageBreak(1, 0);
|
||||
|
||||
// Create pdf instance
|
||||
/*$pdf = pdf_getInstance($this->format);
|
||||
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
|
||||
$pdf->SetAutoPageBreak(1, 0);
|
||||
|
||||
$heightforinfotot = 40; // Height reserved to output the info and total part
|
||||
$heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
|
||||
$heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
|
||||
*/
|
||||
if (class_exists('TCPDF'))
|
||||
{
|
||||
$pdf->setPrintHeader(false);
|
||||
@ -306,13 +315,13 @@ class pdf_espadon extends ModelePdfExpedition
|
||||
$pdf->AddPage();
|
||||
if (!empty($tplidx)) $pdf->useTemplate($tplidx);
|
||||
$pagenb++;
|
||||
$this->_pagehead($pdf, $object, 1, $outputlangs);
|
||||
$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
|
||||
$pdf->SetFont('', '', $default_font_size - 1);
|
||||
$pdf->MultiCell(0, 3, ''); // Set interline to 3
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
|
||||
$tab_top = 90;
|
||||
$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
|
||||
$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift: 10);
|
||||
$tab_height = 130;
|
||||
$tab_height_newpage = 150;
|
||||
|
||||
@ -351,62 +360,153 @@ class pdf_espadon extends ModelePdfExpedition
|
||||
$notetoshow = dol_concatdesc($notetoshow, $extranote);
|
||||
}
|
||||
|
||||
if (!empty($notetoshow) || !empty($object->tracking_number))
|
||||
{
|
||||
$tab_top = 88 + $height_incoterms;
|
||||
$tab_top_alt = $tab_top;
|
||||
|
||||
$pdf->SetFont('', 'B', $default_font_size - 2);
|
||||
$pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
|
||||
|
||||
$tab_top_alt = $pdf->GetY();
|
||||
//$tab_top_alt += 1;
|
||||
if (!empty($notetoshow) || !empty($object->tracking_number)) {
|
||||
$tab_top -= 2;
|
||||
|
||||
// Tracking number
|
||||
if (!empty($object->tracking_number))
|
||||
{
|
||||
if (!empty($object->tracking_number)) {
|
||||
$pdf->SetFont('', 'B', $default_font_size - 2);
|
||||
$pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber") . " : " . $object->tracking_number, 0, 1, false, true, 'L');
|
||||
|
||||
$tab_top_alt = $pdf->GetY();
|
||||
$object->getUrlTrackingStatus($object->tracking_number);
|
||||
if (!empty($object->tracking_url))
|
||||
{
|
||||
if ($object->shipping_method_id > 0)
|
||||
{
|
||||
if (!empty($object->tracking_url)) {
|
||||
if ($object->shipping_method_id > 0) {
|
||||
// Get code using getLabelFromKey
|
||||
$code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
|
||||
$label = '';
|
||||
if ($object->tracking_url != $object->tracking_number) $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
|
||||
$label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
|
||||
if ($object->tracking_url != $object->tracking_number) $label .= $outputlangs->trans("LinkToTrackYourPackage") . "<br>";
|
||||
$label .= $outputlangs->trans("SendingMethod") . ": " . $outputlangs->trans("SendingMethod" . strtoupper($code));
|
||||
//var_dump($object->tracking_url != $object->tracking_number);exit;
|
||||
if ($object->tracking_url != $object->tracking_number)
|
||||
{
|
||||
if ($object->tracking_url != $object->tracking_number) {
|
||||
$label .= " : ";
|
||||
$label .= $object->tracking_url;
|
||||
}
|
||||
$pdf->SetFont('', 'B', $default_font_size - 2);
|
||||
$pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
|
||||
|
||||
$tab_top_alt = $pdf->GetY();
|
||||
$tab_top = $pdf->GetY();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Notes
|
||||
$pagenb = $pdf->getPage();
|
||||
if (!empty($notetoshow))
|
||||
{
|
||||
$pdf->SetFont('', '', $default_font_size - 1); // In loop to manage multi-page
|
||||
$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($notetoshow), 0, 1);
|
||||
$tab_top -= 2;
|
||||
|
||||
$tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
|
||||
$pageposbeforenote = $pagenb;
|
||||
|
||||
$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
|
||||
$notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
|
||||
|
||||
$pdf->startTransaction();
|
||||
|
||||
$pdf->SetFont('', '', $default_font_size - 1);
|
||||
$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
|
||||
// Description
|
||||
$pageposafternote = $pdf->getPage();
|
||||
$posyafter = $pdf->GetY();
|
||||
|
||||
if ($pageposafternote > $pageposbeforenote)
|
||||
{
|
||||
$pdf->rollbackTransaction(true);
|
||||
|
||||
// prepare pages to receive notes
|
||||
while ($pagenb < $pageposafternote) {
|
||||
$pdf->AddPage();
|
||||
$pagenb++;
|
||||
if (!empty($tplidx)) $pdf->useTemplate($tplidx);
|
||||
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
|
||||
// $this->_pagefoot($pdf,$object,$outputlangs,1);
|
||||
$pdf->setTopMargin($tab_top_newpage);
|
||||
// The only function to edit the bottom margin of current page to set it.
|
||||
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
|
||||
}
|
||||
|
||||
// back to start
|
||||
$pdf->setPage($pageposbeforenote);
|
||||
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
|
||||
$pdf->SetFont('', '', $default_font_size - 1);
|
||||
$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
|
||||
$pageposafternote = $pdf->getPage();
|
||||
|
||||
$posyafter = $pdf->GetY();
|
||||
|
||||
if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) // There is no space left for total+free text
|
||||
{
|
||||
$pdf->AddPage('', '', true);
|
||||
$pagenb++;
|
||||
$pageposafternote++;
|
||||
$pdf->setPage($pageposafternote);
|
||||
$pdf->setTopMargin($tab_top_newpage);
|
||||
// The only function to edit the bottom margin of current page to set it.
|
||||
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
|
||||
//$posyafter = $tab_top_newpage;
|
||||
}
|
||||
|
||||
|
||||
// apply note frame to previous pages
|
||||
$i = $pageposbeforenote;
|
||||
while ($i < $pageposafternote) {
|
||||
$pdf->setPage($i);
|
||||
|
||||
|
||||
$pdf->SetDrawColor(128, 128, 128);
|
||||
// Draw note frame
|
||||
if ($i > $pageposbeforenote) {
|
||||
$height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
|
||||
$pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
|
||||
} else {
|
||||
$height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
|
||||
$pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
|
||||
}
|
||||
|
||||
// Add footer
|
||||
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
|
||||
$this->_pagefoot($pdf, $object, $outputlangs, 1);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// apply note frame to last page
|
||||
$pdf->setPage($pageposafternote);
|
||||
if (!empty($tplidx)) $pdf->useTemplate($tplidx);
|
||||
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
|
||||
$height_note = $posyafter - $tab_top_newpage;
|
||||
$pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
|
||||
} else // No pagebreak
|
||||
{
|
||||
$pdf->commitTransaction();
|
||||
$posyafter = $pdf->GetY();
|
||||
$height_note = $posyafter - $tab_top;
|
||||
$pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
|
||||
|
||||
|
||||
if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))
|
||||
{
|
||||
// not enough space, need to add page
|
||||
$pdf->AddPage('', '', true);
|
||||
$pagenb++;
|
||||
$pageposafternote++;
|
||||
$pdf->setPage($pageposafternote);
|
||||
if (!empty($tplidx)) $pdf->useTemplate($tplidx);
|
||||
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
|
||||
|
||||
$posyafter = $tab_top_newpage;
|
||||
}
|
||||
}
|
||||
|
||||
$tab_height = $tab_height - $height_note;
|
||||
$tab_top = $posyafter + 6;
|
||||
} else {
|
||||
$height_note = 0;
|
||||
}
|
||||
|
||||
$nexY = $pdf->GetY();
|
||||
$height_note = $nexY - $tab_top;
|
||||
|
||||
// Rect takes a length in 3rd parameter
|
||||
$pdf->SetDrawColor(192, 192, 192);
|
||||
$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
|
||||
|
||||
$tab_height = $tab_height - $height_note;
|
||||
$tab_top = $nexY + 6;
|
||||
} else {
|
||||
$height_note = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -415,13 +515,15 @@ class pdf_espadon extends ModelePdfExpedition
|
||||
|
||||
// Table simulation to know the height of the title line
|
||||
$pdf->startTransaction();
|
||||
$this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
|
||||
$this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
|
||||
$pdf->rollbackTransaction(true);
|
||||
|
||||
|
||||
$nexY = $tab_top + $this->tabTitleHeight;
|
||||
|
||||
// Loop on each lines
|
||||
$pageposbeforeprintlines = $pdf->getPage();
|
||||
$pagenb = $pageposbeforeprintlines;
|
||||
for ($i = 0; $i < $nblines; $i++)
|
||||
{
|
||||
$curY = $nexY;
|
||||
@ -590,7 +692,7 @@ class pdf_espadon extends ModelePdfExpedition
|
||||
while ($pagenb < $pageposafter)
|
||||
{
|
||||
$pdf->setPage($pagenb);
|
||||
if ($pagenb == 1)
|
||||
if ($pagenb == $pageposbeforeprintlines)
|
||||
{
|
||||
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user