<?php
   class clsHs extends BDConexion
   {
     function clsHs()
     {
       $this->conectar();
     } 
	 
	 function ListPersonal($varPersonal,$val_per,$disabled=0){
		 $sql="Select * from personal  order by appat_per  asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varPersonal\" size=\"1\" $disabled onchange='EnviarcodPer();'>";
	     $i=0;
		 echo "<option $selected value='0'>-----------Personal----------- </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila['dociden_per'] == $val_per) 
					 $selected = "selected";
					echo "<option $selected value=".$fila['dociden_per'].">".$fila['appat_per']." ".$fila['apmat_per'].",".$fila['nom_per']."</option>";
			   }
			   echo "</select>";
		}  

	 	 
	 function ListCasa($varCasa,$val_casa,$disabled=0){
		 $sql="Select * from casa_staff order by nombre_casa  asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varCasa\" size=\"1\" $disabled onchange='EnviarcodCasa();'>";
	     $i=0;
		 echo "<option $selected value='0'>-----------Casa Staff----------- </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila['id_casastaff'] == $val_casa) 
					 $selected = "selected";
					echo "<option $selected value=".$fila['id_casastaff'].">".$fila['nombre_casa']."</option>";
			   }
			   echo "</select>";
		}  
	 	 
	 function ListHabitaDisp($varhabDispo,$val_habita,$idcasa,$disabled=0){
		 $sql="Select * from habitacion_staff Where id_casastaff=$idcasa And estado='l' order by n_habitacion  asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varhabDispo\" size=\"1\" $disabled >";
	     $i=0;
		  while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila['id_habitacion'] == $val_habita) 
					 $selected = "selected";
					echo "<option $selected value=".$fila['id_habitacion'].">".$fila['n_habitacion']."</option>";
			   }
			   echo "</select>";
		} 
	function VerificarSiFueHabitado($idhabita,$fecha){
	    $sql = "Select h.*, concat(p.appat_per,' ',p.apmat_per,' ',p.nom_per) as nombre, p.cargo_per  from hospedaje_staff as h, personal as p Where h.id_persona = p.dociden_per AND '$fecha' >=  h.fecha_ingreso  AND '$fecha' < h.fecha_salida  AND h.id_habitacion =$idhabita AND h.estado = 0"; 
	    return $this->BDConsulta($sql);
	        } 
			
	function DevolverHs($codhs){
	         $sql = 'select * from casa_staff where id_casastaff='.$codhs;
			 return $this->BDConsulta($sql);
	           }
	function DevolverHabitaLibrexCodcasa($codcasa){
	    	$sql = 'select * from habitacion_staff where id_casastaff='.$codcasa.' ORDER BY n_habitacion asc';
			 return $this->BDConsulta($sql);
	
	               }
	 function DevolverHospedajeStaffOcupado($codHabita){
	         $sql = "Select h.*, concat(p.appat_per,' ',p.apmat_per,' ',p.nom_per) as nombre, p.cargo_per  from hospedaje_staff as h, personal as p Where h.id_persona = p.dociden_per  and id_habitacion = $codHabita AND estado=1 ";
	         return $this->BDConsulta($sql);
	               } 
    function GrabarHospedajeStaff($idhabita, $idper, $fechaIng){
	             $sql="Insert Into hospedaje_staff(id_habitacion,id_persona,fecha_ingreso,estado) values($idhabita,'$idper','$fechaIng',1)";
				 $sql2="Update habitacion_staff set estado='o' where id_habitacion=$idhabita";
	             $this->BDConsulta($sql);
				 $this->BDConsulta($sql2);
	              }
	function DevolverNLibres($codcasa){
	              $sql="Select count(*) from habitacion_staff where id_casastaff=$codcasa AND estado='l'";
				  return $this->BDConsulta($sql);
					} 
     function PesonaOcupandoHabitacion($codper){
	              $sql="Select * From hospedaje_staff where id_persona='$codper' And estado=1";
				  $rs = $this->BDConsulta($sql);
				  if($f=$this->NextRow($rs)){
				     $existe = 1;
				  }else{ $existe = 0;}
				  $this->Liberar($rs);
				  return $existe;
				}
				
  function GrabarCasaStaff($nombre_casa, $ciudad, $pais, $direccion, $n_habitaciones,$descripcion){
           $sql="Insert Into casa_staff (nombre_casa,ciudad,pais,direccion,n_habitaciones,descripcion) VALUES ('$nombre_casa','$ciudad', '$pais', '$direccion', $n_habitaciones,'$descripcion')";
           $this->BDConsulta($sql);
    			   }
  
  function  GrabarHabitaciones($idcasa, $nh){
               for ($i=1; $i<=$nh; $i++){
			     $sql = "Insert Into habitacion_staff(id_casastaff, n_habitacion, estado) values($idcasa,$i,'l')";
			     $this->BDConsulta($sql);	
			                          }
			  }
  function UpdatefechaSalida($idhospeda, $fechasalida){
            $sql ="UPDATE hospedaje_staff set fecha_salida = '$fechasalida' WHERE id_hospedaje = $idhospeda ";
			$this->BDConsulta($sql);	
                        } 
  function UpdateHabitacioLibre($idhospeda,$nuha){
            $sql ="UPDATE hospedaje_staff set dias_hospedado = $nuha, estado = 0 WHERE id_hospedaje = $idhospeda ";
			$this->BDConsulta($sql);	
		   }
  function UpdateHabitacion($idhabita){
            $sql ="UPDATE habitacion_staff set estado = 'l' WHERE id_habitacion = $idhabita ";
			$this->BDConsulta($sql);			
			}
 function DevolverConsultadeHabitacionesStaff($idcasa,$fechaI,$fechaF){
          $sql ="select hos.*, concat(p.appat_per,' ',p.apmat_per,' ',p.nom_per) as nombre, has.n_habitacion from hospedaje_staff as hos, habitacion_staff as has, personal as p where (hos.id_persona = p.dociden_per AND hos.id_habitacion = has.id_habitacion AND has.id_casastaff = $idcasa AND NOT (hos.fecha_ingreso >'$fechaF') AND NOT (hos.fecha_salida < '$fechaI'))OR (hos.id_persona = p.dociden_per AND hos.id_habitacion = has.id_habitacion AND has.id_casastaff = $idcasa AND hos.fecha_salida IS NULL AND hos.fecha_ingreso <= '$fechaI') OR (hos.id_persona = p.dociden_per AND hos.id_habitacion = has.id_habitacion AND has.id_casastaff = $idcasa AND hos.fecha_salida IS NULL AND hos.fecha_ingreso <= '$fechaF') ORDER BY has.n_habitacion ASC"; 
          return $this->BDConsulta($sql); 
		   }
	 }
	?>