<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
require_once("DF80000.php");
class PDF extends FPDF{
//Cabecera de página
	function Header(){
	    //Logo
	         include("DYIM_VER.php");
	    //Arial bold 14
		$this->SetFont('Arial','B',12);
		//Título
		$this->Cell(225,5,'REPORTE DE COLGADOS.',0,1,'C',0);
		//Salto de línea
		if($_POST['r1']=="f"){
		$this->Cell(55,5,'Periodo: '.$_POST['fec'].' al '.$_POST['fec2'],0,0,'C',0);
		}
		$this->Ln(8);
		$this->SetFont('Arial','B',6);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(-2,5,'',0,0,'C',0);
		$this->Cell(10,5,'FOLIO',1,0,'C',1);
		$this->Cell(50,5,'NOMBRE Y APELLIDO',1,0,'C',1);
		$this->cell(7,5,'ADUL',1,0,'C',1);
		$this->cell(6,5,'MEN',1,0,'C',1);
		$this->cell(6,5,'HAB',1,0,'C',1);
		$this->cell(12,5,'TIPO',1,0,'C',1);
		$this->cell(16,5,'FEC LLEGADA',1,0,'C',1);
		$this->cell(15,5,'FEC SALIDA',1,0,'C',1);
		$this->cell(13,5,'F DE PAGO',1,0,'C',1);
		$this->cell(16,5,'TARIFA',1,0,'C',1);
		$this->cell(32,5,'MERCADO',1,0,'C',1);
		$this->cell(32,5,'SEGMENTO',1,0,'C',1);	
		$this->cell(50,5,'NOTAS',1,1,'C',1);				
		
	}	
	//Pie de página
	function Footer()
	{
	//Posición: a 1,5 cm del final
	$this->SetY(-15);
	//Arial italic 8
	$this->SetFont('Arial','I',8);
	//Número de página
	$this->Cell(0,10, $this->PageNo(),0,0,'C');
	}
}

$pdf=new PDF('L','mm','Letter');
$pdf->AddPage();

$pdf->SetFillColor(192,192,192);
$pdf->SetFont('Arial','',7);//establece tamaño de letra

$tbus=mysqli_real_escape_string($GLOBALS['con'],$_POST['tbus']);
if($_POST['bot']==""){
	$sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'");
	@$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 where status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
   @$tothb=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where status = 'HUESPED' and ffecsalida='".$dt_empres['fec_alta']."' ");
	@$jso=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnumadu) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
	@$ahj=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnummenor) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
	  }
	if($_POST['r1']=="no"){
		$sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' order by n_reg");
		@$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 where status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
		@$tothb=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where status = 'HUESPED' and ffecsalida='".$dt_empres['fec_alta']."' ");
	    @$jso=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnumadu) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
	    @$ahj=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnummenor) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
	 	  }
	   elseif($_POST['r1']=="p"){
		  $sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' order by fapellido");
		  @$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 where status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
		  @$tothb=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' ");	
	      @$jso=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnumadu) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
	      @$ahj=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnummenor) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."'"));
	        }elseif($_POST['r1']=="hb"){
		echo '<input name="tbusqueda" type="hidden" value="hb">';
	  	$result = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' order by fnumcto ");
	    @$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 where status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' order by fnumcto"));
	    @$tothb=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where status = 'huesped' and fnumcto='".$_POST['cto']."' and ffecsalida='".$dt_empres['fec_alta']."' ");		
	    @$jso=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnumadu) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' order by fnumcto"));
	    @$ahj=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(fnummenor) AS total FROM valeryus19 WHERE status = 'huesped' and ffecsalida='".$dt_empres['fec_alta']."' order by fnumcto"));
	}
	
	$tohb1=mysqli_num_rows($tothb);
$a=0;
while($row = mysqli_fetch_array($sql)){
$a++;
	$pdf->SetFont('Arial','',6);
    $pdf-> Cell(-2,5,'',0,0,'C',0);
	if ($a>1){
	$pdf-> Cell(265,0.3,'',0,1,'L',1);		
	$pdf-> Cell(-2,5,'',0,0,'C',0);
	}
	$pdf-> Cell(10,5, $row["n_reg"],10,0,'C',0);
	$pdf-> Cell(50,5,' '.$row["fapellido"].' '.$row["fnombre"],10,0,'L',0);
	$pdf-> Cell(7,5, $row["fnumadu"],10,0,'C',0);
	$pdf-> Cell(6,5, $row["fnummenor"],10,0,'C',0);
	$pdf-> Cell(6,5, $row["fnumcto"],10,0,'C',0);
	$CuarTo=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from valeryus05 where descripcion='".$row['ftipocto']."'"));
	$pdf-> Cell(12,5, $CuarTo["clavetp"],10,0,'C',0);
	$pdf-> Cell(16,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	$pdf-> Cell(15,5, chfecha($row['ffecsalida'],'Y-m-d'),10,0,'C',0);
	$Forma=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from valeryus09 where descripcion='".$row['fformpago']."'"));
	$pdf-> Cell(13,5, $Forma["pclave"],10,0,'C',0);
	$pdf-> Cell(16,5, '$' .number_format($row["suma"], 2, '.', ','),10,0,'C',0);
	$pdf-> Cell(32,5, $row["fcodmeca"],10,0,'C',0);
	$pdf-> Cell(32,5, $row["codseg"],10,0,'C',0);	
	$pdf-> Cell(50,5, $row["fnorasvip"],10,1,'C',0);	
	$Totaf +=$row['suma'];

}

	$pdf->SetFont('Arial','B',7);
    $pdf-> Cell(-2,5,'',0,0,'C',0);
	$pdf-> Cell(11,5,'FOLIOS',1,0,'C',1);
	$pdf-> Cell(28,5,' '.$tot['total'],1,0,'C',1);
	$pdf-> Cell(20,5,' PERSONAS',1,0,'C',1);
	$pdf-> Cell(7,5, $jso['total'],1,0,'C',1);
	$pdf-> Cell(7,5, $ahj['total'],1,0,'C',1);
	$pdf-> Cell(7,5, $tohb1,1,0,'C',1);
	$pdf-> Cell(25,5,'',1,0,'C',1);
	$pdf-> Cell(25,5,'',1,0,'C',1);
	$pdf-> Cell(20,5, '$' .number_format($Totaf, 2, '.', ','),1,0,'C',1);
	$pdf-> Cell(20,5,'',1,0,'C',1);
	$pdf-> Cell(95,5,'',1,1,'C',1);	

$pdf->Output("Reporte De Colgados.pdf","D");
//135 --> 100 ULTIMA ACTUALZACION 15/DICIEMBRE/2011 TODO EN UN SOLO RENGLON
?> 