Completed Tour Booking sql
This commit is contained in:
parent
78ebce3ba4
commit
98fd718ef5
3 changed files with 70 additions and 17 deletions
22
doc/booking_query_2_of_2.all_users_unbooked.sql
Normal file
22
doc/booking_query_2_of_2.all_users_unbooked.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
-- Display all booked users (regardless of booked room)
|
||||||
|
-- restrict to unbooked users
|
||||||
|
SELECT
|
||||||
|
b.tour_id,
|
||||||
|
b.room_id,
|
||||||
|
b.user_id,
|
||||||
|
u.name as user_name,
|
||||||
|
tr.capacity,
|
||||||
|
COALESCE(tr.name,'Ungebucht') as room_name,
|
||||||
|
COALESCE(tr.name,'ZZZZZZZZZ') as room_sort_order
|
||||||
|
FROM
|
||||||
|
users u,
|
||||||
|
bookings b
|
||||||
|
LEFT JOIN tour_rooms as tr
|
||||||
|
ON b.room_id = tr.id
|
||||||
|
WHERE
|
||||||
|
b.tour_id= 17
|
||||||
|
AND
|
||||||
|
b.user_id = u.id
|
||||||
|
AND
|
||||||
|
capacity is null
|
||||||
|
;
|
||||||
|
|
@ -149,29 +149,60 @@ class TourController extends Controller
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private function fetch_rooms($tour_id) {
|
private function fetch_rooms($tour_id) {
|
||||||
// tour_room based display ( Suppresses users without room)
|
// - all existing rooms with booked users (if any)
|
||||||
$sql="SELECT
|
// - all users without room
|
||||||
|
$sql="
|
||||||
|
SELECT
|
||||||
qry.tour_id,
|
qry.tour_id,
|
||||||
qry.room_id,
|
qry.room_id,
|
||||||
b.user_id,
|
u.id as user_id,
|
||||||
|
u.name as user_name,
|
||||||
qry.capacity,
|
qry.capacity,
|
||||||
qry.room_name,
|
|
||||||
COALESCE(qry.room_name,'Ungebucht') room_name,
|
COALESCE(qry.room_name,'Ungebucht') room_name,
|
||||||
COALESCE(qry.room_name,'ZZZZZZZZZ') room_sort_order
|
COALESCE(qry.room_name,'ZZZZZZZZZ') room_sort_order
|
||||||
FROM (
|
FROM
|
||||||
SELECT
|
(
|
||||||
tr.tour_id,
|
SELECT
|
||||||
tr.id as room_id,
|
tr.tour_id,
|
||||||
tr.capacity,
|
tr.id as room_id,
|
||||||
tr.name as room_name
|
tr.capacity,
|
||||||
FROM
|
tr.name as room_name,
|
||||||
tour_rooms tr
|
b.user_id
|
||||||
WHERE
|
FROM
|
||||||
|
tour_rooms tr
|
||||||
|
LEFT JOIN bookings as b
|
||||||
|
ON b.tour_id = tr.tour_id AND b.room_id = tr.id
|
||||||
|
WHERE
|
||||||
tr.tour_id= ".$tour_id."
|
tr.tour_id= ".$tour_id."
|
||||||
) qry LEFT JOIN bookings as b
|
) qry
|
||||||
ON b.tour_id = qry.tour_id AND b.room_id=qry.room_id
|
LEFT JOIN users as u
|
||||||
ORDER BY 6,4
|
ON qry.user_id = u.id
|
||||||
;";
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
-- unbooked tour users
|
||||||
|
SELECT
|
||||||
|
b.tour_id,
|
||||||
|
b.room_id,
|
||||||
|
b.user_id,
|
||||||
|
u.name as user_name,
|
||||||
|
tr.capacity,
|
||||||
|
COALESCE(tr.name,'Ungebucht') as room_name,
|
||||||
|
COALESCE(tr.name,'ZZZZZZZZZ') as room_sort_order
|
||||||
|
FROM
|
||||||
|
users u,
|
||||||
|
bookings b
|
||||||
|
LEFT JOIN tour_rooms as tr
|
||||||
|
ON b.room_id = tr.id
|
||||||
|
WHERE
|
||||||
|
b.tour_id= ".$tour_id."
|
||||||
|
AND
|
||||||
|
b.user_id = u.id
|
||||||
|
AND
|
||||||
|
capacity is null
|
||||||
|
ORDER BY room_name, user_name
|
||||||
|
;
|
||||||
|
";
|
||||||
|
|
||||||
$rooms=DB::select($sql);
|
$rooms=DB::select($sql);
|
||||||
return($rooms);
|
return($rooms);
|
||||||
|
|
|
||||||
0
tools/motorradig_2022-05-11_072937.sql
Normal file
0
tools/motorradig_2022-05-11_072937.sql
Normal file
Loading…
Add table
Add a link
Reference in a new issue