#!
/bin/bash
# Load configuration
source ./canteen_config.sh
# Function to display menu options
display_menu() {
clear
echo "Canteen Management System"
echo "-------------------------"
echo "1. Display Menu"
echo "2. Place Order"
echo "3. View Orders"
echo "4. Exit"
}
# Function to display menu items
display_menu_items() {
echo "Menu Items:"
for i in "${!MENU_ITEMS[@]}"; do
echo "$((i + 1)). ${MENU_ITEMS[i]} - \$${MENU_PRICES[i]}"
done
}
# Function to place an order
place_order() {
display_menu_items
echo "Enter your choice:"
read choice
if ((choice < 1 || choice > ${#MENU_ITEMS[@]})); then
echo "Invalid choice"
return
fi
item="${MENU_ITEMS[choice - 1]}"
price="${MENU_PRICES[choice - 1]}"
echo "Enter quantity:"
read quantity
if [[ ! $quantity =~ ^[0-9]+$ ]]; then
echo "Invalid quantity. Please enter a number."
return
fi
total=$((quantity * price))
echo "Ordered: $quantity x $item - Total: $total"
echo "$quantity x $item - $total" >> "$ORDERS_FILE"
}
# Function to view orders
view_orders() {
if [[ -f $ORDERS_FILE ]]; then
echo "Orders:"
cat "$ORDERS_FILE"
else
echo "No orders placed yet."
fi
}
# Main script
while true; do
display_menu
echo "Enter your choice:"
read option
case $option in
1) display_menu_items ;;
2) place_order ;;
3) view_orders ;;
4) echo "Exiting..."; break ;;
*) echo "Invalid choice. Please try again." ;;
esac
echo "Press Enter to continue..."
read
done