1
0
Fork 0

Added limitation on editing Rooms & Beds informations

This commit is contained in:
p1907961 2021-01-16 23:17:02 +01:00
parent 81ecec446e
commit ef13a69083
2 changed files with 32 additions and 3 deletions

View file

@ -8,7 +8,7 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Accomoda
if (isset($path[1])) { if (isset($path[1])) {
switch ($path[1]) { switch ($path[1]) {
case 'add': case 'add':
if (!$_SESSION['USER']->getAccomodationId() && $_SESSION['USER']->getType() == 'AccomodationOwner') { if (!$_SESSION['USER']->getAccomodationId()) {
/* /*
* Creating Accomodation * Creating Accomodation
*/ */
@ -87,10 +87,33 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Accomoda
case 'date': case 'date':
if ($_SESSION['USER']->getAccomodationId()) { if ($_SESSION['USER']->getAccomodationId()) {
$allRange = AccomodationLoad::getByAccomodationId($_SESSION['USER']->getAccomodationId()); $allRange = AccomodationLoad::getByAccomodationId($_SESSION['USER']->getAccomodationId());
/*
* Calcul des minimum / disponibilités
*/
$minimum = AccomodationLoad::getRange();
$reservations = AccomodationReservation::fetchByAccomodationId($_SESSION['USER']->getAccomodationId());
forEach($reservations as $reservation){
$start = date_create($reservation->getStartDate());
$end = date_create($reservation->getEndDate());
$end->add(new DateInterval('P1D'));
$period = new DatePeriod(
$start,
new DateInterval('P1D'),
$end
);
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();
}
}
}
/* /*
* Formulaire POST * Formulaire POST
*/ */
$filteredPost = []; $filteredPost = [];
$error = false;
forEach($_POST as $key=>$value){ forEach($_POST as $key=>$value){
$parts = explode('-', $key); $parts = explode('-', $key);
$last = array_pop($parts); $last = array_pop($parts);
@ -101,11 +124,16 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Accomoda
*/ */
$col = $parts[1]; $col = $parts[1];
if(in_array($col, ['beds','rooms'])){ if(in_array($col, ['beds','rooms'])){
if($minimum[$parts[0]][$col] > (int)$value){
$error = true;
$alert = alert('danger','Impossible de réduire le compte de \'' .$col. '\' pour le ' . dateToFrench($parts[0], "j F Y") . ' due a des reservations déjà enregistrées.');
}else {
$filteredPost[$parts[0]][$col] = (int)$value; $filteredPost[$parts[0]][$col] = (int)$value;
} }
} }
} }
if(count($filteredPost) > 0){ }
if(count($filteredPost) > 0 && $error == false){
AccomodationLoad::setAccomodationLoad($_SESSION['USER']->getAccomodationId(), $filteredPost); AccomodationLoad::setAccomodationLoad($_SESSION['USER']->getAccomodationId(), $filteredPost);
$allRange = AccomodationLoad::getByAccomodationId($_SESSION['USER']->getAccomodationId()); $allRange = AccomodationLoad::getByAccomodationId($_SESSION['USER']->getAccomodationId());
} }

View file

@ -8,6 +8,7 @@ require_once('template/head.php');
<h3 class="card-title">Gestion des disponibilités de "<?= $accomodation->getName() ?>"</h3> <h3 class="card-title">Gestion des disponibilités de "<?= $accomodation->getName() ?>"</h3>
<div style="margin: auto;"> <div style="margin: auto;">
<?php <?php
echo $alert;
$rowCount = 0; $rowCount = 0;
$maxPerRow = 4; $maxPerRow = 4;
$mdCalc = ceil(12 / $maxPerRow); $mdCalc = ceil(12 / $maxPerRow);