Added reservation button
This commit is contained in:
parent
570786c7be
commit
6986b51cfd
4 changed files with 106 additions and 12 deletions
|
@ -1,8 +1,68 @@
|
|||
<?php
|
||||
if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Staff') {
|
||||
|
||||
if(isset($path[1])){
|
||||
switch ($path[1]){
|
||||
case 'hotel':
|
||||
if(isset($path[2],$path[3],$path[4],$path[5])){
|
||||
// 2 = people
|
||||
// 3 = room
|
||||
// 4 = start
|
||||
// 5 = end
|
||||
// Simple checks
|
||||
$start = strtotime($path[4]);
|
||||
$end = strtotime($path[5]);
|
||||
|
||||
$goodAccomodation = [];
|
||||
if($end >= $start) {
|
||||
$dates_check = [];
|
||||
// Good
|
||||
$start = date_create($path[4]);
|
||||
$end = date_create($path[5]);
|
||||
$end->add(new DateInterval('P1D'));
|
||||
$period = new DatePeriod(
|
||||
$start,
|
||||
new DateInterval('P1D'),
|
||||
$end
|
||||
);
|
||||
foreach ($period as $key => $value) {
|
||||
$dates_check[] = $value->format('Y-m-d');
|
||||
}
|
||||
|
||||
$accomodations = Accomodation::fetch();
|
||||
|
||||
forEach($accomodations as $accomodation){
|
||||
$disponibility = AccomodationLoad::getByAccomodationId($accomodation->getId());
|
||||
/*
|
||||
* Calcul minimum / occupants
|
||||
*/
|
||||
$minimum = AccomodationLoad::getRange();
|
||||
$reservations = AccomodationReservation::fetchByAccomodationId($accomodation->getId());
|
||||
forEach($reservations as $reservation){
|
||||
foreach ($period as $key => $value) {
|
||||
if(in_array($value->format('Y-m-d'), array_keys($minimum))){
|
||||
$minimum[$value->format('Y-m-d')]['rooms'] += $reservation->getRoomCount();
|
||||
$minimum[$value->format('Y-m-d')]['beds'] += $reservation->getPeopleCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
forEach($disponibility as $date=>$dispo){
|
||||
if(in_array($date, $dates_check)){
|
||||
if(((int)$path[2] + (int)$minimum[$date]['beds'] > (int)$dispo['beds']) || ((int)$path[3] + (int)$minimum[$date]['rooms'] > (int)$dispo['rooms'])){
|
||||
break;
|
||||
}else{
|
||||
if($dates_check[count($dates_check) - 1] == $date){
|
||||
$goodAccomodation[] = $accomodation->getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo json_encode($goodAccomodation);
|
||||
}
|
||||
}
|
||||
die();
|
||||
case 'date':
|
||||
if(isset($path[2])){
|
||||
$dates = [];
|
||||
|
@ -34,6 +94,14 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Staff')
|
|||
$bornes_date = array_keys(AccomodationLoad::getRange());
|
||||
$bornes_date = [$bornes_date[0], $bornes_date[count($bornes_date) - 1]];
|
||||
$vips = User::fetch(array(['UserTypeName', '=', 'VIP']));
|
||||
|
||||
if(getPost('vip',false) && getPost('people',false) && getPost('rooms',false) && getPost('dateStart',false) && getPost('dateEnd',false) && getPost('location',false)){
|
||||
$accomodationID = Accomodation::fetchByName(getPost('location',false))->getId();
|
||||
AccomodationReservation::create(getPost('vip',false), getPost('people',false), getPost('rooms',false), getPost('dateStart',false), getPost('dateEnd',false), $accomodationID);
|
||||
$alert = alert('success','Reservation ajouté');
|
||||
}
|
||||
|
||||
|
||||
require_once(VIEW_PATH . $path[0] . '.php');
|
||||
} else {
|
||||
redirect('login');
|
||||
|
|
|
@ -87,6 +87,14 @@ class Accomodation extends Model
|
|||
}
|
||||
return false;
|
||||
}
|
||||
public static function fetchByName(string $name)
|
||||
{
|
||||
$data = Accomodation::fetch(array(['name','=', $name]));
|
||||
if(count($data) === 1){
|
||||
return $data[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function setServices(array $names)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -70,6 +70,16 @@ class AccomodationReservation extends Model
|
|||
return $data;
|
||||
}
|
||||
|
||||
public static function create($email, $people, $room, $start, $end, $accomodationId){
|
||||
return AccomodationReservation::insert(array(
|
||||
'UserEmail'=> $email,
|
||||
'AccomodationId'=> $accomodationId,
|
||||
'startDate'=> $start,
|
||||
'endDate'=> $end,
|
||||
'peopleCount'=> $people,
|
||||
'roomCount'=> $room,
|
||||
));
|
||||
}
|
||||
public static function remove($AccomodationId, $email, $startDate){
|
||||
return AccomodationReservation::delete(array(['AccomodationId','=',$AccomodationId],['UserEmail','=',$email],['startDate','=',$startDate]));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ require_once('template/head.php');
|
|||
<h2>Ajout d'une reservation</h2>
|
||||
</div>
|
||||
<div class="container-fluid section">
|
||||
<?=$alert?>
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<form id="msform" method="POST" action="">
|
||||
|
@ -43,17 +44,8 @@ require_once('template/head.php');
|
|||
<fieldset>
|
||||
<h2 class="fs-title">Logement</h2>
|
||||
<h3 class="fs-subtitle">Choix du logement</h3>
|
||||
<input type="search" id="location-filter" placeholder="Rechercher..." name="location" data-list="location-list" autocomplete="off" required />
|
||||
<input type="search" id="location-filter" placeholder="Rechercher..." name="location" autocomplete="off" required />
|
||||
<label for="location-filter" data-icon="🔍"></label>
|
||||
<datalist id="location-list">
|
||||
<select>
|
||||
<?php
|
||||
forEach($vips as $vip){
|
||||
echo '<option value="' .$vip->getEmail(). '" />';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</datalist>
|
||||
<input type="button" name="previous" class="previous action-button-previous" value="Retour"/>
|
||||
<button type="submit" class="submit action-button">Ajouter</button>
|
||||
</fieldset>
|
||||
|
@ -80,7 +72,23 @@ require_once('template/head.php');
|
|||
});
|
||||
$("#dateEnd").change(function (e){
|
||||
$.get( '<?=genURL('reservation/hotel/')?>' + $("#people").val() + '/' + $("#rooms").val() + '/' + $("#dateStart").val() + '/' + $("#dateEnd").val() , function( data ) {
|
||||
console.log("a");
|
||||
locations = [];
|
||||
locations = locations.concat(JSON.parse(data));
|
||||
$( "#location-filter" ).autocomplete({
|
||||
source: locations,
|
||||
messages: {
|
||||
noResults: 'no results',
|
||||
results: function (obj) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
}).on('focus', function () {
|
||||
$( "#location-filter" ).autocomplete('search', ' ');
|
||||
}).on('search', function () {
|
||||
if ($( "#location-filter" ).val() === '') {
|
||||
$( "#location-filter" ).autocomplete('search', ' ');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue