<?php
require_once ("../../config/Cado.php");
require_once ("../igv/cIgv.php");
$oIgv = new cIgv();
if($_POST['action']=="insertar")
{

	$m = date('m');
	$y_1 = date('Y')+1;
	$y = date('Y');
	
}
if($_POST['action']=="editar"){
	$y_1 = date('Y')+1;
	$dts=$oIgv->mostrarUno($_POST['igv_id']);
	$dt = mysqli_fetch_array($dts);
	$m=$dt['tb_igv_mes'];
	$y=$dt['tb_igv_anio'];
	$dat=$dt['tb_igv_dat'];
	mysqli_free_result($dts);
}
?>
				<form role="form" id="for_igv" method="POST">
						<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
						<input name="hdd_igv_id" id="hdd_igv_id" type="hidden" value="<?php echo $_POST['igv_id']?>">
						
					<div class="box-header">
						<h3 class="box-title">Información de Igv</h3>
					</div>

					<?php if($_POST['vista']=="base"){
					?>
					<div class="box-header">
						<strong class="" style="color:blue;font-size: 1rem;" >IGV NO REGISTRADO, INGRESE EL IGV CORRESPONDIENTE. <BR/>
						Casi siempre el campo <strong style="color:red;font-size: 2rem;">DATO </strong> es 18, luego click en GUARDAR</strong>
					</div>

					<?php
					}?>



					<div class="box-body">
					<div class="form-group">							
							<div class="row">
								
								
								
								<div class="col-lg-4 col-sm-4 col-xs-6">
								<label for="cmb_igv_mes">Mes:</label>												
									<select name="cmb_igv_mes" id="cmb_igv_mes" style="cursor:pointer" class="form-control">
											<option value="">----</option>												
											<option <?php if($m==1) echo 'selected'; ?> value="1" >Enero</option>
											<option <?php if($m==2) echo 'selected'; ?> value="2" >Febrero</option>
											<option <?php if($m==3) echo 'selected'; ?> value="3" >Marzo</option>
											<option <?php if($m==4) echo 'selected'; ?> value="4" >Abril</option>
											<option <?php if($m==5) echo 'selected'; ?> value="5" >Mayo</option>
											<option <?php if($m==6) echo 'selected'; ?> value="6" >Junio</option>
											<option <?php if($m==7) echo 'selected'; ?> value="7" >Julio</option>
											<option <?php if($m==8) echo 'selected'; ?> value="8" >Agosto</option>
											<option <?php if($m==9) echo 'selected'; ?> value="9" >Septiembre</option>
											<option <?php if($m==10) echo 'selected'; ?> value="10" >Octubre</option>
											<option <?php if($m==11) echo 'selected'; ?> value="11" >Noviembre</option>
											<option <?php if($m==12) echo 'selected'; ?> value="12" >Diciembre</option>
									</select>																									
								</div>
				
				
				
				
							<div class="col-lg-4 col-sm-4 col-xs-6">
									<label for="cmb_igv_anio">Año:</label>
															
									<select style="cursor:pointer" name="cmb_igv_anio" id="cmb_igv_anio" class="form-control">
									<option value="">----</option>
									<?php  
									for($i=2020;$i<= $y_1 ;$i++){	
									?>
									<option value="<?php echo $i;?>"  <?php if($i==$y) echo 'selected'; ?> ><?php echo $i;?></option>
									<?php
									}
									?>
									</select>
															
							</div>	

								<div class="col-lg-4 col-sm-4 col-xs-12">
									<label for="txt_igv_dat">Dato:</label>
									<input name="txt_igv_dat" id="txt_igv_dat" type="text" value="<?php echo $dat ?>" autocomplete="off" class="form-control">
								</div>
								
							</div>
						</div>
					</div>
				</form>
			<div class="box-footer float-right">
				<?php if($_POST['vista']!="base"){
					?>
				<button type="button" data-dismiss="modal" class="btn btn-default cancel">Cancelar</button>
				<?php }?>
				<button class="btn btn-primary" id="save_formigv">Guardar</button>
			</div>
		
<script type="text/javascript">
	
	$("#save_formigv").click(function() {
		$("#for_igv").submit();
	});

		$('#for_igv').bootstrapValidator({
	      //live: 'disabled',
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {	      	
	      	txt_igv_dat: {
	      		group: '.col-xs-6',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) {
	  
	  	
	  	$.ajax({
	  		type: "POST",
	  		url: "../igv/igv_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_igv").serialize(),
	  		beforeSend: function() {
	  			
	  		},
	  		success: function(data){			
	  			
	  			$('.modal').modal('hide');
				$('.in').removeClass('modal-backdrop');			
				toastr["success"](data.msj);			
				
	  		},
	  		complete: function(){
	  			<?php if($_POST['vista']!="base"){
					?>
					igv_tabla();
				<?php }else{
					?>
					 location.reload();
					<?php 
				}
					?>
				
				
				}
			});
	  });


	
	$("#txt_igv_dat").keypress(function(e){
		if(e.which==13){return false;}
	});
	
	
</script>