<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
include('DF80000.php');
 $f_m="";
 $totAbono=0;
 $totCargo=0;
 $sumTotal=0;
class PDF extends FPDF{
	//Cabecera de Página
	function Header(){
	    //Logotipo
	    include("DYIM_VER.php");
	    //Arial Bold (14)
	    $this->SetFont('Arial','B',12);
	    //Espacio
		
	    //Título		
	    $this->Cell(190,3,'REPORTE DE SALDOS',0,1,'C');
		$this->SetFont('Arial','B',8);
		$this->Cell(190,3,'',0,1,'L');		
		$fec1=$dt_empres["fec_alta"];
		include('DF20000.php');
		$this->Cell(190,3,'PERIODO DEL '.$_POST['fec'].' AL '.$_POST['fec2'].'',0,1,'C');
		//$this->Cell(190,3,'FECHA: '. $f_f .'',0,1,'C');	
	    //Salto de línea
	    $this->Ln(3);
	}
	//Pie de Página
	function Footer()
	{
	    //Posición: 1,5 cm del Final
	    $this->SetY(-15);
	    //Arial Italic 8
	    $this->SetFont('Arial','I',8);
	    //Número de página
	    $this->Cell(0,0, $this->PageNo().'/{nb}',0,0,'C');
	}
}
$pdf;
$pdf=new PDF('P','mm','Letter');
$pdf->AddPage();
$pdf->AliasNbPages();
$binit=-1;

$pdf->SetFillColor(240,240,240);
$pdf->SetFont('Arial','',8);

	$pdf->SetFont('ARIAL','B',7);
	$pdf->SetFillColor(230,230,230);
	$pdf->Cell(5,3,'',0,0,'C',0);
	$pdf->Cell(10,3,'FOLIO',0,0,'C',1);
	$pdf->Cell(39,3,'HUESPED',0,0,'C',1);
	$pdf->Cell(10,3,'HAB',0,0,'C',1);
	$pdf->Cell(20,3,'TIPO',0,0,'C',1);
	$pdf->Cell(18,3,'FEC. LLEGADA',0,0,'C',1);
	$pdf->Cell(18,3,'FEC. SALIDA',0,0,'C',1);
	$pdf->Cell(30,3,'FORMA DE PAGO',0,0,'C',1);
	$pdf->Cell(15,3,'CARGO',0,0,'C',1);
	$pdf->Cell(15,3,'ABONO',0,0,'C',1);
	$pdf->Cell(15,3,'TOTAL',0,1,'C',1);	
	
	// --->
	  	$fec = $_POST['fec'];
		include('DF20000.php');
		$fecha_inicial = $f_m;
		
		$fec = $_POST['fec2'];
		include('DF20000.php');
		$fecha_final = $f_m;
	  // -->
if(!isset($_POST['r1']))$_POST['r1']="";	
 if ($_POST['r1']==''){
 $sql=mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE status='HUESPED' or status='MISCELANEOS' order by fnumcto");
 }else if($_POST['r1']=='f'){
 $sql=mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE (ffecllegada <= '".$fecha_final."' and fecha_real >= '".$fecha_final."' and cancelado='0') or (ffecllegada <= '".$fecha_final."' and ffecsalida >= '".$fecha_final."' and cancelado='0') order by fmuncto, fnumcto");
 } 
  while ($reg=mysqli_fetch_array($sql)){
  
  $tcto=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select clavetp from valeryus05 where descripcion='".$reg['ftipocto']."'"));
			$pdf->SetFont('ARIAL','',6);
			$pdf->Cell(5,3,'',0,0,'C',0);
			$pdf->Cell(10,3,$reg['n_reg'],0,0,'C',0);
			if(!isset($row['fnombre']))$row['fnombre']="";
			$pdf->Cell(39,3,substr($reg['fapellido'] .' '.$row['fnombre'] ,0,30),0,0,'L',0);
			if ($reg['fnumcto']==''){
		    $reg['fnumcto']=$reg['fmuncto'];
		    }
			$pdf->Cell(10,3,$reg['fnumcto'],0,0,'C',0);
			$pdf->Cell(20,3,$tcto['clavetp'],0,0,'C',0);
			$pdf->Cell(18,3,'  '.chfecha($reg['ffecllegada'],'Y-m-d','d/m/Y'),0,0,'C',0);
			$pdf->Cell(18,3,'  '.chfecha($reg['ffecsalida'],'Y-m-d','d/m/Y'),0,0,'C',0);
			$pdf->Cell(30,3,$reg['fformpago'],0,0,'C',0);
			$folio=$reg['n_reg'];
			$cargo=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(costo) AS cargo FROM valeryus030 WHERE nparte1='".$folio."' and (cancelado='0' OR cancelado='2')"));
			$pdf->Cell(15,3,number_format($cargo['cargo'],2,'.',','),0,0,'C',0);
			$abono=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT SUM(total) AS abono FROM valeryus030 WHERE nparte1='".$folio."' and (cancelado='0' or cancelado='2')"));
			$pdf->Cell(15,3,number_format($abono['abono'],2,'.',','),0,0,'C',0);			
			$total=$cargo['cargo']-$abono['abono'];
			$pdf->Cell(15,3,number_format($total,2,'.',',').'  ',0,1,'C',0);

		$totCargo +=$cargo['cargo'];
		$totAbono +=$abono['abono'];
		$sumTotal +=$total;
 }
  		$pdf->SetFont('ARIAL','B',8);
		$pdf->SetFillColor(230,230,230);
		$pdf->Cell(5,3,'',0,0,'C',0);
		$pdf->Cell(15,3,'',0,0,'C',1);
		$pdf->Cell(70,3,' TOTAL DE SALDOS ',0,0,'L',1);
		$pdf->Cell(60,3,'  ',0,0,'C',1);
		$pdf->Cell(15,3,number_format($totCargo,2,'.',','),0,0,'C',1);
		$pdf->Cell(15,3,number_format($totAbono,2,'.',','),0,0,'C',1);
		$pdf->Cell(15,3,number_format($sumTotal,2,'.',','),0,1,'C',1);
ob_end_clean();
$pdf->Output("Reporte_De_Saldos.pdf","D");
//102 ULTIMA ACTUALIZACION JACARANDAS 24/10/2012?>
