Real-time profit margin analysis per order with cost breakdown and optimization insights.
import json, pandas as pd
def calc_margin(order):
revenue = order["selling_price"]
cogs = order["cogs"]
commission = order["commission"]
shipping = order["shipping_cost"]
overhead = order.get("overhead", 0)
total_cost = cogs + commission + shipping + overhead
profit = revenue - total_cost
margin_pct = (profit / revenue) * 100 if revenue else 0
return {"profit": round(profit,2), "margin": round(margin_pct,2)}
orders = pd.read_csv("orders_export.csv")
results = []
for _, o in orders.iterrows():
r = calc_margin(o.to_dict())
r["order_id"] = o["id"]
if r["margin"] < 10:
print(f"ALERT: Order {o['id']} margin {r['margin']}%")
results.append(r)
print(json.dumps(results))
Basic Package
Special SME traction programme by AINNA.
Limited starter website offer. AI usage, hosting, maintenance and custom integrations depend on the confirmed scope.
View SME Offer โ
Ask about AINNA pages, services and articles.
AINNA website sources only ยท answers up to 5 lines
No section data available yet.
Sites with documented sections will appear here.
We value your privacy
We use browser storage to remember your choice. Optional analytics runs only after you allow it; your choice is recorded with an anonymous ID. Privacy Policy