<?php require_once('../Connections/cn_conexion.php'); ?>
<?php include_once('../includes/funciones.php');?>
<?php  mysql_query("SET NAMES 'utf8'"); ?>
<?php
$consulta=$_POST["consulta"];
$reporte_titulo=$_POST["reporte_titulo"];
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_cn_conexion, $cn_conexion);
$query_rs_cajareporte = "".$consulta."";
$rs_cajareporte = mysql_query($query_rs_cajareporte, $cn_conexion) or die(mysql_error());
$row_rs_cajareporte = mysql_fetch_assoc($rs_cajareporte);
$totalRows_rs_cajareporte = mysql_num_rows($rs_cajareporte);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SISTEMA DE FACTURACION</title>
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=reporte.xls");
header("Pragma: no-cache");
header("Expires: 0");
?>
</head>

<body>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
  <td colspan="5"><h1><?php echo($reporte_titulo);?></h1></td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td width="3%" align="center" bgcolor="#000066"><p style="color:#fff">&nbsp;</p></td>
  <td width="10%" align="center" bgcolor="#000066"><p style="color:#fff">CAJA</p></td>
  <td width="54%" bgcolor="#000066"><p style="color:#fff">CLIENTE</p></td>
  <td width="14%" align="center" bgcolor="#000066"><p style="color:#fff">MONTO &nbsp;S/</p></td>
  <td width="19%" align="center" bgcolor="#000066"><p style="color:#fff">EMISIÓN</p></td>
</tr>
<?php $i=1;?>
<?php do { ?>
<?php 
$res=$i%2;
if($res==0){
    $color="#CDEBFC";
    }else{
        $color="#ffffff";
        }
if($row_rs_cajareporte['hab_cajagasto']=='0'){
	$classe_colortexto="enlace_cancelar";
	$clase_texto='style="color:#FF00FF"';
	}else{
		$classe_colortexto="enlace_normal";
		$clase_texto="";
		}
?>
<tr>
  <td height="20" style="background-color:<?php echo($color);?>"><p <?php echo($clase_texto);?>>
    <?php $hab_cajagasto=$row_rs_cajareporte['hab_cajagasto']; echo $hab_cajagasto; ?>
  </p></td>
  <td align="center" style="background-color:<?php echo($color);?>"><p <?php echo($clase_texto);?>>
    <?php $numcaja=$row_rs_cajareporte['num_caja']; echo $numcaja; ?>
  </p></td>
  <td style="background-color:<?php echo($color);?>"><p <?php echo($clase_texto);?>><?php echo $row_rs_cajareporte['nom_cliente']; ?></p></td>
  <td align="right" style="background-color:<?php echo($color);?>"><p <?php echo($clase_texto);?>><?php echo number_format(decimals($row_rs_cajareporte['SUM(gastos.monto_real)']),2); ?>&nbsp;&nbsp;&nbsp;&nbsp;</p></td>
  <td align="center" style="background-color:<?php echo($color);?>"><p <?php echo($clase_texto);?>><?php echo $row_rs_cajareporte['fecha_inicio']; ?></p></td>
</tr>
<?php $i++;?>
<?php } while ($row_rs_cajareporte = mysql_fetch_assoc($rs_cajareporte)); ?>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rs_cajareporte);
?>
