<?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");
$f_m=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(55,5,'Periodo: '.$_POST['fec'].' al '.$_POST['fec2'],0,1,'C',0);
		$this->Cell(6,5,'',0,0,'C',0);
		$this->Cell(225,5,'AUDITORIA DE TURNO (TURNO N)',0,1,'C',0);
		//Salto de línea
		//if($_POST['r2']=="f"){
		//$this->Cell(55,5,'Periodo: '.$_POST['fec'].' al '.$_POST['fec2'],0,0,'C',0);
		//}
		$this->Ln(8);
		$this->SetFont('Arial','B',8);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(6,5,'',0,0,'C',0);
		$this->cell(20,5,'CARGO',1,0,'C',1);
		$this->cell(39,5,'NOTAS',1,0,'C',1);
		$this->cell(15,5,'FOLIO',1,0,'C',1);
		$this->Cell(12,5,'# HAB.',1,0,'C',1);
		$this->Cell(18,5,'CARGOS',1,0,'C',1);
		$this->Cell(18,5,'ABONOS',1,0,'C',1);
		$this->cell(16,5,'CAJERO',1,0,'C',1);
		$this->cell(47,5,'HUESPED',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('P','mm','Letter');
$pdf->AddPage();

$pdf->SetFillColor(192,192,192);
$pdf->SetFont('Arial','',7);//establece tamaño de letra
if(!isset($_POST['tbus']))$_POST['tbus']="";
$tbus=mysqli_real_escape_string($GLOBALS['con'],$_POST['tbus']);
$fec = $_POST['fec'];
include('DF20000.php');
$fecha_inicial = $f_m;
$fec = $_POST['fec2'];
include('DF20000.php');
$fecha_final = $f_m;

	$carDet=mysqli_query($GLOBALS['con'] ,"SELECT 
		DISTINCT(ftarifad.nparte1_det) AS detalle 
		FROM 
		valeryus19 
		LEFT JOIN valeryus030 ON valeryus19.n_reg=valeryus030.nparte1
		LEFT JOIN ftarifas ON valeryus19.tex=ftarifas.gclave 
		LEFT JOIN ftarifad ON ftarifas.n_reg=ftarifad.nparte1
		WHERE 
		valeryus030.acc_fec BETWEEN '$fecha_inicial' AND '$fecha_final'
		AND valeryus19.cancelado='0' 
		AND (valeryus030.cancelado='0' or valeryus030.cancelado='2')");
		
	while($det=mysqli_fetch_array($carDet)){
	
		$sql = mysqli_query($GLOBALS['con'] ,"select *, valeryus030.usuario as usuArIo from valeryus030 left join valeryus19 on valeryus19.n_reg=valeryus030.nparte1 where valeryus030.nparte1_det='".$det['detalle']."' AND valeryus030.acc_fec between '$fecha_inicial' and '$fecha_final' AND valeryus19.cancelado='0' AND (valeryus030.cancelado='0' or valeryus030.cancelado='2')");
	 	  
$costo=0;	   
$a=0;
while($row = mysqli_fetch_array($sql)){
$a++;
	$pdf->SetFont('Arial','',7);
    $pdf-> Cell(6,5,'',0,0,'C',0);
	$cargo=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from valeryus09 where n_reg='".$row['nparte1_det']."'"));
    if($row["fnumcto"]==''){
		$row["fnumcto"]=$row["fmuncto"];
		}
	$pdf-> Cell(20,5, $cargo["pclave"],10,0,'C',0);
    $pdf-> Cell(39,5, $row["tex2"],10,0,'C',0);
	$pdf-> Cell(15,5, $row["n_reg"],10,0,'C',0);
	$pdf-> Cell(12,5, $row["fnumcto"],10,0,'C',0);
	//$pdf-> Cell(50,5,' '.$row["fapellido"].' '.$row["fnombre"],10,0,'L',0);
	$pdf-> Cell(18,5,'$ '.number_format($row["costo"],2,'.',','),10,0,'C',0);
	$pdf-> Cell(18,5, number_format($row["total"],2,'.',','),10,0,'C',0);
	$pdf-> Cell(16,5, $row["usuArIo"],10,0,'C',0);
	$pdf-> Cell(47,5, $row["fapellido"].' '.$row["fnombre"],10,1,'L',0);
	
	$pdf->SetFont('Arial','',6);
	
	$pdf->SetFont('Arial','',8);
    $costo+=$row['costo'];
	}
	if ($a>=1){
	$pdf-> Cell(195,0.3,'',0,1,'L',1);		
	$pdf-> Cell(0.1,5,'',0,0,'C',0);
	
	$pdf->SetFont('Arial','B',7);
    $pdf-> Cell(6,5,'',0,0,'C',0);
	$pdf-> Cell(20,5,'Totales',1,0,'C',1);
	$pdf-> Cell(39,5,' '.$a,1,0,'C',1);
	$pdf-> Cell(27,5,' ',1,0,'C',1);
	$pdf-> Cell(18,5,'$ '.number_format($costo,2,'.',','),1,0,'C',1);
	$pdf-> Cell(80,5,' ',1,1,'C',1);
	}
}
		
$pdf->Output("Auditoria de Turno (Turno N).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.
//ULTIMA ACTUALIZACION 12/ENERO/2012 REPORTE DE CAMBIO DE HAB
?> 