Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Route to home page with form
|
| 7 |
+
@app.route('/')
|
| 8 |
+
def index():
|
| 9 |
+
return render_template('index.html')
|
| 10 |
+
|
| 11 |
+
# Route to handle invoice generation
|
| 12 |
+
@app.route('/generate_invoice', methods=['POST'])
|
| 13 |
+
def generate_invoice():
|
| 14 |
+
# Get the form data
|
| 15 |
+
customer_name = request.form.get('customer_name')
|
| 16 |
+
items = request.form.getlist('item')
|
| 17 |
+
prices = request.form.getlist('price')
|
| 18 |
+
|
| 19 |
+
# Calculate subtotal, tax, and total
|
| 20 |
+
subtotal = sum(float(price) for price in prices)
|
| 21 |
+
tax = subtotal * 0.08 # 8% tax
|
| 22 |
+
total = subtotal + tax
|
| 23 |
+
|
| 24 |
+
# Get current date and time
|
| 25 |
+
now = datetime.now()
|
| 26 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
| 27 |
+
|
| 28 |
+
# Generate a wish message
|
| 29 |
+
wish_message = f"Thank you for dining with us, {customer_name}! We hope to see you again soon."
|
| 30 |
+
|
| 31 |
+
# Render invoice template with the data
|
| 32 |
+
return render_template('invoice.html', customer_name=customer_name, items=items, prices=prices,
|
| 33 |
+
subtotal=subtotal, tax=tax, total=total, date_time=date_time, wish_message=wish_message)
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
app.run(debug=True)
|