Term of Payment Calculator
Calculates the final TOP for transporter invoices based on baseline TOP and penalties for late POD / ePOD submissions.
Formula
- ▶ podDelay = min( max(podLateDays, 0), 30)
- ▶ epodDelay = min( max(epodLateDays, 0), 30)
- ▶ penalty = podDelay + epodDelay
- ▶ total = baselineTop + penalty
- ▶ result = min(total, 45)
Try It
All 8 Test Cases
8 / 8 passing| # | Baseline | POD Late | ePOD Late | Expected | Note |
|---|---|---|---|---|---|
| 1 | 7 | 5 | 3 | ✓ 15 | Basic: 7 + 5 + 3 = 15 |
| 2 | 10 | 35 | 25 | ✓ 45 | POD capped → 10+30+25=65 → 45 |
| 3 | 20 | 30 | 30 | ✓ 45 | Both at max → 20+30+30=80 → 45 |
| 4 | 14 | 0 | 0 | ✓ 14 | No penalty, baseline only |
| 5 | 5 | -2 | 0 | ✓ 5 | Negative POD treated as 0 |
| 6 | 15 | 20 | 15 | ✓ 45 | Total 50 exceeds max cap |
| 7 | 10 | 30 | 0 | ✓ 40 | POD at max, ePOD = 0 |
| 8 | 45 | 0 | 0 | ✓ 45 | Baseline at max, no penalty |
a) Why cap POD and ePOD individually rather than the total penalty?
Individual caps enforce a per-document-type fairness rule: neither a very late physical POD nor a very late ePOD can impose more than 30 days of penalty on its own. If only the total were capped at 30, one extremely late document could consume the entire penalty budget, hiding the other document's lateness. Individual caps make each document's contribution independently bounded.
b) What would happen without the final 45-day cap?
The maximum possible result would be baseline + 30 + 30 = baseline + 60. A transporter with a 30-day baseline and both documents 45 days late would wait 90 days for payment — causing cash-flow crises, inability to cover fuel and salaries, and potential supply-chain disruption. The 45-day cap is a business viability safeguard.
c) How would you make the caps configurable?
Two approaches: (1) config/top.php reading from .env — zero DB overhead, values change per environment without a deploy; (2) a top_config DB table with a 5-minute cache — allows runtime changes via a back-office UI without a deploy. Start with config files; promote to DB if a live-editing requirement emerges.