2004-10-19 20:19:58 +00:00
< ? php
2005-08-19 17:26:57 +00:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-12-30 11:40:32 +00:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 14:11:07 +00:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2004-03-01 10:51:02 +00:00
*
* 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
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2004-03-01 10:51:02 +00:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-07-31 23:24:38 +00:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2004-03-01 10:51:02 +00:00
* or see http :// www . gnu . org /
*/
2005-01-09 01:46:34 +00:00
2005-08-19 17:26:57 +00:00
/**
2011-10-24 12:11:49 +00:00
* \file htdocs / core / modules / action / rapport . pdf . php
2010-02-24 16:25:34 +00:00
* \ingroup commercial
2011-02-20 15:37:56 +00:00
* \brief File to build PDF with events
2009-03-28 19:59:12 +00:00
*/
2005-01-09 01:46:34 +00:00
2012-08-22 21:11:24 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2005-01-09 01:46:34 +00:00
2005-08-19 17:26:57 +00:00
/**
2012-12-30 11:40:32 +00:00
* Class to generate event report
2009-03-28 19:59:12 +00:00
*/
2005-08-19 17:26:57 +00:00
class CommActionRapport
{
2009-03-28 19:59:12 +00:00
var $db ;
var $description ;
var $date_edition ;
var $year ;
var $month ;
var $title ;
var $subject ;
2012-11-14 10:31:08 +00:00
var $marge_gauche ;
var $marge_droite ;
var $marge_haute ;
var $marge_basse ;
2012-10-31 12:48:59 +00:00
2012-01-10 09:53:04 +00:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
* @ param int $month Month
* @ param int $year Year
*/
2012-03-14 10:49:11 +00:00
function __construct ( $db , $month , $year )
2009-03-28 19:59:12 +00:00
{
2012-10-31 12:48:59 +00:00
global $conf , $langs ;
2009-03-28 19:59:12 +00:00
$langs -> load ( " commercial " );
$this -> db = $db ;
$this -> description = " " ;
$this -> date_edition = time ();
$this -> month = $month ;
$this -> year = $year ;
// Dimension page pour format A4
$this -> type = 'pdf' ;
2011-08-31 12:24:47 +00:00
$formatarray = pdf_getFormat ();
$this -> page_largeur = $formatarray [ 'width' ];
$this -> page_hauteur = $formatarray [ 'height' ];
2009-03-28 19:59:12 +00:00
$this -> format = array ( $this -> page_largeur , $this -> page_hauteur );
2012-10-31 12:48:59 +00:00
$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 ;
2009-03-28 19:59:12 +00:00
2011-02-20 15:22:07 +00:00
$this -> title = $langs -> transnoentitiesnoconv ( " ActionsReport " ) . ' ' . $this -> year . " - " . $this -> month ;
$this -> subject = $langs -> transnoentitiesnoconv ( " ActionsReport " ) . ' ' . $this -> year . " - " . $this -> month ;
2009-03-28 19:59:12 +00:00
}
2010-11-11 01:09:41 +00:00
/**
* Write the object to document file to disk
2012-01-10 09:53:04 +00:00
*
* @ param int $socid Thirdparty id
* @ param int $catid Cat id
* @ param Translate $outputlangs Lang object for output language
* @ return int 1 = OK , 0 = KO
2010-11-11 01:09:41 +00:00
*/
function write_file ( $socid = 0 , $catid = 0 , $outputlangs = '' )
2009-03-28 19:59:12 +00:00
{
global $user , $conf , $langs ;
2005-08-19 17:26:57 +00:00
2008-05-02 19:19:02 +00:00
if ( ! is_object ( $outputlangs )) $outputlangs = $langs ;
2010-10-02 11:12:20 +00:00
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
2011-08-11 12:13:59 +00:00
if ( ! empty ( $conf -> global -> MAIN_USE_FPDF )) $outputlangs -> charset_output = 'ISO-8859-1' ;
2009-01-15 22:49:06 +00:00
2008-05-02 19:19:02 +00:00
$outputlangs -> load ( " main " );
$outputlangs -> load ( " dict " );
$outputlangs -> load ( " companies " );
$outputlangs -> load ( " bills " );
$outputlangs -> load ( " products " );
2009-01-15 22:49:06 +00:00
2011-02-20 15:22:07 +00:00
$dir = $conf -> agenda -> dir_temp . " / " ;
2009-03-28 19:59:12 +00:00
$file = $dir . " actions- " . $this -> month . " - " . $this -> year . " .pdf " ;
if ( ! file_exists ( $dir ))
{
2012-02-19 17:34:22 +00:00
if ( dol_mkdir ( $dir ) < 0 )
2009-03-28 19:59:12 +00:00
{
$this -> error = $langs -> trans ( " ErrorCanNotCreateDir " , $dir );
return 0 ;
}
}
if ( file_exists ( $dir ))
{
2010-12-20 23:43:45 +00:00
$pdf = pdf_getInstance ( $this -> format );
2012-09-19 12:49:13 +00:00
$heightforinfotot = 50 ; // Height reserved to output the info and total part
2012-11-03 12:49:31 +00:00
$heightforfreetext = ( isset ( $conf -> global -> MAIN_PDF_FREETEXT_HEIGHT ) ? $conf -> global -> MAIN_PDF_FREETEXT_HEIGHT : 5 ); // Height reserved to output the free text on last page
2012-11-02 23:37:10 +00:00
$heightforfooter = $this -> marge_basse + 8 ; // Height reserved to output the footer (value include bottom margin)
2012-08-17 13:13:10 +00:00
$pdf -> SetAutoPageBreak ( 1 , 0 );
2008-05-02 19:19:02 +00:00
2010-09-01 14:32:13 +00:00
if ( class_exists ( 'TCPDF' ))
{
$pdf -> setPrintHeader ( false );
$pdf -> setPrintFooter ( false );
}
2010-11-13 02:58:29 +00:00
$pdf -> SetFont ( pdf_getPDFFont ( $outputlangs ));
2010-09-01 11:44:27 +00:00
2008-05-02 19:19:02 +00:00
$pdf -> Open ();
2009-01-29 01:57:56 +00:00
$pagenb = 0 ;
2008-05-02 19:19:02 +00:00
$pdf -> SetDrawColor ( 128 , 128 , 128 );
2009-03-28 19:59:12 +00:00
$pdf -> SetFillColor ( 220 , 220 , 220 );
2009-01-15 22:49:06 +00:00
$pdf -> SetTitle ( $outputlangs -> convToOutputCharset ( $this -> title ));
2009-03-28 19:59:12 +00:00
$pdf -> SetSubject ( $outputlangs -> convToOutputCharset ( $this -> subject ));
$pdf -> SetCreator ( " Dolibarr " . DOL_VERSION );
2010-07-18 10:39:07 +00:00
$pdf -> SetAuthor ( $outputlangs -> convToOutputCharset ( $user -> getFullName ( $outputlangs )));
2009-03-28 19:59:12 +00:00
$pdf -> SetKeywords ( $outputlangs -> convToOutputCharset ( $this -> title . " " . $this -> subject ));
2009-01-15 22:49:06 +00:00
2008-05-02 19:19:02 +00:00
$pdf -> SetMargins ( $this -> marge_gauche , $this -> marge_haute , $this -> marge_droite ); // Left, Top, Right
2009-01-15 22:49:06 +00:00
2009-03-28 19:59:12 +00:00
$nbpage = $this -> _pages ( $pdf , $outputlangs );
2008-05-02 19:19:02 +00:00
2013-06-08 14:29:59 +00:00
if ( method_exists ( $pdf , 'AliasNbPages' )) $pdf -> AliasNbPages ();
2009-03-28 19:59:12 +00:00
$pdf -> Close ();
2005-08-19 17:26:57 +00:00
2010-09-01 10:22:11 +00:00
$pdf -> Output ( $file , 'F' );
2009-01-15 22:49:06 +00:00
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
2009-03-28 19:59:12 +00:00
@ chmod ( $file , octdec ( $conf -> global -> MAIN_UMASK ));
2009-01-15 22:49:06 +00:00
2009-03-28 19:59:12 +00:00
return 1 ;
}
}
2005-08-19 17:26:57 +00:00
2008-05-02 19:19:02 +00:00
/**
* Write content of pages
*
2012-01-10 09:53:04 +00:00
* @ param PDF & $pdf Object pdf
* @ param Translate $outputlangs Object langs
* @ return int 1
2008-05-02 19:19:02 +00:00
*/
2009-03-28 19:59:12 +00:00
function _pages ( & $pdf , $outputlangs )
{
2008-05-02 19:19:02 +00:00
$height = 3 ; // height for text separation
2009-03-28 19:59:12 +00:00
$pagenb = 1 ;
2009-01-15 22:49:06 +00:00
2008-05-02 19:19:02 +00:00
$y = $this -> _pagehead ( $pdf , $outputlangs , $pagenb );
2009-03-28 19:59:12 +00:00
$y ++ ;
2010-09-07 22:36:45 +00:00
$pdf -> SetFont ( '' , '' , 8 );
2009-01-15 22:49:06 +00:00
2008-05-02 19:19:02 +00:00
$sql = " SELECT s.nom as societe, s.rowid as socid, s.client, " ;
2010-05-08 16:45:47 +00:00
$sql .= " a.id, a.datep as dp, a.datep2 as dp2, " ;
2012-06-23 13:01:08 +00:00
$sql .= " a.fk_contact, a.note, a.percent as percent, a.label, " ;
$sql .= " c.code, c.libelle, " ;
2008-05-02 19:19:02 +00:00
$sql .= " u.login " ;
2011-02-20 15:37:56 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_actioncomm as c, " . MAIN_DB_PREFIX . " user as u, " . MAIN_DB_PREFIX . " actioncomm as a " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON a.fk_soc = s.rowid " ;
$sql .= " WHERE c.id=a.fk_action AND a.fk_user_author = u.rowid " ;
$sql .= " AND a.datep BETWEEN ' " . $this -> db -> idate ( dol_get_first_day ( $this -> year , $this -> month , false )) . " ' " ;
$sql .= " AND ' " . $this -> db -> idate ( dol_get_last_day ( $this -> year , $this -> month , false )) . " ' " ;
2009-03-28 19:59:12 +00:00
$sql .= " ORDER BY a.datep DESC " ;
2012-01-04 20:23:50 +00:00
dol_syslog ( get_class ( $this ) . " ::_page sql= " . $sql );
2009-03-28 19:59:12 +00:00
$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 );
$y = max ( $y , $pdf -> GetY (), $y0 , $y1 , $y2 , $y3 );
// Calculate height of text
2012-06-23 13:01:08 +00:00
$text = '' ;
if ( ! preg_match ( '/^' . preg_quote ( $obj -> label ) . '/' , $obj -> note )) $text = $obj -> label . " \n " ;
$text .= $obj -> note ;
$text = dol_trunc ( dol_htmlentitiesbr_decode ( $text ), 150 );
2009-03-28 19:59:12 +00:00
//print 'd'.$text; exit;
$nboflines = dol_nboflines ( $text );
$heightlinemax = max ( 2 * $height , $nboflines * $height );
2008-05-02 19:19:02 +00:00
// Check if there is enough space to print record
2009-03-28 19:59:12 +00:00
if (( 1 + $y + $heightlinemax ) >= ( $this -> page_hauteur - $this -> marge_haute ))
{
// We need to break page
$pagenb ++ ;
2008-05-02 19:19:02 +00:00
$y = $this -> _pagehead ( $pdf , $outputlangs , $pagenb );
2009-03-28 19:59:12 +00:00
$y ++ ;
2010-09-07 22:36:45 +00:00
$pdf -> SetFont ( '' , '' , 8 );
2009-03-28 19:59:12 +00:00
}
$y ++ ;
2012-12-30 11:40:32 +00:00
// Date
2009-03-28 19:59:12 +00:00
$pdf -> SetXY ( $this -> marge_gauche , $y );
2010-05-08 16:45:47 +00:00
$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 );
2009-03-28 19:59:12 +00:00
$y0 = $pdf -> GetY ();
2012-12-30 11:40:32 +00:00
// Third party
2009-03-28 19:59:12 +00:00
$pdf -> SetXY ( 26 , $y );
$pdf -> MultiCell ( 32 , $height , dol_trunc ( $outputlangs -> convToOutputCharset ( $obj -> societe ), 32 ), 0 , 'L' , 0 );
$y1 = $pdf -> GetY ();
2012-12-30 11:40:32 +00:00
// Action code
$code = $obj -> code ;
if ( empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ))
{
2013-01-10 07:27:12 +00:00
if ( $code == 'AC_OTH' ) $code = 'AC_MANUAL' ;
if ( $code == 'AC_OTH_AUTO' ) $code = 'AC_AUTO' ;
2012-12-30 11:40:32 +00:00
}
2009-03-28 19:59:12 +00:00
$pdf -> SetXY ( 60 , $y );
2012-12-30 11:40:32 +00:00
$pdf -> MultiCell ( 32 , $height , dol_trunc ( $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Action " . $code )), 32 ), 0 , 'L' , 0 );
2009-03-28 19:59:12 +00:00
$y2 = $pdf -> GetY ();
2012-12-30 11:40:32 +00:00
// Description of event
2009-03-28 19:59:12 +00:00
$pdf -> SetXY ( 106 , $y );
$pdf -> MultiCell ( 94 , $height , $outputlangs -> convToOutputCharset ( $text ), 0 , 'L' , 0 );
$y3 = $pdf -> GetY ();
$i ++ ;
}
}
return 1 ;
}
/**
2012-01-23 17:43:30 +00:00
* Show top header of page .
2011-08-31 14:42:47 +00:00
*
2012-01-23 17:43:30 +00:00
* @ param PDF & $pdf Object PDF
* @ param Translate $outputlangs Object lang for output
2012-01-04 20:23:50 +00:00
* @ param int $pagenb Page nb
2012-01-23 17:43:30 +00:00
* @ return void
2009-03-28 19:59:12 +00:00
*/
function _pagehead ( & $pdf , $outputlangs , $pagenb )
{
2008-05-02 19:19:02 +00:00
global $conf , $langs ;
2009-01-15 22:49:06 +00:00
2009-06-15 18:57:34 +00:00
// Do not add the BACKGROUND as this is a report
2010-08-31 21:02:01 +00:00
//pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
2009-06-15 18:57:34 +00:00
2008-05-02 19:19:02 +00:00
// New page
2009-03-28 19:59:12 +00:00
$pdf -> AddPage ();
2004-03-01 10:51:02 +00:00
2009-03-28 19:59:12 +00:00
// Show title
2010-09-07 22:36:45 +00:00
$pdf -> SetFont ( '' , 'B' , 10 );
2009-03-28 19:59:12 +00:00
$pdf -> SetXY ( $this -> marge_gauche , $this -> marge_haute );
2011-02-20 15:22:07 +00:00
$pdf -> MultiCell ( 120 , 1 , $outputlangs -> convToOutputCharset ( $this -> title ), 0 , 'L' , 0 );
2011-08-31 14:42:47 +00:00
// Show page nb only on iso languages (so default Helvetica font)
if ( pdf_getPDFFont ( $outputlangs ) == 'Helvetica' )
{
$pdf -> SetXY ( $this -> page_largeur - $this -> marge_droite - 40 , $this -> marge_haute );
$pdf -> MultiCell ( 40 , 1 , $pagenb . '/' . $pdf -> getAliasNbPages (), 0 , 'R' , 0 );
}
2009-01-15 22:49:06 +00:00
2009-03-28 19:59:12 +00:00
$y = $pdf -> GetY () + 2 ;
2008-05-02 19:19:02 +00:00
2012-01-04 20:23:50 +00:00
$pdf -> Rect ( $this -> marge_gauche , $y , ( $this -> page_largeur - $this -> marge_gauche - $this -> marge_droite ), ( $this -> page_hauteur - $this -> marge_haute - $this -> marge_basse ));
2008-05-02 19:19:02 +00:00
$y = $pdf -> GetY () + 1 ;
2009-01-15 22:49:06 +00:00
2008-05-02 19:19:02 +00:00
return $y ;
2009-03-28 19:59:12 +00:00
}
2004-03-01 10:51:02 +00:00
}
?>