Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, render_template,
|
| 2 |
from simple_salesforce import Salesforce
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
|
@@ -27,6 +27,11 @@ except Exception as e:
|
|
| 27 |
sf = None
|
| 28 |
|
| 29 |
# Route for login page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@app.route('/auth', methods=['POST'])
|
| 31 |
def auth():
|
| 32 |
email = request.form['email']
|
|
@@ -52,11 +57,9 @@ def auth():
|
|
| 52 |
except Exception as e:
|
| 53 |
return render_template('login.html', error_message=f"Error during authentication: {e}")
|
| 54 |
|
| 55 |
-
|
| 56 |
# Route to display rewards page
|
| 57 |
@app.route('/rewards/<customer_id>')
|
| 58 |
def rewards(customer_id):
|
| 59 |
-
print(f"Rewards route accessed for customer {customer_id}") # Debug statement
|
| 60 |
try:
|
| 61 |
customer = sf.Customer_Login__c.get(customer_id)
|
| 62 |
points = customer['Reward_Points__c']
|
|
@@ -66,52 +69,5 @@ def rewards(customer_id):
|
|
| 66 |
except Exception as e:
|
| 67 |
return f"Error fetching rewards: {e}"
|
| 68 |
|
| 69 |
-
# Route to apply rewards
|
| 70 |
-
@app.route('/apply_rewards', methods=['POST'])
|
| 71 |
-
def apply_rewards():
|
| 72 |
-
print("Apply rewards route accessed") # Debug statement
|
| 73 |
-
customer_id = request.form['customer_id']
|
| 74 |
-
bill_amount = float(request.form['bill_amount'])
|
| 75 |
-
apply_rewards = request.form.get('apply_rewards')
|
| 76 |
-
|
| 77 |
-
try:
|
| 78 |
-
customer = sf.Customer_Login__c.get(customer_id)
|
| 79 |
-
points = customer['Reward_Points__c']
|
| 80 |
-
gst = 0.18 * bill_amount
|
| 81 |
-
|
| 82 |
-
if points >= 500 and apply_rewards:
|
| 83 |
-
discount = 0.1 * bill_amount
|
| 84 |
-
final_bill = bill_amount - discount + gst
|
| 85 |
-
updated_points = points - 500
|
| 86 |
-
|
| 87 |
-
# Update the customer's reward points in Salesforce
|
| 88 |
-
sf.Customer_Login__c.update(customer_id, {'Reward_Points__c': updated_points})
|
| 89 |
-
|
| 90 |
-
message = "You saved 10% on your total bill!"
|
| 91 |
-
else:
|
| 92 |
-
# Customers with below 500 points earn 10% of their bill amount as reward points
|
| 93 |
-
discount = 0
|
| 94 |
-
earned_points = 0.1 * bill_amount
|
| 95 |
-
final_bill = bill_amount + gst
|
| 96 |
-
updated_points = points + earned_points
|
| 97 |
-
|
| 98 |
-
# Update the customer's reward points in Salesforce
|
| 99 |
-
sf.Customer_Login__c.update(customer_id, {'Reward_Points__c': updated_points})
|
| 100 |
-
|
| 101 |
-
message = f"You earned 10% of your bill amount ({earned_points} points) as reward points!"
|
| 102 |
-
|
| 103 |
-
# Render the summary page with Dollar symbol
|
| 104 |
-
return render_template(
|
| 105 |
-
'apply_rewards.html',
|
| 106 |
-
original_bill=bill_amount,
|
| 107 |
-
discount=discount,
|
| 108 |
-
gst=gst,
|
| 109 |
-
final_bill=final_bill,
|
| 110 |
-
updated_points=updated_points,
|
| 111 |
-
message=message
|
| 112 |
-
)
|
| 113 |
-
except Exception as e:
|
| 114 |
-
return f"Error applying rewards: {e}"
|
| 115 |
-
|
| 116 |
if __name__ == '__main__':
|
| 117 |
-
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, redirect, url_for
|
| 2 |
from simple_salesforce import Salesforce
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
|
|
|
| 27 |
sf = None
|
| 28 |
|
| 29 |
# Route for login page
|
| 30 |
+
@app.route('/')
|
| 31 |
+
def login():
|
| 32 |
+
return render_template('login.html', error_message=None)
|
| 33 |
+
|
| 34 |
+
# Route to process login
|
| 35 |
@app.route('/auth', methods=['POST'])
|
| 36 |
def auth():
|
| 37 |
email = request.form['email']
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
return render_template('login.html', error_message=f"Error during authentication: {e}")
|
| 59 |
|
|
|
|
| 60 |
# Route to display rewards page
|
| 61 |
@app.route('/rewards/<customer_id>')
|
| 62 |
def rewards(customer_id):
|
|
|
|
| 63 |
try:
|
| 64 |
customer = sf.Customer_Login__c.get(customer_id)
|
| 65 |
points = customer['Reward_Points__c']
|
|
|
|
| 69 |
except Exception as e:
|
| 70 |
return f"Error fetching rewards: {e}"
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
if __name__ == '__main__':
|
| 73 |
+
app.run(debug=True, host="0.0.0.0", port=7860) # Ensure it runs on port 7860
|