<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I"; 
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
include('DF80000.php');
 
class PDF extends FPDF{
	//Cabecera de Página
	function Header(){
	    //Logotipo
	    include("DYIM_VER.php");
	    //Arial Bold (14)
	    $this->SetFont('Arial','B',12);
	    //Espacio
		$varfa=(isset($dt_empres['fec_alta']))?$dt_empres['fec_alta']:"";
	    //Título		
	 
	
	    //Salto de línea
	    $this->Ln(3);
	}
	//Pie de Página
	function Footer()
	{
	    //Posición: 1,5 cm del Final
	    $this->SetY(-15);
	    //Arial Italic 8
	    $this->SetFont('Arial','I',8);
	    //Número de página
	    $this->Cell(0,0, $this->PageNo().'/{nb}',0,0,'C');
	}
}
$pdf;
$pdf=new PDF('L','mm','Letter');
$pdf->AddPage('L','Letter');
$pdf->AliasNbPages();
$binit=-1;
$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo<>'MAESTRA' and nstarecep='OCUPADO' and nstaamalla='LIMPIO' order by ncto");
	$lm=0;
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm=0;
	
	$pdf->Cell(180,3,' OCUPADO-LIMPIO',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if (($fila['nstaamalla']=='LIMPIO') && ($fila['nstarecep']=='OCUPADO')){
				$st='LIMPIO';	
				$lm++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,$st,0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if(isset($resto)&&$resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"JJJJSSSSSSSSSSSSSSSSSSSSSSSSSS",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if(isset($resto)&&$resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"FFFFFFFFFFFFFFF",0,1,'C',0); 
  	} //**********************************************************************************************************
	
	$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo<>'MAESTRA' and nstarecep='VACIO' and ocupado='#00CC00' order by ncto");
	$lm1=0;
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm1=0;
	
	$pdf->Cell(180,3,' VACIAS-LIMPIAS',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if (($fila['ocupado']=='#00CC00') && ($fila['nstarecep']=='VACIO')){
				$st='LIMPIO';	
				$lm1++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,$st,0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if($resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if($resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"",0,1,'C',0); 
  	} //********************************************************************************************************** 
	
	$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo!='MAESTRA' and nstarecep='OCUPADO' and nstaamalla='SUCIO' order by ncto");
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm2=0;
	
	$pdf->Cell(180,3,' OCUPADO-SUCIO',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if (($fila['nstaamalla']=='SUCIO') && ($fila['nstarecep']=='OCUPADO')){
				$st='SUCIO';	
				$lm2++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,$st,0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if($resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if($resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"",0,1,'C',0); 
  	} //**********************************************************************************************************
	
	$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo<>'MAESTRA' and nstarecep='VACIO' and nstaamalla='SUCIO' order by ncto");
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm3=0;
	
	$pdf->Cell(180,3,' VACIO-SUCIO',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if (($fila['nstaamalla']=='SUCIO') && ($fila['nstarecep']=='VACIO')){
				$st='SUCIO';	
				$lm3++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,$st,0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if($resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if($resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"",0,1,'C',0); 
  	} //**********************************************************************************************************
	
	$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo<>'MAESTRA' and nstarecep='RESERVADO' order by ncto");
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm5=0;
	
	$pdf->Cell(180,3,' RESERVADO',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if ($fila['nstarecep']=='RESERVADO'){
				//$st='SUCIO';	
				$lm5++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,'',0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if($resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if($resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"",0,1,'C',0); 
  	} //**********************************************************************************************************

$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo<>'MAESTRA' and nstaamalla='FUERA' order by ncto");
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm7=0;
	
	$pdf->Cell(180,3,' FUERA DE SERVICIO',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if (($fila['nstaamalla']=='FUERA')){
				$st='FUERA';	
				$lm7++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,$st,0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if($resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if($resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"",0,1,'C',0); 
  	}

$fecha=(isset($_POST['fecha']))?$_POST['fecha']:"";
	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	 $numcolumnas = 3;  
	$consulta = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus08 where ntipo<>'MAESTRA' and nstaamalla='BLOQUEADO' order by ncto");
	
	$pdf->Cell(10,3,'',0,0,'C',0);
	$lm6=0;
	
	$pdf->Cell(180,3,' BLOQUEADO',0,1,'C',1);
	$total_resultados = mysqli_num_rows($consulta);  
		while($fila = mysqli_fetch_array($consulta)){   
		$resto = ($i % $numcolumnas);   
  		if($resto == 1){ /*si es el primer elemento creamos una nueva fila*/  
			$pdf->Cell(10,0,'',0,1,'C',0);
	  	}
  		//aqui va el contenido 
			$pdf->SetFont('ARIAL','B',6);
			$pdf->Cell(5,4,'',0,0,'C',0);			
		    $pdf->Cell(15,4,$fila['ncto'],0,0,'R',0);	
		    $pdf->Cell(15,4,$fila['ntipo'],0,0,'L',0);	
			if (($fila['nstaamalla']=='BLOQUEADO')){
				$st='BLOQUEADO';	
				$lm6++;		
			}
		
		
			$pdf->Cell(15,4,$fila['nstarecep'],0,0,'L',0);							
			$pdf->Cell(15,4,$st,0,0,'L',0);					
//			$pdf->Cell(20,4,'',0,0,'L',0);			
	   if($resto == 0){/*cerramos la fila*/  
   			$pdf->Cell(195,4,"",0,1,'C',0); 
	   }   
	   
   	   $i++;   
   	}   
  	if($resto != 0){/*Si en la última fila sobran columnas, creamos celdas vacías*/  
 		for ($j = 0; $j < ($numcolumnas - $resto); $j++){   
		$pdf->Cell(39,4,"",0,0,'C',0); 
  		}   
	$pdf->Cell(195,4,"",0,1,'C',0); 
  	}


$pdf->SetFont('Arial','B',9);//establece tamaño de letra
		$pdf->SetFillColor(192,192,192);
		$pdf->Cell(30,5,'',0,1,'C',0);
		$pdf->Cell(30,5,'',0,0,'C',0);
		$pdf->Cell(40,5,'STATUS ',10,0,'C',1);
		$pdf->Cell(30,5,'CANTIDAD',10,0,'C',1);		
		$pdf->Cell(40,5,'STATUS ',10,0,'C',1);
		$pdf->Cell(30,5,'CANTIDAD',10,1,'C',1);				

		$pdf->Cell(30,5,'',0,0,'C',0);
		$pdf->Cell(40,5,'OCUPADO-LIMPIO: ',10,0,'R',1);
		$pdf->Cell(30,5,$lm,0,0,'C',0);		
		$pdf->Cell(40,5,'OCUPADO-SUCIO: ',10,0,'R',1);
		$pdf->Cell(30,5,$lm2,0,1,'C',0);		
		
		$pdf->Cell(30,5,'',0,0,'C',0);
		$pdf->Cell(40,5,'VACIO-LIMPIO: ',10,0,'R',1);
		$pdf->Cell(30,5,$lm1,0,0,'C',0);		
		$pdf->Cell(40,5,'VACIO-SUCIO: ',10,0,'R',1);
		$pdf->Cell(30,5,$lm3,0,1,'C',0);				
		
		$pdf->Cell(30,5,'',0,0,'C',0);
		$pdf->cell(40,5,'CHECAR: ',10,0,'R',1);
                $varc=(isset($ch))?$ch:"";
		$pdf->Cell(30,5,$varc,0,0,'C',0);				
		$pdf->cell(40,5,'FUERA DE SERVICIO: ',10,0,'R',1);
		$pdf->Cell(30,5,$lm7,0,1,'C',0);				

		$pdf->Cell(30,5,'',0,0,'C',0);
		$pdf->cell(40,5,'BLOQUEADO:  ',10,0,'R',1);
				$pdf->Cell(30,5,$lm6,0,0,'C',0);		
		$pdf->cell(40,5,'RESERVADO: ',10,0,'R',1);
				$pdf->Cell(30,5,$lm5,0,1,'C',0);	
				
		$pdf->Cell(30,5,'',0,0,'C',0);	
		$pdf->cell(80,5,'TOTAL: ',10,0,'R',1);
				$pdf->Cell(30,5,$e=$lm+$lm1+$lm2+$lm3+$lm5+$lm6+$lm7,0,1,'C',0);				


$pdf->Output("REPORTE AMA DE LLAVES.pdf","D");
?>


