Skip to content

Commit

Permalink
Merge pull request #71 from ranggaadithia/uas
Browse files Browse the repository at this point in the history
UAS ADDITIONAL
  • Loading branch information
ranggaadithia authored Dec 18, 2023
2 parents 7173de2 + 943abaf commit a269836
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 210 deletions.
32 changes: 1 addition & 31 deletions app/Http/Controllers/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,10 @@

namespace App\Http\Controllers;

use App\Models\LabsBooking;
use Carbon\Carbon;
use Illuminate\Http\Request;

class HistoryController extends Controller
{
public function history()
{
$now = Carbon::now();

$upcomingHistories = LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) use ($now) {
$query->where('booking_date', '>=', $now->format('Y-m-d'))
->orWhere(function ($subquery) use ($now) {
$subquery->where('booking_date', '=', $now->format('Y-m-d'))
->where('start_time', '>', $now->format('H:i:s'));
});
})
->orderBy('booking_date', 'asc')
->get();

$expiredHistories = LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) use ($now) {
$query->where('booking_date', '<', $now->format('Y-m-d'))
->orWhere(function ($subquery) use ($now) {
$subquery->whereDate('booking_date', '=', $now->format('Y-m-d'))
->whereTime('start_time', '<', $now->format('H:i:s'));
});
})
->orderBy('booking_date', 'desc')
->get();

return view('home.history', compact('upcomingHistories', 'expiredHistories'));
return view('home.history');
}
}
71 changes: 71 additions & 0 deletions app/Livewire/BookingHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Livewire;

use Carbon\Carbon;
use Livewire\Component;
use App\Models\LabsBooking;
use Livewire\Attributes\On;

class BookingHistory extends Component
{
public $now, $upcomingHistories, $expiredHistories, $totalRecords;
public $loadAmount = 5;

public function loadMore()
{
$this->loadAmount += 10;
}

public function mount()
{
$this->now = Carbon::now();

$this->upcomingHistories = LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) {
$query->where('booking_date', '>', $this->now->format('Y-m-d'))
->orWhere(function ($subquery) {
$subquery->where('booking_date', '=', $this->now->format('Y-m-d'))
->where('start_time', '>', $this->now->format('H:i:s'));
});
})
->orderBy('booking_date', 'asc')
->get();

$this->expiredHistories = LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) {
$query->where('booking_date', '<', $this->now->format('Y-m-d'))
->orWhere(function ($subquery) {
$subquery->whereDate('booking_date', '=', $this->now->format('Y-m-d'))
->whereTime('start_time', '<', $this->now->format('H:i:s'));
});
})
->orderBy('booking_date', 'desc')
->limit($this->loadAmount)
->get();

$this->totalRecords = LabsBooking::count();
}



public function render()
{
return view('livewire.booking-history', [
'expiredHistories' => LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) {
$query->where('booking_date', '<', $this->now->format('Y-m-d'))
->orWhere(function ($subquery) {
$subquery->whereDate('booking_date', '=', $this->now->format('Y-m-d'))
->whereTime('start_time', '<', $this->now->format('H:i:s'));
});
})
->orderBy('booking_date', 'desc')
->limit($this->loadAmount)
->get()
]);
}
}
4 changes: 3 additions & 1 deletion app/Livewire/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire;

use Carbon\Carbon;
use App\Models\Lab;
use Livewire\Component;
use Livewire\Attributes\On;

Expand Down Expand Up @@ -44,6 +45,7 @@ public function nextWeek()
}
public function render()
{
return view('livewire.navbar');
$labs = Lab::all();
return view('livewire.navbar', compact('labs'));
}
}
7 changes: 4 additions & 3 deletions resources/views/components/modal-button.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<button
style="background-color: #172554;"
type="button"
class="rounded-full bg-white p-2 text-primary drop-shadow-md text-4xl border border-blue-100"
class="rounded-xl bg-blue-950 p-2 drop-shadow-md text-4xl border border-blue-100 fixed bottom-0 right-0 mb-6 mr-6"
data-te-toggle="modal"
data-te-target="#exampleModal"
data-te-ripple-init
{{-- data-te-ripple-init --}}
data-te-toggle="tooltip"
title="Booking Ruangan"
data-te-ripple-color="light">
<i class="bi bi-plus-lg"></i>
<i class="bi bi-plus-lg text-white"></i>
</button>
136 changes: 1 addition & 135 deletions resources/views/home/history.blade.php
Original file line number Diff line number Diff line change
@@ -1,139 +1,5 @@
@extends('layouts.index')

@section('container')
<div>
<nav
class="fixed top-0 z-20 flex-no-wrap flex w-full items-center justify-between bg-white/90 py-4 lg:flex-wrap border-b drop-shadow backdrop-blur-md">
<div class="flex w-full flex-wrap items-center justify-between px-4 md:px-10">
<div class="flex items-center justify-center">
<a href="/">
<img class="h-10" src="{{ asset('undiksha.png') }}" alt="">
</a>
<a href="/" class="text-2xl font-bold ml-1">SIMARU</a>
</div>
<div class="text-xl flex items-center justify-between text-center md:w-80">
</div>
<div class="">
@auth
<div class="relative" data-te-dropdown-ref>
<button
class="flex items-center whitespace-nowrap rounded first-letter:text-sm font-medium uppercase leading-normal"
type="button"
id="dropdownMenuButton1"
data-te-dropdown-toggle-ref
aria-expanded="false"
data-te-ripple-init
data-te-ripple-color="light">
<i class="bi bi-person-circle text-4xl mr-1"></i>
</button>
<ul
class="absolute z-[1000] float-left m-0 hidden min-w-max list-none overflow-hidden rounded-lg border-none bg-white bg-clip-padding text-left text-base shadow-lg dark:bg-neutral-700 [&[data-te-dropdown-show]]:block"
aria-labelledby="dropdownMenuButton1"
data-te-dropdown-menu-ref>
@if (auth()->user()->role === 'admin')
<li>
<a
class="block w-full whitespace-nowrap bg-transparent px-4 py-2 text-sm font-normal text-neutral-700 hover:bg-neutral-100 active:text-neutral-800 active:no-underline disabled:pointer-events-none disabled:bg-transparent disabled:text-neutral-400 dark:text-neutral-200 dark:hover:bg-neutral-600"
href="/dashboard"
data-te-dropdown-item-ref
><i class="bi bi-speedometer2 text-blue-400"></i><span class="ml-2">Dashboard</span></a
>
</li>
@endif
<li>
<a
class="block w-full whitespace-nowrap bg-transparent px-4 py-2 text-sm font-normal text-neutral-700 hover:bg-neutral-100 active:text-neutral-800 active:no-underline disabled:pointer-events-none disabled:bg-transparent disabled:text-neutral-400 dark:text-neutral-200 dark:hover:bg-neutral-600"
href="/history"
data-te-dropdown-item-ref
><i class="bi bi-clock-history text-blue-400"></i><span class="ml-2">Riwayat</span></a
>
</li>
<li>
<form action="{{ route('logout') }}" method="post">
@csrf
<button
class="text-left w-full bg-transparent px-4 py-2 text-sm font-normal text-neutral-700 hover:bg-neutral-100 active:text-neutral-800 active:no-underline disabled:pointer-events-none disabled:bg-transparent disabled:text-neutral-400 dark:text-neutral-200 dark:hover:bg-neutral-600 "
data-te-dropdown-item-ref
><i class="bi bi-box-arrow-right text-blue-400"></i><span class="ml-2">Keluar</span></button
>
</form>

</li>
</ul>
</div>
@else
<a href="{{ route('login') }}" class="text-lg uppercase font-semibold hidden md:block">Masuk</a>
<a href="{{ route('login') }}" class="text-3xl uppercase font-semibold md:hidden"><i class="bi bi-box-arrow-in-right"></i></a>
@endauth

</div>
</div>
</nav>
</div>

<div class="mt-24 px-4 md:px-8">
<h1 class="text-center mx-auto text-xl font-bold">Riwayat Peminjaman Ruangan </h1>

@if (count($upcomingHistories) == 0 && count($expiredHistories) == 0)
<div class="mt-20 text-center">
<h1 class="mt-5 font-semibold text-3xl">Anda belum memesan Ruangan</h1>
</div>
@endif



@if(count($upcomingHistories) > 0)
<h1 class=" text-lg font-semibold mt-5 text-neutral-600 dark:text-neutral-200 ">Mendatang</h1>

@foreach ($upcomingHistories as $history)
<div class="block rounded-lg bg-white shadow-[0_2px_15px_-3px_rgba(0,0,0,0.07),0_10px_20px_-2px_rgba(0,0,0,0.04)] dark:bg-neutral-700 mt-3 w-full">
<div class="border-b-2 border-neutral-100 px-6 py-3 dark:border-neutral-600 dark:text-neutral-50 text-xl font-semibold ">
{{ $history->reason_to_booking }} | <span class="font-medium text-lg">R. {{ str_replace('Ruang ', '', $history->lab->name) }}</span>
</div>
<div class="p-6">
<h5 class="mb-2 text-lg font-medium leading-tight text-neutral-600 dark:text-neutral-200">
{{ \Carbon\Carbon::parse($history->booking_date)->format('d F Y') }}
<span class="text-base font-normal">({{ \Carbon\Carbon::parse("$history->booking_date $history->start_time")->diffForHumans()}})</span>
</h5>
<p class="mb-4 text-base text-neutral-600 dark:text-neutral-200">
{{ $history->start_time }} - {{ $history->end_time }}
</p>

<form action="{{ route('labs-booking.destroy', $history->id) }}" method="POST">
@csrf
@method('delete')
<button type="submit" class="px-4 py-2 bg-red-500 font-semibold text-white text-sm rounded-md"
onclick="return confirm('Apakah anda yakin ingin membatalkan booking ini?')"
>Batalkan Peminjam</button></form>
</form>
</div>
</div>
@endforeach
@endif



@if ($expiredHistories->count() > 0)


<h1 class="text-lg font-semibold mt-10 text-neutral-600 dark:text-neutral-200">Selesai</h1>
@foreach ($expiredHistories as $history)
<div class="block rounded-lg bg-gray-200 shadow-[0_2px_15px_-3px_rgba(0,0,0,0.07),0_10px_20px_-2px_rgba(0,0,0,0.04)] dark:bg-neutral-700 mt-3">
<div class="border-b-2 border-neutral-100 px-6 py-3 dark:border-neutral-600 dark:text-neutral-50 text-xl font-semibold ">
{{ $history->reason_to_booking }} | <span class="font-medium text-lg">R. {{ str_replace('Ruang ', '', $history->lab->name) }}</span>
</div>
<div class="p-6">
<h5 class="mb-2 text-lg font-medium leading-tight text-neutral-600 dark:text-neutral-200">
{{ \Carbon\Carbon::parse($history->booking_date)->format('d F Y') }}
</h5>
<p class="mb-2 text-base text-neutral-600 dark:text-neutral-200">
{{ $history->start_time }} - {{ $history->end_time }}
</p>
</div>
</div>

@endforeach
@endif
</div>

<livewire:booking-history />
@endsection
Loading

0 comments on commit a269836

Please sign in to comment.