<?php require_once('../Connections/cn_conexion.php'); ?>
<?php require_once('../includes/funciones.php'); ?>
<?php
$idcli=$_GET['idcli'];
?>
<?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_gastos = "SELECT * FROM gastos, cuentas, clientes WHERE cuentas.id_cuenta=gastos.id_cuenta AND gastos.hab_gasto='1' AND clientes.id_cliente=gastos.id_cliente AND gastos.hab_gasto='1' AND gastos.id_cliente='".$idcli."' ORDER BY gastos.fecha DESC";
$rs_gastos = mysql_query($query_rs_gastos, $cn_conexion) or die(mysql_error());
$row_rs_gastos = mysql_fetch_assoc($rs_gastos);
$totalRows_rs_gastos = mysql_num_rows($rs_gastos);

?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="25" colspan="4">Lista de Gastos</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td width="14%" bgcolor="#110167"><p class="texto_normal">Fecha</p></td>
        <td width="57%" height="25" bgcolor="#110167"><p class="texto_normal">Cuenta</p></td>
        <td width="9%" bgcolor="#110167"><p class="texto_normal">Monto</p></td>
        <td width="19%" align="center" bgcolor="#110167"><p class="texto_normal">Moneda</p></td>
        <td width="1%" bgcolor="#110167"><p>&nbsp;</p></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><div id="cont_listgasto2">
      <?php do { ?>
      <?php
              	if($row_rs_gastos['tipo_cuenta']=='-1'){
					$classe_colortexto="enlace_rojo";
					$clase_texto='class="texto_rojo"';
					}else{
						$classe_colortexto="enlace_normal";
						$clase_texto="";
						}
				 if($totalRows_rs_gastos>0){
			  ?>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="14%" height="25"><p <?php echo($clase_texto);?>>
            <?php $fecha=fecha_peru($row_rs_gastos['fecha']); echo $fecha;?>
          </p></td>
          <td width="57%"><p><a href="#" class="<?php echo($classe_colortexto);?>" onclick="modificar_gasto('<?php echo $row_rs_gastos['id_gasto']; ?>')"><?php echo $row_rs_gastos['nom_cuenta']; ?></a></p></td>
          <td width="9%"><p <?php echo($clase_texto);?>>
            <?php $ruc=$row_rs_gastos['monto_real']; echo number_format(decimals($ruc),2) ; ?>
          </p></td>
          <td width="20%" align="center"><p <?php echo($clase_texto);?>>
            <?php $moneda=$row_rs_gastos['moneda']; if($moneda=='S'){echo("Soles");}else{echo("Dolares");}?>
          </p></td>
        </tr>
      </table>
      <?php }else{
					  echo("<p>&nbsp;</p>");
					  echo("No se ha encontrado documentos");
					  }?>
      <?php } while ($row_rs_gastos = mysql_fetch_assoc($rs_gastos)); ?>
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<?php


mysql_free_result($rs_gastos);
?>