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}