<?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 SALIDAS DEL '.$_POST['fec'].'',0,1,'C',0);
		//Salto de línea
		
		$this->Ln(8);
		$this->SetFont('Arial','B',6);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(-1,5,'',0,0,'C',0);
		$this->Cell(9,5,'FOLIO',1,0,'C',1);
		$this->Cell(44,5,'NOMBRE Y APELLIDO',1,0,'C',1);
		$this->cell(8,5,'ADUL.',1,0,'C',1);
		$this->cell(6,5,'MEN.',1,0,'C',1);
		$this->cell(7,5,'HAB.',1,0,'C',1);
		$this->cell(19,5,'TIPO',1,0,'C',1);
		$this->cell(17,5,'FEC. LLEGADA',1,0,'C',1);
		$this->cell(17,5,'FEC. SALIDA',1,0,'C',1);
		$this->cell(14,5,'F DE PAGO',1,0,'C',1);
		$this->cell(9,5,'SALDO',1,0,'C',1);
		$this->cell(30,5,'MERCADO',1,0,'C',1);
		$this->cell(30,5,'SEGMENTO',1,0,'C',1);	
		$this->cell(55,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'],isset($_POST['tbus'])?$_POST['tbus']:"");

        $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['r1'])||$_POST['r1']==""){

                $sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE (fecha_real='$fecha_inicial' and cancelado='0' and status='HISTORICO') OR (ffecsalida='$fecha_inicial' and cancelado='0' and status='HUESPED')");
                $salidas=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as folios, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 where (fecha_real='$fecha_inicial' and cancelado='0' and status='HISTORICO') OR (ffecsalida='$fecha_inicial' and cancelado='0' and status='HUESPED')"));
  }elseif(isset($_POST['r1'])&&$_POST['r1']=="f"){
		$sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE (fecha_real='$fecha_inicial' and cancelado='0' and status='HISTORICO') OR (ffecsalida='$fecha_inicial' and cancelado='0' and status='HUESPED')");
		$salidas=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as folios, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 where status = 'HISTORICO' and fecha_real='".$dt_empres['fec_alta']."'"));
	 	  }
    
	   
	
	//$tohb1=mysqli_num_rows($salidas); <--
$a=0;
while($row = mysqli_fetch_array($sql)){

$a++;
	$pdf->SetFont('Arial','',6);
    $pdf-> Cell(-1,5,'',0,0,'C',0);
	if ($a>1){
	$pdf-> Cell(265,0.3,'',0,1,'L',1);		
	$pdf-> Cell(-1,5,'',0,0,'C',0);
	}
	$fdp=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from valeryus09 where descripcion='".$row['fformpago']."'"));
	$tcto=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select clavetp from valeryus05 where descripcion='".$row['ftipocto']."'"));
	if ($row["status"]=='HISTORICO'){
	$pdf-> Cell(9,5, $row["n_reg"],10,0,'C',1);
	$pdf-> Cell(44,5,substr($row["fapellido"].' '.$row["fnombre"],0,35),10,0,'L',1);
	//$pdf-> Cell(20,5, $row["fcodagen"],0,0,'C',1);
	$pdf-> Cell(8,5, $row["fnumadu"],10,0,'C',1);
	$pdf-> Cell(6,5, $row["fnummenor"],10,0,'C',1);
	$pdf-> Cell(7,5, $row["fmuncto"],10,0,'C',1);
	$pdf-> Cell(19,5, substr($tcto["clavetp"],0,12),10,0,'C',1);
	$pdf-> Cell(17,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',1);
	$pdf-> Cell(17,5, chfecha($row['ffecsalida'],'Y-m-d'),10,0,'C',1);
	$pdf-> Cell(14,5, $fdp["pclave"],10,0,'C',1);
	$pdf-> Cell(9,5, '$ '.number_format($row["suma"],2,'.',','),10,0,'L',1);
	//$pdf-> Cell(20,5, '$' .number_format($sum_cg["cargos"], 2, '.', ','),10,0,'L',1);
	$pdf-> Cell(30,5, $row["fcodmeca"],10,0,'C',1);
	$pdf-> Cell(30,5, $row["codseg"],10,0,'C',1);	
	$pdf-> Cell(55,5, substr($row["fnorasvip"],0,40),10,1,'L',1);	
	
	//$pdf-> Cell(264,5,' NOTAS:  '. $row["fnorasvip"],10,1,'L',1);
	}else{
	$pdf-> Cell(9,5, $row["n_reg"],10,0,'C',0);
	$pdf-> Cell(44,5,substr($row["fapellido"].' '.$row["fnombre"],0,35),10,0,'L',0);
	//$pdf-> Cell(20,5, $row["fcodagen"],0,0,'C',0);
	$pdf-> Cell(8,5, $row["fnumadu"],10,0,'C',0);
	$pdf-> Cell(6,5, $row["fnummenor"],10,0,'C',0);
	$pdf-> Cell(7,5, $row["fnumcto"],10,0,'C',0);
	$pdf-> Cell(19,5, substr($tcto["clavetp"],0,12),10,0,'C',0);
	$pdf-> Cell(17,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	$pdf-> Cell(17,5, chfecha($row['ffecsalida'],'Y-m-d'),10,0,'C',0);	
	$pdf-> Cell(14,5, $fdp["pclave"],10,0,'C',0);
	$pdf-> Cell(9,5, '$ '.number_format($row["suma"],2,'.',','),10,0,'L',0);
	//$pdf-> Cell(20,5, '$' .number_format($sum_cg["cargos"], 2, '.', ','),10,0,'L',0);
	$pdf-> Cell(30,5, $row["fcodmeca"],10,0,'C',0);
	$pdf-> Cell(30,5, $row["codseg"],10,0,'C',0);
	$pdf-> Cell(55,5, substr($row["fnorasvip"],0,40),10,1,'L',0);	
	//$pdf-> Cell(264,5,' NOTAS:  '. $row["fnorasvip"],10,1,'L',0);
	}
	
}


	$pdf->SetFont('Arial','B',7);
    $pdf-> Cell(-1,5,'',0,0,'C',0);
	$pdf-> Cell(9,5,'Folios',1,0,'C',1);
	$pdf-> Cell(44,5,$a,1,0,'C',1);
        //if(isset($_POST['r1'])&&$_POST['r1']==""){
	//$salidas=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as folios, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 where (fecha_real='$fecha_inicial' and cancelado='0' and status='HISTORICO') OR (ffecsalida='$fecha_inicial' and cancelado='0' and status='HUESPED')"));
	  //}elseif(isset($_POST['r1'])&&$_POST['r1']=="f"){
	//$salidas=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as folios, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 where status = 'HISTORICO' and fecha_real='".$dt_empres['fec_alta']."'"));
	 	//  }
	$pdf-> Cell(8,5,$salidas['adultos'],1,0,'C',1);
	$pdf-> Cell(6,5,$salidas['menores'] ,1,0,'C',1);
	$pdf-> Cell(198,5,'',1,1,'C',1);	
                  
$pdf->Output("Reporte_De_Salidas.pdf","D");
?> 