diff --git a/htdocs/includes/modules/action/rapport.pdf.php b/htdocs/includes/modules/action/rapport.pdf.php index 7c552ec0145..9ca49357d52 100644 --- a/htdocs/includes/modules/action/rapport.pdf.php +++ b/htdocs/includes/modules/action/rapport.pdf.php @@ -20,10 +20,10 @@ */ /** - * \file htdocs/includes/modules/action/rapport.pdf.php - * \ingroup commercial - * \brief Fichier de generation de PDF pour les rapports d'actions - * \version $Id$ + * \file htdocs/includes/modules/action/rapport.pdf.php + * \ingroup commercial + * \brief Fichier de generation de PDF pour les rapports d'actions + * \version $Id$ */ require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); @@ -31,93 +31,93 @@ require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php'); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); /** - * \class CommActionRapport - * \brief Classe permettant la generation des rapports d'actions + * \class CommActionRapport + * \brief Classe permettant la generation des rapports d'actions */ class CommActionRapport { - var $db; - var $description; - var $date_edition; - var $year; - var $month; + var $db; + var $description; + var $date_edition; + var $year; + var $month; - var $title; - var $subject; + var $title; + var $subject; - function CommActionRapport($db=0, $month, $year) - { - global $langs; - $langs->load("commercial"); + function CommActionRapport($db=0, $month, $year) + { + global $langs; + $langs->load("commercial"); - $this->db = $db; - $this->description = ""; - $this->date_edition = time(); - $this->month = $month; - $this->year = $year; + $this->db = $db; + $this->description = ""; + $this->date_edition = time(); + $this->month = $month; + $this->year = $year; - // Dimension page pour format A4 - $this->type = 'pdf'; - $this->page_largeur = 210; - $this->page_hauteur = 297; - $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=5; - $this->marge_droite=5; - $this->marge_haute=10; - $this->marge_basse=10; + // Dimension page pour format A4 + $this->type = 'pdf'; + $this->page_largeur = 210; + $this->page_hauteur = 297; + $this->format = array($this->page_largeur,$this->page_hauteur); + $this->marge_gauche=5; + $this->marge_droite=5; + $this->marge_haute=10; + $this->marge_basse=10; - $this->title=$langs->trans("ActionsReport").' '.$this->year."-".$this->month; - $this->subject=$langs->trans("ActionsReport").' '.$this->year."-".$this->month; - } + $this->title=$langs->transnoentitiesnoconv("ActionsReport").' '.$this->year."-".$this->month; + $this->subject=$langs->transnoentitiesnoconv("ActionsReport").' '.$this->year."-".$this->month; + } - /** + /** * Write the object to document file to disk * @param socid * @param catid * @param outputlangs Lang object for output language * @return int 1=OK, 0=KO - */ - function write_file($socid = 0, $catid = 0, $outputlangs='') - { - global $user,$conf,$langs; + */ + function write_file($socid = 0, $catid = 0, $outputlangs='') + { + global $user,$conf,$langs; - if (! is_object($outputlangs)) $outputlangs=$langs; - // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO - if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1'; + if (! is_object($outputlangs)) $outputlangs=$langs; + // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO + if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1'; - $outputlangs->load("main"); - $outputlangs->load("dict"); - $outputlangs->load("companies"); - $outputlangs->load("bills"); - $outputlangs->load("products"); + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("products"); - $dir = $conf->agenda->dir_temp."/"; - $file = $dir . "actions-".$this->month."-".$this->year.".pdf"; + $dir = $conf->agenda->dir_temp."/"; + $file = $dir . "actions-".$this->month."-".$this->year.".pdf"; - if (! file_exists($dir)) - { - if (create_exdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } - if (file_exists($dir)) - { - // Protection et encryption du pdf -/* if ($conf->global->PDF_SECURITY_ENCRYPTION) - { - $pdf=new FPDI_Protection('P','mm',$this->format); - $pdfrights = array('print'); // Ne permet que l'impression du document - $pdfuserpass = ''; // Mot de passe pour l'utilisateur final - $pdfownerpass = NULL; // Mot de passe du proprietaire, cree aleatoirement si pas defini - $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); - } - else - { - $pdf=new FPDI('P','mm',$this->format); - } + if (file_exists($dir)) + { + // Protection et encryption du pdf +/* if ($conf->global->PDF_SECURITY_ENCRYPTION) + { + $pdf=new FPDI_Protection('P','mm',$this->format); + $pdfrights = array('print'); // Ne permet que l'impression du document + $pdfuserpass = ''; // Mot de passe pour l'utilisateur final + $pdfownerpass = NULL; // Mot de passe du proprietaire, cree aleatoirement si pas defini + $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); + } + else + { + $pdf=new FPDI('P','mm',$this->format); + } */ $pdf=pdf_getInstance($this->format); @@ -128,148 +128,148 @@ class CommActionRapport } $pdf->SetFont(pdf_getPDFFont($outputlangs)); - $pdf->Open(); - $pagenb=0; - $pdf->SetDrawColor(128,128,128); - $pdf->SetFillColor(220,220,220); + $pdf->Open(); + $pagenb=0; + $pdf->SetDrawColor(128,128,128); + $pdf->SetFillColor(220,220,220); - $pdf->SetTitle($outputlangs->convToOutputCharset($this->title)); - $pdf->SetSubject($outputlangs->convToOutputCharset($this->subject)); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject)); + $pdf->SetTitle($outputlangs->convToOutputCharset($this->title)); + $pdf->SetSubject($outputlangs->convToOutputCharset($this->subject)); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject)); - $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - $pdf->SetAutoPageBreak(1,0); + $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right + $pdf->SetAutoPageBreak(1,0); - $nbpage = $this->_pages($pdf, $outputlangs); + $nbpage = $this->_pages($pdf, $outputlangs); - $pdf->AliasNbPages(); - $pdf->Close(); + $pdf->AliasNbPages(); + $pdf->Close(); - $pdf->Output($file,'F'); - if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + $pdf->Output($file,'F'); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); - return 1; - } - } + return 1; + } + } - /** - * Write content of pages - * - * @param $pdf + /** + * Write content of pages + * + * @param $pdf * @param $outputlangs - * @return int 1 - */ - function _pages(&$pdf, $outputlangs) - { - $height=3; // height for text separation - $pagenb=1; + * @return int 1 + */ + function _pages(&$pdf, $outputlangs) + { + $height=3; // height for text separation + $pagenb=1; - $y=$this->_pagehead($pdf, $outputlangs, $pagenb); - $y++; - $pdf->SetFont('','',8); + $y=$this->_pagehead($pdf, $outputlangs, $pagenb); + $y++; + $pdf->SetFont('','',8); - $sql = "SELECT s.nom as societe, s.rowid as socid, s.client,"; - $sql.= " a.id, a.datep as dp, a.datep2 as dp2,"; - $sql.= " a.fk_contact, a.note, a.percent as percent,"; - $sql.= " c.libelle,"; - $sql.= " u.login"; - $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE a.fk_soc = s.rowid AND c.id=a.fk_action AND a.fk_user_author = u.rowid"; + $sql = "SELECT s.nom as societe, s.rowid as socid, s.client,"; + $sql.= " a.id, a.datep as dp, a.datep2 as dp2,"; + $sql.= " a.fk_contact, a.note, a.percent as percent,"; + $sql.= " c.libelle,"; + $sql.= " u.login"; + $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u"; + $sql.= " WHERE a.fk_soc = s.rowid AND c.id=a.fk_action AND a.fk_user_author = u.rowid"; // TODO remove usage of date_format - $sql.= " AND date_format(a.datep, '%m') = '".$this->month."'"; - $sql.= " AND date_format(a.datep, '%Y') = '".$this->year."'"; - $sql.= " ORDER BY a.datep DESC"; + $sql.= " AND date_format(a.datep, '%m') = '".$this->month."'"; + $sql.= " AND date_format(a.datep, '%Y') = '".$this->year."'"; + $sql.= " ORDER BY a.datep DESC"; - dol_syslog("Rapport.pdf::_page sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - $y0=$y1=$y2=$y3=0; + dol_syslog("Rapport.pdf::_page sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + $y0=$y1=$y2=$y3=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); - $y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3); + $y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3); - // Calculate height of text - $text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150); - //print 'd'.$text; exit; - $nboflines=dol_nboflines($text); - $heightlinemax=max(2*$height,$nboflines*$height); - // Check if there is enough space to print record - if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute)) - { - // We need to break page - $pagenb++; - $y=$this->_pagehead($pdf, $outputlangs, $pagenb); - $y++; - $pdf->SetFont('','',8); - } - $y++; + // Calculate height of text + $text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150); + //print 'd'.$text; exit; + $nboflines=dol_nboflines($text); + $heightlinemax=max(2*$height,$nboflines*$height); + // Check if there is enough space to print record + if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute)) + { + // We need to break page + $pagenb++; + $y=$this->_pagehead($pdf, $outputlangs, $pagenb); + $y++; + $pdf->SetFont('','',8); + } + $y++; - $pdf->SetXY($this->marge_gauche, $y); - $pdf->MultiCell(22, $height, dol_print_date($this->db->jdate($obj->dp),"day")."\n".dol_print_date($this->db->jdate($obj->dp),"hour"), 0, 'L', 0); - $y0 = $pdf->GetY(); + $pdf->SetXY($this->marge_gauche, $y); + $pdf->MultiCell(22, $height, dol_print_date($this->db->jdate($obj->dp),"day")."\n".dol_print_date($this->db->jdate($obj->dp),"hour"), 0, 'L', 0); + $y0 = $pdf->GetY(); - $pdf->SetXY(26, $y); - $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0); - $y1 = $pdf->GetY(); + $pdf->SetXY(26, $y); + $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0); + $y1 = $pdf->GetY(); - $pdf->SetXY(60,$y); - $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0); - $y2 = $pdf->GetY(); + $pdf->SetXY(60,$y); + $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0); + $y2 = $pdf->GetY(); - $pdf->SetXY(106,$y); - $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0); - $y3 = $pdf->GetY(); + $pdf->SetXY(106,$y); + $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0); + $y3 = $pdf->GetY(); - //$pdf->MultiCell(94,2,"y=$y y3=$y3",0,'L',0); + //$pdf->MultiCell(94,2,"y=$y y3=$y3",0,'L',0); - $i++; - } - } + $i++; + } + } - return 1; - } + return 1; + } - /** - * \brief Affiche en-tete facture - * \param pdf Objet PDF - * \param outputlang Objet lang cible - * \param pagenb Page nb - */ - function _pagehead(&$pdf, $outputlangs, $pagenb) - { - global $conf,$langs; + /** + * \brief Affiche en-tete facture + * \param pdf Objet PDF + * \param outputlang Objet lang cible + * \param pagenb Page nb + */ + function _pagehead(&$pdf, $outputlangs, $pagenb) + { + global $conf,$langs; - // Do not add the BACKGROUND as this is a report - //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); + // Do not add the BACKGROUND as this is a report + //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); - // New page - $pdf->AddPage(); + // New page + $pdf->AddPage(); - // Show title - $pdf->SetFont('','B',10); - $pdf->SetXY($this->marge_gauche, $this->marge_haute); - $pdf->MultiCell(80, 1, $this->title, 0, 'L', 0); - $pdf->SetXY($this->page_largeur-$this->marge_droite-40, $this->marge_haute); - $pdf->MultiCell(40, 1, $pagenb.'/{nb}', 0, 'R', 0); + // Show title + $pdf->SetFont('','B',10); + $pdf->SetXY($this->marge_gauche, $this->marge_haute); + $pdf->MultiCell(120, 1, $outputlangs->convToOutputCharset($this->title), 0, 'L', 0); + $pdf->SetXY($this->page_largeur-$this->marge_droite-40, $this->marge_haute); + $pdf->MultiCell(40, 1, $pagenb.'/{nb}', 0, 'R', 0); - $y=$pdf->GetY()+2; + $y=$pdf->GetY()+2; - $pdf->Rect($this->marge_gauche, $y, - $this->page_largeur - $this->marge_gauche - $this->marge_droite, - $this->page_hauteur - $this->marge_haute - $this->marge_basse); - $y=$pdf->GetY()+1; + $pdf->Rect($this->marge_gauche, $y, + $this->page_largeur - $this->marge_gauche - $this->marge_droite, + $this->page_hauteur - $this->marge_haute - $this->marge_basse); + $y=$pdf->GetY()+1; - return $y; - } + return $y; + } } ?>