<?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 ("../cancha/cCancha.php");
$oCancha = new cCancha();

$datos=$oCancha->mostrarUno($_POST['cancha_id']);
$num_rows= mysqli_num_rows($datos);
$dt1 = mysqli_fetch_array($datos);
$can_nom = $dt1['tb_cancha_nom'];


$fec = date('d-m-Y');

/* $fec1 = date('d-m-Y 09:30:00');
$fec2 = date('d-m-Y 10:30:00');

echo strtotime($fec1).'---';
echo strtotime($fec2); */


?>




 <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_cansep">
<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
<input name="hdd_can_id" id="hdd_can_id" type="hidden" value="<?php echo $_POST['cancha_id']?>">
	<div class="box-header">
            <h3 class="box-title">Reservar campo <span style="color:#8E24AA;" ><?php echo $can_nom; ?></span></h3>
     </div>
          <div class="box-body">
    <div class="form-group">
      <div class="row">
        
		<input type="hidden" id="hdd_sep_cli_id" name="hdd_sep_cli_id" value="<?php echo '' ?>" />
		
        <div class="col-lg-4 col-sm-4 col-12 errorprov ">
			<label for="txt_sep_cli_doc">RUC/DNI:</label>
					<div class="input-group">
							<span id="" style=""  class="input-group-btn">
									<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" class="form-control form-control-sm " autocomplete="off" 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-12">
 				<label for="txt_sep_cli_nom">Cliente/Raz. Social:</label>
 				<input type="text" id="txt_sep_cli_nom" name="txt_sep_cli_nom" autocomplete="off"  value="<?php echo $cli_nom?>" class="form-control form-control-sm" />
		</div> 
		
		<div class="col-lg-4 col-sm-8 col-12">
 				<label for="txt_sep_cli_tel">Telefono:</label>
 				<input type="number" id="txt_sep_cli_tel" name="txt_sep_cli_tel" autocomplete="off"  value="<?php echo $cli_nom?>" class="form-control form-control-sm" />
		</div> 
												
		<div class="col-lg-12 col-sm-12 col-12">
          <label for="txt_sep_det">Detalle:</label>      
		   <input name="txt_sep_det" autocomplete="off" id="txt_sep_det" type="text" value="<?php echo $dir?>" 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" type="text" autocomplete="off" class="form-control form-control-sm" id="txt_sep_fecini" value="<?php echo $fec?>" >															
						<select name="txt_sep_horini" id="txt_sep_horini" style="cursor:pointer;" class="form-control form-control-sm"></select>
					</div>
									 
				</div>
				
				<div class="col-lg-4 col-sm-4 col-6" >
					<label for="txt_sep_min">Tiempo:</label>
		
					<select name="txt_sep_min" id="txt_sep_min" style="cursor:pointer;" class="form-control form-control-sm">
						<option value="">--- Seleccionar tiempo ---</option>
							<option value="60" selected>1 H</option>
							<option value="90">1 H 30 min</option>
							<option value="120">2 H</option>
							<option value="150">2 H 30 min</option>
							<option value="180">3 H</option>
							<option value="210">3 H 30 min</option>
							<option value="240">4 H</option>
							<option value="270">4 H 30 min</option>
							<option value="300">5 H</option>
							<option value="330">5 H 30 min</option>
							<option value="360">6 H</option>
							<option value="390">6 H 30 min.</option>
							<option value="420">7 H</option>
							<option value="450">7 H 30 min</option>
							<option value="480">8 H</option>
							<option value="510">8 H 30 min</option>
							<option value="540">9 H</option>
							<option value="570">9 H 30 min</option>
							<option value="600">10 H</option>
							<option value="630">10 H 30 min</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" value="<?php echo $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>
            <button class="btn btn-primary" id="btn_save">Guardar</button>
		  </div>
		  
 </div>
      
<script type="text/javascript">
	
	function cmb_hor_ini()
	{	
		$.ajax({
			type: "POST",
			url: "../hora/cmb_hor_id.php",
			async:true,
			dataType: "html",                      
			data: ({
			//cat_id: "<?php //echo $cat_id?>"
		}),
			beforeSend: function() {
				$('#txt_sep_horini').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#txt_sep_horini').html(html);
			}
		});
	}
	
	
	
	
function cliente_form(act,idf){
	$('#div_cliente_form_dialog').modal();
	$.ajax({
		type: "POST",
		url: "../cliente/cliente_form.php",
		async:true,
		dataType: "html",                      
		data: ({
			action: act,
			cli_id:	idf,
			vista:	'venta'
		}),
		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_cliente_form').html(div); 
		},
		success: function(html){ 	
			$('.div_cliente_form').html(html); 				
		},
		complete: function(){
				
				
		}
	});
}

function cliente_cargar_datos(idf){	
	$.ajax({
		type: "POST",
		url: "../cliente/cliente_reg.php",
		async:true,
		dataType: "json",                      
		data: ({
			action: "obtener_datos",
			cli_id:	idf
		}),
		beforeSend: function() {
		
		},
		success: function(data){
			
			$('#hdd_sep_cli_id').val(idf);	
			$('#txt_sep_cli_nom').val(data.nombre);	
			$('#txt_sep_cli_doc').val(data.documento);						
			$("#txt_sep_cli_tel").val(data.telefono);
			
			
		}
	});		
}

	
	
	$(document).ready(function() {
	
		cmb_hor_ini();
		
		$('#txt_sep_fecini').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			
		}); 
		
		$( "#txt_sep_cli_nom" ).autocomplete({
			minLength: 1,
			source: "../cliente/cliente_complete_nom.php",
			select: function(event, ui){			
				$("#hdd_sep_cli_id").val(ui.item.id);							
				$("#txt_sep_cli_doc").val(ui.item.documento);	
				$("#txt_sep_cli_tel").val(ui.item.telefono);
				cliente_cargar_datos(ui.item.id);
			}
		});
		
		$( "#txt_sep_cli_doc" ).autocomplete({
			minLength: 1,
			source: "../cliente/cliente_complete_doc.php",
			select: function(event, ui){			
				$("#hdd_sep_cli_id").val(ui.item.id);							
				$("#txt_sep_cli_nom").val(ui.item.nombre);
				$("#txt_sep_cli_tel").val(ui.item.telefono);	
			}
		});	
		
		
		
	$('#txt_sep_det, #txt_sep_cli_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
	

  	
	
	$("#btn_save").click(function() {
		if($("#txt_sep_cli_nom").val()==""){
			toastr["error"]('Debe ingresar el nombre de un cliente.');	
		}else if($("#txt_sep_cli_tel").val()==""){
			toastr["error"]('Debe ingresar el telefono de un cliente.');	
		}else{
		
	    $("#for_cansep").submit();
		}
	});

    $('#for_cansep').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_cansep").serialize(),
				beforeSend: function(){
					
				},
				success: function(data){
				
				if(data.sep_est == 0){
					toastr["warning"](data.sep_msj);	
				}else{
					$('#div_canchapos_form').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_det').focus(); return false;}
	});
	$('#txt_sep_det').keydown(function(ev) {
		if(ev.keyCode==13){$('#btn_save').focus(); return false;}
	});
    $('#txt_sep_mon').keydown(function(ev) {
		if(ev.keyCode==13){$('#btn_save').focus(); return false;}
	});


	
</script>