1
📥
Ambil data POSAPI terminal — jualan setiap shift
2
🧮
Kira agregatJumlah jualan, transaksi, purata tiket
3
🔍
Analisis bayaranKaedah pembayaran setiap shift
4
📊
Laporan & anomalReconciliation dengan bank + amaran
import requests, json, pandas as pd
API_POS = "http://localhost:8080/api/v2/pos/sales"
def fetch_pos_summary(start_date, end_date):
resp = requests.get(API_POS, params={
"start": start_date, "end": end_date
})
return resp.json().get("shifts", [])
def aggregate_sales(shifts):
df = pd.DataFrame(shifts)
total = df["amount"].sum()
count = df["items"].sum()
avg_ticket = round(total / len(shifts), 2)
cash_pct = df[df["payment"] == "Cash"]["amount"].sum() / total * 100
return {
"total_sales": round(total, 2),
"transactions": int(count),
"avg_ticket": avg_ticket,
"cash_pct": round(cash_pct, 1),
"card_pct": round(100 - cash_pct, 1),
"anomalies": int((df["amount"] > df["amount"].mean() * 1.5).sum())
}
report = aggregate_sales(fetch_pos_summary("2026-06-01", "2026-06-30"))
print(json.dumps(report))