<?php
//ini_set('display_errors',1);

date_default_timezone_set('America/Lima');
session_start();
require_once ("../../config/Cado.php");

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

require_once("../almacen/cAlmacen.php");
$oAlmacen = new cAlmacen();

// echo $_POST['vista'];

if($_POST['vista']=="cotizacion_form"){
	$_POST['cotid']=$_POST['cotid'];
	
}else{
    ////	$_POST['vista']='nada';
	$_POST['cotid']=0;
}

 //echo $_POST['punven_id'].'||';

 $dts1=$oAlmacen->mostrarAlmCajEmp($_POST['punven_id']);
	$dt1 = mysqli_fetch_array($dts1);
 	$emp=$dt1['tb_empresa_id'];
 	$punven_id=$dt1['tb_puntoventa_id'];
 	$piso_id=$dt1['tb_piso_id'];
 	$alm = $dt1['tb_almacen_id'];
 			//$caj_id = $dt1['tb_caja_id'];
	mysqli_free_result($dts1);

	//echo $alm.'--.';
	
?>



<div class="modal-header">
<h4 class="modal-title" id="titlemodal">Seleccione un producto para ir agregando</strong> </h4> 
	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	
</div>

    <div class="" id="div_tablatotales"></div>
	<div class="col-lg-12 col-md-12 col-12 " style="height:10px;" >	</div>


	 <input type="hidden" id="hdd_alm_id" name="hdd_alm_id" value="<?php echo $alm;?>" />
	<div class="row">

		<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_cod">Codigo:</label>
			<input type="text" id="txt_pro_cod" name="txt_pro_cod"  class="form-control" autocomplete="off" value="<?php  echo $_POST['codmar']; ?>" />
		</div>
		
	<!--	<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_codbar">COD BAR:</label>
			<input type="text" id="txt_pro_codbar" name="txt_pro_codbar"  class="form-control"  value="<?php  echo $_POST['dat1']; ?>" />
		</div>
	-->
		<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_mar">Marca:</label>
			<input type="text" id="txt_pro_mar" name="txt_pro_mar"  class="form-control" autocomplete="off"  value="<?php  echo $_POST['mar']; ?>" />
		</div>
		
		<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_dat1">Busqueda:</label>
			<input type="text" id="txt_pro_dat1" name="txt_pro_dat1"  class="form-control" autocomplete="off" value="<?php  echo $_POST['dat1']; ?>" />
		</div>
		
		<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_dat2">-</label>
			<input type="text" id="txt_pro_dat2" name="txt_pro_dat2"  class="form-control" autocomplete="off" value="<?php  echo $_POST['dat2']; ?>" />
		</div>

		
		<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_dat3">-</label>
			<input type="text" id="txt_pro_dat3" name="txt_pro_dat3"  class="form-control" autocomplete="off" value="<?php  echo $_POST['dat3']; ?>" />
		</div>

		
		<div class="col-lg-2 col-sm-6 col-6">
			<label for="txt_pro_dat4">-</label>
			<input type="text" id="txt_pro_dat4" name="txt_pro_dat4"  class="form-control" autocomplete="off" value="<?php  echo $_POST['dat4']; ?>" />
		</div>

	<div class="col-lg-12 col-md-12 col-12 " style="height:10px;" >	</div>
	
	<div class="col-lg-12 col-md-12 col-12 no-padding" id="div_tablaproductos">	</div>

	</div> 

		

<div class="modal-footer pull-right">	 
	<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancelar</button>
</div>


<script type="text/javascript">


$(function(){
	
	
producto_tabla_seleccionar('<?php echo $_POST['codmar'];?>','<?php echo $_POST['dat1'];?>','<?php echo $_POST['dat2'];?>','<?php echo $_POST['dat3'];?>',
'<?php echo $_POST['dat4'];?>','<?php echo $_POST['mar'];?>');

	//cmb_almacen_id('<?php echo $alm?>');

	$(document).keyup(function(event){
			if(event.which==27)
			{
					$('#div_productomarca_form_dialog').modal('hide');
			}
	});

$("#txt_pro_dat1").focus();

});




<?php if( $_POST['vista']=='venta_form'){
			?>
			tabla_totales();
			<?php
		} ?>
		
		
		

$('#txt_pro_cod').change(function()
{
	$(this).val($(this).val().toUpperCase());
});

	$("#txt_pro_cod").keydown(function(e){
			if (e.which == 13){
			producto_tabla_seleccionar('','','','','');
			return false;
			}
		});
		
		$("#txt_pro_mar").keydown(function(e){
			if (e.which == 13){
			producto_tabla_seleccionar('','','','','');
			return false;
			}
		});
		
		$("#txt_pro_dat1").keydown(function(e){
			if (e.which == 13){
			producto_tabla_seleccionar('','','','','');
			return false;
			}
		});
		
			$("#txt_pro_dat2").keydown(function(e){
			if (e.which == 13){
			producto_tabla_seleccionar('','','','','');
			return false;
			}
		});
		
			$("#txt_pro_dat3").keydown(function(e){
			if (e.which == 13){
			producto_tabla_seleccionar('','','','','');
			return false;
			}
		});
		
			$("#txt_pro_dat4").keydown(function(e){
			if (e.which == 13){
			producto_tabla_seleccionar('','','','','');
			return false;
			}
		});
		
		
		
		$( "#txt_pro_dat1" ).keydown(function(e){
			if(e.which==32)
			{
				
				$( "#txt_pro_dat2" ).focus();
				
				// producto_tabla();
				e.preventDefault();
			}
		});

		$( "#txt_pro_dat2" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_pro_dat3" ).focus();
				// producto_tabla();
				e.preventDefault();
			}
		});

		$( "#txt_pro_dat3" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_pro_dat4" ).focus();
				// producto_tabla();
				e.preventDefault();
			}
		});
		 
		
			$("#txt_pro_dat4").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_pro_dat4").val()==""){
					$("#txt_pro_dat3").focus();
				}	
			//	e.preventDefault();	
			}
		});
		
		
		$("#txt_pro_dat3").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_pro_dat3").val()==""){
					$("#txt_pro_dat2").focus();
				}	
			//	e.preventDefault();	
			}
		});
		
		
		$("#txt_pro_dat2").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_pro_dat2").val()==""){
					$("#txt_pro_dat1").focus();
				}	
				//e.preventDefault();	
			}
		});
		
		
	

function producto_tabla_seleccionar(codmar,dat1,dat2,dat3,dat4,mar)
{
	$.ajax({
		type: "POST",
		url: "../producto/producto_tabla_x_codigo.php",
		async:true,
		dataType: "html", 
		data: ({
			codmar:codmar || $("#txt_pro_cod").val(),
			dat1:dat1 || $("#txt_pro_dat1").val(),
			dat2:dat2 || $("#txt_pro_dat2").val(),
			dat3:dat3 || $("#txt_pro_dat3").val(),
			dat4:dat4 || $("#txt_pro_dat4").val(),
			mar:mar || $("#txt_pro_mar").val(),
			alm_id: $("#hdd_alm_id").val(),
			vista: '<?php echo $_POST['vista'] ?>',
			cot_id: '<?php echo $_POST['cotid'] ?>'
		}) ,                   
		beforeSend: function() {
			
			$('#div_tablaproductos').addClass("ui-state-disabled");
        },
		success: function(html){
			$('#div_tablaproductos').html(html);
		},
		complete: function(){			
			$('#div_tablaproductos').removeClass("ui-state-disabled");
	
		}
	});     
}


function tabla_totales()
{

	$.ajax({
		type: "POST",
		url: "../compra/tabla_totales.php",
		async:true,
		dataType: "html", 
		data: ({
			vista: '<?php echo $_POST['vista']; ?>'
		}),                   
		beforeSend: function() {
				
	
			$('#div_tablatotales').addClass("ui-state-disabled");
        },
		success: function(html){
			$('#div_tablatotales').html(html);
		},
		complete: function(){			
			$('#div_tablatotales').removeClass("ui-state-disabled");
	
		}
	});     
}

	

</script>