File size: 1,736 Bytes
46f20e2
60c7f69
 
 
 
 
 
06acbd0
 
97e16dc
60c7f69
 
 
 
 
 
06acbd0
60c7f69
06acbd0
 
60c7f69
06acbd0
60c7f69
 
13d0646
06acbd0
 
 
 
 
 
 
 
 
 
 
60c7f69
 
06acbd0
 
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
from flask import Blueprint, render_template, request, session, jsonify  # Added jsonify import
from salesforce import get_salesforce_connection

order_blueprint = Blueprint('order', __name__)

# Initialize Salesforce connection
sf = get_salesforce_connection()


@order_blueprint.route("/order", methods=["GET"])
def order_summary():
    email = session.get('user_email')  # Fetch logged-in user's email
    if not email:
        return redirect(url_for("login"))

    try:
        # Fetch all pending orders for the user
        result = sf.query(f"""
            SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, 
                   Order_Status__c, Discount__c, Total_Bill__c
            FROM Order__c
            WHERE Customer_Email__c = '{email}' AND Billing_Status__c = 'pending'
            ORDER BY CreatedDate DESC
        """)
        orders = result.get("records", [])

        if not orders:
            return render_template("order.html", orders=None, total_subtotal=0, total_discount=0, total_bill=0)

        # Calculate aggregate totals
        total_subtotal = sum(float(order['Total_Amount__c']) for order in orders)
        total_discount = sum(float(order['Discount__c']) for order in orders)
        total_bill = sum(float(order['Total_Bill__c']) for order in orders)

        return render_template("order.html", orders=orders, total_subtotal=total_subtotal, 
                             total_discount=total_discount, total_bill=total_bill)
    except Exception as e:
        print(f"Error fetching order details: {str(e)}")
        return render_template("order.html", orders=None, total_subtotal=0, total_discount=0, 
                             total_bill=0, error=str(e))