Commit c5ebb174 authored by Estéban Ristich's avatar Estéban Ristich
Browse files

Fix the overlapping of dates for the edition of a single reservation

parent 976b2c7a
......@@ -74,6 +74,7 @@ if ($param_mode == "loan-now") {
// CHECK FUTUR
$tomorrow = strtotime('+1 day', strtotime(date("Y-m-d", time())));
$emprunt = strtotime(date('Y-m-d', strtotime($date_emprunt)));
if ($emprunt >= $tomorrow) {
// CHECK DATE OVERLAP
......@@ -104,10 +105,17 @@ if ($param_mode == "loan-now") {
// CHECK FUTUR
$tomorrow = strtotime('+1 day', strtotime(date("Y-m-d", time())));
$emprunt = strtotime(date('Y-m-d', strtotime($date_emprunt)));
if (isset($loan_id))
var_dump($loan_id);
else
echo 'no variable $loan_id';
if ($emprunt >= $tomorrow) {
// CHECK DATE OVERLAP
$loan_dates = get_loans_interval_by_id($pdo, $equipment_id, $date_emprunt, $date_retour);
#$loan_dates = get_loans_interval_by_id($pdo, $equipment_id, $date_emprunt, $date_retour);
$loan_dates = get_loans_interval_by_id_except_self($pdo, $equipment_id, $date_emprunt, $date_retour, $loan_id);
if (!empty($loan_dates) || $loan_dates != false) {
$action = 'loan-edit.php?id='.$loan_id.'&mode='.$param_mode;
$title = 'Impossible d\'éditer sur la même plage qu\'une autre réservation';
......
......@@ -479,6 +479,7 @@ function get_loans_blacklist_by_equipment($pdo, $id_equipment) {
return $result_fetch;
return false;
}
// ---------------------------------------------------------------------
function get_loans_interval_by_id($pdo, $id_equipment, $from, $to) {
......@@ -493,6 +494,18 @@ function get_loans_interval_by_id($pdo, $id_equipment, $from, $to) {
// ---------------------------------------------------------------------
function get_loans_interval_by_id_except_self($pdo, $id_equipment, $from, $to, $except_id) {
$sql = 'SELECT * FROM pret WHERE (((`emprunt` <= ? AND `retour` >= ?) AND `nom` = ?) OR ((`emprunt` <= ? AND `retour` >= ?) AND `nom` = ?) OR ((`emprunt` >= ? AND `retour` <= ?) AND `nom` = ?)) AND NOT id = ?;';
$stmt = $pdo->prepare($sql);
$stmt->execute(array($from, $from, $id_equipment, $to, $to, $id_equipment, $from, $to, $id_equipment, $except_id));
$result_fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result_fetch) > 0)
return $result_fetch;
return false;
}
// ---------------------------------------------------------------------
function get_loan_status_by_id($pdo, $id_loan) {
$sql = 'SELECT status FROM pret WHERE id = ?;';
$stmt = $pdo->prepare($sql);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment