Skip to content

Commit 38a1dce

Browse files
authored
Merge pull request #3 from dmieuop/dev
Internal booking added
2 parents 1e64677 + eb395d6 commit 38a1dce

69 files changed

Lines changed: 4641 additions & 3118 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ yarn-error.log
1717
/.fleet
1818
/.idea
1919
/.vscode
20+
docker-compose.yml
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Mail\FacilityBookingRemindingForTO;
6+
use App\Mail\FacilityBookingRemindingForUser;
7+
use App\Models\BookingLab;
8+
use App\Models\Lab;
9+
use App\Models\User;
10+
use Illuminate\Console\Command;
11+
use Illuminate\Support\Facades\Mail;
12+
13+
class RemindFacilityBooking extends Command
14+
{
15+
/**
16+
* The name and signature of the console command.
17+
*
18+
* @var string
19+
*/
20+
protected $signature = 'RemindFacilityBooking';
21+
22+
/**
23+
* The console command description.
24+
*
25+
* @var string
26+
*/
27+
protected $description = 'This command will check the approved facility booking and send a reminder email to the relevant parties 30min before the booking time.';
28+
29+
/**
30+
* Create a new command instance.
31+
*
32+
* @return void
33+
*/
34+
public function __construct()
35+
{
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* Execute the console command.
41+
*
42+
* @return void
43+
*/
44+
public function handle()
45+
{
46+
$bookings = BookingLab::where('approved', 1)->where('date', now()->format('Y-m-d'))->where('start_time', now()->addMinutes(30)->format('H:i:s'))->get();
47+
48+
// dd($bookings);
49+
50+
foreach ($bookings as $booking) {
51+
$user = User::where('id', $booking->technical_staff)->firstOrFail();
52+
53+
$body = [
54+
'name' => $booking->name,
55+
'email' => $booking->email,
56+
'phone' => $booking->phone,
57+
'to_name' => $user->name,
58+
'to_email' => $user->email,
59+
'to_phone' => $user->phone,
60+
'department' => 'Manufacturing and Industrial Engineering',
61+
'facility' => Lab::find($booking->lab_id)->name,
62+
'date' => date('Y-m-d', strtotime($booking->date)),
63+
'start_time' => date('h:i a', strtotime($booking->start_time)),
64+
'end_time' => date('h:i a', strtotime($booking->end_time)),
65+
'notes' => $booking->notes,
66+
];
67+
68+
Mail::to($user->email)->send(new FacilityBookingRemindingForTO($body));
69+
Mail::to($booking->email)->send(new FacilityBookingRemindingForUser($body));
70+
}
71+
}
72+
}

app/Console/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ protected function schedule(Schedule $schedule)
1717
$schedule->command('cache:prune-stale-tags')->hourly();
1818
$schedule->command('AllocateMaintenanceTasks')->onOneServer()->environments(['production'])->dailyAt('00:30');
1919
$schedule->command('RemindAdvisorsToLogComments')->onOneServer()->environments(['production'])->weeklyOn(2, '8:00');
20+
$schedule->command('RemindFacilityBooking')->onOneServer()->everyThirtyMinutes()->environments(['production']);
2021
}
2122

2223

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\DMIEsys;
4+
5+
use App\Models\BookingLab;
6+
use Illuminate\Http\Request;
7+
use App\Http\Controllers\Controller;
8+
use App\Mail\FacilityBookingApproved;
9+
use App\Mail\FacilityBookingAssigned;
10+
use App\Mail\FacilityBookingPlaced;
11+
use App\Mail\FacilityBookingReceived;
12+
use App\Mail\FacilityBookingRejected;
13+
use App\Models\Lab;
14+
use App\Models\User;
15+
use Illuminate\Support\Facades\Mail;
16+
17+
class BookingLabController extends Controller
18+
{
19+
/**
20+
* Display a listing of the resource.
21+
*/
22+
public function index()
23+
{
24+
if ($this->can('approve booking')) {
25+
$approve_booking_auth = true;
26+
} else {
27+
abort(404);
28+
}
29+
30+
$bookings = BookingLab::where('rejected', 0)->where('date', '>=', now()->format('Y-m-d'))
31+
->where('approved', 0)->where('rejected', 0)
32+
->orderBy('date', 'desc')->orderBy('start_time', 'desc')->with('getLab')->get();
33+
34+
// dd($bookings);
35+
36+
return view('dmiesys.laboratories.book-facility', compact('approve_booking_auth', 'bookings'));
37+
}
38+
39+
/**
40+
* Show the form for creating a new resource.
41+
*/
42+
public function create()
43+
{
44+
$book_lab_auth = true;
45+
46+
$starting_times = config('settings.starting_times');
47+
$ending_times = config('settings.ending_times');
48+
49+
$min_days = config('settings.booking.min_days');
50+
$max_days = config('settings.booking.max_days');
51+
52+
return view('dmiesys.laboratories.book-facility', compact('book_lab_auth', 'starting_times', 'ending_times', 'min_days', 'max_days'));
53+
}
54+
55+
/**
56+
* Store a newly created resource in storage.
57+
*/
58+
public function store(Request $request)
59+
{
60+
$request->validate([
61+
'lab' => 'required|exists:labs,id',
62+
'date' => ['required', 'date', 'after:' . now()->addDays(config('settings.booking.min_days'))->format('Y-m-d'), 'before:' . now()->addDays(config('settings.booking.max_days'))->format('Y-m-d')],
63+
'phone' => ['bail', 'nullable', 'alpha_num:ascii', 'min:10', 'max:10', 'regex:/^0[0-9]{9}$/'],
64+
'start_time' => 'required|date_format:H:i|before:end_time|after:07:59|before:17:01',
65+
'end_time' => 'required|date_format:H:i|after:start_time|after:07:59|before:17:01',
66+
'note' => 'nullable|string',
67+
]);
68+
69+
//validate if the lab is available for booking on the selected date and time
70+
71+
$bookings = BookingLab::where('date', date('Y-m-d', strtotime($request->date)))
72+
->where('lab_id', $request->lab)
73+
->where('rejected', 0)
74+
->where(function ($query) use ($request) {
75+
$query->whereBetween('start_time', [$request->start_time, $request->end_time])
76+
->orWhereBetween('end_time', [$request->start_time, $request->end_time]);
77+
})
78+
->get();
79+
80+
81+
if ($bookings->count() > 0) {
82+
return back()->withErrors('The lab is not available for booking on the selected date and time. Please select another date and time.')->withInput();
83+
}
84+
85+
86+
try {
87+
$lab_booking = new BookingLab();
88+
$lab_booking->lab_id = $request->lab;
89+
$lab_booking->date = date('Y-m-d', strtotime($request->date));
90+
$lab_booking->start_time = $request->start_time;
91+
$lab_booking->end_time = $request->end_time;
92+
$lab_booking->from = 'internal';
93+
$lab_booking->name = auth()->user()->name;
94+
$lab_booking->email = auth()->user()->email;
95+
$lab_booking->phone = $request->phone;
96+
$lab_booking->department = 'Department of Manufacturing and Industrial Engineering';
97+
$lab_booking->notes = $request->note;
98+
$lab_booking->save();
99+
} catch (\Throwable $th) {
100+
$this->failed($th);
101+
return back()->withErrors("There was a problem, please check the logs to see more about this!")->withInput();
102+
}
103+
104+
$this->passed('Lab booked by internal members ' . auth()->user()->name . ' ' . ' on ' . $request->date . ' from ' . $request->start_time . ' to ' . $request->end_time);
105+
106+
//send email LabBookingPlaced to the person who placed the booking
107+
$body = [
108+
'name' => auth()->user()->name,
109+
'email' => auth()->user()->email,
110+
'phone' => $request->phone,
111+
'request_type' => 'internal',
112+
'department' => 'Manufacturing and Industrial Engineering',
113+
'facility' => Lab::find($request->lab)->name,
114+
'date' => date('Y-m-d', strtotime($request->date)),
115+
'start_time' => date('h:i a', strtotime($request->start_time)),
116+
'end_time' => date('h:i a', strtotime($request->end_time)),
117+
'notes' => $request->note,
118+
'url' => route('book-labs.index'),
119+
];
120+
121+
Mail::to(auth()->user()->email)->send(new FacilityBookingPlaced($body));
122+
Mail::to(config('settings.emails.office'))->send(new FacilityBookingReceived($body));
123+
124+
return redirect()->route('book-labs.create')->with('toast_success', 'Your booking request has been sent successfully. Please wait for the approval.');
125+
}
126+
127+
/**
128+
* Display the specified resource.
129+
*/
130+
public function show($booking_id)
131+
{
132+
if ($this->can('approve booking')) {
133+
$approve_booking_single_auth = true;
134+
} else {
135+
abort(404);
136+
}
137+
138+
$booking = BookingLab::where('id', $booking_id)->where('rejected', 0)->where('approved', 0)->where('date', '>=', now()->format('Y-m-d'))->with('getLab')->firstOrFail();
139+
140+
$technical_officers = User::active()->role(['Technical Officer', 'Instrument Mechanic', 'Machine Operator'])->get(['id', 'name']);
141+
142+
143+
return view('dmiesys.laboratories.book-facility', compact('approve_booking_single_auth', 'booking', 'technical_officers'));
144+
}
145+
146+
/**
147+
* Update the specified resource in storage.
148+
*/
149+
public function update(Request $request, $booking_id)
150+
{
151+
abort_unless(($this->can('approve booking')), 404);
152+
153+
$booking = BookingLab::where('id', $booking_id)->where('rejected', 0)->where('approved', 0)->where('date', '>=', now()->format('Y-m-d'))->firstOrFail();
154+
155+
$request->validate([
156+
'status' => 'required|in:approved,rejected',
157+
'technical_officer' => 'required_if:status,approved',
158+
'reason' => 'required_if:status,rejected',
159+
]);
160+
161+
if ($request->status == 'approved') {
162+
$user = User::role(['Technical Officer', 'Instrument Mechanic', 'Machine Operator'])
163+
->where('id', $request->technical_officer)->firstOrFail();
164+
165+
$body = [
166+
'name' => $booking->name,
167+
'email' => $booking->email,
168+
'phone' => $booking->phone,
169+
'to_name' => $user->name,
170+
'to_email' => $user->email,
171+
'to_phone' => $user->phone,
172+
'department' => 'Manufacturing and Industrial Engineering',
173+
'facility' => Lab::find($booking->lab_id)->name,
174+
'date' => date('Y-m-d', strtotime($booking->date)),
175+
'start_time' => date('h:i a', strtotime($booking->start_time)),
176+
'end_time' => date('h:i a', strtotime($booking->end_time)),
177+
'notes' => $booking->notes,
178+
];
179+
180+
$booking->approved = 1;
181+
$booking->technical_staff = $request->technical_officer;
182+
$booking->save();
183+
184+
Mail::to($booking->email)->send(new FacilityBookingApproved($body));
185+
Mail::to($user->email)->send(new FacilityBookingAssigned($body));
186+
187+
$this->passed('Lab booking approved for ' . $booking->name . ' ' . ' on ' . $booking->date . ' from ' . $booking->start_time . ' to ' . $booking->end_time);
188+
189+
return redirect()->route('book-labs.index')->with('toast_success', 'Booking approved successfully!');
190+
} else {
191+
$booking->rejected = 1;
192+
$booking->save();
193+
194+
$body = [
195+
'name' => $booking->name,
196+
'email' => $booking->email,
197+
'phone' => $booking->phone,
198+
'request_type' => 'internal',
199+
'department' => 'Manufacturing and Industrial Engineering',
200+
'facility' => Lab::find($booking->lab_id)->name,
201+
'date' => date('Y-m-d', strtotime($booking->date)),
202+
'start_time' => date('h:i a', strtotime($booking->start_time)),
203+
'end_time' => date('h:i a', strtotime($booking->end_time)),
204+
'reason' => $request->reason,
205+
];
206+
207+
Mail::to($booking->email)->send(new FacilityBookingRejected($body));
208+
209+
$this->passed('Lab booking rejected for ' . $booking->name . ' ' . ' on ' . $booking->date . ' from ' . $booking->start_time . ' to ' . $booking->end_time);
210+
211+
return redirect()->route('book-labs.index')->with('toast_success', 'Booking rejected successfully!');
212+
}
213+
}
214+
}

app/Http/Controllers/DMIEsys/DashboardController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public function pgAdmin()
8686
return view('dmiesys.general.pg-admin');
8787
}
8888

89+
public function bookFacility()
90+
{
91+
return view('dmiesys.laboratories.book-facility');
92+
}
93+
8994
public function viewLogs()
9095
{
9196
/* This is checking if the user has the permission to see logs. If they do, it returns the

app/Http/Controllers/DMIEsys/LabController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,29 @@ public function create()
3939
*/
4040
public function store(Request $request)
4141
{
42-
4342
abort_unless(($this->can('add laboratory')), 404);
4443

4544
Validator::make($request->all(), [
4645
'name' => 'required|string|max:100',
47-
'description' => 'required|string',
46+
'description' => 'nullable|string',
4847
'academicstaff' => 'nullable|exists:users,id',
49-
'technicalstaff' => 'required|exists:users,id',
48+
'technicalstaff' => 'nullable|exists:users,id',
5049
'temporarystaff' => 'nullable|exists:users,id',
50+
'allow_internal_booking' => 'sometimes|boolean',
51+
'allow_external_booking' => 'sometimes|boolean',
5152
])->validate();
5253

54+
// dd($request->request);
55+
5356
try {
5457
Lab::create([
5558
'name' => $request->name,
5659
'description' => $request->description,
5760
'academicstaff' => $request->academicstaff,
5861
'technicalstaff' => $request->technicalstaff,
5962
'temporarystaff' => $request->temporarystaff,
63+
'book_by_internal_members' => $request->allow_internal_booking ?? false,
64+
'book_by_external_members' => $request->allow_external_booking ?? false,
6065
]);
6166
} catch (\Throwable $th) {
6267
$this->failed($th);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Home;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
8+
class HomeController extends Controller
9+
{
10+
public function index()
11+
{
12+
return view('home.home');
13+
}
14+
}

0 commit comments

Comments
 (0)