<?php
// ini_set('display_errors',1);
require_once ("../../config/Cado.php");
require_once ("../producto/cProducto.php");
$oProducto = new cProducto();
require_once ("../stock/cStock.php");
$oStock = new cStock();
require_once("../producto/cProductomarca.php");
$oProductomarca = new cProductomarca();
require_once("../producto/cProductomarcacodigo.php");
$oProductomarcacodigo = new cProductomarcacodigo();
require_once ("../formatos/formato.php");

//echo '--'.$_POST['alm_id'];

if($_POST['dat1']=="" && $_POST['dat2']=="" && $_POST['dat3']=="" && $_POST['dat4']=="" && $_POST['mar']==""&& $_POST['codmar']=="")
{
?>
	
	<div class="table-responsive">		
				<div class="col-lg-12 col-md-12 col-xs-12 " >
				
            <table id="tabla_producto" class="table table-bordered table-striped">
			    <thead>
			        <tr>
			            <th nowrap >CANTIDAD</th>
						<th nowrap >NOMBRE</th>
			            <th >UNIDAD</th>
			            <th >MARCA</th>
			            <th >PRECIO VENTA</th>
			            <th >PRECIO COSTO</th>
			            <th >STOCK</th>
			        </tr>
			    </thead> 
				    <tbody>
					
					<tr>
					<td <?php if($_POST['vista']=='cotizacion_form'){echo 'colspan="7"'; }else{ echo 'colspan="7"'; }?> >NO HAY FILTROS DE BUSQUEDA</td>
					</tr>
				       
					</tbody> 
            </table>
          
		  </div>
		  </div>
		  
	
<?php 
	
}else{
	
$dts1 = $oProducto->mostrar_filtro_proceso($_POST['dat1'],$_POST['dat2'],$_POST['dat3'],$_POST['dat4'],'','',$_POST['mar'],$_POST['codmar'],'','','');
$num_rows= mysqli_num_rows($dts1);
//}
?>
<!--
<section class="content" id="table" style="min-height:0px;padding-bottom:0px;margin-bottom:-30px;">
  <div class="row">
    <div class="col-xs-12">
      <div class="box">
	  <div class="box-body">
-->	
<style>
	#tabla_producto td{
		vertical-align: middle;
		padding: 4px 4px !important;
	}
	#tabla_producto td.editable,#tabla_producto td.editable *{
		cursor: text !important;
		height: 100%; 
		border-bottom-color: #ccc;
		border-bottom-style: dashed; 
		border-bottom-width: 0.5px;
	}
	#tabla_producto td.editando{
		background-color: rgba(18, 180, 243, 0.05);
		outline: 2px solid #35A4F3;
	}
	#tabla_producto td input{
		height: 100%;
		width: 100%;
		box-sizing: border-box;
		display: inline-block;
		border: none;
		background: transparent;
	}
	#tabla_producto td input:focus{
		background: transparent;
		height: 100%;
		width: 100%;
		outline: none;
		border: none;
	}
	#tabla_producto td input[readonly]{
		background: transparent;
	}
</style> 
	<div class="table-responsive">		
				<div class="col-lg-12 col-md-12 col-xs-12 " >
				
            <table id="tabla_producto" class="table table-bordered table-striped">
			    <thead>
			        <tr>
			           <!-- <th nowrap >CODIGO</th>
			            -->
						<th nowrap >CANTIDAD</th>
						<th nowrap >NOMBRE</th>
			            <th >UNIDAD</th>
			            <th >MARCA</th>
			            <th >PRECIO COSTO</th>
			            <th class="" >PRECIO VENTA</th>
			            <th >STOCK</th>
			        </tr>
			    </thead> 
				    <tbody>
					
					
					 <?php 
					 	
						if($num_rows>=1){ 
						
						while($dt1 = mysqli_fetch_array($dts1)) {
							
						/* 	$dtspri = $oProductomarcacodigo->mostrarUno($dt1['tb_catalogo_id'],'1');
							$dtpri = mysqli_fetch_array($dtspri);
							$codpri = $dtpri['tb_productomarcacodigo_cod'];
							 */
						//echo $dt1['tb_presentacion_id'].' - - '.$dt1['tb_marca_id'];
							$stock = mysqli_fetch_array($oStock->stock_por_presentacion($dt1['tb_catalogo_id'],$dt1['tb_marca_id'],$_POST['alm_id']))['tb_stock_num'];
							// 	echo $stock;
						//	$dias = $oProducto->calcula_fecha($dt1['tb_productomarca_fecven'],date('d-m-Y'));
							
						?>
				            <tr	class="tr_pro" data-catid = "<?php echo $dt1['tb_catalogo_id']?>" 
							data-proid = "<?php echo $dt1['tb_producto_id']?>" style="cursor:pointer;font-weight:bold">
				            	
				            <!--	<td nowrap="" ><?php echo '<span style="font-size:16px;" class="label label-warning label-sm">'.$codpri.'</span>'; ?></td>
				            	-->
								<td align="right" width="50" class="editable" style="font-size:9pt; font-weight:bold" > 
							
							<input type="text" value="<?php echo $can ?>" 
							readonly data-cat_id="<?php echo $dt1['tb_catalogo_id'] ?>" 
							data-mar_id ="<?php echo $dt1['tb_marca_id'] ?>" class=" " style="text-align: right;">
				
								</td>
								<td nowrap="" data-toggle="tooltip" data-placement="top"  > <strong class="lblnom" data-pro_id="<?php echo $dt1['tb_producto_id'] ?>" > <?php echo $dt1['tb_producto_nom']?> </strong> </td>
				                <td ><?php echo $dt1['tb_unidad_abr'];?></td>
				                <td > <strong class="text-orange text-md"> <?php echo $dt1['tb_marca_nom'];?> </strong></td>
				                <td align="right" > <strong class="text-md "> <?php echo formato_money($dt1['tb_productomarca_precos']);?></strong></td>
				                <td align="right" class="" > <strong style="font-size:1.5rem;" class="text-orange"> <?php echo formato_money($dt1['tb_productomarca_preven']);?></strong></td>			               
				         <td align="right" ><?php if($stock==''){}else{  if($stock<=10){ echo '<strong style="color:red;font-size:2rem;">'.$stock*1 .'</strong>';}else{ echo '<strong>'.$stock*1 .'</strong>';}} ?></td>
				              					   
				            </tr>
													
				        <?php
						
						} 
						mysqli_free_result($dts1); 
						}
							
					//	if($_POST['codmar']!=""){}else{
							?>
						<!--	<tr>
							<td colspan="4" >INGRESE UN CODIGO Y BUSQUE</td>
							</tr>
							-->
							<?php 
					//	}
						?>
					
				       
					</tbody> 
            </table>
		
		  </div>
		  </div>
		 
		
		  
		  
		  <script type="text/javascript">
		  
		  	$('#tabla_producto td input').keydown(function(ev) {
			if(ev.keyCode == 13 && !$(this).attr('readonly')) {
			
			var cat_id = $(this).attr('data-cat_id');
			var mar_id = $(this).attr('data-mar_id');
			var cantidad = $(this).val();
	
			agregar_producto('agregar',cat_id,cantidad,'',mar_id,'','','<?php echo $_POST['cot_id'] ?>')
			
				$(this).attr('readonly', 'true');
				$(this).parent().removeClass('editando');
				return false;
			}
		});
		  
		  
		  $(".lblnom").click(function() { 
			
			var pro_id = $(this).attr('data-pro_id');
			
			producto_form('verinfo',pro_id);
			
		});
		
		
		  
		  	$('#tabla_producto td input').parent().click(function(ev) {
			var $input = $(this).find('input');
			var $td = $input.parent().addClass('editando');
			$input.removeAttr('readonly').focus().select();
		});
		$('#tabla_producto td input').blur(function(event) {
			$(this).val($(this).attr('data-original'));
			$(this).attr('readonly', 'true');
			$(this).parent().removeClass('editando');
		});
		$('#tabla_producto td input').keydown(function(ev) {
			if(ev.keyCode==27){
				$(this).val($(this).attr('data-original'));
				$(this).attr('readonly', 'true');
				$(this).parent().removeClass('editando');
			}
		});
		 
		  
		  
		  		
	function producto_form(act,idf){
		$('#div_producto_form_dialog').modal();
		$('body').css('overflow-y','hidden');
	$.ajax({
		type: "POST",
		url: "../producto/producto_infoseleccion.php",
		async:true,
		dataType: "html",                      
		data: ({
			action: act,
			pro_id:		idf,
			vista:	'producto_seleccion',
			vistaban: '<?php echo $_POST['vista']; ?>'	
		}),
		beforeSend: function() {	
			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
					$('.div_producto_form').html(div);
        },
		success: function(html){
			$('.div_producto_form').html(html);				
		}
	});
}
		  
		  
		  </script>
	
<?php }?>