Fix page break when using a large html footer.

This commit is contained in:
Laurent Destailleur 2016-07-28 23:58:13 +02:00
parent 74a9bbbf38
commit 5d97ce038b
3 changed files with 45 additions and 31 deletions

View File

@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
/**
* Classe permettant de generer les commandes au modele Einstein
* Classe to generate PDF orders with template Einstein
*/
class pdf_einstein extends ModelePDFCommandes
{
@ -173,7 +173,7 @@ class pdf_einstein extends ModelePDFCommandes
{
$object->fetch_thirdparty();
$deja_regle = "";
$deja_regle = 0;
// Definition of $dir and $file
if ($object->specimen)
@ -213,11 +213,12 @@ class pdf_einstein extends ModelePDFCommandes
// Create pdf instance
$pdf=pdf_getInstance($this->format);
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
$heightforinfotot = 50; // Height reserved to output the info and total part
$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 + 8; // Height reserved to output the footer (value include bottom margin)
$pdf->SetAutoPageBreak(1,0);
if (class_exists('TCPDF'))
{
$pdf->setPrintHeader(false);
@ -552,11 +553,13 @@ class pdf_einstein extends ModelePDFCommandes
$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
// Affiche zone versements
/*
if ($deja_regle)
{
$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
}
*/
// Pied de page
$this->_pagefoot($pdf,$object,$outputlangs);
if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();

View File

@ -251,15 +251,17 @@ class pdf_crabe extends ModelePDFFactures
// Set nblignes with the new facture lines content after hook
$nblignes = count($object->lines);
$nbpayments = count($object->getListOfPayments());
// Create pdf instance
$pdf=pdf_getInstance($this->format);
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
$heightforinfotot = 50; // Height reserved to output the info and total part
$pdf->SetAutoPageBreak(1,0);
$heightforinfotot = 50+(4*$nbpayments); // Height reserved to output the info and total part and payment 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 + 8; // Height reserved to output the footer (value include bottom margin)
$pdf->SetAutoPageBreak(1,0);
if (class_exists('TCPDF'))
{
$pdf->setPrintHeader(false);
@ -746,6 +748,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetFont('','', $default_font_size - 4);
// Loop on each deposits and credit notes included
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
$sql.= " re.description, re.fk_facture_source,";
@ -790,12 +793,15 @@ class pdf_crabe extends ModelePDFFactures
}
// Loop on each payment
$sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,";
// TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
$sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount,";
$sql.= " cp.code";
$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
//$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
$sql.= " ORDER BY p.datep";
$resql=$this->db->query($sql);
if ($resql)
{

View File

@ -91,8 +91,8 @@ class pdf_azur extends ModelePDFPropales
$this->option_condreg = 1; // Affiche conditions reglement
$this->option_codeproduitservice = 1; // Affiche code produit-service
$this->option_multilang = 1; // Dispo en plusieurs langues
$this->option_escompte = 1; // Affiche si il y a eu escompte
$this->option_credit_note = 1; // Support credit notes
$this->option_escompte = 0; // Affiche si il y a eu escompte
$this->option_credit_note = 0; // Support credit notes
$this->option_freetext = 1; // Support add of a personalised text
$this->option_draft_watermark = 1; //Support add of a watermark on drafts
@ -230,7 +230,7 @@ class pdf_azur extends ModelePDFPropales
{
$object->fetch_thirdparty();
// $deja_regle = 0;
$deja_regle = 0;
// Definition of $dir and $file
if ($object->specimen)
@ -270,11 +270,8 @@ class pdf_azur extends ModelePDFPropales
// Create pdf instance
$pdf=pdf_getInstance($this->format);
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
$heightforinfotot = 50; // 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 + 8; // Height reserved to output the footer (value include bottom margin)
$pdf->SetAutoPageBreak(1,0);
$pdf->SetAutoPageBreak(1,0);
if (class_exists('TCPDF'))
{
$pdf->setPrintHeader(false);
@ -323,12 +320,20 @@ class pdf_azur extends ModelePDFPropales
$pdf->AddPage();
if (! empty($tplidx)) $pdf->useTemplate($tplidx);
$pagenb++;
$heightforinfotot = 40; // Height reserved to output the info and total part
$heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE)?(pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature"))+10):0;
$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 + 8; // Height reserved to output the footer (value include bottom margin)
//print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
$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 = 90;
$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
$tab_height = 130;
$tab_height_newpage = 150;
@ -406,7 +411,7 @@ class pdf_azur extends ModelePDFPropales
if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
$pdf->setTopMargin($tab_top_newpage);
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
$pageposbefore=$pdf->getPage();
$showpricebeforepagebreak=1;
@ -414,7 +419,7 @@ class pdf_azur extends ModelePDFPropales
$posYAfterDescription=0;
// We start with Photo of product line
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) // If photo too high, we moved completely on new page
{
$pdf->AddPage('','',true);
if (! empty($tplidx)) $pdf->useTemplate($tplidx);
@ -436,9 +441,10 @@ class pdf_azur extends ModelePDFPropales
// Description of product line
$curX = $this->posxdesc-1;
$showpricebeforepagebreak=1;
$pdf->startTransaction();
pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
$pageposafter=$pdf->getPage();
if ($pageposafter > $pageposbefore) // There is a pagebreak
{
@ -451,7 +457,7 @@ class pdf_azur extends ModelePDFPropales
$pageposafter=$pdf->getPage();
$posyafter=$pdf->GetY();
//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) // There is no space left for total+free text
{
if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
{
@ -624,13 +630,13 @@ class pdf_azur extends ModelePDFPropales
// Show square
if ($pagenb == 1)
{
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
}
else
{
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
}
// Affiche zone infos
@ -765,7 +771,7 @@ class pdf_azur extends ModelePDFPropales
/**
* Show payments table
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param Object $object Object proposal
* @param int $posy Position y in PDF
* @param Translate $outputlangs Object langs for output
@ -780,7 +786,7 @@ class pdf_azur extends ModelePDFPropales
/**
* Show miscellaneous information (payment mode, payment term, ...)
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param Object $object Object to show
* @param int $posy Y
* @param Translate $outputlangs Langs object
@ -1581,7 +1587,6 @@ class pdf_azur extends ModelePDFPropales
$default_font_size = pdf_getPDFFontSize($outputlangs);
$tab_top = $posy + 4;
$tab_hl = 4;
$pdf->SetFont('','', $default_font_size - 1);
$posx = 120;
$largcol = ($this->page_largeur - $this->marge_droite - $posx);
@ -1594,7 +1599,7 @@ class pdf_azur extends ModelePDFPropales
$pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
$pdf->SetXY($posx, $tab_top + $tab_hl);
$pdf->MultiCell($largcol, $tab_hl*6, '', 1, 'R');
$pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
return ($tab_hl*7);
}