<?php require_once('../Connections/cn_conexion.php'); ?>
<?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 = "SELECT * FROM gastos, clientes, cuentas WHERE gastos.num_caja='".$numcaja."' AND clientes.id_cliente=gastos.id_cliente AND gastos.id_cuenta =cuentas.id_cuenta  ORDER BY gastos.fecha  ASC";
$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);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="14%">Número</td>
    <td width="81%"><?php echo $row_rs_detcaja['num_caja']; ?></td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Nombre</td>
    <td><?php echo $row_rs_detcaja['nom_cliente']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Dirección</td>
    <td><?php echo $row_rs_detcaja['dir_cliente']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Distrito</td>
    <td><?php echo $row_rs_detcaja['dis_cliente']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>RUC</td>
    <td><?php echo $row_rs_detcaja['ruc_cliente']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12%" bgcolor="#000066"><p class="texto_normal">Fecha</p></td>
        <td width="26%" bgcolor="#000066"><p class="texto_normal">Cuenta</p></td>
        <td width="50%" bgcolor="#000066"><p class="texto_normal">Concepto</p></td>
        <td width="12%" bgcolor="#000066"><p class="texto_normal">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 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 style="background-color:<?php echo($color);?>"><?php echo $row_rs_detcaja['descripcion']; ?></td>
        <td style="background-color:<?php echo($color);?>"><?php echo $monto; ?></td>
      </tr>
      <?php $i++?>
      <?php } while ($row_rs_detcaja = mysql_fetch_assoc($rs_detcaja)); ?>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="right">Total:&nbsp;&nbsp;&nbsp;&nbsp;</td>
        <td><?php echo($suma_gastos);?></td>
      </tr>
    </table></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="button" name="button3" id="button3" value="Exportar Excel" />
      <input type="button" name="button4" id="button4" value="Generar Carta de Pago" />
      <input type="button" name="button5" id="button5" value="Cerrar" onClick="cerrarcaja_detalle()"/></td>
    <td>&nbsp;</td>
  </tr>
</table>
<?php
mysql_free_result($rs_detcaja);
?>
