<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("cEgreso.php");
$oEgreso = new cEgreso();
require_once("../cliente/cCliente.php");
$oCliente = new cCliente();
require_once("../proveedor/cProveedor.php");
$oProveedor = new cProveedor();
require_once("../formatos/formato.php");
$fecha1 = $_POST['txt_fil_egre_fec1']; 
$fecha2 = $_POST['txt_fil_egre_fec2']; 
$dts1=$oEgreso->mostrar_filtro($_SESSION['empresa_id'],$_POST['cmb_fil_caj_id'],fecha_mysql($fecha1),fecha_mysql($fecha2),$_POST['cmb_fil_cue_id'],$_POST['cmb_fil_subcue_id'],$_POST['cmb_fil_doc_id'],$_POST['txt_fil_egr_numdoc'],$_POST['hdd_fil_pro_id'],$_POST['cmb_fil_egr_est'],$_POST['cmb_moneda_id']);
$num_rows= mysqli_num_rows($dts1);
?>
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		    <div class="card">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:5px;">
	
					<div class="table-responsive">
	 
	 
	 <table id="tabla_egreso" class="table table-bordered table-striped">
       <thead>
        <tr>
          <th title="Editar">&nbsp;</th>
          <th nowrap title="Fecha">FECHA</th>
          <th>ANEXO</th>
          <th>DETALLE</th>
          <th>CUENTA</th>
          <th align="right">IMPORTE</th>
          <th align="center">ESTADO</th>
          <th align="center">CAJA</th>
          <th>ID</th>
          
          </tr>
        </thead>
           <tbody>
<?php
while($dt1 = mysqli_fetch_array($dts1)){
  $sum_imp+=$dt1['tb_egreso_imp'];
  
 // echo $dt1['modid'].'-';
  
  if($dt1['modid']==20 || $dt1['modid']==7){
	
	$dts=$oCliente->mostrarUno($dt1['perid']);
	$dt = mysqli_fetch_array($dts);
	$nom=$dt['tb_cliente_nom'];
	$doc=$dt['tb_cliente_doc'];
	mysqli_free_result($dts);
	
  }else{
	if($dt1['perid']>0){
	
	$dts=$oProveedor->mostrarUno($dt1['perid']);
	$dt = mysqli_fetch_array($dts);
	$nom=$dt['tb_proveedor_nom'];
	$doc=$dt['tb_proveedor_doc'];
	mysqli_free_result($dts);
	}
	else{
		$nom = 'SALIDA S/PROVEEDOR';
		$doc = '';
	}
  }
?>
        <tr>
           <td align="center" nowrap="nowrap">
           <?php 
           if($_SESSION['usuariogrupo_id']!=1){
         if($dt1['tb_egreso_modide']==0){
           ?>
           <span title="Editar" class="btn btn-info btn-sm" onClick="egreso_form('editar','<?php echo $dt1['tb_egreso_id']?>')"><i class="fas fa-edit"></i></span>
           <?php 
         }
      }else{
        ?>
        <span title="Editar" class="btn btn-info btn-sm " onClick="egreso_form('editar','<?php echo $dt1['tb_egreso_id']?>')"><i class="fas fa-edit"></i></span>
        <span  title="Eliminar" class="btn btn-danger btn-sm "  onClick="egreso_eliminar('<?php echo $dt1['tb_egreso_id']?>')"><i class="fas fa-trash"></i></span> 
       
        <?php 
      }
          ?>

           <span class="btn btn-sm btn-warning" title="IMPRIMIR FORMATO TICKET" data-toggle="tooltip" data-placement="top" onclick="egreso_ticket_datos('<?php echo $dt1['tb_egreso_id']?>')"><i class="fa fa-print"></i></span>

          </td>

          <td nowrap ><?php echo mostrarFecha($dt1['tb_egreso_fec'])?></td>
          <td nowrap ><?php echo $nom.' '.$doc ?></td>  
          <td nowrap ><?php echo $dt1['tb_egreso_det']?></td>
          <td nowrap ><?php echo $dt1['tb_cuenta_nom'].' '.$dt1['tb_subcuenta_nom']?></td>
          <td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_imp'])?></td>
          <td nowrap align="center"><?php 
            if($dt1['tb_egreso_est']==1)echo 'REGISTRADO';
            if($dt1['tb_egreso_est']==2)echo 'ANULADO';
          ?></td>
          <td align="center" nowrap><?php echo $dt1['tb_caja_nom']?></td>
          <td><?php echo $dt1['tb_egreso_id']?></td>
          

          </tr>
<?php
}
mysqli_free_result($dts1);
?>
    </tbody>
	  <tr class="even">
          <td colspan="4"><strong>TOTAL</strong></td>
          <td align="right"><strong><?php echo formato_money($sum_imp)?></strong></td>
          <td colspan="4">&nbsp;</td>
      </tr> 
        </table>
      </div>
    </div>
    </div>
  </div>
</div>
</div>
</section>
<script type="text/javascript">
  $(function() {  
  
	 $('#tabla_egreso').DataTable({
 
        "language": {
                "lengthMenu": "Mostrar _MENU_ registros",
                "zeroRecords": "No se encontraron resultados",
                "info": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
                "infoFiltered": "(filtrado de un total de _MAX_ registros)",
                "sSearch": "Buscar:",
                "oPaginate": {
                    "sFirst": "Primero",
                    "sLast":"Último",
                    "sNext":"Siguiente",
                    "sPrevious": "Anterior"
			     },
			     "sProcessing":"Procesando...",
            }
    });  
	
	
  }); 
</script>  
 