<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
$cuartos=array();
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,'ROOMING LIST X GRUPO DEL '.$_POST['fec'].'',0,1,'C',0);
		//Salto de línea
		
		//$this->Cell(55,5,'Fecha del: '.$_POST['fec'].'',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(9,5,'HAB',1,0,'C',1);
		$this->Cell(9,5,'TIPO',1,0,'C',1);
		$this->cell(40,5,'HUESPED',1,0,'C',1);
		$this->cell(12,5,'FOLIO',1,0,'C',1);
		$this->cell(6,5,'ADU',1,0,'C',1);
		$this->cell(6,5,'MEN',1,0,'C',1);
		$this->cell(12,5,' LLEGADA ',1,0,'C',1);
		$this->cell(12,5,' SALIDA ',1,0,'C',1);
		$this->cell(13,5,'F DE PAGO',1,0,'C',1);
		$this->cell(15,5,'TARIFA',1,0,'C',1);
		$this->cell(13,5,'TAR-XTRA',1,0,'C',1);
		$this->cell(20,5,'MERCADO',1,0,'C',1);
		$this->cell(20,5,'SEGMENTO',1,0,'C',1);
		$this->cell(20,5,'AGENCIA',1,0,'C',1);
		$this->cell(20,5,'GRUPO',1,0,'C',1);	
		$this->cell(30,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','',6);//establece tamaño de letra
$vtb=(isset($_POST['tbus']))?$_POST['tbus']:"";
$tbus=mysqli_real_escape_string($GLOBALS['con'],$vtb);

$fec = $_POST['fec'];
include('DF20000.php');
$fecha_inicial = $f_m;
$fec = (isset($_POST['fec2']))?$_POST['fec2']:"";
include('DF20000.php');
$fecha_final = $f_m;

 if(isset($_POST['r2'])&&$_POST['r2']=='g'){
		  
   	      @$huesped=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 WHERE ffecllegada <= '$fecha_inicial' and ffecsalida >= '$fecha_inicial' and cancelado='0' AND tus!='OUT' and valeryus19.STATUS='HUESPED' and fcodgrupo='".$_POST['fcodgrupo']."'"));

	      }else{
		  
	      @$huesped=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 where (status='HUESPED' or status='MISCELANEOS') AND tus!='OUT'"));
		  
		  }
$d=0;
$seccion=mysqli_query($GLOBALS['con'] ,"select distinct(seccion) from valeryus08 order by seccion");

while($secciones=mysqli_fetch_array($seccion)){
	
		$pdf-> Cell(-2,5,"",10,0,'L',0);
		$pdf-> Cell(257,5,"SECCION: ".$secciones["seccion"]."",1,1,'L',1);
		
		if($_POST['r2']=='g'){
	  	    $sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 inner join valeryus08 on valeryus19.fnumcto=valeryus08.ncto WHERE  (valeryus19.ffecllegada <= '$fecha_inicial' AND valeryus19.ffecsalida >= '$fecha_inicial' and valeryus19.cancelado='0' and valeryus19.STATUS='HUESPED' or  valeryus19.status='MISCELANEOS') and valeryus19.fcodgrupo='".$_POST['fcodgrupo']."' and valeryus08.seccion='".$secciones['seccion']."' AND tus!='OUT' order by valeryus08.ncto");
		}else{
		    $sql=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 left join valeryus08 on valeryus19.fnumcto=valeryus08.ncto where valeryus08.seccion = '".$secciones['seccion']."' and (valeryus19.status='HUESPED' or  valeryus19.status='MISCELANEOS') order by valeryus08.ncto");
		}

while($row = mysqli_fetch_array($sql)){
	$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);
	}
	$CuarTo=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from valeryus05 where descripcion='".$row['ftipocto']."'"));
	    if ($row["fnumcto"]==''){
		$row["fnumcto"]=$row["fmuncto"];
		}
		$pdf-> Cell(9,5,$row["fnumcto"],10,0,'L',0);
		$pdf-> Cell(9,5,$CuarTo["clavetp"],10,0,'C',0);
		$pdf-> Cell(40,5,substr($row["fapellido"].' '.$row["fnombre"],0,30),10,0,'L',0);
	    $pdf-> Cell(12,5,$row["n_reg"],10,0,'C',0);
	$pdf-> Cell(6,5,$row["fnumadu"],10,0,'C',0);
	$pdf-> Cell(6,5,$row["fnummenor"],10,0,'C',0);
	$pdf-> Cell(12,5,chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	$pdf-> Cell(12,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);
	$tarext=$row["fmonmen"]+$row["fmonadu"];
	$pdf-> Cell(15,5, '$ ' .number_format($row["tex4"],2,'.',','),10,0,'C',0);
	$pdf-> Cell(13,5, '$ ' .number_format($tarext,2,'.',','),10,0,'C',0);
	$pdf-> Cell(20,5, substr($row["fcodmeca"],0,15),10,0,'L',0);
	$pdf-> Cell(20,5, substr($row["codseg"],0,15),10,0,'L',0);	
	$pdf-> Cell(20,5, substr($row["fcodagen"],0,15),10,0,'L',0);	
	$pdf-> Cell(20,5, substr($row["fcodgrupo"],0,15),10,0,'L',0);	
	$pdf-> Cell(30,5, substr($row["fnorasvip"],0,40),10,1,'L',0);
if ($row["ftipocto"] != 'MAESTRA'  ) {
		$d++;
		} 
              $cuartos[]= $row["fnumcto"]   ; 
                	
}
}
	$pdf->SetFont('Arial','B',7);
    $pdf-> Cell(-2,5,'',0,0,'C',0);
	$pdf-> Cell(26,5,'HABITACIONES',1,0,'C',1);
	$pdf-> Cell(20,5,$d,1,0,'C',1);
	$pdf-> Cell(29,5,'PERSONAS',1,0,'C',1);
	$pdf-> Cell(7,5, $huesped['adultos'],1,0,'C',1);
	$pdf-> Cell(6,5, $huesped['menores'],1,0,'C',1);
	$pdf-> Cell(173,5,'',1,1,'C',1);	

        
       	        $C=  implode(",", $cuartos);
		$pdf-> Cell(-2,5,"",10,0,'L',0);
		$pdf-> Cell(257,5,"MISCELANEOS",1,1,'L',1);
		//$pdf-> Cell(9,5,$C,10,0,'L',0);
		if($_POST['r2']=='g'){
            
	  	    $sql = mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where valeryus19.ffecllegada <= '$fecha_inicial' AND valeryus19.ffecsalida >= '$fecha_inicial' and valeryus19.cancelado='0') and status='MISCELANEOS' and fnumcto in($C) ");
		

while($row = mysqli_fetch_array($sql)){
	$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);
	}
	$CuarTo=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from valeryus05 where descripcion='".$row['ftipocto']."'"));
	    if ($row["fnumcto"]==''){
		$row["fnumcto"]=$row["fmuncto"];
		}
		$pdf-> Cell(9,5,$row["fnumcto"],10,0,'L',0);
		$pdf-> Cell(9,5,$CuarTo["clavetp"],10,0,'C',0);
		$pdf-> Cell(40,5,substr($row["fapellido"].' '.$row["fnombre"],0,30),10,0,'L',0);
	    $pdf-> Cell(12,5,$row["n_reg"],10,0,'C',0);
	$pdf-> Cell(6,5,$row["fnumadu"],10,0,'C',0);
	$pdf-> Cell(6,5,$row["fnummenor"],10,0,'C',0);
	$pdf-> Cell(12,5,chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	$pdf-> Cell(12,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);
	$tarext=$row["fmonmen"]+$row["fmonadu"];
	$pdf-> Cell(15,5, '$ ' .number_format($row["tex4"],2,'.',','),10,0,'C',0);
	$pdf-> Cell(13,5, '$ ' .number_format($tarext,2,'.',','),10,0,'C',0);
	$pdf-> Cell(20,5, substr($row["fcodmeca"],0,15),10,0,'L',0);
	$pdf-> Cell(20,5, substr($row["codseg"],0,15),10,0,'L',0);	
	$pdf-> Cell(20,5, substr($row["fcodagen"],0,15),10,0,'L',0);	
	$pdf-> Cell(20,5, substr($row["fcodgrupo"],0,15),10,0,'L',0);	
	$pdf-> Cell(30,5, substr($row["fnorasvip"],0,40),10,1,'L',0);

		$E++;
		
}
$pdf->SetFont('Arial','B',7);
    $pdf-> Cell(-2,5,'',0,0,'C',0);
	$pdf-> Cell(26,5,'MISCELANEOS',1,0,'C',1);
	$pdf-> Cell(20,5,$E,1,0,'C',1);
	$pdf-> Cell(29,5,'',1,0,'C',1);
	$pdf-> Cell(7,5, '',1,0,'C',1);
	$pdf-> Cell(6,5,'',1,0,'C',1);
	$pdf-> Cell(173,5,'',1,1,'C',1);	

                }

	

        
       
        
        
        
        
        
        
$pdf->Output("Rooming List x Grupo.pdf","D");
//170 --> 100 ULTIMA ACTUALZACION
//148 --> 100 ULTIMA ACTUALZACION 15/DICIEMBRE/2011 TODO EN UN SOLO RENGLON
//182 --> 100 ULTIMA ACTUALZACION 6/ENERO/2012 AGRUPAR POR ORDENADOR.
//144 --> 100 ULTIMA ACTUALZACION 22/ENERO/2014 MONTE TAXCO
?> 