Update main.py
Browse files
main.py
CHANGED
|
@@ -263,14 +263,17 @@ def get_user_dashboard():
|
|
| 263 |
last_seen_currency_code = default_currency_code
|
| 264 |
|
| 265 |
# Process Sales
|
| 266 |
-
sales_query = bot_user_ref.collection('sales')
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
sales_query = sales_query.where('createdAt', '<=', end_date)
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 275 |
last_seen_currency_code = currency_code
|
| 276 |
quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
|
|
@@ -279,13 +282,16 @@ def get_user_dashboard():
|
|
| 279 |
sales_count += 1
|
| 280 |
|
| 281 |
# Process Expenses
|
| 282 |
-
expenses_query = bot_user_ref.collection('expenses')
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
-
for doc in expenses_query.stream():
|
| 289 |
details = doc.to_dict().get('details', {})
|
| 290 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 291 |
last_seen_currency_code = currency_code
|
|
@@ -865,14 +871,17 @@ def get_admin_dashboard_stats():
|
|
| 865 |
user_sales_data[phone] = {'total_revenue_by_currency': {}, 'item_sales': {}}
|
| 866 |
last_seen_currency_code = normalize_currency_code(phone_to_user_map.get(phone, {}).get('defaultCurrency'), 'USD')
|
| 867 |
|
| 868 |
-
sales_query = bot_user_ref.collection('sales')
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 873 |
|
| 874 |
-
|
| 875 |
-
details = sale_doc.to_dict().get('details', {})
|
| 876 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 877 |
last_seen_currency_code = currency_code
|
| 878 |
quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
|
|
@@ -888,14 +897,17 @@ def get_admin_dashboard_stats():
|
|
| 888 |
if item_name not in global_item_revenue: global_item_revenue[item_name] = {}
|
| 889 |
global_item_revenue[item_name][currency_code] = global_item_revenue[item_name].get(currency_code, 0) + sale_revenue
|
| 890 |
|
| 891 |
-
expenses_query = bot_user_ref.collection('expenses')
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
|
|
|
|
|
|
|
|
|
| 899 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 900 |
last_seen_currency_code = currency_code
|
| 901 |
amount = float(details.get('amount', 0))
|
|
|
|
| 263 |
last_seen_currency_code = default_currency_code
|
| 264 |
|
| 265 |
# Process Sales
|
| 266 |
+
sales_query = bot_user_ref.collection('sales').stream()
|
| 267 |
+
for doc in sales_query:
|
| 268 |
+
doc_data = doc.to_dict()
|
| 269 |
+
created_at = doc_data.get('createdAt')
|
|
|
|
| 270 |
|
| 271 |
+
if start_date and (not created_at or created_at < start_date):
|
| 272 |
+
continue
|
| 273 |
+
if end_date and (not created_at or created_at > end_date):
|
| 274 |
+
continue
|
| 275 |
+
|
| 276 |
+
details = doc_data.get('details', {})
|
| 277 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 278 |
last_seen_currency_code = currency_code
|
| 279 |
quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
|
|
|
|
| 282 |
sales_count += 1
|
| 283 |
|
| 284 |
# Process Expenses
|
| 285 |
+
expenses_query = bot_user_ref.collection('expenses').stream()
|
| 286 |
+
for doc in expenses_query:
|
| 287 |
+
doc_data = doc.to_dict()
|
| 288 |
+
created_at = doc_data.get('createdAt')
|
| 289 |
+
|
| 290 |
+
if start_date and (not created_at or created_at < start_date):
|
| 291 |
+
continue
|
| 292 |
+
if end_date and (not created_at or created_at > end_date):
|
| 293 |
+
continue
|
| 294 |
|
|
|
|
| 295 |
details = doc.to_dict().get('details', {})
|
| 296 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 297 |
last_seen_currency_code = currency_code
|
|
|
|
| 871 |
user_sales_data[phone] = {'total_revenue_by_currency': {}, 'item_sales': {}}
|
| 872 |
last_seen_currency_code = normalize_currency_code(phone_to_user_map.get(phone, {}).get('defaultCurrency'), 'USD')
|
| 873 |
|
| 874 |
+
sales_query = bot_user_ref.collection('sales').stream()
|
| 875 |
+
for sale_doc in sales_query:
|
| 876 |
+
sale_data = sale_doc.to_dict()
|
| 877 |
+
created_at = sale_data.get('createdAt')
|
| 878 |
+
|
| 879 |
+
if start_date and (not created_at or created_at < start_date):
|
| 880 |
+
continue
|
| 881 |
+
if end_date and (not created_at or created_at > end_date):
|
| 882 |
+
continue
|
| 883 |
|
| 884 |
+
details = sale_data.get('details', {})
|
|
|
|
| 885 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 886 |
last_seen_currency_code = currency_code
|
| 887 |
quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
|
|
|
|
| 897 |
if item_name not in global_item_revenue: global_item_revenue[item_name] = {}
|
| 898 |
global_item_revenue[item_name][currency_code] = global_item_revenue[item_name].get(currency_code, 0) + sale_revenue
|
| 899 |
|
| 900 |
+
expenses_query = bot_user_ref.collection('expenses').stream()
|
| 901 |
+
for expense_doc in expenses_query:
|
| 902 |
+
expense_data = expense_doc.to_dict()
|
| 903 |
+
created_at = expense_data.get('createdAt')
|
| 904 |
+
|
| 905 |
+
if start_date and (not created_at or created_at < start_date):
|
| 906 |
+
continue
|
| 907 |
+
if end_date and (not created_at or created_at > end_date):
|
| 908 |
+
continue
|
| 909 |
+
|
| 910 |
+
details = expense_data.get('details', {})
|
| 911 |
currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
|
| 912 |
last_seen_currency_code = currency_code
|
| 913 |
amount = float(details.get('amount', 0))
|