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

session_start();
require_once ("../../config/Cado.php");
require_once ("../canchapos/cCanchapos.php");
$oCanchapos = new cCanchapos();
require_once("../formatos/formato.php");
	$dts=$oCanchapos->mostrarUno($_POST['sepcan_id']);
	$dt = mysqli_fetch_array($dts);
			$fec = $dt['tb_separacioncancha_fecforini'];
			$hini = $dt['tb_separacioncancha_horforini'];
			$cli_tel = $dt['tb_cliente_tel'];
			$cli_nom = $dt['tb_cliente_nom'];
			$est = $dt['tb_separacioncancha_est'];
			$det = $dt['tb_separacioncancha_des'];
			$tiemin = $dt['tb_separacioncancha_tiemin'];
			$horainitime = $dt['tb_separacioncancha_horainitime'];
			$horafintime = $dt['tb_separacioncancha_horafintime'];
			$mon = $dt['tb_separacioncancha_ade'];
	mysqli_free_result($dts);
	
	//echo date('d-m-Y H:i:s',$horainitime).'--';
	//echo date('d-m-Y H:i:s',$horafintime);

?>




 <style type="text/css">
.ui-autocomplete
{
    z-index: 99999; 
}


</style>
 	





<div class="col-lg-12 col-sm-12 col-md-12 col-12">
<form role="form" id="for_cansepinfo">
<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
<input name="hdd_sepcan_id" id="hdd_sepcan_id" type="hidden" value="<?php echo $_POST['sepcan_id']?>">
	<div class="box-header">
            <h3 class="box-title">Modificar la reserva</h3>
     </div>
          <div class="box-body">
    <div class="form-group">
      <div class="row">
        
		<input type="hidden" id="hdd_sep_cli_id_info" name="hdd_sep_cli_id_info" value="<?php echo $cli_id ?>" />
		
        <div class="col-lg-4 col-sm-4 col-12 errorprov d-none">
			<label for="txt_sep_cli_doc">RUC/DNI:</label>
					<div class="input-group">					
							<span id="" style=""   class="input-group-btn <?php if($est==2) echo 'd-none'; ?> ">
									<span id="" style="cursor:pointer" class="btn btn-info btn-sm btn-flat" onClick="cliente_form('insertar')"><i class="fa fa-plus"></i></span> 
						</span>																
						<input type="text" <?php if($est==2) echo 'readonly'; ?> class="form-control form-control-sm " id="txt_sep_cli_doc" name="txt_sep_cli_doc" value="<?php echo $cli_doc?>" /> 
				</div>
		</div>
		
		<div class="col-lg-8 col-sm-8 col-6">
 				<label for="txt_sep_cli_nominfo">Cliente/Raz. Social:</label>
 				<input type="text" id="txt_sep_cli_nominfo" <?php if($est==2) echo 'readonly'; ?> name="txt_sep_cli_nominfo"  value="<?php echo $cli_nom; ?>" class="form-control form-control-sm" />
		</div> 

		<div class="col-lg-4 col-sm-4 col-6">
 				<label for="txt_sep_cli_telinfo">Telefono:</label>
 				<input type="text" id="txt_sep_cli_telinfo" <?php if($est==2) echo 'readonly'; ?> name="txt_sep_cli_telinfo"  value="<?php echo $cli_tel; ?>" class="form-control form-control-sm" />
		</div> 
												
		<div class="col-lg-12 col-sm-12 col-12">
          <label for="txt_sep_detin">Detalle:</label>      
		   <input name="txt_sep_detin" autocomplete="off" <?php if($est==2) echo 'readonly'; ?> id="txt_sep_detin" type="text" value="<?php echo $det?>" class="form-control form-control-sm ">
        </div>
		
		
			
				<div class="col-lg-5 col-sm-5 col-6" >
					<label for="txt_sep_fecini">Fecha - Hora Inicio:</label>
					<div class="input-group">
						<input name="txt_sep_fecini" readonly <?php if($est==2) echo 'readonly'; ?> type="text" class="form-control form-control-sm" id="txt_sep_fecini" value="<?php echo mostrarFecha($fec)?>" >															
						<select name="txt_sep_horini_info" readonly <?php if($est==2) echo 'readonly'; ?> id="txt_sep_horini_info" style="cursor:pointer;" class="form-control form-control-sm"></select>
					</div>
					<input id="hdd_sep_fecini" name="hdd_sep_fecini" type="hidden" value="<?php echo mostrarFecha($fec)?>" >
					<input id="hdd_sep_horini_info" name="hdd_sep_horini_info" type="hidden">
				</div>
				
				<div class="col-lg-4 col-sm-4 col-6" >
					<label for="txt_sep_min">Tiempo:</label>
		
					<select name="txt_sep_min" <?php if($est==2) echo 'readonly'; ?> readonly id="txt_sep_min" style="cursor:pointer;" class="form-control form-control-sm">
						<option value="">--- Seleccionar tiempo ---</option>
							<option value="60" <?php if($tiemin==60) echo 'selected'; ?>>1 H</option>
							<option value="90" <?php if($tiemin==90) echo 'selected'; ?>>1 H 30 min</option>
							<option value="120" <?php if($tiemin==120) echo 'selected'; ?> >2 H</option>
							<option value="150" <?php if($tiemin==150) echo 'selected'; ?> >2 H 30 min</option>
							<option value="180" <?php if($tiemin==180) echo 'selected'; ?>>3 H</option>
							<option value="210" <?php if($tiemin==210) echo 'selected'; ?> >3 H 30 min</option>
							<option value="240" <?php if($tiemin==240) echo 'selected'; ?> >4 H</option>
							<option value="270" <?php if($tiemin==270) echo 'selected'; ?> >4 H 30 min</option>
							<option value="300" <?php if($tiemin==300) echo 'selected'; ?> >5 H</option>
							<option value="330" <?php if($tiemin==330) echo 'selected'; ?> >5 H 30 min</option>
							<option value="360" <?php if($tiemin==360) echo 'selected'; ?> >6 H</option>
					</select>
								
				</div>
			
			 <div class="col-lg-3 col-sm-3 col-12">
          <label for="txt_sep_mon">Adelanto:</label>      
		   <input name="txt_sep_mon" autocomplete="off" id="txt_sep_mon" type="text" <?php if($est==2) echo 'readonly'; ?> value="<?php echo formato_money($mon)?>" class="form-control form-control-sm ">
        </div>
		
		
		</div>
    </div>
    </div>
</form>
		<div class="box-footer  float-right">
			<button type="button" data-dismiss="modal" class="btn btn-default cancel">Cancelar</button>
				<?php if($est==1){?>
				<button class="btn btn-primary" id="btn_save_info">Guardar</button>
				<?php }?>
		 </div>
		  
 </div>
      
<script type="text/javascript">
	
	function cmb_hor_ini_info()
	{	
		$.ajax({
			type: "POST",
			url: "../hora/cmb_hor_id.php",
			async:true,
			dataType: "html",                      
			data: ({
			hini: "<?php echo $hini?>"
		}),
			beforeSend: function() {
				$('#txt_sep_horini_info').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#txt_sep_horini_info').html(html);
				
				$('#hdd_sep_horini_info').val($('#txt_sep_horini_info').val());
				
			}
		});
	}
	
	
	
	
	
	
	$(document).ready(function() {
	
		cmb_hor_ini_info();
		$('#txt_sep_fecini').prop('disabled', true);
		$('#txt_sep_horini_info').prop('disabled', true);
		
		$( "#txt_sep_cli_nominfo" ).autocomplete({
			minLength: 1,
			source: "../cliente/cliente_complete_nom.php",
			select: function(event, ui){			
				$("#hdd_sep_cli_id_info").val(ui.item.id);							
				$("#txt_sep_cli_doc").val(ui.item.documento);	
			}
		});
		
		$( "#txt_sep_cli_doc" ).autocomplete({
			minLength: 1,
			source: "../cliente/cliente_complete_doc.php",
			select: function(event, ui){			
				$("#hdd_sep_cli_id_info").val(ui.item.id);							
				$("#txt_sep_cli_nominfo").val(ui.item.nombre);	
			}
		});	
		
		
		
	$('#txt_sep_detin').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
	

  	
	
	$("#btn_save_info").click(function() {
		if($("#txt_sep_cli_nominfo").val()==""){
			toastr["error"]('Debe ingresar el nombre de un cliente.');	
		}else if($("#txt_sep_cli_telinfo").val()==""){
			toastr["error"]('Debe ingresar el telefono de un cliente.');	
		}else{
		
	    $("#for_cansepinfo").submit();
		}
	});

    $('#for_cansepinfo').bootstrapValidator({
	      message: 'This value is not valid',
	      feedbackIcons: {
	        valid: 'glyphicon glyphicon-ok',
	        invalid: 'glyphicon glyphicon-remove',
	        validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {
	        cmb_cli_tip: {
	          group: '.col-lg-2',
	          validators: {
	            notEmpty: {
	              message: 'Este campo es requerido'
	            }
	          }
	        }
	
	      }
	    }).on('success.form.bv', function(e) {
	   
	      $.ajax({
				type: "POST",
				url: "../canchapos/canchapos_reg.php",
				async:true,
				dataType: "json",
				data: $("#for_cansepinfo").serialize(),
				beforeSend: function(){
					
				},
				success: function(data){
				
				$('#div_canchapos_info_dialog').modal('hide');	
				toastr["success"](data.sep_msj);	
				canchapos_form_calendar('<?php echo $_POST['cancha_id']?>');
				
				},
				complete: function(){
					
				}
			});	
	    });
	});
	
	
	$('#cmb_cli_tip').focus();
	
	$('#txt_cli_nom').blur(function() {
		
		cli = $(this).val();
		
	
		$(this).val(cli);
		
	});
	
	
	$('#txt_cli_nom').keydown(function(ev) {
		if(ev.keyCode==13){$('#txt_sep_detin').focus(); return false;}
	});
	$('#txt_sep_detin').keydown(function(ev) {
		if(ev.keyCode==13){$('#btn_save').focus(); return false;}
	});
	
</script>