stepolan commited on
Commit ·
396465d
1
Parent(s): bd920df
Fix session state conflict — use _default() helper on all widgets for plan loading
Browse files
app.py
CHANGED
|
@@ -338,11 +338,21 @@ if load_choice != "— New plan —" and load_choice in saved_plans:
|
|
| 338 |
|
| 339 |
st.sidebar.caption("Adjust these to model different comp plan structures. Changes update results instantly.")
|
| 340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
with st.sidebar.expander("Compensation Structure", expanded=True):
|
| 342 |
-
base_salary = st.number_input("Base Salary ($)",
|
| 343 |
-
help="Annual base salary before any variable compensation"
|
| 344 |
-
|
| 345 |
-
|
|
|
|
|
|
|
| 346 |
|
| 347 |
with st.sidebar.expander("Draw", expanded=False):
|
| 348 |
st.caption(
|
|
@@ -351,11 +361,14 @@ with st.sidebar.expander("Draw", expanded=False):
|
|
| 351 |
"**Recoverable** = deducted from future commissions (an advance). "
|
| 352 |
"**Non-recoverable** = paid on top of whatever they earn."
|
| 353 |
)
|
| 354 |
-
draw_amount = st.number_input("Draw total ($)",
|
| 355 |
-
help="Total draw amount spread over the draw period"
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
st.sidebar.divider()
|
| 361 |
commission_mode = st.sidebar.radio(
|
|
@@ -375,7 +388,8 @@ avg_rate = 0.0
|
|
| 375 |
retroactive_mode = False
|
| 376 |
if commission_mode == "Attainment-based rates":
|
| 377 |
with st.sidebar.expander("Commission Tiers (attainment)", expanded=True):
|
| 378 |
-
retroactive_mode = st.toggle("Retroactive rates",
|
|
|
|
| 379 |
help="**Marginal** (off): each rate applies only to revenue in that band. "
|
| 380 |
"**Retroactive** (on): once a threshold is crossed, the higher rate applies to ALL revenue from dollar one. "
|
| 381 |
"Retroactive is much more expensive for the company.")
|
|
@@ -383,7 +397,8 @@ if commission_mode == "Attainment-based rates":
|
|
| 383 |
st.caption("Retroactive — highest tier reached applies to ALL revenue")
|
| 384 |
else:
|
| 385 |
st.caption("Marginal — each rate applies only to revenue in that band")
|
| 386 |
-
num_tiers = st.number_input("Number of tiers", 1, 8,
|
|
|
|
| 387 |
att_defaults = [(100, 4.0), (125, 5.0), (150, 6.0), (None, 7.0)]
|
| 388 |
for i in range(int(num_tiers)):
|
| 389 |
c1, c2 = st.columns(2)
|
|
@@ -394,29 +409,36 @@ if commission_mode == "Attainment-based rates":
|
|
| 394 |
c1.text(f"Tier {i+1}: above prior")
|
| 395 |
upper = None
|
| 396 |
else:
|
| 397 |
-
upper = c1.number_input(f"Tier {i+1} upper %",
|
| 398 |
-
|
|
|
|
|
|
|
| 399 |
att_tiers.append((upper, rate))
|
| 400 |
else:
|
| 401 |
with st.sidebar.expander("Deal-Size Commission Rates", expanded=True):
|
| 402 |
-
num_deal_tiers = st.number_input("Number of deal-size tiers", 1, 6,
|
|
|
|
| 403 |
deal_defaults = [(0, 29_999, 20.0), (30_000, 100_000, 40.0), (100_001, None, 40.0)]
|
| 404 |
for i in range(int(num_deal_tiers)):
|
| 405 |
c1, c2, c3 = st.columns(3)
|
| 406 |
d = deal_defaults[i] if i < len(deal_defaults) else (0, None, 40.0)
|
| 407 |
-
mn = c1.number_input(f"Tier {i+1} min ACV",
|
|
|
|
| 408 |
is_last = i == int(num_deal_tiers) - 1
|
| 409 |
if is_last:
|
| 410 |
mx = None
|
| 411 |
c2.text("Uncapped")
|
| 412 |
else:
|
| 413 |
-
mx = c2.number_input(f"Tier {i+1} max ACV",
|
| 414 |
-
|
|
|
|
|
|
|
| 415 |
deal_rate_tiers.append((mn, mx, rt))
|
| 416 |
|
| 417 |
with st.sidebar.expander("Attainment Accelerators", expanded=True):
|
| 418 |
st.caption("Multiplier applied to deal commission based on annual attainment")
|
| 419 |
-
num_accels = st.number_input("Number of accelerator tiers", 1, 6,
|
|
|
|
| 420 |
accel_defaults = [(99, 1.0), (124, 1.3), (None, 1.5)]
|
| 421 |
for i in range(int(num_accels)):
|
| 422 |
c1, c2 = st.columns(2)
|
|
@@ -426,8 +448,10 @@ else:
|
|
| 426 |
c1.text("Above prior")
|
| 427 |
upper = None
|
| 428 |
else:
|
| 429 |
-
upper = c1.number_input(f"Accel {i+1} up to %",
|
| 430 |
-
|
|
|
|
|
|
|
| 431 |
accel_tiers.append((upper, mult))
|
| 432 |
|
| 433 |
# -- Ramp --
|
|
@@ -438,24 +462,29 @@ with st.sidebar.expander("Ramp Schedule", expanded=False):
|
|
| 438 |
"while getting up to speed. Unlike a draw, the rep still has to close "
|
| 439 |
"deals to earn variable comp. Set each month's quota as a % of full quota."
|
| 440 |
)
|
| 441 |
-
ramp_months = st.number_input("Ramp months", 0, 12,
|
|
|
|
| 442 |
ramp_pcts = []
|
| 443 |
ramp_defaults = [0, 0, 25, 25, 50, 50, 75, 75, 75]
|
| 444 |
for i in range(int(ramp_months)):
|
| 445 |
d = ramp_defaults[i] if i < len(ramp_defaults) else 75
|
| 446 |
-
pct = st.number_input(f"Month {i+1} quota %",
|
|
|
|
| 447 |
ramp_pcts.append(pct)
|
| 448 |
|
| 449 |
# -- Company economics --
|
| 450 |
with st.sidebar.expander("Company Economics", expanded=False):
|
| 451 |
-
cogs_pct = st.number_input("COGS (% of revenue)",
|
| 452 |
-
|
| 453 |
-
|
|
|
|
|
|
|
| 454 |
|
| 455 |
# -- Projection settings --
|
| 456 |
with st.sidebar.expander("Projection Settings", expanded=False):
|
| 457 |
st.caption("Attainment levels used when auto-generating plan projections.")
|
| 458 |
-
attainment_str = st.text_input("Attainment levels (%)",
|
|
|
|
| 459 |
attainment_levels = [int(x.strip()) for x in attainment_str.split(",") if x.strip().isdigit()]
|
| 460 |
if not attainment_levels:
|
| 461 |
attainment_levels = [75, 100, 150, 200]
|
|
@@ -496,15 +525,17 @@ if active_tab == "builder":
|
|
| 496 |
author = st.text_input("Plan author", key="author",
|
| 497 |
placeholder="e.g. 'Founder', 'VP Sales'",
|
| 498 |
help="A generic label for who created this plan — avoid real names")
|
| 499 |
-
months_employed = st.slider("Months in plan year", 1, 12,
|
| 500 |
-
help="Set to less than 12 for mid-year hires — ramp schedule adjusts the quota automatically"
|
|
|
|
| 501 |
|
| 502 |
effective_quota = calc_ramp_adjusted_quota(annual_quota, ramp_pcts, months_employed)
|
| 503 |
st.metric("Effective Quota (ramp-adjusted)", f"${effective_quota:,.0f}",
|
| 504 |
help="Annual quota reduced by the ramp schedule for months where quota is below 100%")
|
| 505 |
|
| 506 |
-
actual_revenue = st.number_input("Total Revenue Closed ($)",
|
| 507 |
-
help="Actual or projected closed revenue for the period"
|
|
|
|
| 508 |
attainment_pct = (actual_revenue / effective_quota * 100) if effective_quota > 0 else 0
|
| 509 |
|
| 510 |
# Commission uses full annual quota for tier boundaries
|
|
|
|
| 338 |
|
| 339 |
st.sidebar.caption("Adjust these to model different comp plan structures. Changes update results instantly.")
|
| 340 |
|
| 341 |
+
|
| 342 |
+
def _default(key, fallback):
|
| 343 |
+
"""Return {} if key is already in session_state (widget will use that), else set value=fallback."""
|
| 344 |
+
if key in st.session_state:
|
| 345 |
+
return {}
|
| 346 |
+
return {"value": fallback}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
with st.sidebar.expander("Compensation Structure", expanded=True):
|
| 350 |
+
base_salary = st.number_input("Base Salary ($)", step=5_000, key="base",
|
| 351 |
+
help="Annual base salary before any variable compensation",
|
| 352 |
+
**_default("base", 150_000))
|
| 353 |
+
annual_quota = st.number_input("Annual Quota ($)", step=50_000, key="quota",
|
| 354 |
+
help="Full-year revenue target at 100% attainment",
|
| 355 |
+
**_default("quota", 1_250_000))
|
| 356 |
|
| 357 |
with st.sidebar.expander("Draw", expanded=False):
|
| 358 |
st.caption(
|
|
|
|
| 361 |
"**Recoverable** = deducted from future commissions (an advance). "
|
| 362 |
"**Non-recoverable** = paid on top of whatever they earn."
|
| 363 |
)
|
| 364 |
+
draw_amount = st.number_input("Draw total ($)", step=5_000, key="draw",
|
| 365 |
+
help="Total draw amount spread over the draw period",
|
| 366 |
+
**_default("draw", 50_000))
|
| 367 |
+
draw_months = st.number_input("Draw duration (months)", step=1, key="draw_months",
|
| 368 |
+
**_default("draw_months", 12))
|
| 369 |
+
draw_recoverable = st.checkbox("Recoverable", key="draw_rec",
|
| 370 |
+
help="If recoverable, draw is deducted from earned commissions. If non-recoverable, it's paid on top.",
|
| 371 |
+
**_default("draw_rec", False))
|
| 372 |
|
| 373 |
st.sidebar.divider()
|
| 374 |
commission_mode = st.sidebar.radio(
|
|
|
|
| 388 |
retroactive_mode = False
|
| 389 |
if commission_mode == "Attainment-based rates":
|
| 390 |
with st.sidebar.expander("Commission Tiers (attainment)", expanded=True):
|
| 391 |
+
retroactive_mode = st.toggle("Retroactive rates", key="retroactive",
|
| 392 |
+
**_default("retroactive", False),
|
| 393 |
help="**Marginal** (off): each rate applies only to revenue in that band. "
|
| 394 |
"**Retroactive** (on): once a threshold is crossed, the higher rate applies to ALL revenue from dollar one. "
|
| 395 |
"Retroactive is much more expensive for the company.")
|
|
|
|
| 397 |
st.caption("Retroactive — highest tier reached applies to ALL revenue")
|
| 398 |
else:
|
| 399 |
st.caption("Marginal — each rate applies only to revenue in that band")
|
| 400 |
+
num_tiers = st.number_input("Number of tiers", 1, 8, key="num_tiers",
|
| 401 |
+
**_default("num_tiers", 4))
|
| 402 |
att_defaults = [(100, 4.0), (125, 5.0), (150, 6.0), (None, 7.0)]
|
| 403 |
for i in range(int(num_tiers)):
|
| 404 |
c1, c2 = st.columns(2)
|
|
|
|
| 409 |
c1.text(f"Tier {i+1}: above prior")
|
| 410 |
upper = None
|
| 411 |
else:
|
| 412 |
+
upper = c1.number_input(f"Tier {i+1} upper %", step=5, key=f"at_u_{i}",
|
| 413 |
+
**_default(f"at_u_{i}", d_upper or 100))
|
| 414 |
+
rate = c2.number_input(f"Tier {i+1} rate %", step=0.5, format="%.1f", key=f"at_r_{i}",
|
| 415 |
+
**_default(f"at_r_{i}", d_rate))
|
| 416 |
att_tiers.append((upper, rate))
|
| 417 |
else:
|
| 418 |
with st.sidebar.expander("Deal-Size Commission Rates", expanded=True):
|
| 419 |
+
num_deal_tiers = st.number_input("Number of deal-size tiers", 1, 6, key="num_deal_tiers",
|
| 420 |
+
**_default("num_deal_tiers", 3))
|
| 421 |
deal_defaults = [(0, 29_999, 20.0), (30_000, 100_000, 40.0), (100_001, None, 40.0)]
|
| 422 |
for i in range(int(num_deal_tiers)):
|
| 423 |
c1, c2, c3 = st.columns(3)
|
| 424 |
d = deal_defaults[i] if i < len(deal_defaults) else (0, None, 40.0)
|
| 425 |
+
mn = c1.number_input(f"Tier {i+1} min ACV", step=5_000, key=f"dt_mn_{i}",
|
| 426 |
+
**_default(f"dt_mn_{i}", d[0]))
|
| 427 |
is_last = i == int(num_deal_tiers) - 1
|
| 428 |
if is_last:
|
| 429 |
mx = None
|
| 430 |
c2.text("Uncapped")
|
| 431 |
else:
|
| 432 |
+
mx = c2.number_input(f"Tier {i+1} max ACV", step=5_000, key=f"dt_mx_{i}",
|
| 433 |
+
**_default(f"dt_mx_{i}", d[1] or 100_000))
|
| 434 |
+
rt = c3.number_input(f"Tier {i+1} rate %", step=1.0, format="%.1f", key=f"dt_rt_{i}",
|
| 435 |
+
**_default(f"dt_rt_{i}", d[2]))
|
| 436 |
deal_rate_tiers.append((mn, mx, rt))
|
| 437 |
|
| 438 |
with st.sidebar.expander("Attainment Accelerators", expanded=True):
|
| 439 |
st.caption("Multiplier applied to deal commission based on annual attainment")
|
| 440 |
+
num_accels = st.number_input("Number of accelerator tiers", 1, 6, key="num_accels",
|
| 441 |
+
**_default("num_accels", 3))
|
| 442 |
accel_defaults = [(99, 1.0), (124, 1.3), (None, 1.5)]
|
| 443 |
for i in range(int(num_accels)):
|
| 444 |
c1, c2 = st.columns(2)
|
|
|
|
| 448 |
c1.text("Above prior")
|
| 449 |
upper = None
|
| 450 |
else:
|
| 451 |
+
upper = c1.number_input(f"Accel {i+1} up to %", step=5, key=f"ac_u_{i}",
|
| 452 |
+
**_default(f"ac_u_{i}", d[0] or 100))
|
| 453 |
+
mult = c2.number_input(f"Accel {i+1} multiplier", step=0.1, format="%.1f", key=f"ac_m_{i}",
|
| 454 |
+
**_default(f"ac_m_{i}", d[1]))
|
| 455 |
accel_tiers.append((upper, mult))
|
| 456 |
|
| 457 |
# -- Ramp --
|
|
|
|
| 462 |
"while getting up to speed. Unlike a draw, the rep still has to close "
|
| 463 |
"deals to earn variable comp. Set each month's quota as a % of full quota."
|
| 464 |
)
|
| 465 |
+
ramp_months = st.number_input("Ramp months", 0, 12, key="ramp_months",
|
| 466 |
+
**_default("ramp_months", 9))
|
| 467 |
ramp_pcts = []
|
| 468 |
ramp_defaults = [0, 0, 25, 25, 50, 50, 75, 75, 75]
|
| 469 |
for i in range(int(ramp_months)):
|
| 470 |
d = ramp_defaults[i] if i < len(ramp_defaults) else 75
|
| 471 |
+
pct = st.number_input(f"Month {i+1} quota %", step=5, key=f"ramp_{i}",
|
| 472 |
+
**_default(f"ramp_{i}", d))
|
| 473 |
ramp_pcts.append(pct)
|
| 474 |
|
| 475 |
# -- Company economics --
|
| 476 |
with st.sidebar.expander("Company Economics", expanded=False):
|
| 477 |
+
cogs_pct = st.number_input("COGS (% of revenue)", step=5.0, format="%.1f", key="cogs_pct",
|
| 478 |
+
**_default("cogs_pct", 20.0))
|
| 479 |
+
other_cost_per_rep = st.number_input("Other cost per rep ($)", step=5_000, key="other_cost",
|
| 480 |
+
help="Annual cost for benefits, tools, travel, etc. — pro-rated if less than 12 months",
|
| 481 |
+
**_default("other_cost", 20_000))
|
| 482 |
|
| 483 |
# -- Projection settings --
|
| 484 |
with st.sidebar.expander("Projection Settings", expanded=False):
|
| 485 |
st.caption("Attainment levels used when auto-generating plan projections.")
|
| 486 |
+
attainment_str = st.text_input("Attainment levels (%)", key="att_levels",
|
| 487 |
+
**_default("att_levels", "75, 100, 150, 200"))
|
| 488 |
attainment_levels = [int(x.strip()) for x in attainment_str.split(",") if x.strip().isdigit()]
|
| 489 |
if not attainment_levels:
|
| 490 |
attainment_levels = [75, 100, 150, 200]
|
|
|
|
| 525 |
author = st.text_input("Plan author", key="author",
|
| 526 |
placeholder="e.g. 'Founder', 'VP Sales'",
|
| 527 |
help="A generic label for who created this plan — avoid real names")
|
| 528 |
+
months_employed = st.slider("Months in plan year", 1, 12, key="months_emp",
|
| 529 |
+
help="Set to less than 12 for mid-year hires — ramp schedule adjusts the quota automatically",
|
| 530 |
+
**_default("months_emp", 12))
|
| 531 |
|
| 532 |
effective_quota = calc_ramp_adjusted_quota(annual_quota, ramp_pcts, months_employed)
|
| 533 |
st.metric("Effective Quota (ramp-adjusted)", f"${effective_quota:,.0f}",
|
| 534 |
help="Annual quota reduced by the ramp schedule for months where quota is below 100%")
|
| 535 |
|
| 536 |
+
actual_revenue = st.number_input("Total Revenue Closed ($)", step=50_000, key="rev",
|
| 537 |
+
help="Actual or projected closed revenue for the period",
|
| 538 |
+
**_default("rev", 1_250_000))
|
| 539 |
attainment_pct = (actual_revenue / effective_quota * 100) if effective_quota > 0 else 0
|
| 540 |
|
| 541 |
# Commission uses full annual quota for tier boundaries
|