Si quieres el codigo entero:
Código PHP:
<?
require("../../../../aut_verifica.inc.php");
error_reporting(E_ALL);
include('../../../class/class.ezpdf.php');
$pdf = & new Cezpdf('A4','landscape');
$pdf->selectFont('../../../class/fonts/Helvetica');
$pdf->ezStartPageNumbers(800,10,10,'','{PAGENUM} de {TOTALPAGENUM}',1); */
//-------------------------------------
//-- Variable per fer la clausula Where
$WHEREHAN = '';
$WHEREEMPRESA = '';
$ur = '';
if (isset($_GET['id_empresa']) && ($_GET['id_empresa'] > 0)){
$WHEREEMPRESA = " WHERE id_empresa=$_GET[id_empresa]";
$ur .= "&id_empresa=$_GET[id_empresa]";
}else{
$WHEREEMPRESA = " WHERE id_empresa=1 or id_empresa=3";
}
if (isset($_GET['id_seccio']) && ($_GET['id_seccio'] > 0)){
$WHERESECCIO = " AND hores= 1 AND id_seccio=$_GET[id_seccio]";
$ur .= "&id_seccio=$_GET[id_seccio]";
}else{
$WHERESECCIO = " AND hores = 1";
}
if (isset($_GET['cooperativa']) && ($_GET['cooperativa'] != 3)){
$WHEREHAN .= " AND cooperativa = $_GET[cooperativa]";
$ur .= "&cooperativa=$_GET[cooperativa]";
}
if (isset($_GET['desde'])){
$desde = ($_GET['desde']);
$ur .= "&desde=$desde";
}
if(isset($_GET['fins'])){
$fins = ($_GET['fins']);
$ur .= "&fins=$fins";
}
if($_GET['desde'] == $_GET['fins']){
$capcesetmana = "Fecha ".$_GET['desde'];
}else{
$capcesetmana = "Fecha Desde ".$_GET['desde']." - Hasta ".$_GET['fins'];
}
// --------------------------------------------------------------------------------- //
$data = array();
// -- Absencies entre dates --//
$str_abs = "SELECT DISTINCT h.id_tipoabsencia, tipoabsencia
FROM hores h,tipo_absencia ta
WHERE h.id_tipoabsencia != 0 AND ta.situacio = 0 AND festiu=0
AND h.id_tipoabsencia = ta.id_tipoabsencia
AND data >=".$desde." AND data <=".$fins."
GROUP BY h.id_tipoabsencia";
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
$nreg_abs = mysql_num_rows($sql_abs);
// ---------------------------- //
// -- Busquem la empresa ---- //
$str_empresa = "SELECT id_empresa,nom_empresa FROM empresa $WHEREEMPRESA
ORDER BY id_empresa ASC";
$sql_empresa = mysql_query($str_empresa) or die("ERROR SQL EMPRESA: ".mysql_error());
$nreg_empresa = mysql_num_rows($sql_empresa);
if($nreg_empresa != 0){
while($res_empresa = mysql_fetch_row($sql_empresa)){
$idempresa = $res_empresa[0];
$nomempresa = $res_empresa[1];
/*
echo $idempresa."<br>";
*/
$pdf->ezText($nomempresa,10,array('justification' => 'center'));
$pdf->ezText('',10);
$str_seccio = "SELECT id_seccio, nom_seccio
FROM seccio WHERE id_empresa = ".$res_empresa['0']."
$WHERESECCIO
ORDER BY nom_seccio ASC";
$sql_seccio = mysql_query($str_seccio) or die("ERROR SQL EMPRESA: ".mysql_error());
$nreg_seccio = mysql_num_rows($sql_seccio);
if($nreg_seccio != 0){
while($res_seccio= mysql_fetch_row($sql_seccio)){
//echo $WHEREHAN;
$str_hores_persona = "SELECT p.id_persona,p.dni, p.nom, p.cognom1, p.cognom2, p.cooperativa
FROM hores h INNER JOIN personal p
ON h.id_persona = p.id_persona
WHERE p.id_seccio=".$res_seccio['0']." AND p.id_persona != ''
AND data >= ".$desde." AND data <= ".$fins." $WHEREHAN
GROUP BY p.dni ORDER BY p.id_seccio,p.dni";
/*
echo $str_hores_persona."<br>";
*/
$sql_hores_persona = mysql_query($str_hores_persona) or die("Error en consulta 1: ".mysql_error());
$nreg_hores_persona = mysql_num_rows($sql_hores_persona);
/*
echo $nreg_hores_persona."<br>";
*/
if ($nreg_hores_persona != 0){
/**/
//-- coloca una linia a dalt i baix a totes les pagines
$all = $pdf->openObject();
$pdf->saveState();
$pdf->setStrokeColor(0,0,0,1);
$pdf->line(20,20,830,20);
$pdf->line(20,575,830,575);
$pdf->addText(20,580,10,'Horas Semanales por Seccion - Arcadíe España - '.$capcesetmana);
$pdf->addText(750,580,10,'RRHH');
$pdf->addText(730,10,10,'Pagina');
$pdf->restoreState();
$pdf->closeObject();
//-- acaba les lineas
$pdf->addObject($all,'all');
/**/
//-- Aqui es coloca la capçelera de la Taula -- //
$cols = array('persona' => 'Persona');
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
while($res_abs = mysql_fetch_row($sql_abs)){
$cols[] = array($res_abs['0'] => $res_abs['1']) ;
}
// ------------------------------------------- //
/*
echo "<pre>";
print_r($cols);
echo "</pre>";
*/
while ($res_hores_persona = mysql_fetch_row($sql_hores_persona)) {
//nom de la persona
$nomcomplet = $res_hores_persona['3']." ".$res_hores_persona['4'].", ".$res_hores_persona['2'];
$nomcomplet = htmlentities($nomcomplet);
$data[] = array('Persona' => $nomcomplet);
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
while($res_abs = mysql_fetch_row($sql_abs)){
$str_hores_abs = "SELECT sum(absencia)
FROM hores h INNER JOIN personal p
ON h.id_persona = p.id_persona
WHERE p.id_seccio=".$res_seccio['0']." AND p.id_persona = ".$res_hores_persona['0']."
AND id_tipoabsencia = ".$res_abs['0']." AND data >= ".$desde." AND data <= ".$fins."
GROUP BY p.dni,id_tipoabsencia";
//echo $str_hores_abs."<br>";
$sql_hores_abs = mysql_query($str_hores_abs)or die("Error SQL Horas Ausencia: ".mysql_error());
$nreg_hores_abs = mysql_num_rows($sql_hores_abs);
if($nreg_hores_abs !=0){
$res_hores_abs = mysql_fetch_row($sql_hores_abs);
$hores_abs = $res_hores_abs['0'];
}else{
$hores_abs = 0;
}
$data[] = array($res_abs[0] => number_format($hores_abs,2,",","."));
}// -- while($res_abs = mysql_fetch_row($sql_abs)){
}// -- while ($res_hores_persona = mysql_fetch_row($sql_hores_persona)) {
}// -- if ($nreg_hores_persona != 0){
}// -- while($res_seccio= mysql_fetch_row($sql_seccio)){
}// -- if($nreg_seccio != 0){
}// -- while($res_empresa = mysql_fetch_row($sql_empresa)){
}// --if($nreg_empresa != 0){
$pdf->ezTable($data,$cols,'',array('fontSize'=>8,
'cols'=>array( 'persona' => array('justification' => 'left'),
'$res_abs['1']' => array('justification' => 'right'))
));//-- sortida
$pdf->ezText('',10);
$data = '';
if (isset($d) && $d){
$pdfcode = $pdf->ezOutput(); //-- Necessari xq funcioni ezStartPageNumbers
$pdfcode = str_replace('\n','\n<br>',htmlspecialchars($pdfcode));
echo '<html><body>';
echo trim($pdfcode);
echo '</body></html>';
} else {
$pdf->ezStream(); //Necessari xq funcioni ezStartPageNumbers
}
/*
echo "<pre>";
print_r($data);
echo "</pre>";
/**/
?>
El problema lo tengo en el final:
Código PHP:
$pdf->ezTable($data,$cols,'',array('fontSize'=>8,
'cols'=>array( 'persona'=> array('justification' => 'left'),
//AQUI TENDRIA Q METER EL BUCLE PARA CUADRAR LAS COLUMNAS Y NO SER COMO HACERLO
/*
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
while($res_abs = mysql_fetch_row($sql_abs)){
$cols[] = array($res_abs['0'] => array('justification' => 'right') ;
}
*/
$res_abs['0']=> array('justification' => 'right'))
));//-- sortida