Skip to content

Commit

Permalink
Fix page break when using a large html footer.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 28, 2016
1 parent 74a9bbb commit 5d97ce0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
15 changes: 9 additions & 6 deletions htdocs/core/modules/commande/doc/pdf_einstein.modules.php
Expand Up @@ -36,7 +36,7 @@


/**
* Classe permettant de generer les commandes au modele Einstein
* Classe to generate PDF orders with template Einstein
*/
class pdf_einstein extends ModelePDFCommandes
{
Expand Down Expand Up @@ -173,7 +173,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
{
$object->fetch_thirdparty();

$deja_regle = "";
$deja_regle = 0;

// Definition of $dir and $file
if ($object->specimen)
Expand Down Expand Up @@ -213,11 +213,12 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
// 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);
Expand Down Expand Up @@ -552,11 +553,13 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
$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();
Expand Down
14 changes: 10 additions & 4 deletions htdocs/core/modules/facture/doc/pdf_crabe.modules.php
Expand Up @@ -251,15 +251,17 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid

// 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);
Expand Down Expand Up @@ -746,6 +748,7 @@ function _tableau_versements(&$pdf, $object, $posy, $outputlangs)

$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,";
Expand Down Expand Up @@ -790,12 +793,15 @@ function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
}

// 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)
{
Expand Down
47 changes: 26 additions & 21 deletions htdocs/core/modules/propale/doc/pdf_azur.modules.php
Expand Up @@ -91,8 +91,8 @@ function __construct($db)
$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

Expand Down Expand Up @@ -230,7 +230,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
{
$object->fetch_thirdparty();

// $deja_regle = 0;
$deja_regle = 0;

// Definition of $dir and $file
if ($object->specimen)
Expand Down Expand Up @@ -270,11 +270,8 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
// 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);
Expand Down Expand Up @@ -323,12 +320,20 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
$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;
Expand Down Expand Up @@ -406,15 +411,15 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
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;
$posYAfterImage=0;
$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);
Expand All @@ -436,9 +441,10 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
// 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
{
Expand All @@ -451,7 +457,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
$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
{
Expand Down Expand Up @@ -624,13 +630,13 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
// 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
Expand Down Expand Up @@ -765,7 +771,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
/**
* 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
Expand All @@ -780,7 +786,7 @@ function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
/**
* 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
Expand Down Expand Up @@ -1581,7 +1587,6 @@ function _signature_area(&$pdf, $object, $posy, $outputlangs)
$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);
Expand All @@ -1594,7 +1599,7 @@ function _signature_area(&$pdf, $object, $posy, $outputlangs)
$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);
}
Expand Down

0 comments on commit 5d97ce0

Please sign in to comment.