Spaces:
Paused
Paused
Upload 94 files
Browse files
app/api/__pycache__/analytics.cpython-312.pyc
CHANGED
|
Binary files a/app/api/__pycache__/analytics.cpython-312.pyc and b/app/api/__pycache__/analytics.cpython-312.pyc differ
|
|
|
app/api/analytics.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
from fastapi import APIRouter, Depends, Query, HTTPException
|
| 2 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 3 |
-
from sqlalchemy import select, func, cast, Date, and_, distinct
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
from typing import Dict, Any, Optional
|
| 6 |
from ..core.dependencies import get_current_active_user
|
| 7 |
from ..db.database import get_db
|
| 8 |
-
from ..db.models import Order, Product, User, Brand
|
| 9 |
|
| 10 |
router = APIRouter()
|
| 11 |
|
|
@@ -101,16 +101,18 @@ async def get_product_analytics(
|
|
| 101 |
# Top selling products
|
| 102 |
stmt = select(
|
| 103 |
Product,
|
| 104 |
-
func.sum(
|
| 105 |
func.count().label('total_orders')
|
| 106 |
).join(
|
| 107 |
-
|
|
|
|
|
|
|
| 108 |
).where(
|
| 109 |
-
and_(*conditions)
|
| 110 |
).group_by(
|
| 111 |
Product.id
|
| 112 |
).order_by(
|
| 113 |
-
func.sum(
|
| 114 |
).limit(10)
|
| 115 |
|
| 116 |
result = await db.execute(stmt)
|
|
@@ -131,13 +133,15 @@ async def get_product_analytics(
|
|
| 131 |
{
|
| 132 |
"id": product.id,
|
| 133 |
"name": product.name,
|
| 134 |
-
"
|
| 135 |
-
"
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
for product, revenue, orders in top_products
|
| 138 |
],
|
| 139 |
-
"total_products": total_products,
|
| 140 |
-
"low_stock_products": low_stock_count
|
| 141 |
}
|
| 142 |
|
| 143 |
@router.get("/customers")
|
|
|
|
| 1 |
from fastapi import APIRouter, Depends, Query, HTTPException
|
| 2 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 3 |
+
from sqlalchemy import select, func, cast, Date, and_, distinct, case
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
from typing import Dict, Any, Optional
|
| 6 |
from ..core.dependencies import get_current_active_user
|
| 7 |
from ..db.database import get_db
|
| 8 |
+
from ..db.models import Order, Product, User, Brand, OrderItem
|
| 9 |
|
| 10 |
router = APIRouter()
|
| 11 |
|
|
|
|
| 101 |
# Top selling products
|
| 102 |
stmt = select(
|
| 103 |
Product,
|
| 104 |
+
func.sum(OrderItem.price * OrderItem.quantity).label('total_revenue'),
|
| 105 |
func.count().label('total_orders')
|
| 106 |
).join(
|
| 107 |
+
OrderItem, Product.id == OrderItem.product_id
|
| 108 |
+
).join(
|
| 109 |
+
Order, OrderItem.order_id == Order.id
|
| 110 |
).where(
|
| 111 |
+
and_(*conditions, Order.status.in_(['completed', 'delivered']))
|
| 112 |
).group_by(
|
| 113 |
Product.id
|
| 114 |
).order_by(
|
| 115 |
+
func.sum(OrderItem.price * OrderItem.quantity).desc()
|
| 116 |
).limit(10)
|
| 117 |
|
| 118 |
result = await db.execute(stmt)
|
|
|
|
| 133 |
{
|
| 134 |
"id": product.id,
|
| 135 |
"name": product.name,
|
| 136 |
+
"category": product.category,
|
| 137 |
+
"total_revenue": float(revenue or 0),
|
| 138 |
+
"total_orders": int(orders or 0),
|
| 139 |
+
"inventory_count": product.inventory_count
|
| 140 |
}
|
| 141 |
for product, revenue, orders in top_products
|
| 142 |
],
|
| 143 |
+
"total_products": total_products or 0,
|
| 144 |
+
"low_stock_products": low_stock_count or 0
|
| 145 |
}
|
| 146 |
|
| 147 |
@router.get("/customers")
|
app/services/__pycache__/pos_analytics.cpython-312.pyc
CHANGED
|
Binary files a/app/services/__pycache__/pos_analytics.cpython-312.pyc and b/app/services/__pycache__/pos_analytics.cpython-312.pyc differ
|
|
|
app/services/pos_analytics.py
CHANGED
|
@@ -14,9 +14,11 @@ import aiohttp
|
|
| 14 |
class POSAnalyticsService:
|
| 15 |
def __init__(self):
|
| 16 |
self.pos_api_url = settings.POS_API_URL
|
| 17 |
-
self.
|
|
|
|
| 18 |
self._headers = {
|
| 19 |
-
"Authorization": f"Bearer {self.
|
|
|
|
| 20 |
"Content-Type": "application/json"
|
| 21 |
}
|
| 22 |
self._last_sync_time = None
|
|
|
|
| 14 |
class POSAnalyticsService:
|
| 15 |
def __init__(self):
|
| 16 |
self.pos_api_url = settings.POS_API_URL
|
| 17 |
+
self.pos_api_key = settings.POS_API_KEY
|
| 18 |
+
self.pos_api_version = settings.POS_API_VERSION
|
| 19 |
self._headers = {
|
| 20 |
+
"Authorization": f"Bearer {self.pos_api_key}",
|
| 21 |
+
"X-API-Version": self.pos_api_version,
|
| 22 |
"Content-Type": "application/json"
|
| 23 |
}
|
| 24 |
self._last_sync_time = None
|