Spaces:
Sleeping
Sleeping
File size: 5,052 Bytes
24ffd77 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
import streamlit as st
import airtable
import os
menu = {
'Nourriture': {
'Pizza': 10.00,
'Burger': 8.00,
'Sandwich': 6.00,
'Salade': 7.00,
},
'Boisson': {
'Soda': 2.00,
'Jus': 3.00,
'Café': 4.00,
'Thé': 3.50,
},
'Mystère': {
'Lot mystère A': 15.00,
'Lot mystère B': 20.00,
},
}
def add_to_airtable(name, num_person, order):
base_key = os.environ.get('AIRTABLE_BASE_KEY')
api_key = os.environ.get('AIRTABLE_API_KEY')
base = airtable.Airtable(base_key, 'Orders', api_key)
items = []
total = 0
for category, items_dict in order.items():
for item, qty in items_dict.items():
if qty > 0:
item_str = f'{qty} x {item} ({menu[category][item] * qty} €)'
items.append(item_str)
total += menu[category][item] * qty
record = {
'Nom': name,
'Nombre de Personne': num_person,
'Items': ', '.join(items),
'Total': total
}
base.insert(record)
def restaurant_ordering_system():
st.set_page_config(page_title="📎 Soirée Collecte de Fond")
st.title('📎 Soirée Collecte de Fond')
st.markdown("---")
if 'page' not in st.session_state:
st.session_state.page = 0
if 'order' not in st.session_state:
st.session_state.order = {'Nourriture': {}, 'Boisson': {}, 'Mystère': {}}
if 'name' not in st.session_state:
st.session_state.name = None
if 'num_person' not in st.session_state:
st.session_state.num_person = None
if st.session_state.page == 0:
st.write('# 📍 **Information:**')
st.session_state.name = st.text_input('✏️ Nom')
st.session_state.num_person = st.number_input('✏️ Nombre de personnes', min_value=1, max_value=10, value=1)
disabled = not st.session_state.name or st.session_state.num_person < 1
if st.button('Suivant ➡️', key='next1', disabled=disabled):
st.session_state.page += 1
st.rerun()
elif st.session_state.page == 1:
st.write('# 🏷️ **Menu:**')
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("---")
st.markdown('### 😋 Nourriture')
food_order = st.multiselect('Sélectionner les plats:', list(menu['Nourriture'].keys()), key='food_select')
st.session_state.order['Nourriture'] = {item: st.number_input(f'Quantité pour {item}:', min_value=1, max_value=10, value=1, key=f'food_{item}') for item in food_order}
with col2:
st.markdown("---")
st.markdown('### 🥤 Boissons')
drink_order = st.multiselect('Sélectionner les boissons:', list(menu['Boisson'].keys()), key='drink_select')
st.session_state.order['Boisson'] = {item: st.number_input(f'Quantité pour {item}:', min_value=1, max_value=10, value=1, key=f'drink_{item}') for item in drink_order}
with col3:
st.markdown("---")
st.markdown('### 👁️🗨️ Lots mystères')
mystery_order = st.multiselect('Sélectionner les lots mystères:', list(menu['Mystère'].keys()), key='mystery_select')
st.session_state.order['Mystère'] = {item: st.number_input(f'Quantité pour {item}:', min_value=1, max_value=10, value=1, key=f'mystery_{item}') for item in mystery_order}
# Désactiver le bouton si moins d'un élément est sélectionné
disabled = sum(st.session_state.order['Nourriture'].values()) < 1 and sum(st.session_state.order['Boisson'].values()) < 1 and sum(st.session_state.order['Mystère'].values()) < 1
if st.button('Suivant ➡️', key='next2', disabled=disabled):
st.session_state.page += 1
st.rerun()
if st.button('⬅️ Précédent', key='prev2'):
st.session_state.page -= 1
st.rerun()
elif st.session_state.page == 2:
total = 0.0
st.write('# 🧺 **Récapitulatif de la commande:**')
for category, items in st.session_state.order.items():
if items:
for item, qty in items.items():
if qty > 0: # Affiche seulement si la quantité est supérieure à 0
price = menu[category][item] * qty
st.write(f'- {qty} x {item}: {price} €')
total += price
st.metric('🧮 Total de la commande', f'{total} €')
if st.button('💵 Passer la commande'):
add_to_airtable(st.session_state.name, st.session_state.num_person, st.session_state.order)
st.success(f'✅ Merci {st.session_state.name} pour votre commande! Vous pouvez fermer cet onglet.')
if st.button('⬅️ Précédent', key='prev3'):
st.session_state.page -= 1
st.rerun()
if __name__ == '__main__':
restaurant_ordering_system()
|