<?php
//ini_set('display_errors',1);
session_start();
require_once ("../../config/Cado.php");
require_once ("../productogeneral_cst/cProductogeneral_cst.php");
$oProductogeneral_cst = new cProductogeneral_cst();
require_once("../producto/cProductomarcacodigo.php");
$oProductomarcacodigo = new cProductomarcacodigo();
require_once ("../stock/cStock.php");
$oStock = new cStock();

require_once ("../formatos/formato.php");
require_once ("../formatos/fechas.php");
?>

<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;">
		<!--
		<a  class="btn btn-sm" style="background-color:#00897b;color:#fff;text-align:left" 
		href="../../files/compra/compraconsolidadasfecha_impcpe_doc.php?fec1=<?php echo $_POST['fec1'] ?>&fec2=<?php echo $_POST['fec2']?>
		&agrufec=<?php echo $_POST['agrufec']?>&agruemp=<?php echo $_POST['agruemp']?>&agrucli=<?php echo $_POST['agrucli']?>" 
		target="_blank"><i class="fa fa-file-pdf-o"></i>  DESCARGAR E IMPRIMIR PDF</a>
		-->
		<button class="btn btn-success " id="btn_excel"> <i class="fas fa-file-excel"></i> DESCARGAR EXCEL </button>
		
<?php 
//echo $_POST['agrufec'].'-'.$_POST['agruemp'].'-'.$_POST['agrucli'];
$dtsa = $oProductogeneral_cst->mostrar_filtro_proceso($_POST['txt_fil_pro_dat1'],$_POST['txt_fil_pro_dat2'],$_POST['txt_fil_pro_dat3'],$_POST['cmb_fil_cat_id'],$_POST['txt_fil_pro_mar']);
$num_rows= mysqli_num_rows($dtsa);
 
?>
        	<div class="table-responsive" id="">
			 
			<div class="col-lg-12 col-xs-12" style="height:10px;"></div>
			 
          <table id="tabla_productogeneral" class="table table-bordered table-striped">
           <thead>
							
			<tr class="header_row" style="font-weight:bold;font-size:16px;">
				<th>COD. BAR. *</th>
				<th>PRODUCTO</th>
				<th>MARCA / CATEGORIA</th>
				<th>PRESENTACION / EMPAQUE</th>
				<th>P. COMPRA *</th>
				<th>P. VENTA *</th>			
			</tr>
		</thead>
         <tbody>	
		<?php
		if($num_rows>0){
		
		
		
		while($dta = mysqli_fetch_array($dtsa))
		{ 										
			
			
			$dtspri = $oProductomarcacodigo->mostrarUno($dta['tb_catalogo_id'],'1');
			$dtpri = mysqli_fetch_array($dtspri);
			$codpri = $dtpri['tb_productomarcacodigo_cod'];
							
						
			//$stock = mysqli_fetch_array($oStock->stock_por_presentacion($dta['tb_presentacion_id'],$dta['tb_marca_id'],'1'))['tb_stock_num'];
			
		?>
			<tr class="even" data-dat = "<?php echo $dt1['tb_cliente_id'].'- E'.$dt1['tb_empresa_id']; ?>"  data-comid ="<?php echo $dt1['tb_venta_id']?>" >
						
				<td nowrap align="left"><?php echo $dta['tb_productomarca_codbar']?></td>
				<td align="left" nowrap ><?php echo $dta['tb_producto_nom']?></td>
				<td align="left" nowrap ><?php echo $dta['tb_marca_nom'].' / '.$dta['tb_categoria_nom']?></td>
				<td align="left" nowrap ><?php echo $dta['tb_presentacion_nom'].' / '.$dta['tb_empaque_nom']?></td>
				<td align="left"><?php echo formato_money($dta['tb_productomarca_precom'])?></td>
				<td align="left" nowrap ><?php echo formato_money($dta['tb_productomarca_preven'])?></td>									
						
											           
			</tr>
		<?php 	

		}
		
		mysqli_free_result($dtsa); 

		}		
	?>
		</tbody>
      </table>
	  	
	    </div>
    
	
	
	
	</div>
  </div>
</div>
</div>
</section>
<script type="text/javascript">
function abrirEnPestana(url) {
		var a = document.createElement("a");
		a.target = "_blank";
		a.href = url;
		a.click();
}
$(function(){
	
$("#btn_excel").click(function(){
		dat1 = "<?php echo $_POST['txt_fil_pro_dat1'] ?>";
		dat2 = "<?php echo $_POST['txt_fil_pro_dat2'] ?>";
		dat3 = "<?php echo $_POST['txt_fil_pro_dat3'] ?>";
		
		mar = "<?php echo $_POST['txt_fil_pro_mar'] ?>";
		cat = "<?php echo $_POST['cmb_fil_cat_id'] ?>";
		
	abrirEnPestana('../../files/producto/reporte_producto_generalmodulo.php?dat1='+dat1+'&dat2='+dat1+'&dat3='+dat1+'&mar='+mar+'&cat='+cat);
});
	
	  
	  
	   $('#tabla_productogeneral').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>  