<?php

require_once ("../../config/Cado.php");

require_once ("cPiso.php");

$oPiso  = new cPiso();



if($_POST['action']=="editar")

{

	$id = $_POST['salon_id'];

	

	    $datos = $oPiso->MostrarUno($id);

     while ($fila = mysqli_fetch_array($datos)) {

		 

		 $piso = $fila["tb_piso_nom"];

		 $punven_id = $fila["tb_puntoventa_id"];

		 $alm_id = $fila["tb_almacen_id"];

		 $caj_id = $fila["tb_caja_id"];

		 $imp_id = $fila["tb_impresora_id"];

		 

	 }

	

}

?>



				<form role="form" id="for_piso" method="POST"> 

						<input name="action_piso" id="action_piso" type="hidden" value="<?php echo $_POST['action']?>">

						<input name="hdd_piso_id" id="hdd_piso_id" type="hidden" value="<?php echo $_POST['salon_id']?>">



					<div class="box-header">

						<h3 class="box-title">Información del salon</h3>

					</div>

					<div class="box-body">



						<div class="form-group">							

							<div class="row">

								<div class="col-lg-4 col-xs-6">

									<label for="txt_piso_nom">Nombre:</label>

									<input name="txt_piso_nom" type="text" id="txt_piso_nom" value="<?php echo  $piso; ?>" class="form-control" > 

								</div>

								<div class="col-lg-4 col-xs-6">

									<label for="cmb_local_id">Punto de venta:</label>

									<select name="cmb_local_id" id="cmb_local_id" class="form-control"></select>  

								</div>

								<div class="col-lg-4 col-xs-6">

									<label for="cmb_alm_id">Almacén para ventas:</label>

									<select name="cmb_alm_id" id="cmb_alm_id" class="form-control"></select>

								</div> 

								



							</div>

						</div>

					</div>

				</form>

				<div class="box-footer float-right">

					<button type="button" data-dismiss="modal" class="btn btn-default cancel">Cancelar</button>

					<button  class="btn btn-primary " id="save_form">Guardar</button> 

				</div>

			





<script type="text/javascript">



	

	function cmb_alm_id(){

		$.ajax({

			type: "POST",

			url: "../almacen/cmb_alm_id.php",

			async:true,

			dataType: "html",                      

			data: ({

				alm_id: '<?php echo $alm_id?>'

			}),

			beforeSend: function() {

				$('#cmb_alm_id').html('<option value="">Cargando...</option>');

			},

			success: function(html){

				$('#cmb_alm_id').html(html);

			}

		});

	}







	function cmb_local_id(idf)

{	

	$.ajax({

		type: "POST",

		url: "../puntoventa/cmb_punven_id.php",

		async:false,

		dataType: "html",                      

		data: ({

			punven_id: idf

		}),

		beforeSend: function() {

			$('#cmb_local_id').html('<option value="">Cargando...</option>');

        },

		success: function(html){

			$('#cmb_local_id').html(html);

		},

		complete: function(){

			//venta_tabla();

		}

	});

}





	cmb_local_id(<?php echo $punven_id; ?>);

	cmb_alm_id();





	$('#txt_piso_nom').change(function(){

		$(this).val($(this).val().toUpperCase());

	});



	$('#txt_piso_nom').focus();



	$('#txt_piso_nom').keydown(function(ev) {

		if(ev.keyCode==13){$('#cmb_local_id').focus(); return false;}

	});

	$('#cmb_local_id').keydown(function(ev) {

		if(ev.keyCode==13){$('#cmb_alm_id').focus(); return false;}

	});

	$('#cmb_alm_id').keydown(function(ev) {

		if(ev.keyCode==13){ return false;}

	});

	

	



	$("#save_form").click(function() {

		$("#for_piso").submit();

	});

	

	

	

	$('#for_piso').bootstrapValidator({

	      //live: 'disabled',

	      message: 'Valor no valido',

	      feedbackIcons: {

	      	valid: 'glyphicon glyphicon-ok',

	      	invalid: 'glyphicon glyphicon-remove',

	      	validating: 'glyphicon glyphicon-refresh'

	      },  

	      fields: {	       	

	      	txt_piso_nom: {

	      		group: '.col-lg-4',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	},	

			cmb_alm_id: {

	      		group: '.col-lg-4',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	},

			

			

	      }

	  }).on('success.form.bv', function(e) {

		  

	  	$.ajax({

	  		type: "POST",

	  		url: "../piso/piso_reg.php",

	  		async:true,

	  		dataType: "json",

	  		data: $("#for_piso").serialize(),

	  		beforeSend: function() {					 

	  			

	  		},

	  		success: function(data){	

			

				$('.modal').modal('hide');

				$('.in').removeClass('modal-backdrop');			

				toastr["success"](data.piso_msj);	

	  		

			},

	  		complete: function(){

				piso_tabla();

	  			//$("#contenido").load("../piso/piso_vista.php");

	  		}

	  	}); 



	  });

	  

	  

	  



</script>