<?php require_once('../Connections/cn_conexion.php'); ?>
<?php include_once("../includes/funciones.php");?>
<?php  mysql_query("SET NAMES 'utf8'"); ?>
<?php
$consulta=$_POST["consulta"];
?>
<?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_detcaja = "".$consulta."";
$rs_detcaja = mysql_query($query_rs_detcaja, $cn_conexion) or die(mysql_error());
$row_rs_detcaja = mysql_fetch_assoc($rs_detcaja);
$totalRows_rs_detcaja = mysql_num_rows($rs_detcaja);
?>
<!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="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="16%">&nbsp;</td>
    <td width="3%">&nbsp;</td>
    <td width="81%">&nbsp;</td>
  </tr>
  <tr>
    <td>Número</td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo $row_rs_detcaja['num_caja']; ?></td>
  </tr>
  <tr>
    <td>Nombre</td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo $row_rs_detcaja['nom_cliente']; ?></td>
  </tr>
  <tr>
    <td>Dirección</td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo $row_rs_detcaja['dir_cliente']; ?></td>
  </tr>
  <tr>
    <td>Distrito</td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo $row_rs_detcaja['dis_cliente']; ?></td>
  </tr>
  <tr>
    <td>RUC</td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo $row_rs_detcaja['ruc_cliente']; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" bgcolor="#000066"><p style="color:#fff">Fecha</p></td>
    <td bgcolor="#000066"><p style="color:#fff">Cuenta</p></td>
    <td bgcolor="#000066"><p style="color:#fff">Gasto en S/.</p></td>
  </tr>
  <?php
        $suma_gastos=0;
		$i=1;
		?>
  <?php do { ?>
  <?php
        $suma_gastos+=$row_rs_detcaja['monto_real'];
		$res=$i%2;
		if($res==0){
			$color="#CDEBFC";
			}else{
				$color="#ffffff";
				}
		$monto=$row_rs_detcaja['monto_real'];
		$moneda=$row_rs_detcaja['moneda'];
		$tipocambio=$row_rs_detcaja['tipo_cambio'];
		?>
  <tr>
    <td align="center" style="background-color:<?php echo($color);?>"><?php echo fecha_peru($row_rs_detcaja['fecha']); ?></td>
    <td style="background-color:<?php echo($color);?>"><?php echo $row_rs_detcaja['nom_cuenta']; ?></td>
    <td align="left" style="background-color:<?php echo($color);?>"><?php echo number_format($monto,2); ?></td>
  </tr>
  <?php $i++?>
  <?php } while ($row_rs_detcaja = mysql_fetch_assoc($rs_detcaja)); ?>
  <tr>
    <td width="200">&nbsp;</td>
    <td width="200" align="right">Total:&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td width="300" align="left"><?php echo(number_format($suma_gastos,2));?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rs_detcaja);
?>
