<?php

date_default_timezone_set('America/Lima');

session_start();

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



require_once ("../compra/cComprapago.php");

$oComprapago = new cComprapago();





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

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



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

{



	$dts= $oComprapago->mostrarUno($_POST['compag_id']);

	$dt = mysqli_fetch_array($dts);

	$compag_mon =$dt['tb_comprapago_mon'];

	

	$pro_id		=$dt['tb_proveedor_id'];

	$pro_nom		=$dt['tb_proveedor_nom'];

	$mone_id		=$dt['tb_moneda_id'];

	$emp_id		=$dt['tb_empresa_id'];

	$tipcam		=$dt['tb_compra_tipcam'];

	$com_numdoc		=$dt['tb_compra_numdoc'];

	$ref		=$dt['tb_comprapago_ref'];

	$aval		=$dt['tb_comprapago_aval'];

	$lug		=$dt['tb_comprapago_lug'];

	$banid		=$dt['tb_banco_id'];

	$conid		=$dt['tb_comprapago_con'];

	$doc_nom = $dt['tb_compra_numdoc'];

	$mon = $dt['tb_comprapago_mon'];

	$fecven =$dt['tb_comprapago_fecven'];

	$numuni = $dt['tb_comprapago_numuni'];







	if($mone_id==1){

		$lbl_mone = 'S/ ';

	}else if($mone_id==2){

		$lbl_mone = 'US$ ';

	}



	mysqli_free_result($dts);



}

?>

<script type="text/javascript" src="../cotizacion/NumberFormat.js"></script>



<script type="text/javascript">





	$(function() {



	validar(<?php echo $conid; ?>);



		//proveedor_cargar_datos('<?php echo $pro_id?>');



		$('#txt_pro_doc,#txt_pro_nom,#txt_egr_imp,#txt_egr_fecven,#txt_egre_tot,#txt_egres_imp').attr('readonly','readonly');	



		<?php if($_POST['vista']=='pagado'){

			?>

			$('#txt_pro_doc,#txt_pro_nom,#txt_egr_imp,#txt_egr_fecven,#txt_egre_tot,#txt_egres_imp,#cmb_let_con,#txt_let_lug,#txt_let_numdoc,#cmb_let_ban').attr('readonly','readonly');	

			<?php 

		} ?>



	

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

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

		});

		

		$('#for_let').bootstrapValidator({ 

	      message: 'Valor no valido',

	      feedbackIcons: {

	      	valid: 'glyphicon glyphicon-ok',

	      	invalid: 'glyphicon glyphicon-remove',

	      	validating: 'glyphicon glyphicon-refresh'

	      },

	      fields: {	      	

		  

	      }

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

	  	

		$(".modal-footer").hide(100);

		 

	  	$.ajax({

	  		type: "POST",

	  		url: "../comprapago/comprapago_reg.php",

	  		async:true,

	  		dataType: "json",

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

	  		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_egresoletra_form').html(div);

			

	  		},

	  		success: function(data){



	  			<?php if($_POST['vista']=='canje'){

	  				?>

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

					canje_letras_tabla_vista('',<?php echo $_POST['canid']; ?>);



				<?php }else if($_POST['vista']=='cuentapagar'){

	  				?>

	  				

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

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

					cuentapagar_tabla_prov_fac('<?php echo $_POST['pro_id']; ?>','<?php echo $_POST['emp_id']; ?>','','<?php echo $_POST['mon_id']; ?>',doctod,letr,fac,nd,nc,esttod,pen,canj,pag);





	  				<?php 

	  			}else{?>

	  			//$('#div_letra_form_dialog').modal('hide');

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

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

				

				<?php } ?>	

				

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

	  		},

	  		complete: function(){

				

				// cuentapagar_tabla_prov_fac('<?php echo $_POST['pro_id']; ?>','<?php echo $_POST['emp_id']; ?>','','<?php echo $_POST['mon_id']; ?>',doctod,letr,fac,nd,nc,esttod,pen,canj,pag); 

	  		}

	  	});



	  });



	    $("#txt_let_lug").change(function(e){

	  	

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

	  	});





	  $("#txt_let_lug").keydown(function(e){

	  	if (e.which == 13){$("#txt_let_numdoc").focus();return false; } });



	  $("#txt_let_numdoc").keydown(function(e){

	  	if (e.which == 13){$("#cmb_let_ban").focus();return false;  } }); 



	  $("#cmb_let_ban").keydown(function(e){

	  	if (e.which == 13){$("#cmb_let_con").focus();return false;  } });



	  $("#cmb_let_con").keydown(function(e){

	  	if (e.which == 13){$("#txt_let_numuni").focus();return false; } });



		

	  $("#txt_let_numuni").keydown(function(e){

	  	if (e.which == 13){$("#btn_let_guardar").focus();return false; } });







	  $("#cmb_let_con").change(function(){



	  	validar($(this).val());

	  	

	  });



	});





function validar(con){

	

	if(con == 3){

	  		$("#div_ban").hide(100);

	  		$("#div_numuni").hide(100);

	  	}else if(con == 2 || con == 1){

	  		$("#div_ban").show(100);

	  		$("#div_numuni").show(100);

	  		

	  	}else{

	  		$("#div_ban").hide(100);

	  		$("#div_numuni").hide(100);

	  	}

}





</script>



<!-- Form content -->

<div class="modal-header">

	

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

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

	

</div>



<div class="modal-body">



<form id="for_let">



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

	<input type="hidden" name="hdd_compag_id" id="hdd_compag_id" value="<?php echo $_POST['compag_id']; ?>">



	<div class="row">



		<div class="col-lg-7 col-sm-6 col-xs-8">

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

			<input type="text" id="txt_pro_nom" name="txt_pro_nom"  class="form-control"  value="<?php echo $pro_nom;?>" />

			<input type="hidden" id="hdd_pro_id" name="hdd_pro_id" value="<?php echo $pro_id?>" />

		</div>



		<div class="col-lg-2 col-sm-4 col-xs-4">

			<label for="txt_egr_imp">Importe: </label><?php echo ' '.$lbl_mone; ?>

			<input type="text" name="txt_egr_imp" id="txt_egr_imp" class="moneda2 form-control" style="text-align:right"   value="<?php echo formato_money($mon)?>" >

			<input type="hidden" name="hdd_egr_imp" id="hdd_egr_imp" value="<?php echo $imp ?>" >

		</div> 





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

		<label for="txt_let_ref">Referencia: </label>

	<input type="text" name="txt_let_ref" id="txt_let_ref" class="moneda2 form-control" style="text-align:right" readonly="" value="<?php echo $ref?>" >

		</div> 



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

		<label for="txt_let_aval">Aval: </label>

		<input type="text" name="txt_let_aval" id="txt_let_aval" class="moneda2 form-control" style="text-align:right" readonly  value="<?php echo $aval?>" >

		</div> 



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

			<label for="txt_let_fecven">Fecha Venc.:</label>

			<input name="txt_let_fecven" type="text"  id="txt_let_fecven" readonly value="<?php echo mostrarfecha($fecven) ?>" class="form-control" > 

		</div>



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

		<label for="txt_let_lug">Lugar: </label>

		<input type="text" name="txt_let_lug" id="txt_let_lug" class="moneda2 form-control" style="text-align:right"    value="<?php echo $lug ?>" >

		</div> 



	



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

		<label for="txt_let_numdoc">Numero Letra: </label>

	<input type="text" name="txt_let_numdoc" id="txt_let_numdoc" class="moneda2 form-control"  style="text-align:right"   value="<?php echo $doc_nom?>" >

		</div> 



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

			<label for="cmb_let_con">Condicion:</label>

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

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

			<option value="1" <?php if($conid==1) echo 'selected';?>  >COBRANZAS</option>

			<option value="2" <?php if($conid==2) echo 'selected';?>  >DESCUENTOS</option>

			<option value="3" <?php if($conid==3) echo 'selected';?>  >CARTERA</option>

			

			</select>

		</div>



		<div class="col-lg-3 col-sm-4 col-xs-6"  id="div_ban" style="display: none">

			<label for="cmb_let_ban">Banco:</label>

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

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

			<option value="1" <?php if($banid==1) echo 'selected';?> >BCP</option>

			<option value="2" <?php if($banid==2) echo 'selected';?>  >BBVA</option>

			<option value="3" <?php if($banid==3) echo 'selected';?>  >SCT</option>

			

			</select>

		</div>



		<div class="col-lg-2 col-sm-4 col-xs-6"  id="div_numuni" style="display: none">

		<label for="txt_let_numuni">Numero Unico: </label>

		<input type="text" name="txt_let_numuni" id="txt_let_numuni" class="moneda2 form-control" style="text-align:right"   value="<?php echo $numuni ; ?>" >

		</div> 



		

	</div> 







</form>

   

<div class="modal-footer pull-right">	 

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

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

</div>



</div>



