<?php
//ini_set('display_errors',1);
session_start();
require_once ("../../config/Cado.php");
require_once ("cProducto.php");
$oProducto = new cProducto();
require_once ("../stock/cStock.php");
$oStock = new cStock();
require_once("../producto/cProductomarca.php");
$oProductomarca = new cProductomarca();
require_once ("../historial/cHistorial.php");
$oHistorial = new cHistorial();
require_once ("../formatos/formato.php");
//echo $_POST['txt_fil_pro_nom'].'-'.$cat_id.'-'.$_POST['cmb_fil_pro_est'].'-'.$_POST['cmb_fil_lim'];
if($_POST['txt_fil_pro_dat1']=="" && $_POST['txt_fil_pro_dat2']=="" && $_POST['txt_fil_pro_dat3']=="" && $_POST['txt_fil_pro_dat4']=="" && $_POST['txt_fil_pro_mar']==""&& $_POST['txt_fil_pro_codmar']=="" && $_POST['txt_fil_pro_acc'] == "")
{
?>
	
<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_producto" class="table table-bordered table-striped">
			    <thead>
			         <tr>
			        	 <th>&nbsp;</th>
			            <th nowrap >CODIGO</th>
			            <th nowrap >NOMBRE</th>			    
			            <th >UNIDAD</th>
			            <th style="white-space: nowrap;">CATEGORIA</th>		           			        
			        </tr>
			    </thead> 
				    <tbody>
					
					<tr>
					<td <?php if($_POST['vista']=='cotizacion_form'){echo 'colspan="5"'; }else{ echo 'colspan="5"'; }?> >NO HAY FILTROS DE BUSQUEDA</td>
					</tr>
				       
					</tbody> 
            </table>
         </div>
		  </div>
		  </div>
        </div>
    </div>
  </div>
</section>
	
<?php 
	
}else{
$dts1 = $oProducto->mostrar_filtro($_POST['txt_fil_pro_dat1'],$_POST['txt_fil_pro_dat2'],$_POST['txt_fil_pro_dat3'],$_POST['txt_fil_pro_dat4'],
$_POST['cmb_fil_cat_id'],$_POST['cmb_fil_lim'],$_POST['txt_fil_pro_mar'],$_POST['txt_fil_pro_codmar'],$_POST['txt_fil_pro_fam'],$_POST['txt_fil_pro_acc']);
$num_rows= mysqli_num_rows($dts1);
		$user_agen = $_SERVER['HTTP_USER_AGENT'];
		$mod = '21';
		$mod_ide = '0';
		$det = 'BUSQUEDA DE PRODUCTO SEGUN ['.$_POST['txt_fil_pro_codmar'].' '.$_POST['txt_fil_pro_dat1'].' '.$_POST['txt_fil_pro_dat2'].' '.
		$_POST['txt_fil_pro_dat3'].' '.$_POST['txt_fil_pro_dat4'].' '.$_POST['txt_fil_pro_mar'].']';
		$fec = date('Y-m-d');
		$doc_id = '';
		$numdoc = '';
	 	$ip = mostrar_ip();
		
		$oHistorial->insertar(
		fecha_mysql($fec),
		$det,
		$ip,
		$_SESSION['usuario_id'],
		$mod,
		$mod_ide,
		intval($doc_id),
		$numdoc
		);
		
?>
<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_producto" class="table table-bordered table-striped">
			    <thead>
			        <tr>
			        	 <th>&nbsp;</th>
			            <th nowrap >CODIGO</th>
			            <th nowrap >NOMBRE</th>
			           <!-- <th nowrap >DESCRIPCION</th>-->
			           <!-- <th >CATEGORIA</th>  -->
			            <th >UNIDAD</th>
			            <th style="white-space: nowrap;">CATEGORIA</th>		           
			           <!-- <th style="white-space: nowrap;" align="right">STOCK</th> 
			           -->
			        </tr>
			    </thead> 
				    <tbody>
				        <?php if($num_rows>=1){ 
						while($dt1 = mysqli_fetch_array($dts1)) {
						
						
						$dtscod = $oProducto->mostrarCod_principal($dt1['tb_catalogo_id']);
						$rowcod = mysqli_num_rows($dtscod);
						
						$dtcod = mysqli_fetch_array($dtscod);
						$codprin = $dtcod['tb_productomarcacodigo_cod']; 
						
						
						if($dt1['tb_producto_est']==2){
							$color="bg-red";
							$title="title ='INACTIVO'";
						}else{
							$color="";
							$title="";
						}
						
						?>
				            <tr class="<?php echo $color; ?>"  <?php  echo $title; ?> data-catid = "<?php echo $dt1['tb_catalogo_id']?>" data-proid = "<?php echo $dt1['tb_producto_id']?>" style="cursor:pointer;">
				            						
				            	<td align="center" nowrap>
									<button class="btn btn-sm btn-primary" onClick="producto_form('editar','<?php echo $dt1['tb_producto_id']?>')"><i class="fas fa-edit"></i></button>
									<button class="btn btn-sm btn-danger" onClick="eliminar_producto('<?php echo $dt1['tb_producto_id']?>')"><i class="fas fa-trash"></i></button>	
								<!--	<button class="btn btn-sm btn-warning" 
									onClick="ver_info('<?php echo $dt1['tb_catalogo_id']?>','<?php echo $dt1['tb_presentacion_id']?>','<?php echo $dt1['tb_producto_id']?>')"><i class="fa fa-bar-chart"></i></button>	
								-->
								</td>
				            	<td nowrap="" ><?php echo '<span style="font-size:16px;" class="label label-warning label-sm">'.$codprin.'</span>'; ?></td>
				            	<td nowrap="" title="MODIFICADO EL <?php echo mostrarFechaHora($dt1['tb_producto_mod']) ?>" ><?php echo $dt1['tb_producto_nom']?></td>
				                <td ><?php echo $dt1['tb_unidad_abr'];?></td>
				                <td style="white-space: nowrap;"  > 
									<span style="font-size:13px;"  class="label label-success "><?php echo $dt1['tb_categoria_nom']; ?></span>
								</td>
				           
							
							 							   
				            </tr>
							
				        <?php } 
						mysqli_free_result($dts1); 
						}
						?>
					</tbody> 
            </table>
          
		  </div>
		  </div>
		  </div>
        </div>
    </div>
  </div>
</section>
<?php }?>
<script type="text/javascript">
  $(function() {  
   	
	 $('#tabla_producto').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>