Spaces:
Paused
Paused
File size: 641 Bytes
2e91995 1804a7a 2e91995 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from sqlalchemy import create_engine, text
from src.core.config import Config
class SaasAPI:
def __init__(self):
self.config = Config()
try: self.engine = create_engine(self.config.DB_URL)
except: self.engine = None
def get_sales_report(self, workspace_id=1, period="today"):
if not self.engine: return {"revenue": "0", "orders": 0}
with self.engine.connect() as conn:
res = conn.execute(text("SELECT SUM(amount), COUNT(*) FROM sales WHERE workspace_id = :wid"), {"wid": workspace_id}).fetchone()
return {"revenue": f"{res[0] or 0:,.0f} VND", "orders": res[1] or 0}
|