<?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");
$a=0;
$totTar=0;
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,'CONTEO DE OCUPACION 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(45,5,'HUESPED',1,0,'C',1);
		$this->cell(12,5,'FOLIO',1,0,'C',1);
		$this->cell(7,5,'ADUL',1,0,'C',1);
		$this->cell(6,5,'MEN',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(13,5,'AGENCIA',1,0,'C',1);
		$this->cell(23,5,'MERCADO',1,0,'C',1);
		$this->cell(23,5,'VOUCHER',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','',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']=='f'){
		  
   	      @$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'"));

	      }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')"));
		  
		  }
$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(isset($_POST['r2'])&&$_POST['r2']=='f'){
	  	    $sql=mysqli_query($GLOBALS['con'] ,"SELECT valeryus19.n_reg as fol1,valeryus19.*,valeryus08.* FROM valeryus19 inner join valeryus08 on valeryus19.fmuncto=valeryus08.ncto WHERE  (valeryus19.ffecllegada <= '$fecha_inicial' AND valeryus19.ffecsalida > '$fecha_inicial' and valeryus19.cancelado='0') and valeryus08.seccion='".$secciones['seccion']."' order by valeryus08.ncto");
		}else{
		    $sql=mysqli_query($GLOBALS['con'] ,"select valeryus19.n_reg as fol1,valeryus19.*,valeryus08.* 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(45,5,substr($row["fapellido"].' '.$row["fnombre"],0,35),10,0,'L',0);
	
		$pdf-> Cell(12,5, $row["fol1"],10,0,'C',0);
	    //$pdf-> Cell(12,5,$row["n_reg"],10,0,'C',0);
	$pdf-> Cell(7,5,$row["fnumadu"],10,0,'C',0);
	$pdf-> Cell(6,5,$row["fnummenor"],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);
	$tarext=$row["fmonmen"]+$row["fmonadu"];
        $valt=(isset($row["tex4"]))?$row["tex4"]:0;
	$pdf-> Cell(16,5, '$ ' .number_format(floatval($valt),2,'.',','),10,0,'C',0);
	$pdf-> Cell(13,5, substr($row["fcodagen"],0,8),10,0,'L',0);
	$pdf-> Cell(23,5, substr($row["fcodmeca"],0,16),10,0,'L',0);
	$bou=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select can_ref from valeryus030 where nparte1='".$row['fol1']."' and can_ref!='AUT'  limit 1"));
	
	//mail('jacbgy@gmail.com','hola',"select can_ref from valeryus030 where nparte1='".$row['fol1']."' and nparte1_det=1 and acc_fec='".$fecha_inicial."'");
	$pdf-> Cell(23,5, $bou["can_ref"],10,0,'C',0);	
	$pdf-> Cell(50,5, substr($row["fnorasvip"],0,40),10,1,'L',0);
	$totTar+=$row["tex4"];	
	if ($row["ftipocto"]!='MAESTRA' and $row["extra1"]=='0'){
		$d++;
		}	
}
}
	$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(44,5,'TOTAL :',1,0,'R',1);
	$pdf-> Cell(16,5,"$ ".number_format($totTar,2,'.',','),1,0,'C',1);
	$pdf-> Cell(108,5,'',1,1,'C',1);	
//ob_end_flush(); 
$pdf->Output("Conteo_De_rec_ocupacion.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.
?> 
