import bcrypt import gradio as gr from datetime import datetime from simple_salesforce import Salesforce # Salesforce Connection sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') # Function to Hash Password def hash_password(password): return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8') # Function to Verify Password def verify_password(plain_password, hashed_password): return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8')) # Fetch menu items from Salesforce def fetch_menu_items(): try: query = "SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c" result = sf.query(query) return result['records'] except Exception as e: print(f"Error fetching menu items: {e}") return [] # Fetch add-ons from Salesforce def fetch_add_ons(): try: query = "SELECT Name, Price__c FROM Add_Ons__c" result = sf.query(query) return result['records'] except Exception as e: print(f"Error fetching add-ons: {e}") return [] # Save cart details to Salesforce def save_cart(cart_items, total_cost): try: # Create order record order_record = { 'Name': f"Order {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}", 'Total_Cost__c': total_cost, 'Order_Date__c': datetime.now().isoformat() } order_result = sf.Order__c.create(order_record) order_id = order_result['id'] # Save cart items as order items for item in cart_items: extras = ", ".join(extra['name'] for extra in item.get('extras', [])) order_item_record = { 'Name': item['name'], 'Order__c': order_id, 'Quantity__c': item['quantity'], 'Price__c': item['price'], 'Extras__c': extras, 'Instructions__c': item.get('instructions', ''), 'Total_Cost__c': item['total_cost'] } sf.Order_Item__c.create(order_item_record) return f"Order {order_id} saved successfully!" except Exception as e: print(f"Error saving cart: {e}") return f"Error saving cart: {str(e)}" # Function to filter menu based on preference def filter_menu(preference): menu_items = fetch_menu_items() filtered_items = [item for item in menu_items if preference == "All" or item['Veg_NonVeg__c'] == preference] menu_output = {} for item in filtered_items: section = item.get('Section__c', 'Uncategorized') if section not in menu_output: menu_output[section] = [] menu_output[section].append(item) return menu_output # Gradio App with gr.Blocks() as app: with gr.Row(): gr.HTML("