Meilleur formatage du rapport mensuel des actions

This commit is contained in:
Laurent Destailleur 2005-08-19 17:26:57 +00:00
parent cc9868337b
commit 00179a5643

View File

@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -18,178 +19,165 @@
*
* $Id$
* $Source$
*
*/
/** \file htdocs/comm/action/rapport/rapport.pdf.php
/**
\file htdocs/comm/action/rapport/rapport.pdf.php
\ingroup commercial
\brief Fichier de generation de PDF pour les rapports d'actions
\version $Revision$
*/
require (DOL_DOCUMENT_ROOT ."/includes/fpdf/fpdf_indexes.php");
require (DOL_DOCUMENT_ROOT ."/includes/fpdf/fpdf_html.php");
/**
\class CommActionRapport
\brief Classe permettant la generation des rapports d'actions
*/
class CommActionRapport {
function CommActionRapport($db=0, $month, $year)
{
$this->db = $db;
$this->description = "";
$this->date_edition = strftime("%d %B %Y", time());
$this->month = $month;
$this->year = $year;
}
function generate($socid = 0, $catid = 0)
class CommActionRapport
{
var $title;
var $subject;
function CommActionRapport($db=0, $month, $year)
{
global $user,$conf;
global $langs;
$this->db = $db;
$this->description = "";
$this->date_edition = dolibarr_print_date(time(),"%d %B %Y");
$this->month = $month;
$this->year = $year;
$dir = $conf->commercial->dir_output;
if (! file_exists($dir))
{
umask(0);
if (! mkdir($dir, 0755))
{
return "Error";
}
}
$dir = $conf->commercial->dir_output . "/comm";
if (! file_exists($dir))
{
umask(0);
if (! mkdir($dir, 0755))
{
return "Error";
}
}
$dir = $conf->commercial->dir_output . "/comm/actions";
if (! file_exists($dir))
{
umask(0);
if (! mkdir($dir, 0755))
{
return "Error";
}
}
$file = $dir . "/rapport-action-".$this->month."-".$this->year.".pdf";
if (file_exists($dir))
{
$pdf=new PDF_html('P','mm','A4');
$pdf->Open();
$pdf->SetTitle("Rapport Commercial");
$pdf->SetSubject("Rapport Commercial");
$pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($user->fullname);
$pdf->SetFillColor(220,220,220);
$pdf->SetFont('Arial','', 9);
// $nbpage = $this->_cover($pdf);
$nbpage = $this->_pages($pdf);
$pdf->Close();
$pdf->Output($file);
return 1;
}
$this->title=$langs->trans("ActionsReport").' '.$this->year."-".$this->month;
$this->subject=$langs->trans("ActionsReport").' '.$this->year."-".$this->month;
}
/*
*
*
*
*/
function _cover(&$pdf)
function generate($socid = 0, $catid = 0)
{
global $user,$conf,$langs;
$dir = $conf->commercial->dir_output."/comm/actions";
$file = $dir . "/rapport-action-".$this->month."-".$this->year.".pdf";
create_exdir($dir);
if (file_exists($dir))
{
$pdf=new PDF_html('P','mm','A4');
$pdf->Open();
$pdf->SetTitle($this->title);
$pdf->SetSubject($this->subject);
$pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($user->fullname);
$pdf->SetFillColor(220,220,220);
$pdf->SetFont('Arial','', 9);
// $nbpage = $this->_cover($pdf);
$nbpage = $this->_pages($pdf);
$pdf->Close();
$pdf->Output($file);
return 1;
}
}
/*
*
*/
function _cover(&$pdf)
{
global $user;
$pdf->AddPage();
$pdf->SetAutoPageBreak(false);
$pdf->SetFont('Arial','',40);
$pdf->SetXY (10, 80);
$pdf->MultiCell(190, 20, "Rapport Commercial", 0, 'C', 0);
$pdf->SetFont('Arial','',30);
$pdf->SetXY (10, 140);
$pdf->MultiCell(190, 20, "Edition du ".$this->date_edition, 0, 'C', 0);
$pdf->AddPage();
$pdf->SetAutoPageBreak(false);
$pdf->SetFont('Arial','',40);
$pdf->SetXY (10, 80);
$pdf->MultiCell(190, 20, $langs->trans("ActionsReport").' '.$title, 0, 'C', 0);
$pdf->SetFont('Arial','',30);
$pdf->SetXY (10, 140);
$pdf->MultiCell(190, 20, $langs->trans("Date").': '.$this->date_edition, 0, 'C', 0);
$pdf->SetXY (10, 170);
$pdf->SetFont('Arial','B',18);
$pdf->MultiCell(190, 15, $user->fullname, 0, 'C');
$pdf->SetFont('Arial','B',16);
$pdf->MultiCell(190, 15, "Tél : +33 (0) 6 13 79 63 41", 0, 'C');
$pdf->SetXY (10, 170);
$pdf->SetFont('Arial','B',18);
$pdf->MultiCell(190, 15, $user->fullname, 0, 'C');
$pdf->SetFont('Arial','B',16);
$pdf->MultiCell(190, 15, "Tél : +33 (0) 6 13 79 63 41", 0, 'C');
$pdf->SetFont('Arial','',10);
$pdf->SetXY (10, 277);
$pdf->MultiCell(190, 10, "http://www.lafrere.com/", 1, 'C', 1);
$pdf->SetFont('Arial','',10);
$pdf->SetXY (10, 277);
$pdf->MultiCell(190, 10, "http://www.lafrere.com/", 1, 'C', 1);
$pdf->Rect(10, 10, 190, 277);
return 1;
$pdf->Rect(10, 10, 190, 277);
return 1;
}
/*
*
*/
function _pages(&$pdf)
/*
*
*/
function _pages(&$pdf)
{
$pdf->AddPage();
$pdf->SetAutoPageBreak(true);
$pdf->AddPage();
$pdf->SetAutoPageBreak(true);
$sql = "SELECT s.nom as societe, s.idp as socidp, s.client, a.id,".$this->db->pdate("a.datea")." as da, a.datea, c.libelle, u.code, a.fk_contact, a.note, a.percent as percent";
$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.idp AND c.id=a.fk_action AND a.fk_user_author = u.rowid";
$sql .= " AND date_format(a.datea, '%m') = ".$this->month;
$sql .= " AND date_format(a.datea, '%Y') = ".$this->year;
$sql .= " ORDER BY a.datea DESC";
$pdf->SetFont('Arial','B',10);
$pdf->SetXY(5, $pdf->GetY());
$pdf->MultiCell(80, 2, $this->title, 0, 'L', 0);
if ($this->db->query($sql))
{
$num = $this->db->num_rows();
$i = 0;
$y1 = 0;
$y2 = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object();
$y = max($pdf->GetY(), $y1, $y2) + 1;
$pdf->SetFont('Arial','',10);
$pdf->SetFont('Arial','',9);
$y=$pdf->GetY()+1;
$sql = "SELECT s.nom as societe, s.idp as socidp, s.client, a.id,".$this->db->pdate("a.datea")." as da, a.datea, c.libelle, u.code, a.fk_contact, a.note, a.percent as percent";
$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.idp AND c.id=a.fk_action AND a.fk_user_author = u.rowid";
$pdf->SetXY(5, $y);
$pdf->MultiCell(15, 4, strftime('%d/%b',$obj->da), 0, 'L', 0);
$sql .= " AND date_format(a.datea, '%m') = ".$this->month;
$sql .= " AND date_format(a.datea, '%Y') = ".$this->year;
$pdf->SetXY(20, $y);
$pdf->MultiCell(40, 4, $obj->societe, 0, 'L', 0);
$sql .= " ORDER BY a.datea DESC";
$y1 = max($y, $pdf->GetY());
if ($this->db->query($sql))
{
$num = $this->db->num_rows();
$i = 0;
$y0=$y1=$y2=$y3=0;
$pdf->SetXY(60,$y);
$pdf->MultiCell(40, 4, $obj->libelle, 0, 'L', 0);
while ($i < $num)
{
$obj = $this->db->fetch_object();
$pdf->SetXY(100,$y);
$pdf->MultiCell(110, 4, $obj->note, 0, 'L', 0);
$y2 = max($y, $pdf->GetY());
$y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3) + 1;
$i++;
}
}
$pdf->SetXY(5, $y);
$pdf->MultiCell(20, 4, dolibarr_print_date($obj->da)."\n".dolibarr_print_date($obj->da,"%H:%m:%S"), 0, 'L', 0);
$y0 = $pdf->GetY();
$pdf->Rect(5, 5, 200, 287);
return 1;
$pdf->SetXY(25, $y);
$pdf->MultiCell(40, 4, $obj->societe, 0, 'L', 0);
$y1 = $pdf->GetY();
$pdf->SetXY(65,$y);
$pdf->MultiCell(40, 4, $obj->libelle, 0, 'L', 0);
$y2 = $pdf->GetY();
$pdf->SetXY(105,$y);
$pdf->MultiCell(112, 4, eregi_replace('<br>',"\n",$obj->note), 0, 'L', 0);
$y3 = $pdf->GetY();
$i++;
}
}
$pdf->Rect(5, 5, 200, 287);
return 1;
}