v0.14.15 - Removed the first foreach in location show, and made an inner join instead, so it comes in correct order (by time), instead of by time and by machine id.

Added: The Reservations now gets deleted when time is past their washing time, as soon as you go onto your own reservations, the admin page for reservations or when the location show page reloads (every 1 minut)
This commit is contained in:
Anders 2020-08-25 12:26:48 +02:00
parent 0c8791683f
commit bc847b38b0
2 changed files with 23 additions and 17 deletions

View File

@ -15,6 +15,8 @@ use App\WashingReservation;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\View\View; use Illuminate\View\View;
date_default_timezone_set('Europe/Copenhagen');
class WashingReservationController extends Controller class WashingReservationController extends Controller
{ {
public function __construct() public function __construct()
@ -37,6 +39,8 @@ class WashingReservationController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
WashingReservation::query()->where('time', '<', date('Y-m-d H:i:s', strtotime('-1 hour')))->delete();
$reservations = WashingReservation::query()->orderBY('time' , 'asc')->paginate($request->query("limit", 20)); $reservations = WashingReservation::query()->orderBY('time' , 'asc')->paginate($request->query("limit", 20));
return Response::detect("washing-reservations.index", [ "reservations" => $reservations]); return Response::detect("washing-reservations.index", [ "reservations" => $reservations]);
@ -260,6 +264,8 @@ class WashingReservationController extends Controller
public function appindex(Request $request) public function appindex(Request $request)
{ {
WashingReservation::query()->where('time', '<', date('Y-m-d H:i:s', strtotime('-1 hour')))->delete();
$reservations = WashingReservation::query()->where("user_id", "=", auth()->user()->id)->orderBY('time' , 'asc')->paginate($request->query("limit", 20)); $reservations = WashingReservation::query()->where("user_id", "=", auth()->user()->id)->orderBY('time' , 'asc')->paginate($request->query("limit", 20));
return Response::detect("washing-reservations.index", [ "reservations" => $reservations]); return Response::detect("washing-reservations.index", [ "reservations" => $reservations]);

View File

@ -18,23 +18,23 @@
$i = 1; $i = 1;
?> ?>
<div class="row"> <div class="row">
@foreach(\App\WashingMachine::query()->where("location_id", "=", $location->id)->get() as $machine) @foreach(\App\WashingReservation::query()->join('washing_machines', 'washing_machines.id', '=', 'washing_reservations.machine_id')->where("location_id", "=", $location->id)->where("time", "LIKE", date("Y-m-d"). "%")->orderBy("time", "asc")->get() as $reservation)
@foreach(\App\WashingReservation::query()->where("machine_id", "=", $machine->id)->where("time", "LIKE", date("Y-m-d"). "%")->orderBy("time", "asc")->get() as $reservation) @if (date('Y-m-d H:i:s', strtotime('-1 hour')) < $reservation->time)
@if (date('Y-m-d H:i:s', strtotime('-1 hour')) < $reservation->time) @if($i % 3 == 1)
@if($i % 3 == 1)
</div>
<div class="row w-100">
@endif
<div class="reservation col align-items-center" style="margin: 0 32px 1.75rem 32px; width: calc(33% - 64px);">
<h2 style="font-size: 2vw">{{ \App\WashingMachine::query()->find($reservation->machine_id)->name }}</h2>
<div class="col align-items-center">
<span style="font-size: 1vw"><b>Dato:</b> {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('d/m/Y') }}</span>
<span style="font-size: 2vw"><b>Tid:</b> {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('\k\l\. H:i') }} - {{ \App\User::query()->where("id", "=", $reservation->user_id)->first()->name_first }} {{ \App\User::query()->where("id", "=", $reservation->user_id)->first()->name_last }}</span>
</div>
</div> </div>
<?php $i++; ?> <div class="row w-100">
@endif @endif
@endforeach <div class="reservation col align-items-center" style="margin: 0 32px 1.75rem 32px; width: calc(33% - 64px);">
<h2 style="font-size: 2vw">{{ \App\WashingMachine::query()->find($reservation->machine_id)->name }}</h2>
<div class="col align-items-center">
<span style="font-size: 1vw"><b>Dato:</b> {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('d/m/Y') }}</span>
<span style="font-size: 2vw"><b>Tid:</b> {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('\k\l\. H:i') }} - {{ \App\User::query()->where("id", "=", $reservation->user_id)->first()->name_first }} {{ \App\User::query()->where("id", "=", $reservation->user_id)->first()->name_last }}</span>
</div>
</div>
<?php $i++; ?>
@else
{{ \App\WashingReservation::query()->join('washing_machines', 'washing_machines.id', '=', 'washing_reservations.machine_id')->where("location_id", "=", $location->id)->where('time', '<', date('Y-m-d H:i:s'). '%')->delete() }}
@endif
@endforeach @endforeach
@if($i == 1) @if($i == 1)
<b class="w-100 text-center" style="font-size: 2vw; padding-top: 16px;">Der er ingen vaskemaskine reservationer for i dag.</b> <b class="w-100 text-center" style="font-size: 2vw; padding-top: 16px;">Der er ingen vaskemaskine reservationer for i dag.</b>
@ -46,8 +46,8 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
setInterval(function(){ // There has to be a space between " and # or it will not load correctly setInterval(function(){ // There has to be a space between " and # or it will not load correctly
$('#mainDiv').load(" #mainDiv").fadeIn(); $('#mainDiv').load(" #mainDiv");
}, (60000*5)); }, (60000*1));
}); });
</script> </script>
@yield("scripts") @yield("scripts")