Skip to content

Commit

Permalink
fixed the time, synced admin and user areamap, extend time, terminate…
Browse files Browse the repository at this point in the history
… time(the terminate deletes from the table in sql) so sales ledger affected assuming that the reservation is refunded
  • Loading branch information
Ben-Sicat committed Dec 19, 2023
1 parent 2fd7d98 commit d865ad2
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 209 deletions.
144 changes: 107 additions & 37 deletions backend/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,76 @@ def perform_warehouse_process():
# Add the scheduled job to run the ETL process every 168 hours or 1 week
scheduler.add_job(perform_warehouse_process, 'interval', hours=168)

def get_reservation_by_seat(seat):
connection = get_db_connection(db_config)
if connection:
try:
cursor = connection.cursor(dictionary=True)
query = """
SELECT Reservations.ReservationID, Users.Username, Reservations.StartTime, Reservations.EndTime, Reservations.Seat, Reservations.TableFee, Reservations.ResDate
FROM Reservations
JOIN Users ON Reservations.UserID = Users.UserID
WHERE Reservations.Seat = %s
LIMIT 1
"""
cursor.execute (query, (seat,))
result = cursor.fetchone()
cursor.close()
connection.close()
return result
except mysql.connector.Error as err:
print(f"Error fetching reservation by seat: {err}")
return None

def update_reservation_endtime(chair_id, endtime):
connection = get_db_connection(db_config)
try:
cursor = connection.cursor()
current_reservation = get_reservation_by_seat(chair_id)
if current_reservation:
query = """
UPDATE Reservations
SET EndTime = %s
WHERE Seat = %s
"""
values = (endtime, chair_id)
cursor.execute(query, values)
connection.commit()
cursor.close()
connection.close()
return {'message': 'Reservation updated successfully'}
else:
return {'error': 'Reservation not found for the specified seat'}
except mysql.connector.Error as err:
print(f"Error updating reservation: {err}")
connection.rollback()
return {'error': f"Error updating reservation: {err}"}

def remove_reservation(chair_id):
connection = get_db_connection(db_config)
try:
cursor = connection.cursor()
current_reservation = get_reservation_by_seat(chair_id)
if current_reservation:
query = """
DELETE FROM Reservations
WHERE Seat = %s
"""
values = (chair_id,)
cursor.execute(query, values)
connection.commit()
cursor.close()
connection.close()
return {'message': 'Reservation removed successfully'}
else:
return {'error': 'Reservation not found for the specified seat'}
except mysql.connector.Error as err:
print(f"Error removing reservation: {err}")
connection.rollback()
return {'error': f"Error removing reservation: {err}"}


def create_reservation(user_id, reservation_data):
connection = get_db_connection(db_config)
if connection:
Expand Down Expand Up @@ -293,6 +363,42 @@ def get_all_waitlist_entries():
except mysql.connector.Error as err:
print(f"Error fetching waitlist entries: {err}")
return None

@app.route('/api/remove-reservation/<string:chair_id>', methods=['DELETE'])
def remove_reservation_route(chair_id):
try:
result = remove_reservation(chair_id)
if 'error' in result:
return jsonify(result), 404
else:
return jsonify(result), 200
except Exception as e:
print(f"Error removing reservation: {e}")
return jsonify(error='Error removing reservation'), 500

@app.route('/api/update-reservation-endtime/<string:chair_id>/<string:endtime>', methods=['PUT'])
def update_endtime_route(chair_id, endtime):
try:
result = update_reservation_endtime(chair_id, endtime)
if 'error' in result:
return jsonify(result), 404
else:
return jsonify(result), 200
except Exception as e:
print(f"Error updating reservation: {e}")
return jsonify(error='Error updating reservation'), 500

@app.route('/api/get-reservation-by-seat/<string:seat>', methods=['GET'])
def get_reservation_by_seat_route(seat):
try:
reservation = get_reservation_by_seat(seat)
if reservation:
return jsonify({'reservation': reservation}), 200
else:
return jsonify({'error': 'Reservation not found for the specified seat'}), 404
except Exception as e:
print(f"Error fetching reservation by seat: {e}")
return jsonify({'error': str(e)}), 500

@app.route('/api/get-waitlist-entries', methods=['GET'])
def get_waitlist_entries_route():
Expand Down Expand Up @@ -427,43 +533,7 @@ def get_user_by_id_route(user_id):
except Exception as e:
print(f"Error fetching user by ID: {e}")
return jsonify({'error': str(e)}), 500

# @app.route('/api/update-account/', methods=['PUT'])
# def update_account(user_id):
# try:
# updated_data = request.get_json()
# update_user_details(user_id, updated_data)
# updated_user = get_user_by_id(user_id)
# return jsonify({'message': 'Account updated successfully', 'updated_user': updated_user}), 200
# except Exception as e:
# print(f"Error updating account: {e}")
# return jsonify(message='Error updating account'), 500

# @app.route('/api/get-reservations/<int:user_id>', methods=['GET'])
# def get_reservations(user_id):
# try:
# reservations = get_user_reservations(user_id)
# return jsonify(reservations)
# except Exception as e:
# print(f"Error fetching reservations: {e}")
# return jsonify(error='Error fetching reservations'), 500

# @app.route('/api/reservations', methods=['POST'])
# def make_reservation():
# try:
# data = request.get_json()
# user_id = 5 # Replace with the actual user ID; you need to identify the user somehow
# result = create_reservation(user_id, data)
# return jsonify(result)
# except Exception as e:
# print(f"Error creating reservation: {e}")
# return jsonify(error='Error creating reservation'), 500


# Additional user-related functions

# Reservation-related functions (as per your existing code)
# ...


# Main route for testing
@app.route('/')
Expand Down
190 changes: 104 additions & 86 deletions frontend/app/admin_areamap/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,33 @@ function Page() {


const [isModalOpen, setModalOpen] = React.useState(false);
const [chairId, setChairId] = React.useState<string | null>(null);
const [ reservationData, setReservationData] = React.useState<any>(null);


const fetchReservation = async (chairId: string) => {
try{
const response = await fetch(`http://localhost:5000/api/get-reservation-by-seat/${chairId}`);
if(response.ok){
const data = await response.json();
console.log("Reservation Data:", data);
setReservationData(data.reservation);
}
}catch(error){
console.error("Error fetching reservation data:", error);
}
}

//now we need a function to handle the opening of the modal per chair... the funciton must contain a paramete that will be the chair id and the state of the chair if open or close

const handleChairClick = (chairId: string, isChairOpen: boolean) => {
const handleChairClick = async (chairId: string, isChairOpen: boolean) => {
setChairId(chairId);
console.log("chairId", chairId);
setModalOpen(!isModalOpen);
console.log("isChairOpen", isChairOpen);

await fetchReservation(chairId);
console.log("reservationData", reservationData)
// Toggle the modal state
if (isChairOpen) {
setModalOpen(true);
Expand All @@ -43,6 +63,7 @@ function Page() {

const handleModalClose = () => {
setModalOpen(false);
setReservationData(null);
};
const refreshPage = () => {
location.reload();
Expand Down Expand Up @@ -110,93 +131,90 @@ function Page() {

{/* now we need to refractor this modaladmin t only open if the parameter in the onlcick of the button is set to true */}

<ModalAdmin isOpen={isModalOpen} onClose={handleModalClose} />
<ModalAdmin isOpen={isModalOpen} onClose={handleModalClose} reservationData={reservationData}/>
<ChairRight
width="30px"
height="30px"
className="relative top-28 left-64"
onClick={() => handleChairClick("chair1", true)}
/>


<ChairRight
width="30px"
height="30px"
className="relative top-28 left-64"
onClick={() => handleChairClick("chair1", true)}
/>

<ChairRight
width="30px"
height="30px"
className="relative left-64 top-32"
onClick={() => handleChairClick("chair2", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative bottom-5"
onClick={() => handleChairClick("chair3", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative left-16 bottom-12"
onClick={() => handleChairClick("chair4", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative left-10 bottom-2"
onClick={() => handleChairClick("chair5", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative top-1 left-10"
onClick={() => handleChairClick("chair6", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative top-5 left-32"
onClick={() => handleChairClick("chair7", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative left-44 bottom-2"
onClick={() => handleChairClick("chair8", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative left-48 bottom-48"
onClick={() => handleChairClick("chair9", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative left-64 bottom-56"
onClick={() => handleChairClick("chair10", true)}
/>

<ChairDown
width="30px"
height="30px"
className="relative left-32 bottom-44"
onClick={() => handleChairClick("chair11", true)}
/>

<ChairDown
width="30px"
height="30px"
className="relative left-44 bottom-52"
onClick={() => handleChairClick("chair12", true)}
/>

width="30px"
height="30px"
className="relative left-64 top-32"
onClick={() => handleChairClick("chair2", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative bottom-5"
onClick={() => handleChairClick("chair3", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative left-16 bottom-12"
onClick={() => handleChairClick("chair4", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative left-10 bottom-2"
onClick={() => handleChairClick("chair5", true)}
/>

<ChairLeft
width="30px"
height="30px"
className="relative top-1 left-10"
onClick={() => handleChairClick("chair6", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative top-5 left-32"
onClick={() => handleChairClick("chair7", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative left-44 bottom-2"
onClick={() => handleChairClick("chair8", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative left-48 bottom-48"
onClick={() => handleChairClick("chair9", true)}
/>

<ChairUp
width="30px"
height="30px"
className="relative left-64 bottom-56"
onClick={() => handleChairClick("chair10", true)}
/>

<ChairDown
width="30px"
height="30px"
className="relative left-32 bottom-44"
onClick={() => handleChairClick("chair11", true)}
/>

<ChairDown
width="30px"
height="30px"
className="relative left-44 bottom-52"
onClick={() => handleChairClick("chair12", true)}
/>
</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions frontend/app/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ const BasicModal: React.FC<BasicModalProps> = ({ isOpen, onClose, chairId }) =>
};
console.log(apiData)
console.log(tableFee)
router.push(
`https://payment-gateway-weld.vercel.app/gcash/login?amountDue=${tableFee}&merchant=Brew and Brains&redirectUrl=${redirectUrl}`
);
// router.push(
// `https://payment-gateway-weld.vercel.app/gcash/login?amountDue=${tableFee}&merchant=Brew and Brains&redirectUrl=${redirectUrl}`
// );

const response = await fetch(
"http://localhost:5000/api/create-reservation",
Expand Down
Loading

0 comments on commit d865ad2

Please sign in to comment.