sonthaiha
Fresh Deployment with LFS
1804a7a
import math
import datetime
from lunardate import LunarDate
class RetailTools:
@staticmethod
def calculate(expression: str):
try:
allowed = set("0123456789.+-*/() ")
if not all(c in allowed for c in expression): return "Error"
return str(eval(expression, {"__builtins__": None}, {}))
except: return "Error"
@staticmethod
def get_lunar_date():
today = datetime.date.today()
lunar = LunarDate.fromSolarDate(today.year, today.month, today.day)
return f"{lunar.day}/{lunar.month}/{lunar.year} (Lunar)"
@staticmethod
def analyze_financial_health(revenue, total_assets, debt):
"""
Implements the logic from the Research Paper.
Calculates simple ratios to predict health.
"""
try:
revenue = float(revenue)
assets = float(total_assets)
debt = float(debt)
if assets == 0: return "Error: Assets cannot be 0"
# Key Metrics from Paper
asset_turnover = revenue / assets
leverage = debt / assets
advice = []
score = 100
# 1. Asset Turnover Logic
if asset_turnover < 0.5:
advice.append("⚠️ Vòng quay tài sản thấp (<0.5). Bạn đang tồn đọng vốn quá nhiều.")
score -= 20
else:
advice.append("✅ Vòng quay tài sản tốt.")
# 2. Leverage Logic (Paper says high leverage correlates with profit BUT high risk)
if leverage > 0.6:
advice.append("⚠️ Tỷ lệ nợ cao (>60%). Rủi ro tài chính lớn nếu thị trường biến động.")
score -= 30
elif leverage < 0.2:
advice.append("ℹ️ Tỷ lệ nợ thấp. Bạn có thể cân nhắc vay thêm để mở rộng (Đòn bẩy tài chính).")
else:
advice.append("✅ Cấu trúc vốn an toàn.")
return {
"score": score,
"metrics": {"turnover": round(asset_turnover, 2), "leverage": round(leverage, 2)},
"advice": advice
}
except:
return "Invalid Data"
@staticmethod
def health_check(saas_api, store_id):
alerts = []
sales = saas_api.get_sales_report(store_id, "today")
if sales['revenue'] == 0: alerts.append("⚠️ Chưa có doanh thu hôm nay.")
return alerts