<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("cCajageneral_cst.php");
$oCajageneral_cst = new cCajageneral_cst();

require_once ("../formatos/formato.php");

$fecha1 = $_POST['txt_fil_com_fec1']; 
$fecha2 = $_POST['txt_fil_com_fec2'];

$dts1=$oCajageneral_cst->mostrar_filtrocondetalles($_POST['cmb_fil_usuario_id'],$_POST['cmb_fil_puntoventa_id'],
fecha_mysql($fecha1),fecha_mysql($fecha2),$_POST['cmb_fil_mon_id']);
$num_rows= mysqli_num_rows($dts1);

$dtse=$oCajageneral_cst->mostrar_filtrodevolucionescondetalles($_POST['cmb_fil_usuario_id'],$_POST['cmb_fil_puntoventa_id'],
fecha_mysql($fecha1),fecha_mysql($fecha2),$_POST['cmb_fil_mon_id']);
$num_rowse= mysqli_num_rows($dtse);


if($_POST['cmb_fil_mon_id']==1){
	$monsim = 'S/ ';
}else if($_POST['cmb_fil_mon_id']==2){
	$monsim = 'US$ ';
}



?>

<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_ven" class="table">
            <thead>
			
              <tr>
                <th class="" >FECHA</th>
				<th>NUM. DOC.</th>
                <th class="" >USUARIO</th>
                <th class="" >PRODUCTO</th>
                <th class="" >LABORATORIO</th>          
                <th class="" >PRESENTACION | EMPAQUE</th>          
                <th NOWRAP class="" align="right">CAN.</th>
                <th NOWRAP class="" align="right">PRE. COS. TOT.</th>
                <th NOWRAP class="" align="right">UTI %</th>
                <th NOWRAP class="" align="right">PRE. VEN. TOT.</th>
				        <th align="right" >UTI. BRU. TOT.</th>
              </tr>
            </thead>
            <tbody>
      <?php
       if($num_rows>0){
      while($dt1 = mysqli_fetch_array($dts1))
      {

		$can = $dt1['tb_ventadetalle_can'] * 1;
    $emp_fac = $dt1['tb_empaque_fac'];


      if($can>=$emp_fac){
        $can = $can/$emp_fac;
        $canvis =$can;
      }else{
        $can = $can;
        $canvis = 'F'.$can;

      }


		$precos = formato_money4($dt1['tb_ventadetalle_precos']*1); 
		$preven = formato_money4($dt1['tb_ventadetalle_preuni']*1); 
		$preventot = formato_money4($dt1['tb_ventadetalle_preuni']) * $can; 
    
    $diff = formato_money3($preventot - $precos);
    $utinet = ($preventot/$precos)*100 ; 

	
		$totcan += $can;
		$sum_precos += $precos;
    $sum_preven += $preventot;	
		$sum_diff += $diff;			
		
						
		$reg = mostrarFechaHora($dt1['tb_venta_reg']);					
	  
      ?>
      <tr title="FECHA DE REGISTRO : <?php echo "$reg";  ?>" >
        <td class="" nowrap="nowrap"><?php echo mostrarFecha($dt1['tb_venta_fec'])?></td>
        <td NOWRAP ><?php echo $dt1['tb_venta_numdoc']?></td>
        <td NOWRAP class="" ><?php echo $dt1['tb_usuario_nom']; ?></td>
        <td NOWRAP class="" ><strong><?php echo $dt1['tb_producto_nom']?></strong></td>
        <td NOWRAP class="" ><?php echo $dt1['tb_marca_nom']?></td>
        <td NOWRAP class="" ><?php echo $dt1['tb_presentacion_nom'].' | '.$dt1['tb_empaque_nom']; ?></td> 
        <td NOWRAP align="right"><?php echo $canvis ?></td>
        <td NOWRAP class="" align="right"><?php echo ' '.$precos*1;?></td>
        <td NOWRAP class="" align="right"><?php echo ' '.$utinet *1 .' %';?></td>
        <td NOWRAP class="" align="right"><?php echo ' '.$preventot*1;?></td>
        <td NOWRAP class="" align="right"><?php echo ' '.$diff;?></td>
     </tr>
      <?php	  
    }
    mysqli_free_result($dts1);
    }
    ?>
  </tbody>
  <tr class="even ">
  <td colspan="6">TOTAL SOLES</td>
  <td NOWRAP class="" align="right"><strong><?php echo ' '.$totcan * 1?></strong></td>
  <td NOWRAP class="" align="right"><strong><?php echo ' '.formato_money3($sum_precos)?></strong></td>
  <td NOWRAP class="" align="right"><strong><?php echo ' '?></strong></td>
  <td NOWRAP class="" align="right"><strong><?php echo ' '.formato_money3($sum_preven)?></strong></td>
  <td NOWRAP class="" align="right"><strong><?php echo ' '.formato_money3($sum_diff)?></strong></td>
</tr>
            </table>
         </div>

		
	<br/>
	<br/>
	<!--
		<div class="table-responsive">
			<div class="col-lg-5 col-md-5 col-sm-12 col-xs-12" >	
          <table id="tabla_compra" class="table">
            
			<tr>
			<th class="bg bg-yellow" colspan="2" >RESUMENES</th>
			</tr>
            <?php 
			$totcaj = $tot - $totd;
			?>
			<tr>
                <th class="" >TOTAL VENTAS</th>
				<td><?php echo ''.formato_money4($sum_diff) ?></td>
            </tr>
			
            </table>
			
			</div>
		</div>
			-->
		
        </div>
        </div>
      </div>
    </div>
    </div>
  </section>

  
   <script type="text/javascript">
  $(function() {  
    
	 $('#tabla_dev,#tabla_ven').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>  