<?
$r = "../";
require_once($r."inc/funciones.php");
validNotSession($r);
$sql="";
foreach ($_GET as $key => $value)
{
    if($key=="id"){
        if($value!=""){$sql .= $key . " =". $value.' AND ';}
    }
    if($key!="fecha1" && $key!='fecha2' && $key!='id'){
        if($value!=""){$sql .= $key . "=". $value.' AND ';}
    }
    if($key=="fecha1" or $key=='fecha2'){
        if($key=="fecha1"){
            if($value!=""){
            $fecha1=$value;
            $fecha2=$value;
            $fechai= "fecha BETWEEN '$fecha1 00:00:01' AND '$fecha2 23:59:59' AND ";
            
            }
        }
        if($key=="fecha2"){
            if($value!=""){
            $fecha2=$value;
            $fechaf= "fecha BETWEEN '$fecha1 00:00:01' AND '$fecha2 23:59:59' AND ";
            }
        }
    }
   
}
if($fechaf==""){$sql.=$fechai;}else{$sql.=$fechaf;}
$mysqli = connectDB($r);
$row1 = $mysqli->query("SELECT * FROM z_gastos WHERE $sql id!=0");
?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body class="fixed-nav sidenav-toggled sticky-footer bg-dark" id="page-top">
  <?php include $r."inc/nav.php"; ?>
  
  <div class="content-wrapper">
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="h3 card-header">
          <i class="fa fa-table"></i> RESULTADO CONSULTA</div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Usuario</th>
                  <th>Categoria</th>
                  <th>Tipo</th>
                  <th>nota</th>
                  <th>costo</th>
                  <th>fecha </th>
                  <th></th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Usuario</th>
                  <th>Categoria</th>
                  <th>Tipo</th>
                  <th>nota</th>
                  <th>costo</th>
                  <th>fecha </th>
                  <th></th>
                </tr>
              </tfoot>
              <tbody>
                    <?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr>
                          <td><? $u=$row2['iduser'];$row9 = $mysqli->query("SELECT * FROM z_usuarios WHERE id='$u'"); $dato=$row9->fetch_assoc();echo $dato['nombre'];?></td>
                          <td><? $c=$row2['categoria']; $row10 = $mysqli->query("SELECT * FROM z_cinversiones WHERE id='$c'"); $dato=$row10->fetch_assoc();echo $dato['nombre'];?></td>
                          <td><? $t=$row2['tipo']; $row11 = $mysqli->query("SELECT * FROM z_tinversiones WHERE id='$t'"); $dato=$row11->fetch_assoc();echo $dato['nombre'];?></td>
                          <td><? echo $row2['nota'];?></td>
                          <td><? echo $row2['cantidad'];?></td>
                          <td><? echo $row2['fecha'];?></td>
                          <td><a href="<? echo $row2['archivo'];?>">archivo</a></td>
                      </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>
        </div><? echo $subtotal;?>
      </div>
      <input type="button" class="btn btn-primary float-left" value="Atras" name="Back2" onclick="history.back()" />
    </div>
  </div>
  <?php include $r."inc/foot.php"; ?>
 
<script>
    function popitup(url){
	    newwindow=window.open(url,'name','height=600,width=320'); 
	    if (window.focus) {newwindow.print();}
	    return false; 
    }
</script> 
<script>
$('#dataTable').DataTable( {
        "order": [[ 3, "desc" ]],
        "lengthMenu": [[100, 500, 1000, -1], [100, 500, 1000, "All"]]
    } );
  </script>
</body>
</html>   