<?php
// ini_set('display_errors',1);
session_start();
require_once ("../../config/Cado.php");
require_once ("cVentageneral_cst.php");
$oVentageneral_cst = new cVentageneral_cst();

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

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

$dts1=$oVentageneral_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);


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;">	
					
					<span style="cursor:pointer" id="btn_excel" class="btn btn-success"> <i class="fas fa-file-excel"></i> DESCARGAR EXCEL </span>
		
		
		<div class="table-responsive">	
          <table id="tabla_ven" class="table">
            <thead>
			<tr>
			<th class="bg bg-primary" colspan="9" >REGISTRO DE VENTAS</th>
			</tr>
			
              <tr>
				<th class="" >EMPRESA</th>
                <th class="" >USUARIO</th>
                <th class="" >FECHA</th>
                <th class="" >DETALLE</th>
				<th style="white-space: nowrap;">ARTÍCULO</th>
				<th class="" style="white-space: nowrap;" >CATEGORÍA | MARCA</th>		
				<th align="right">CAN</th>			
				<th align="right" >P. UNI.</th>	
				<th align="right" >PRECIO TOTAL</th>
              </tr>
            </thead>
            <tbody>
      <?php
       if($num_rows>0){
      while($dt1 = mysqli_fetch_array($dts1))
      {

		$can = $dt1['tb_ventadetalle_can'];
		$pre_uni=$dt1['tb_ventadetalle_preuni'];
		$des_uni = $dt1['tb_ventadetalle_des'];
		$esp_id = $dt1['tb_especificacion_id'];
		
		
		$valor_uni = $pre_uni/ 1.18;
		$igv_uni = $pre_uni - $valor_uni;
			
		$val_tot = $valor_uni * $can;
		$des_tot = $des_uni * $can;
		$igv_tot = $igv_uni * $can;
		$pre_tot = $pre_uni * $can;
		
		
		$est = $dt1['tb_ventadetalle_est'];

	
	  
      ?>
      <tr  >
			<td NOWRAP ><?php echo $dt1['tb_empresa_nomcom']?></td>
			<td NOWRAP class="" ><?php echo $dt1['tb_usuario_nom'].' '.$dt1['tb_usuario_ape']?></td>
			<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_ventadetalle_nom']?>
			</td>
			
			<td NOWRAP class="" ><?php echo $dt1['tb_marca_nom'].' | '.$dt1['tb_unidad_nom']; ?></td>
       
			<td NOWRAP align="right"><?php echo $dt1['tb_ventadetalle_can'] * 1?></td>
			<td NOWRAP class="" align="right"><?php echo $monsim.' '.formato_money($pre_uni);?></td>
			<td NOWRAP class="" align="right"><?php echo $monsim.' '.formato_money($pre_tot);?></td>
     </tr>
      <?php
	  
	  $totcan += $dt1['tb_ventadetalle_can'];
	  $totpreuni += $pre_uni;
	  $tot += $pre_tot;
	  
    }
    mysqli_free_result($dts1);
    }
    ?>
  </tbody>
  <tr class="even ">
  <td colspan="6">TOTAL SOLES</td>
  <td NOWRAP class="" align="right"><strong><?php echo '<span class="text-primary"></span>'.' '.$totcan * 1?></strong></td>
  <td NOWRAP class="" align="right"><strong><?php echo '<span class="text-primary">'.$monsim.'</span>'.' '.formato_money($totpreuni)?></strong></td>
  <td NOWRAP class="" align="right"><strong><?php echo '<span class="text-primary">'.$monsim.'</span>'.' '.formato_money($tot)?></strong></td>
</tr>
            </table>
         </div>

		
	
		
		
        </div>
        </div>
      </div>
    </div>
    </div>
  </section>

  
   <script type="text/javascript">
  $(function() {  
    
	
	function abrirEnPestana(url) {
		var a = document.createElement("a");
		a.target = "_blank";
		a.href = url;
		a.click();
}


$("#btn_excel").click(function(){
			usu_id = '<?php echo $_POST['cmb_fil_usuario_id']; ?>';
			punven_id = '<?php echo $_POST['cmb_fil_puntoventa_id']; ?>';
			fec1 = '<?php echo $fecha1; ?>';
			fec2 = '<?php echo $fecha2; ?>';
			mon_id = '<?php echo $_POST['cmb_fil_mon_id']; ?>';
			abrirEnPestana('../ventageneral_cst/ventageneral_cst_excel.php?usu_id='+usu_id+'&punven_id='+punven_id+'&fec1='+fec1+'&fec2='+fec2+'&mon_id='+mon_id);
});
	
	
	 $('#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>  