<?php

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

require_once ("cProveedor.php");

$oProveedor = new cProveedor();



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

	$dts=$oProveedor->mostrarUno($_POST['pro_id']);

	$dt = mysqli_fetch_array($dts);

	$tip=$dt['tb_proveedor_tip'];

	$nom=$dt['tb_proveedor_nom'];

	$doc=$dt['tb_proveedor_doc'];

	$dir=$dt['tb_proveedor_dir'];

	$con=$dt['tb_proveedor_con'];

	$tel=$dt['tb_proveedor_tel'];

	$ema=$dt['tb_proveedor_ema'];

	mysqli_free_result($dts);

}

//echo $tip;exit;

?>

<script type="text/javascript"> 



$(function() {

 

	$( "#radio" ).buttonset();



	$('#txt_pro_nom, #txt_pro_dir, #txt_pro_con').change(function(){

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

	});



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

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

	});



// Formulario

$('#for_pro').bootstrapValidator({

	      //live: 'disabled',

	      framework: 'bootstrap',

	      message: 'This value is not valid',

	      feedbackIcons: {

	      	valid: 'glyphicon glyphicon-ok',

	      	invalid: 'glyphicon glyphicon-remove',

	      	validating: 'glyphicon glyphicon-refresh'

	      },

	      fields: { 

	      	cmb_pro_tip: {

	      		group: '.col-lg-2',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	},

	      	txt_pro_doc: {

	      		group: '.col-lg-2',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			},

	      			regexp: {

	      				regexp: /^[0-9]+$/,

	      				message: 'Caracteres no permitidos'

	      			}

	      		}

	      	},

	      	txt_pro_nom: {

	      		group: '.col-lg-8',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	},

	      	txt_pro_dir: {

	      		group: '.col-lg-12',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	},

	      }

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

	  	/*--- Save ---*/

	  	$.ajax({

					type: "POST",

					url: "../proveedor/proveedor_reg.php",

					async:true,

					dataType: "json",

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

					beforeSend: function(){

						$('#msj_proveedor').html("Guardando...");

						$('#msj_proveedor').show(100);

					},

					success: function(data){

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

        			$('#div_proveedor_form .modal-content').html(''); 

						$('#msj_proveedor').html(data.pro_msj);

						<?php

						if($_POST['vista']=="cmb_pro_id")

						{

							echo $_POST['vista'].'(data.pro_id);';

						}

						if($_POST['vista']=="hdd_pro_id")

						{

							echo 'proveedor_cargar_datos(data.pro_id);';

						}

						?>

					},

					complete: function(){

						<?php

						if($_POST['vista']=="proveedor_tabla")

						{

							echo $_POST['vista'].'();';

						}

						?>

					}

				}); 

	  });



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

		

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

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

		});

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

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

		});

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

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

		});

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

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

		});

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

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

		});

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

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

		});

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

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

		});







    });



</script>



<!-- Form content -->

<div class="modal-header">

	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

	<h4 class="modal-title" id="titlemodal">Información de Proveedor</h4> 

</div><div class="modal-body"><div class="row"><div class="col-xs-12"> 

<div id="div_cliente_form"></div>

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

 

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

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

 



	<div class="row">

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

									<label for="cmb_pro_tip" >Tipo</label>

									<?php if ($_POST['action']=='editar'){?>

									<select name="cmb_pro_tip" id="cmb_pro_tip"  class="form-control">

										<?php if ($tip==1) {?>

										<option value="0">-</option>

										<option value="1" selected >DNI</option>

										<option value="2">RUC</option>	

										<?php }else if ($tip==2) {?>

										<option value="0">-</option>

										<option value="1">DNI</option>

										<option value="2" selected>RUC</option>	

										<?php }

										?>

									</select>

									<?php }else if ($_POST['action']=='insertar') {?>

									<select name="cmb_pro_tip" id="cmb_pro_tip"  class="form-control">

										<option value="">-</option>

										<option value="1">DNI</option>

										<option value="2">RUC</option>

									</select>

									<?php } ?>

								</div>

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

									<label for="txt_pro_doc">RUC/DNI:</label>

									<input name="txt_pro_doc" id="txt_pro_doc" type="text" value="<?php echo $doc?>" maxlength="11" class="form-control">

								</div>

								<div class="col-lg-7 col-xs-12">

									<label for="txt_pro_nom">Proveedor:</label>

									<textarea name="txt_pro_nom"  rows="1" id="txt_pro_nom" class="form-control"><?php echo $nom?></textarea> 

								</div>

							</div>

							<div class="row">

								<div class="col-lg-12 col-xs-12">

									<label for="txt_pro_dir">Dirección:</label>

									<textarea name="txt_pro_dir"  rows="1" id="txt_pro_dir"  class="form-control"><?php echo $dir?></textarea>

								</div>

							</div>

							<div class="row">

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

									<label for="txt_pro_con">Contacto:</label>

									<input name="txt_pro_con" id="txt_pro_con" type="text" value="<?php echo $con?>" class="form-control">

								</div>

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

									<label for="txt_pro_tel">Teléfono:</label>

									<input name="txt_pro_tel" type="text" id="txt_pro_tel" value="<?php echo $tel?>"  maxlength="13" class="form-control">

								</div>

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

									<label for="txt_pro_ema">Email:</label>

									<input name="txt_pro_ema" type="text" id="txt_pro_ema" value="<?php echo $ema?>" maxlength="100" class="form-control">

								</div>

							</div>







</form>

<!-- FIN CONTENIDO MODAL -->     

</div></div></div>

<div class="modal-footer">	 

	<button type="button" class="btn btn-default pull-left" id="btn_prov_cancelar" data-dismiss="modal">Cancelar</button>

	<button type="button" class="btn btn-primary pull-right" id="btn_prov_guardar">Guardar</button>

</div>

