From 8bd2f9cfb5b2dcb5a18b4d814ac282f52ba9869b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 Oct 2012 17:14:11 +0100 Subject: [PATCH] Fix: Fix pagebreak. Fix also position for non A4 format. --- .../commande/doc/pdf_einstein.modules.php | 105 +++++--- .../doc/pdf_expedition_merou.modules.php | 240 +++++++++++------- .../doc/pdf_expedition_rouget.modules.php | 217 +++++++++++----- .../modules/facture/doc/pdf_crabe.modules.php | 94 +++++-- .../livraison/pdf/pdf_typhon.modules.php | 177 +++++++------ .../project/pdf/pdf_baleine.modules.php | 19 +- .../modules/propale/doc/pdf_azur.modules.php | 140 ++++++---- .../pdf/pdf_canelle.modules.php | 70 +++-- .../pdf/pdf_muscadet.modules.php | 52 ++-- 9 files changed, 705 insertions(+), 409 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index bf102c4ab5b..81192c56b16 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -78,10 +78,10 @@ class pdf_einstein extends ModelePDFCommandes $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -98,7 +98,7 @@ class pdf_einstein extends ModelePDFCommandes // Get source company $this->emetteur=$mysoc; - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined + if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined // Define position of columns $this->posxdesc=$this->marge_gauche+1; @@ -107,14 +107,14 @@ class pdf_einstein extends ModelePDFCommandes $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; - if ($this->page_largeur < 210) // To work with US executive format - { - $this->posxtva-=20; - $this->posxup-=20; - $this->posxqty-=20; - $this->posxdiscount-=20; - $this->postotalht-=20; - } + if ($this->page_largeur < 210) // To work with US executive format + { + $this->posxtva-=20; + $this->posxup-=20; + $this->posxqty-=20; + $this->posxdiscount-=20; + $this->postotalht-=20; + } $this->tva=array(); $this->localtax1=array(); @@ -126,13 +126,13 @@ class pdf_einstein extends ModelePDFCommandes /** * Function to build pdf onto disk * - * @param int $object Id of object to generate - * @param object $outputlangs Lang output object - * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param int $hidedetails Do not show line details - * @param int $hidedesc Do not show desc - * @param int $hideref Do not show ref - * @param object $hookmanager Hookmanager object + * @param Object $object Object to generate + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref + * @param object $hookmanager Hookmanager object * @return int 1=OK, 0=KO */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false) @@ -184,9 +184,11 @@ class pdf_einstein extends ModelePDFCommandes { $nblignes = count($object->lines); - $pdf=pdf_getInstance($this->format); - $heightforinfotot = 50; // Height reserved to output the info and total part (value include bottom margin) - $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin) + // Create pdf instance + $pdf=pdf_getInstance($this->format); + $heightforinfotot = 50; // Height reserved to output the info and total part + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) @@ -273,12 +275,45 @@ class pdf_einstein extends ModelePDFCommandes $pdf->SetTextColor(0,0,0); $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); // Description of product line $curX = $this->posxdesc-1; + + $showpricebeforepagebreak=1; + + $pdf->startTransaction(); pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + $pageposafter=$pdf->getPage(); + if ($pageposafter > $pageposbefore) // There is a pagebreak + { + $pdf->rollbackTransaction(true); + $pageposafter=$pageposbefore; + //print $pageposafter.'-'.$pageposbefore;exit; + $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + $posyafter=$pdf->GetY(); + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$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 + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager); + $pdf->setPage($pagenb+1); + } + } + else + { + // We found a page break + $showpricebeforepagebreak=0; + } + } + else // No pagebreak + { + $pdf->commitTransaction(); + } $nexY = $pdf->GetY(); $pageposafter=$pdf->getPage(); @@ -287,7 +322,7 @@ class pdf_einstein extends ModelePDFCommandes $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. // We suppose that a too long description is moved completely on next page - if ($pageposafter > $pageposbefore) { + if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { $pdf->setPage($pageposafter); $curY = $tab_top_newpage; } @@ -388,13 +423,13 @@ class pdf_einstein extends ModelePDFCommandes // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } // Affiche zone infos @@ -489,7 +524,9 @@ class pdf_einstein extends ModelePDFCommandes $posy=$pdf->GetY()+4; } - // Show payments conditions + $posxval=52; + + // Show payments conditions if ($object->cond_reglement_code || $object->cond_reglement) { $pdf->SetFont('','B', $default_font_size - 2); @@ -498,7 +535,7 @@ class pdf_einstein extends ModelePDFCommandes $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(52, $posy); + $pdf->SetXY($posxval, $posy); $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc); $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement); $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L'); @@ -515,7 +552,7 @@ class pdf_einstein extends ModelePDFCommandes $pdf->SetXY($this->marge_gauche, $posy); $pdf->SetTextColor(200,0,0); $pdf->SetFont('','B', $default_font_size - 2); - $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0); + $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0); $pdf->SetTextColor(0,0,0); $posy=$pdf->GetY()+1; @@ -533,7 +570,7 @@ class pdf_einstein extends ModelePDFCommandes $pdf->MultiCell(80, 5, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(50, $posy); + $pdf->SetXY($posxval, $posy); $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement); $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L'); @@ -817,7 +854,7 @@ class pdf_einstein extends ModelePDFCommandes * @param string $tab_height Height of table (rectangle) * @param int $nexY Y (not used) * @param Translate $outputlangs Langs object - * @param int $hidetop Hide top bar of array + * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title * @param int $hidebottom Hide bottom bar of array * @return void */ diff --git a/htdocs/core/modules/expedition/doc/pdf_expedition_merou.modules.php b/htdocs/core/modules/expedition/doc/pdf_expedition_merou.modules.php index d22c561d156..3f866e4a2fd 100644 --- a/htdocs/core/modules/expedition/doc/pdf_expedition_merou.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_expedition_merou.modules.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2009 Laurent Destailleur + * Copyright (C) 2005-2012 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -24,17 +24,16 @@ * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Merou */ -require_once DOL_DOCUMENT_ROOT."/core/modules/expedition/modules_expedition.php"; -require_once DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"; -require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"); -require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); +require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; /** - * \class pdf_expedition_merou - * \brief Classe permettant de generer les borderaux envoi au modele Merou + * Classe permettant de generer les borderaux envoi au modele Merou */ -Class pdf_expedition_merou extends ModelePdfExpedition +class pdf_expedition_merou extends ModelePdfExpedition { var $emetteur; // Objet societe qui emet @@ -50,7 +49,6 @@ Class pdf_expedition_merou extends ModelePdfExpedition $this->db = $db; $this->name = "merou"; - //$this->description = "Modele Merou A5"; $this->description = $langs->trans("DocumentModelMerou"); $this->type = 'pdf'; @@ -58,12 +56,12 @@ Class pdf_expedition_merou extends ModelePdfExpedition $this->page_largeur = $formatarray['width']; $this->page_hauteur = round($formatarray['height']/2); $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; - $this->option_logo = 1; // Affiche logo + $this->option_logo = 1; // Recupere emmetteur $this->emetteur=$mysoc; @@ -72,13 +70,18 @@ Class pdf_expedition_merou extends ModelePdfExpedition /** - * Fonction generant le document sur le disque + * Function to build pdf onto disk * - * @param Object &$object Objet expedition a generer (ou id si ancienne methode) - * @param Translate $outputlangs Lang output object - * @return int 1=ok, 0=ko + * @param Object &$object Object expedition to generate (or id if old method) + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref + * @param object $hookmanager Hookmanager object + * @return int 1=OK, 0=KO */ - function write_file(&$object, $outputlangs) + function write_file(&$object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false) { global $user,$conf,$langs,$mysoc; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -95,13 +98,9 @@ Class pdf_expedition_merou extends ModelePdfExpedition $outputlangs->load("bills"); $outputlangs->load("products"); $outputlangs->load("propal"); - $outputlangs->load("sendings"); $outputlangs->load("deliveries"); + $outputlangs->load("sendings"); - //Generation de la fiche - $this->expe = $object; - - //Verification de la configuration if ($conf->expedition->dir_output) { $object->fetch_thirdparty(); @@ -114,13 +113,12 @@ Class pdf_expedition_merou extends ModelePdfExpedition //Creation du destinataire $idcontact = $object->$origin->getIdContact('external','SHIPPING'); $this->destinataire = new Contact($this->db); - if ($idcontact[0]) $this->destinataire->fetch($idcontact[0]); + if (! empty($idcontact[0])) $this->destinataire->fetch($idcontact[0]); //Creation du livreur $idcontact = $object->$origin->getIdContact('internal','LIVREUR'); $this->livreur = new User($this->db); - if ($idcontact[0]) $this->livreur->fetch($idcontact[0]); - + if (! empty($idcontact[0])) $this->livreur->fetch($idcontact[0]); // Definition de $dir et $file if ($object->specimen) @@ -139,15 +137,20 @@ Class pdf_expedition_merou extends ModelePdfExpedition { if (dol_mkdir($dir) < 0) { - $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir); + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } - //Si le dossier existe if (file_exists($dir)) { - $pdf=pdf_getInstance($this->format,'mm','l'); + $nblignes = count($object->lines); + + $pdf=pdf_getInstance($this->format,'mm','l'); + $heightforinfotot = 0; // Height reserved to output the info and total part + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) + $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) { @@ -166,91 +169,130 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pagenb=0; $pdf->SetDrawColor(128,128,128); - //Generation de l entete du fichier + $pdf->AliasNbPages(); + $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Sending")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Sending")); - if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - $pdf->SetAutoPageBreak(1,0); - - $pdf->SetFont('','', $default_font_size - 3); // New page $pdf->AddPage(); $pagenb++; - $this->_pagehead($pdf, $this->expe, 1, $outputlangs); + $this->_pagehead($pdf, $object, 1, $outputlangs, $hookmanager); $pdf->SetFont('','', $default_font_size - 3); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); - //Initialisation des coordonnees - $tab_top = 53; - $tab_height = $this->page_hauteur - 78; + $tab_top = 52; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); + $tab_height = $this->page_hauteur - $tab_top - $heightforfooter; + $tab_height_newpage = $this->page_hauteur - $tab_top_newpage - $heightforfooter; + $pdf->SetFillColor(240,240,240); $pdf->SetTextColor(0,0,0); - $pdf->SetFont('','', $default_font_size - 3); $pdf->SetXY(10, $tab_top + 5); - $iniY = $pdf->GetY(); - $curY = $pdf->GetY(); - $nexY = $pdf->GetY(); - //Generation du tableau - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); - $nblignes = count($object->lines); + $iniY = $tab_top + 7; + $curY = $tab_top + 7; + $nexY = $tab_top + 7; - for ($i = 0 ; $i < $nblignes ; $i++) + $num=count($object->lines); + // Loop on each lines + for ($i = 0; $i < $num; $i++) { + $curY = $nexY; + $pdf->SetFont('','', $default_font_size - 3); + $pdf->SetTextColor(0,0,0); + + $pdf->setTopMargin($tab_top_newpage); + $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + $pageposbefore=$pdf->getPage(); + // Description de la ligne produit + $libelleproduitservice = pdf_writelinedesc($pdf,$object,$i,$outputlangs,90,3,50,$curY,0,1); + + $nexY = $pdf->GetY(); + $pageposafter=$pdf->getPage(); + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } + + $pdf->SetFont('','', $default_font_size - 3); //Creation des cases a cocher - $pdf->Rect(10+3, $curY+1, 3, 3); - $pdf->Rect(20+3, $curY+1, 3, 3); + $pdf->Rect(10+3, $curY, 3, 3); + $pdf->Rect(20+3, $curY, 3, 3); //Insertion de la reference du produit - $pdf->SetXY(30, $curY+1); + $pdf->SetXY(30, $curY); $pdf->SetFont('','B', $default_font_size - 3); $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0); - //Insertion du libelle - $pdf->SetFont('','', $default_font_size - 3); - $pdf->SetXY(50, $curY+1); - //$libelleproduitservice=pdf_getlinedesc($object->$origin,$i,$outputlangs); - $libelleproduitservice = pdf_writelinedesc($pdf,$object->$origin,$i,$outputlangs,90,3,50,$curY+1,1); - //$pdf->writeHTMLCell(90, 3, 50, $curY+1, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 'L', 0); - //Insertion de la quantite commandee - $pdf->SetFont('','', $default_font_size - 3); - $pdf->SetXY(140, $curY+1); + + $pdf->SetXY(140, $curY); $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0); - //Insertion de la quantite a envoyer - $pdf->SetFont('','', $default_font_size - 3); - $pdf->SetXY(170, $curY+1); + + $pdf->SetXY(170, $curY); $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0); - //Generation de la page 2 - $curY += (dol_nboflines_bis($libelleproduitservice,0,$outputlangs->charset_output)*3+1); - $nexY = $curY; - if ($nexY > ($tab_top+$tab_height-10) && $i < $nblignes - 1) + $nexY+=2; // Passe espace entre les lignes + + // Detect if some page were added automatically and output _tableau for past pages + while ($pagenb < $pageposafter) { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); - $this->_pagefoot($pdf, $object, $outputlangs); - $pdf->AliasNbPages(); - - $curY = $iniY; - + $pdf->setPage($pagenb); + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + $pagenb++; + $pdf->setPage($pagenb); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + } + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) + { + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); // New page $pdf->AddPage(); $pagenb++; - $this->_pagehead($pdf, $this->expe, 0, $outputlangs); - $pdf->MultiCell(0, 3, ''); // Set interline to 3 - $pdf->SetTextColor(0,0,0); - $pdf->SetFont('','', $default_font_size - 3); } } - //Insertion du pied de page - $this->_pagefoot($pdf, $object, $outputlangs); + // Show square + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; + } + else + { + $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; + } + + // Pied de page + $this->_pagefoot($pdf, $object, $outputlangs); $pdf->AliasNbPages(); $pdf->Close(); @@ -285,9 +327,11 @@ Class pdf_expedition_merou extends ModelePdfExpedition * @param string $tab_height Height of table (rectangle) * @param int $nexY Y * @param Translate $outputlangs Langs object + * @param int $hidetop Hide top bar of array + * @param int $hidebottom Hide bottom bar of array * @return void */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs) + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) { global $langs; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -295,21 +339,24 @@ Class pdf_expedition_merou extends ModelePdfExpedition $langs->load("main"); $langs->load("bills"); - $pdf->SetFont('','B', $default_font_size - 2); - $pdf->SetXY(10,$tab_top); - $pdf->MultiCell(10,5,"LS",0,'C',1); - $pdf->line(20, $tab_top, 20, $tab_top + $tab_height); - $pdf->SetXY(20,$tab_top); - $pdf->MultiCell(10,5,"LR",0,'C',1); - $pdf->line(30, $tab_top, 30, $tab_top + $tab_height); - $pdf->SetXY(30,$tab_top); - $pdf->MultiCell(20,5,$outputlangs->transnoentities("Ref"),0,'C',1); - $pdf->SetXY(50,$tab_top); - $pdf->MultiCell(90,5,$outputlangs->transnoentities("Description"),0,'L',1); - $pdf->SetXY(140,$tab_top); - $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyOrdered"),0,'C',1); - $pdf->SetXY(170,$tab_top); - $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyToShip"),0,'C',1); + if (empty($hidetop)) + { + $pdf->SetFont('','B', $default_font_size - 2); + $pdf->SetXY(10,$tab_top); + $pdf->MultiCell(10,5,"LS",0,'C',1); + $pdf->line(20, $tab_top, 20, $tab_top + $tab_height); + $pdf->SetXY(20,$tab_top); + $pdf->MultiCell(10,5,"LR",0,'C',1); + $pdf->line(30, $tab_top, 30, $tab_top + $tab_height); + $pdf->SetXY(30,$tab_top); + $pdf->MultiCell(20,5,$outputlangs->transnoentities("Ref"),0,'C',1); + $pdf->SetXY(50,$tab_top); + $pdf->MultiCell(90,5,$outputlangs->transnoentities("Description"),0,'L',1); + $pdf->SetXY(140,$tab_top); + $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyOrdered"),0,'C',1); + $pdf->SetXY(170,$tab_top); + $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyToShip"),0,'C',1); + } $pdf->Rect(10, $tab_top, 190, $tab_height); } @@ -319,9 +366,10 @@ Class pdf_expedition_merou extends ModelePdfExpedition * @param PDF &$pdf PDF * @param Object $object Object to show * @param Translate $outputlangs Object lang for output + * @param int $hidefreetext 1=Hide free text * @return void */ - function _pagefoot(&$pdf, $object, $outputlangs) + function _pagefoot(&$pdf, $object, $outputlangs,$hidefreetext=0) { $default_font_size = pdf_getPDFFontSize($outputlangs); $pdf->SetFont('','', $default_font_size - 2); @@ -534,7 +582,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition if (! empty($usecontact)) { // On peut utiliser le nom de la societe du contact - if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname; + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname; else $socname = $object->client->nom; $carac_client_name=$outputlangs->convToOutputCharset($socname); } diff --git a/htdocs/core/modules/expedition/doc/pdf_expedition_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_expedition_rouget.modules.php index 9f8a105e419..6799179a7e2 100644 --- a/htdocs/core/modules/expedition/doc/pdf_expedition_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_expedition_rouget.modules.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2009 Laurent Destailleur + * Copyright (C) 2005-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -24,16 +24,15 @@ * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Rouget */ -require_once DOL_DOCUMENT_ROOT."/core/modules/expedition/modules_expedition.php"; -require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"); -require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); +require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; /** - * \class pdf_expedition_dorade - * \brief Classe permettant de generer les borderaux envoi au modele Rouget + * Classe permettant de generer les borderaux envoi au modele Rouget */ -Class pdf_expedition_rouget extends ModelePdfExpedition +class pdf_expedition_rouget extends ModelePdfExpedition { var $emetteur; // Objet societe qui emet @@ -56,10 +55,10 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; @@ -69,18 +68,23 @@ Class pdf_expedition_rouget extends ModelePdfExpedition // Defini position des colonnes $this->posxdesc=$this->marge_gauche+1; - $this->posxqtyordered=120; - $this->posxqtytoship=160; + $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 70; + $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 35; } /** - * Fonction generant le document sur le disque + * Function to build pdf onto disk * - * @param Object &$object Objet expedition a generer (ou id si ancienne methode) - * @param Translate $outputlangs Lang output object - * @return int 1=ok, 0=ko + * @param Object &$object Object expedition to generate (or id if old method) + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref + * @param object $hookmanager Hookmanager object + * @return int 1=OK, 0=KO */ - function write_file(&$object, $outputlangs) + function write_file(&$object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false) { global $user,$conf,$langs; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -119,14 +123,20 @@ Class pdf_expedition_rouget extends ModelePdfExpedition { if (dol_mkdir($dir) < 0) { - $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir); + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } if (file_exists($dir)) { - $pdf=pdf_getInstance($this->format); + $nblignes = count($object->lines); + + $pdf=pdf_getInstance($this->format); + $heightforinfotot = 0; // Height reserved to output the info and total part + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) + $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) { @@ -151,23 +161,24 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $pdf->SetSubject($outputlangs->transnoentities("Sending")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($outputlangs->convToOutputCharset($fac->ref)." ".$outputlangs->transnoentities("Sending")); - if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); + $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Sending")); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - $pdf->SetAutoPageBreak(1,0); // New page $pdf->AddPage(); if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; - $this->_pagehead($pdf, $object, 1, $outputlangs); + $this->_pagehead($pdf, $object, 1, $outputlangs, $hookmanager); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); $tab_top = 90; - $tab_height = 170; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); + $tab_height = 130; + $tab_height_newpage = 150; if (! empty($object->note_public) || ! empty($object->tracking_number)) { @@ -213,32 +224,92 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $height_note=0; } - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); - + $iniY = $tab_top + 7; + $curY = $tab_top + 7; $nexY = $tab_top + 7; $num=count($object->lines); + // Loop on each lines for ($i = 0; $i < $num; $i++) { $curY = $nexY; + $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage + $pdf->SetTextColor(0,0,0); - $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page + $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. + $pageposbefore=$pdf->getPage(); // Description de la ligne produit pdf_writelinedesc($pdf,$object,$i,$outputlangs,150,3,$this->posxdesc,$curY,0,1); - $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut $nexY = $pdf->GetY(); + $pageposafter=$pdf->getPage(); + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. - $pdf->SetXY($this->posxqtyordered+5, $curY); - $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked,'','C'); + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } - $pdf->SetXY($this->posxqtytoship+5, $curY); - $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped,'','C'); + $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut + + $pdf->SetXY($this->posxqtyordered, $curY); + $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C'); + + $pdf->SetXY($this->posxqtytoship, $curY); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); $nexY+=2; // Passe espace entre les lignes + + // Detect if some page were added automatically and output _tableau for past pages + while ($pagenb < $pageposafter) + { + $pdf->setPage($pagenb); + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + $pagenb++; + $pdf->setPage($pagenb); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + } + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) + { + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + // New page + $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + $pagenb++; + } } + // Show square + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1; + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1; + } // Pied de page $this->_pagefoot($pdf,$object,$outputlangs); @@ -275,34 +346,51 @@ Class pdf_expedition_rouget extends ModelePdfExpedition * @param string $tab_height Height of table (rectangle) * @param int $nexY Y * @param Translate $outputlangs Langs object + * @param int $hidetop Hide top bar of array + * @param int $hidebottom Hide bottom bar of array * @return void */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs) + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) { global $conf; + // Force to disable hidetop and hidebottom + $hidebottom=0; + if ($hidetop) $hidetop=-1; + $default_font_size = pdf_getPDFFontSize($outputlangs); + // Amount in (at tab_top - 1) $pdf->SetTextColor(0,0,0); - $pdf->SetDrawColor(128,128,128); - - // Rect prend une longueur en 3eme param - $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height); - // line prend une position y en 3eme param - $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); - $pdf->SetFont('','',$default_font_size - 1); - $pdf->SetXY($this->posxdesc-1, $tab_top+1); - $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Description"), '', 'L'); + // Output Rect + $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param + + $pdf->SetDrawColor(128,128,128); + $pdf->SetFont('','',$default_font_size - 1); + + if (empty($hidetop)) + { + $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); + + $pdf->SetXY($this->posxdesc-1, $tab_top+1); + $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L'); + } $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height); - $pdf->SetXY($this->posxqtyordered-1, $tab_top+1); - $pdf->MultiCell(40,2, $outputlangs->transnoentities("QtyOrdered"),'','C'); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxqtyordered, $tab_top+1); + $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C'); + } $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height); - $pdf->SetXY($this->posxqtytoship-1, $tab_top+1); - $pdf->MultiCell(40,2, $outputlangs->transnoentities("QtyToShip"),'','C'); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxqtytoship, $tab_top+1); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C'); + } } /** @@ -361,7 +449,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition } // Show barcode - if ($conf->barcode->enabled) + if (! empty($conf->barcode->enabled)) { $posx=105; } @@ -370,7 +458,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $posx=$this->marge_gauche+3; } //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); - if ($conf->barcode->enabled) + if (! empty($conf->barcode->enabled)) { // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); @@ -378,7 +466,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition } $pdf->SetDrawColor(128,128,128); - if ($conf->barcode->enabled) + if (! empty($conf->barcode->enabled)) { // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); @@ -386,7 +474,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition } - $posx=100; + $posx=$this->page_largeur - 100 - $this->marge_droite; $posy=$this->marge_haute; $pdf->SetFont('','B', $default_font_size + 2); @@ -442,8 +530,8 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $text=$linkedobject->ref; if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')'; $Yoff = $Yoff+8; - $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff); - $pdf->MultiCell(60, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R'); + $pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$Yoff); + $pdf->MultiCell(100, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R'); $Yoff = $Yoff+4; $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff); $pdf->MultiCell(60, 2, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->commande->date,"daytext",false,$outputlangs,true), 0, 'R'); @@ -454,8 +542,9 @@ Class pdf_expedition_rouget extends ModelePdfExpedition { // Sender properties $carac_emetteur=''; - // Add internal contact of proposal if defined - $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL'); + // Add internal contact of origin element if defined + $arrayidcontact=array(); + if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL'); if (count($arrayidcontact) > 0) { $object->fetch_user($arrayidcontact[0]); @@ -468,7 +557,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $posx=$this->marge_gauche; $posy=42; $hautcadre=40; - if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=118; + if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur - 80 - $this->marge_droite; // Show sender frame $pdf->SetTextColor(0,0,0); @@ -493,7 +582,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition // If SHIPPING contact defined, we use it $usecontact=false; - $arrayidcontact=$object->getIdContact('external','SHIPPING'); + $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING'); if (count($arrayidcontact) > 0) { $usecontact=true; @@ -504,7 +593,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition if (! empty($usecontact)) { // On peut utiliser le nom de la societe du contact - if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname; + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname; else $socname = $object->client->nom; $carac_client_name=$outputlangs->convToOutputCharset($socname); } @@ -516,27 +605,29 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target'); // Show recipient + $widthrecbox=100; + if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format $posy=42; - $posx=100; + $posx=$this->page_largeur - $this->marge_droite - $widthrecbox; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; // Show recipient frame $pdf->SetTextColor(0,0,0); $pdf->SetFont('','', $default_font_size - 2); $pdf->SetXY($posx,$posy-5); - $pdf->MultiCell(80, 4, $outputlangs->transnoentities("Recipient").":", 0, 'L'); - $pdf->Rect($posx, $posy, 100, $hautcadre); + $pdf->MultiCell($widthrecbox, 4, $outputlangs->transnoentities("Recipient").":", 0, 'L'); + $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); $pdf->SetTextColor(0,0,0); // Show recipient name $pdf->SetXY($posx+2,$posy+3); $pdf->SetFont('','B', $default_font_size); - $pdf->MultiCell(96,4, $carac_client_name, 0, 'L'); + $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L'); // Show recipient information $pdf->SetFont('','', $default_font_size - 1); $pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4)); - $pdf->MultiCell(86,4, $carac_client, 0, 'L'); + $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); } } diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index e761666c505..fae70279621 100755 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -78,10 +78,10 @@ class pdf_crabe extends ModelePDFFactures $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -109,12 +109,12 @@ class pdf_crabe extends ModelePDFFactures $this->postotalht=174; if ($this->page_largeur < 210) // To work with US executive format { - $this->posxtva-=20; - $this->posxup-=20; - $this->posxqty-=20; - $this->posxdiscount-=20; - $this->postotalht-=20; - } + $this->posxtva-=20; + $this->posxup-=20; + $this->posxqty-=20; + $this->posxdiscount-=20; + $this->postotalht-=20; + } $this->tva=array(); $this->localtax1=array(); @@ -187,7 +187,8 @@ class pdf_crabe extends ModelePDFFactures $pdf=pdf_getInstance($this->format); $heightforinfotot = 50; // Height reserved to output the info and total part - $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin) + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) @@ -252,8 +253,6 @@ class pdf_crabe extends ModelePDFFactures // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192,192,192); - //print $pdf->getStringHeight(200,'SPECIMEN',false,false); - //print "$this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1";exit; $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; @@ -276,12 +275,47 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetTextColor(0,0,0); $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); // Description of product line $curX = $this->posxdesc-1; + + $showpricebeforepagebreak=1; + + $pdf->startTransaction(); pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + $pageposafter=$pdf->getPage(); + if ($pageposafter > $pageposbefore) // There is a pagebreak + { + $pdf->rollbackTransaction(true); + $pageposafter=$pageposbefore; + //print $pageposafter.'-'.$pageposbefore;exit; + $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + $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 ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager); + $pdf->setPage($pagenb+1); + } + } + else + { + // We found a page break + $showpricebeforepagebreak=0; + } + } + else // No pagebreak + { + $pdf->commitTransaction(); + } $nexY = $pdf->GetY(); $pageposafter=$pdf->getPage(); @@ -290,7 +324,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. // We suppose that a too long description is moved completely on next page - if ($pageposafter > $pageposbefore) { + if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { $pdf->setPage($pageposafter); $curY = $tab_top_newpage; } @@ -390,13 +424,13 @@ class pdf_crabe extends ModelePDFFactures // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } // Affiche zone infos @@ -466,14 +500,18 @@ class pdf_crabe extends ModelePDFFactures $tab3_top = $posy + 8; $tab3_width = 80; $tab3_height = 4; + if ($this->page_largeur < 210) // To work with US executive format + { + $tab3_posx -= 20; + } $default_font_size = pdf_getPDFFontSize($outputlangs); - $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY($tab3_posx, $tab3_top - 5); - $pdf->MultiCell(60, 5, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0); + $pdf->SetFont('','', $default_font_size - 3); + $pdf->SetXY($tab3_posx, $tab3_top - 4); + $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0); - $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); + $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top); $pdf->SetFont('','', $default_font_size - 4); $pdf->SetXY($tab3_posx, $tab3_top); @@ -485,6 +523,8 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY($tab3_posx+58, $tab3_top); $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); + $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); + $y=0; $pdf->SetFont('','', $default_font_size - 4); @@ -602,6 +642,8 @@ class pdf_crabe extends ModelePDFFactures $posy=$pdf->GetY()+4; } + $posxval=52; + // Show payments conditions if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) { @@ -611,7 +653,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(52, $posy); + $pdf->SetXY($posxval, $posy); $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc); $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement); $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L'); @@ -629,7 +671,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY($this->marge_gauche, $posy); $pdf->SetTextColor(200,0,0); $pdf->SetFont('','B', $default_font_size - 2); - $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0); + $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0); $pdf->SetTextColor(0,0,0); $posy=$pdf->GetY()+1; @@ -646,7 +688,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->MultiCell(80, 5, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(50, $posy); + $pdf->SetXY($posxval, $posy); $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement); $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L'); diff --git a/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php index e0c44991d37..9b0b79168b8 100644 --- a/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php +++ b/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2008 Chiptronik + * Copyright (C) 2011-2012 Philippe Grand * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,17 +27,15 @@ * \author Laurent Destailleur */ -require_once(DOL_DOCUMENT_ROOT."/core/modules/livraison/modules_livraison.php"); -require_once(DOL_DOCUMENT_ROOT."/livraison/class/livraison.class.php"); -require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"); -require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); +require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php'; +require_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; /** - * \class pdf_typhon - * \brief Classe permettant de generer les bons de livraison au modele Typho + * Classe permettant de generer les bons de livraison au modele Typho */ - class pdf_typhon extends ModelePDFDeliveryOrder { var $emetteur; // Objet societe qui emet @@ -65,10 +64,10 @@ class pdf_typhon extends ModelePDFDeliveryOrder $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -88,6 +87,15 @@ class pdf_typhon extends ModelePDFDeliveryOrder $this->posxqty=168; $this->posxdiscount=162; $this->postotalht=177; + if ($this->page_largeur < 210) // To work with US executive format + { + $this->posxcomm-=20; + //$this->posxtva-=20; + $this->posxup-=20; + $this->posxqty-=20; + $this->posxdiscount-=20; + $this->postotalht-=20; + } $this->tva=array(); $this->atleastoneratenotnull=0; @@ -142,6 +150,10 @@ class pdf_typhon extends ModelePDFDeliveryOrder if (file_exists($dir)) { $pdf=pdf_getInstance($this->format); + $heightforinfotot = 50; // Height reserved to output the info and total part + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) + $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) { @@ -177,10 +189,9 @@ class pdf_typhon extends ModelePDFDeliveryOrder $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder")); - if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - $pdf->SetAutoPageBreak(1,0); /* // Positionne $this->atleastonediscount si on a au moins une remise @@ -203,8 +214,8 @@ class pdf_typhon extends ModelePDFDeliveryOrder $pdf->SetTextColor(0,0,0); $tab_top = 90; - $tab_top_newpage = 50; - $tab_height = 110; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); + $tab_height = 130; $tab_height_newpage = 150; // Affiche notes @@ -233,20 +244,35 @@ class pdf_typhon extends ModelePDFDeliveryOrder $curY = $tab_top + 7; $nexY = $tab_top + 7; - // Boucle sur les lignes + // Loop on each lines for ($i = 0 ; $i < $nblines ; $i++) { $curY = $nexY; + $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage + $pdf->SetTextColor(0,0,0); - $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page + $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. + $pageposbefore=$pdf->getPage(); - // Description de la ligne produit - //$libelleproduitservice=pdf_getlinedesc($object,$i,$outputlangs); - pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$this->posxdesc-1,$curY); - //$pdf->writeHTMLCell(108, 3, $this->posxdesc-1, $curY, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 1); + // Description of product line + $curX = $this->posxdesc-1; + pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$curX,$curY); + + $nexY = $pdf->GetY(); + $pageposafter=$pdf->getPage(); + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut - $nexY = $pdf->GetY(); + + $nexY = $pdf->GetY()+4; /* // TVA @@ -281,68 +307,53 @@ class pdf_typhon extends ModelePDFDeliveryOrder */ $nexY+=2; // Passe espace entre les lignes - // Cherche nombre de lignes a venir pour savoir si place suffisante - if ($i < ($nblines - 1) && empty($hidedesc)) // If it's not last line - { - //on recupere la description du produit suivant - $follow_descproduitservice = $object->lines[$i+1]->desc; - //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres) - $nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4); - } - else // If it's last line - { - $nblineFollowDesc = 0; - } - - // Test if a new page is required - if ($pagenb == 1) - { - $tab_top_in_current_page=$tab_top; - $tab_height_in_current_page=$tab_height; - } - else - { - $tab_top_in_current_page=$tab_top_newpage; - $tab_height_in_current_page=$tab_height_newpage; - } - if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblines - 1)) + // Detect if some page were added automatically and output _tableau for past pages + while ($pagenb < $pageposafter) { + $pdf->setPage($pagenb); if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs); + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { - $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } - - $this->_pagefoot($pdf, $object, $outputlangs); - + $this->_pagefoot($pdf,$object,$outputlangs,1); + $pagenb++; + $pdf->setPage($pagenb); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + } + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) + { + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); // New page $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; - $this->_pagehead($pdf, $object, 0, $outputlangs); - $pdf->SetFont('','', $default_font_size - 1); - $pdf->MultiCell(0, 3, ''); // Set interline to 3 - $pdf->SetTextColor(0,0,0); - - $nexY = $tab_top_newpage + 7; } } // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); - $bottomlasttab=$tab_top + $tab_height + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); - $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; } - /* * Pied de page */ @@ -384,7 +395,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder if ($pdf->GetY() > 250) { - $this->_pagefoot($pdf,$object,$outputlangs); + $this->_pagefoot($pdf,$object,$outputlangs,1); $pdf->AddPage('P', 'A4'); @@ -415,7 +426,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - return 1; // Pas d'erreur + return 1; } else { @@ -437,9 +448,11 @@ class pdf_typhon extends ModelePDFDeliveryOrder * @param string $tab_height Height of table (rectangle) * @param int $nexY Y * @param Translate $outputlangs Langs object + * @param int $hidetop Hide top bar of array + * @param int $hidebottom Hide bottom bar of array * @return void */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs) + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) { global $conf,$mysoc; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -624,9 +637,6 @@ class pdf_typhon extends ModelePDFDeliveryOrder $pdf->SetXY(102,$posy-5); $pdf->MultiCell(80,5, $outputlangs->transnoentities("DeliveryAddress").":", 0, 'L'); - // Cadre client destinataire - $pdf->Rect(100, $posy, 100, $hautcadre); - // If SHIPPING contact defined on invoice, we use it $usecontact=false; $arrayidcontact=$object->commande->getIdContact('external','SHIPPING'); @@ -640,7 +650,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder if (! empty($usecontact)) { // On peut utiliser le nom de la societe du contact - if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname; + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname; else $socname = $object->client->nom; $carac_client_name=$outputlangs->convToOutputCharset($socname); } @@ -651,14 +661,29 @@ class pdf_typhon extends ModelePDFDeliveryOrder $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target'); - // Show customer/recipient - $pdf->SetXY(102,$posy+3); - $pdf->SetFont('','B', $default_font_size); - $pdf->MultiCell(106,4, $carac_client_name, 0, 'L'); + // Show recipient + $widthrecbox=100; + if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format + $posy=42; + $posx=$this->page_largeur-$this->marge_droite-$widthrecbox; + //if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; + // Show recipient frame + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('','', $default_font_size - 2); + $pdf->SetXY($posx+2,$posy-5); + //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L'); + $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); + + // Show recipient name + $pdf->SetXY($posx+2,$posy+3); + $pdf->SetFont('','B', $default_font_size); + $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L'); + + // Show recipient information $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY(102,$posy+8); - $pdf->MultiCell(86,4, $carac_client, 0, 'L'); + $pdf->SetXY($posx+2,$posy+8); + $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); } } diff --git a/htdocs/core/modules/project/pdf/pdf_baleine.modules.php b/htdocs/core/modules/project/pdf/pdf_baleine.modules.php index 38337c4314e..b023097035b 100644 --- a/htdocs/core/modules/project/pdf/pdf_baleine.modules.php +++ b/htdocs/core/modules/project/pdf/pdf_baleine.modules.php @@ -62,10 +62,10 @@ class pdf_baleine extends ModelePDFProjects $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -128,7 +128,8 @@ class pdf_baleine extends ModelePDFProjects { $pdf=pdf_getInstance($this->format); $heightforinfotot = 50; // Height reserved to output the info and total part - $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin) + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) @@ -265,13 +266,13 @@ class pdf_baleine extends ModelePDFProjects // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } /* diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 1ed2bce9c26..f805a2bf936 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -77,10 +77,10 @@ class pdf_azur extends ModelePDFPropales $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -97,7 +97,7 @@ class pdf_azur extends ModelePDFPropales // Get source company $this->emetteur=$mysoc; - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined + if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined // Define position of columns $this->posxdesc=$this->marge_gauche+1; @@ -106,14 +106,14 @@ class pdf_azur extends ModelePDFPropales $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; - if ($this->page_largeur < 210) // To work with US executive format - { - $this->posxtva-=20; - $this->posxup-=20; - $this->posxqty-=20; - $this->posxdiscount-=20; - $this->postotalht-=20; - } + if ($this->page_largeur < 210) // To work with US executive format + { + $this->posxtva-=20; + $this->posxup-=20; + $this->posxqty-=20; + $this->posxdiscount-=20; + $this->postotalht-=20; + } $this->tva=array(); $this->localtax1=array(); @@ -186,7 +186,8 @@ class pdf_azur extends ModelePDFPropales // Create pdf instance $pdf=pdf_getInstance($this->format); $heightforinfotot = 50; // Height reserved to output the info and total part - $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin) + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) @@ -234,10 +235,8 @@ class pdf_azur extends ModelePDFPropales $pdf->SetTextColor(0,0,0); $tab_top = 90; - $tab_top_middlepage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); $tab_height = 130; - $tab_height_middlepage = 200; $tab_height_newpage = 150; // Affiche notes @@ -274,12 +273,46 @@ class pdf_azur extends ModelePDFPropales $pdf->SetTextColor(0,0,0); $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); // Description of product line $curX = $this->posxdesc-1; - pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + + $showpricebeforepagebreak=1; + + $pdf->startTransaction(); + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + $pageposafter=$pdf->getPage(); + if ($pageposafter > $pageposbefore) // There is a pagebreak + { + $pdf->rollbackTransaction(true); + $pageposafter=$pageposbefore; + //print $pageposafter.'-'.$pageposbefore;exit; + $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); + $pageposafter=$pdf->getPage(); + $posyafter=$pdf->GetY(); + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$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 + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager); + $pdf->setPage($pagenb+1); + } + } + else + { + // We found a page break + $showpricebeforepagebreak=0; + } + } + else // No pagebreak + { + $pdf->commitTransaction(); + } $nexY = $pdf->GetY(); $pageposafter=$pdf->getPage(); @@ -288,7 +321,7 @@ class pdf_azur extends ModelePDFPropales $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. // We suppose that a too long description is moved completely on next page - if ($pageposafter > $pageposbefore) { + if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { $pdf->setPage($pageposafter); $curY = $tab_top_newpage; } @@ -299,31 +332,31 @@ class pdf_azur extends ModelePDFPropales { $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY($this->posxtva, $curY); - $pdf->MultiCell($this->posxup-$this->posxtva-1, 4, $vat_rate, 0, 'R'); + $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R'); } // Unit price before discount $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY($this->posxup, $curY); - $pdf->MultiCell($this->posxqty-$this->posxup-1, 4, $up_excl_tax, 0, 'R', 0); + $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, $up_excl_tax, 0, 'R', 0); // Quantity $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY($this->posxqty, $curY); - $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 4, $qty, 0, 'R'); + $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $qty, 0, 'R'); // Enough for 6 chars // Discount on line - $pdf->SetXY($this->posxdiscount, $curY); if ($object->lines[$i]->remise_percent) { + $pdf->SetXY($this->posxdiscount-2, $curY); $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager); - $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 4, $remise_percent, 0, 'R'); + $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); } // Total HT line $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY($this->postotalht, $curY); - $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 4, $total_excl_tax, 0, 'R', 0); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva $tvaligne=$object->lines[$i]->total_tva; @@ -388,13 +421,13 @@ class pdf_azur extends ModelePDFPropales // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } // Affiche zone infos @@ -456,7 +489,7 @@ class pdf_azur extends ModelePDFPropales * Show payments table * * @param PDF &$pdf Object PDF - * @param Object $object Object invoice + * @param Object $object Object proposal * @param int $posy Position y in PDF * @param Translate $outputlangs Object langs for output * @return int <0 if KO, >0 if OK @@ -493,6 +526,8 @@ class pdf_azur extends ModelePDFPropales $posy=$pdf->GetY()+4; } + $posxval=52; + // Show shipping date if ($object->date_livraison) { @@ -502,7 +537,7 @@ class pdf_azur extends ModelePDFPropales $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':'; $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(82, $posy); + $pdf->SetXY($posxval, $posy); $dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true); $pdf->MultiCell(80, 4, $dlp, 0, 'L'); @@ -516,7 +551,7 @@ class pdf_azur extends ModelePDFPropales $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetTextColor(0,0,0); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(82, $posy); + $pdf->SetXY($posxval, $posy); $lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability); $lib_availability=str_replace('\n',"\n",$lib_availability); $pdf->MultiCell(80, 4, $lib_availability, 0, 'L'); @@ -525,7 +560,7 @@ class pdf_azur extends ModelePDFPropales } // Show payments conditions - if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement)) + if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement)) { $pdf->SetFont('','B', $default_font_size - 2); $pdf->SetXY($this->marge_gauche, $posy); @@ -533,7 +568,7 @@ class pdf_azur extends ModelePDFPropales $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(52, $posy); + $pdf->SetXY($posxval, $posy); $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc); $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement); $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L'); @@ -541,8 +576,7 @@ class pdf_azur extends ModelePDFPropales $posy=$pdf->GetY()+3; } - - if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTERMCOND)) + if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND)) { // Check a payment mode is defined /* Not required on a proposal @@ -570,7 +604,7 @@ class pdf_azur extends ModelePDFPropales $titre = $outputlangs->transnoentities("PaymentMode").':'; $pdf->MultiCell(80, 5, $titre, 0, 'L'); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY(50, $posy); + $pdf->SetXY($posxval, $posy); $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement); $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L'); @@ -656,12 +690,13 @@ class pdf_azur extends ModelePDFPropales // Tableau total $col1x = 120; $col2x = 170; - if ($this->page_largeur < 210) // To work with US executive format - { - $col2x-=20; - } - $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x); + if ($this->page_largeur < 210) // To work with US executive format + { + $col2x-=20; + } + $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x); + $useborder=0; $index = 0; // Total HT @@ -670,7 +705,7 @@ class pdf_azur extends ModelePDFPropales $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); $pdf->SetXY($col2x, $tab2_top + 0); - $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 1); + $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0)), 0, 'R', 1); // Show VAT by rates and total $pdf->SetFillColor(248,248,248); @@ -723,9 +758,9 @@ class pdf_azur extends ModelePDFPropales { $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), 0, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), $useborder, 'L', 1); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), 0, 'R', 1); + $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1); } // Total LocalTax2 @@ -733,9 +768,9 @@ class pdf_azur extends ModelePDFPropales { $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), 0, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), $useborder, 'L', 1); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), 0, 'R', 1); + $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1); } } else @@ -758,7 +793,7 @@ class pdf_azur extends ModelePDFPropales $tvakey=str_replace('*','',$tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } - $totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' '; + $totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->country_code).' '; $totalvat.=vatrate($tvakey,1).$tvacompl; $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); @@ -786,7 +821,7 @@ class pdf_azur extends ModelePDFPropales $tvakey=str_replace('*','',$tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } - $totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' '; + $totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' '; $totalvat.=vatrate($tvakey,1).$tvacompl; $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); @@ -798,8 +833,6 @@ class pdf_azur extends ModelePDFPropales } } - $useborder=0; - // Total TTC $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); @@ -854,7 +887,6 @@ class pdf_azur extends ModelePDFPropales $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1); - // Fin $pdf->SetFont('','', $default_font_size - 1); $pdf->SetTextColor(0,0,0); } @@ -869,9 +901,9 @@ class pdf_azur extends ModelePDFPropales * @param PDF &$pdf Object PDF * @param string $tab_top Top position of table * @param string $tab_height Height of table (rectangle) - * @param int $nexY Y + * @param int $nexY Y (not used) * @param Translate $outputlangs Langs object - * @param int $hidetop Hide top bar of array + * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title * @param int $hidebottom Hide bottom bar of array * @return void */ diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index 26e8a0f7e4a..f752ffaf6b0 100755 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -77,10 +77,10 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -103,14 +103,14 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; - if ($this->page_largeur < 210) // To work with US executive format - { - $this->posxtva-=20; - $this->posxup-=20; - $this->posxqty-=20; - $this->posxdiscount-=20; - $this->postotalht-=20; - } + if ($this->page_largeur < 210) // To work with US executive format + { + $this->posxtva-=20; + $this->posxup-=20; + $this->posxqty-=20; + $this->posxdiscount-=20; + $this->postotalht-=20; + } $this->tva=array(); $this->localtax1=array(); @@ -132,7 +132,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices * @param object $hookmanager Hookmanager object * @return int 1=OK, 0=KO */ - function write_file($object,$outputlangs='',$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false) + function write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { global $user,$langs,$conf,$mysoc; @@ -185,7 +185,8 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $pdf=pdf_getInstance($this->format); $heightforinfotot = 50; // Height reserved to output the info and total part - $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin) + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) @@ -271,7 +272,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $pdf->SetTextColor(0,0,0); $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); // Description of product line @@ -284,10 +285,10 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $pdf->setTopMargin($this->marge_haute); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. -// We suppose that a too long description is moved completely on next page -if ($pageposafter > $pageposbefore) { - $pdf->setPage($pageposafter); $curY = $tab_top_newpage; -} + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut @@ -376,13 +377,13 @@ if ($pageposafter > $pageposbefore) { // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } // Affiche zone totaux @@ -738,14 +739,18 @@ if ($pageposafter > $pageposbefore) { $tab3_top = $posy + 8; $tab3_width = 80; $tab3_height = 4; + if ($this->page_largeur < 210) // To work with US executive format + { + $tab3_posx -= 20; + } $default_font_size = pdf_getPDFFontSize($outputlangs); - $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY($tab3_posx, $tab3_top - 5); - $pdf->MultiCell(60, 5, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0); + $pdf->SetFont('','', $default_font_size - 3); + $pdf->SetXY($tab3_posx, $tab3_top - 4); + $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0); - $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); + $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top); $pdf->SetFont('','', $default_font_size - 4); $pdf->SetXY($tab3_posx, $tab3_top); @@ -757,6 +762,8 @@ if ($pageposafter > $pageposbefore) { $pdf->SetXY($tab3_posx+58, $tab3_top); $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); + $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); + $y=0; $pdf->SetFont('','', $default_font_size - 4); @@ -809,9 +816,10 @@ if ($pageposafter > $pageposbefore) { * @param Object $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output + * @param object $hookmanager Hookmanager object * @return void */ - function _pagehead(&$pdf, $object, $showaddress, $outputlangs) + function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $hookmanager) { global $langs,$conf,$mysoc; @@ -887,6 +895,12 @@ if ($pageposafter > $pageposbefore) { $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R'); } + $posy+=2; + $pdf->SetTextColor(0,0,60); + + // Show list of linked objects + $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size, $hookmanager); + if ($showaddress) { // Sender properties diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php index 18e011b20cf..f686c6508ea 100644 --- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php @@ -80,10 +80,10 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $this->page_largeur = $formatarray['width']; $this->page_hauteur = $formatarray['height']; $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=10; - $this->marge_droite=10; - $this->marge_haute=10; - $this->marge_basse=10; + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION @@ -112,14 +112,14 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; - if ($this->page_largeur < 210) // To work with US executive format - { - $this->posxtva-=20; - $this->posxup-=20; - $this->posxqty-=20; - $this->posxdiscount-=20; - $this->postotalht-=20; - } + if ($this->page_largeur < 210) // To work with US executive format + { + $this->posxtva-=20; + $this->posxup-=20; + $this->posxqty-=20; + $this->posxdiscount-=20; + $this->postotalht-=20; + } $this->tva=array(); $this->localtax1=array(); @@ -197,7 +197,8 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $pdf=pdf_getInstance($this->format); $heightforinfotot = 50; // Height reserved to output the info and total part - $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin) + $heightforfreetext= 5; // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 10; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) @@ -283,7 +284,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $pdf->SetTextColor(0,0,0); $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); // Description of product line @@ -296,10 +297,10 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $pdf->setTopMargin($this->marge_haute); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. -// We suppose that a too long description is moved completely on next page -if ($pageposafter > $pageposbefore) { - $pdf->setPage($pageposafter); $curY = $tab_top_newpage; -} + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut @@ -393,13 +394,13 @@ if ($pageposafter > $pageposbefore) { // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } // Affiche zone infos @@ -908,9 +909,10 @@ if ($pageposafter > $pageposbefore) { * @param Object $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output + * @param object $hookmanager Hookmanager object * @return void */ - function _pagehead(&$pdf, $object, $showaddress, $outputlangs) + function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $hookmanager) { global $langs,$conf,$mysoc; @@ -992,6 +994,10 @@ if ($pageposafter > $pageposbefore) { } $posy+=2; + $pdf->SetTextColor(0,0,60); + + // Show list of linked objects + $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size, $hookmanager); if ($showaddress) {