/* Procedura dodawania rezerwacji */
CREATE PROCEDURE [dbo].[p_execute_reservation] @customer_id INT,
@room_id INT,
@spot_id INT,
@date_in SMALLDATETIME,
@date_out SMALLDATETIME,
@employee_id INT
AS
DECLARE @error AS VARCHAR(250);
IF @customer_id IS NULL
OR @room_id IS NULL
OR @spot_id IS NULL
OR @employee_id IS NULL
OR @date_in IS NULL
OR @date_out IS NULL
OR @date_out < @date_in
BEGIN
SET @error = 'Błędne dane!';
RAISERROR (@error,16,1);
END
EXECUTE p_check_room_availabilty @room_id, @date_in, @date_out;
INSERT INTO Bookings(customer_id, payment_status, payment_date)
VALUES(@customer_id, 'U', null);
DECLARE @booking_id int = SCOPE_IDENTITY();
INSERT INTO Booking_detail(booking_id, room_id, spot_id, booking_status, employee_id, date_in, date_out)
VALUES (@booking_id, @room_id, @spot_id, 'U', @employee_id, @date_in, @date_out);
select * from Booking_detail;
select * from Bookings;
GO;
/* Odpalanie procedury z przykładowymi danymi */
EXECUTE p_execute_reservation 4, 1, 3, '2022-03-11 00:00:00', '2023-03-20 00:00:00',1;