# Activity Deadlines Easy Guide (PBPS MIS)

This guide explains, in simple language, how activity deadlines work after the new implementation.

---

## 1) Big idea: what changed?

Old way:
- You had separate deadline columns/rows for `3 months`, `4 months`, `6 months`.

New way:
- Each activity has **duration-specific rules** (3m, 4m, 6m, etc.).
- The system calculates dates dynamically from an **anchor date + offsets**.
- This supports different TP start times without creating huge deadline tables.

---

## 2) Two activity scopes (current design)

There are only 2 scopes now:

1. **Provider-level**
   - One submission for the provider.
   - No training/cohort deadline window is required.
   - Typical examples: contract signing, inception report.

2. **Delivery-level**
   - Submission is tied to a training.
   - If training uses cohorts, submission is tied to cohort too.
   - Deadline windows are enforced here.
   - Typical examples: orientation delivered, post-training report.

Important:
- Provider-level activities do not need anchor/deadline setup.
- Delivery-level activities use activity deadline rules.

---

## 3) What the columns mean on Activity Deadlines page

For delivery-level activities:

- `Anchor`
  - Reference date used to compute deadlines.
- `Open +days`
  - Days added to anchor to compute open/start date.
- `End +days`
  - Days added to anchor to compute end date.
- `Due +days`
  - Days added to anchor to compute due date.
- `Grace (days)`
  - Extra days after end date where submission is still allowed.

How calculation works:
- `openDate = anchor + openOffsetDays`
- `endDate = anchor + endOffsetDays`
- `dueDate = anchor + dueOffsetDays`

Recommended practice:
- Use offsets only (fixed dates were removed from the system).

---

## 4) Anchor types (easy explanation)

`training_start`
- Uses the training start date.
- Most common for delivery-level activities.

`training_anchor`
- Uses training timeline anchor date (if set), otherwise training start date.
- Use when you need manual anchor shift at training level.

`cohort_start`
- Uses cohort start date.
- Best when activity should follow each cohort separately.

`cohort_anchor`
- Uses cohort timeline anchor date (if set), otherwise cohort start date.
- Use when you need manual anchor shift at cohort level.

Rule of thumb:
- Default globally to `cohort_start` for delivery activities.
- If a selected training has no cohorts, the backend gracefully falls back to training start/anchor logic for that training.
- This allows one global rule to work even when some TPs use cohorts and others do not.

What is "timeline anchor date"?
- It is an optional manual date override stored on each training/cohort (`timelineAnchorDate`).
- If not set, system uses normal start date.
- "Manual anchor shift" means changing timeline base date for one training/cohort without changing the real start date.
- Example: training started on May 1, but approved delay means schedule should count from May 10 -> set timeline anchor date to May 10.
- In UI, record this as **Actual Start** (outside create form, in training detail / cohort section).
- Option available: "Actual start is same as planned start" (clears anchor override).

---

## 5) Breakdown impact (important)

For delivery-level activities:
- Approved breakdown days are added to `endDate` and `dueDate`.
- Submission is blocked during active approved breakdown period (freeze behavior).
- Cohort breakdown affects only that cohort.
- Training-level breakdown affects training and all cohorts under it.

For provider-level activities:
- Breakdown does not drive submission windows (no delivery window enforcement).

---

## 6) How to set deadlines for 3/4/6 month trainings now

You no longer set separate columns for 3m/4m/6m in one matrix.

Instead:
1. Choose activity scope (`provider` or `delivery`).
2. For delivery activities, add one rule per duration (3m/4m/6m).
3. At runtime system selects:
   - the matching duration rule.
4. Dates are then computed from anchor + offsets for that selected rule.

Why this still works:
- A 3-month training started in April and a 6-month training started in June both get correct dates from their own anchor.
- Different start times are handled automatically.

Result:
- One activity can now have different timing policies for 3m vs 4m vs 6m without duplicating activities.

---

## 7) Practical examples

### Example A: Orientation session delivered
- Scope: `delivery`
- Anchor: `training_start` (or `cohort_start` if cohort-based)
- Open +days: `0`
- End +days: `14`
- Due +days: `21`
- Grace: `7`

Meaning:
- Opens on day 0 from start.
- Closes at day 14.
- Late flag after day 21.
- Can still submit until day 21+grace if allowed.

### Example B: Signed contract
- Scope: `provider`
- No delivery rule needed.

Meaning:
- Provider submits one evidence set (not per training/cohort).

---

## 8) Duration-specific rules (implemented)

Each delivery activity now requires duration-specific rules:
- `Duration rule = 3 months` -> applies only to 3-month trainings.
- `Duration rule = 4 months` -> applies only to 4-month trainings.
- `Duration rule = 6 months` -> applies only to 6-month trainings.

Rule selection:
1. Match training duration rule.
2. If no matched rule, submission is blocked with configuration error.

---

## 9) Step-by-step: what you should do now

1. Open `Activities -> Activity deadlines`.
2. For each activity, confirm scope first:
   - Provider-level: no strict delivery window setup required.
   - Delivery-level: configure anchor + offsets.
3. Use `Activities -> [Activity]` preview panel:
   - Select training (and cohort if needed).
   - Verify computed open/end/due dates.
4. Adjust offsets until dates match your policy.

---

## 10) Quick checklist before go-live

- Every activity has correct scope (`provider` or `delivery`).
- Delivery activities have sensible anchor and offsets.
- Cohort trainings tested with at least one cohort preview.
- Breakdown scenario tested (window extension + freeze behavior).
- TP can only see assigned activities.

---

## 11) Detailed scenarios (with cohorts, durations, anchors, breakdowns)

### Scenario A: Mixed providers in one project (some with cohorts, some without)

Setup:
- Activity: `post_placement_followup`
- Scope: `delivery`
- Rules:
  - 3m duration: `anchor = cohort_start`, `open +90`, `end +110`, `due +120`
  - 4m duration: `anchor = cohort_start`, `open +120`, `end +140`, `due +150`
- 6m duration: `anchor = cohort_anchor`, `open +150`, `end +170`, `due +180`

What happens:
- TP-A training has cohorts and duration=3m -> 3m rule is used; dates are based on each cohort start.
- TP-B training has cohorts and duration=4m -> 4m rule is used; dates are based on each cohort start.
- TP-C training has no cohorts and duration=6m -> 6m rule is used. If missing, submission is blocked until a 6m rule is added.
- No mismatch occurs because cohort-based anchors automatically fallback to training anchor/start when cohort is not selected/available.

### Scenario B: Same TP, two trainings with different durations

Setup:
- TP-D has:
  - Training T1: 3 months, starts 2026-05-01
  - Training T2: 4 months, starts 2026-06-15
- Activity has both 3m and 4m rules.

What happens:
- T1 submissions use 3m offsets from T1 anchor.
- T2 submissions use 4m offsets from T2 anchor.
- One activity definition, two timing policies, no duplicate activity rows needed.

### Scenario C: Cohort-level breakdown only

Setup:
- Training T3 (uses cohorts) has C1 and C2.
- Activity rule anchor is `cohort_start`.
- Approved breakdown for C2 only: 2026-08-01 to 2026-08-10.

What happens:
- C2:
  - submissions are frozen during 2026-08-01..2026-08-10,
  - `end` and `due` are extended by 10 days.
- C1:
  - unaffected (no freeze, no extension).
- Other trainings in same TP:
  - unaffected.

### Scenario D: Training-level breakdown with cohorts

Setup:
- Training T4 uses cohorts C1, C2, C3.
- Approved training-level breakdown (no cohort selected): 2026-09-01 to 2026-09-07.

What happens:
- All cohorts in T4 inherit freeze and extension (+7 days).
- Trainings outside T4 are unaffected.
- This is not TP-global blocking.

### Scenario E: Training anchor vs training start

Setup:
- Training starts 2026-05-01.
- Timeline anchor date manually set to 2026-05-10 after approved delayed mobilization.
- Rule uses `training_anchor`, open +0.

What happens:
- Open date is 2026-05-10 (not 2026-05-01).
- Real training start date remains unchanged for historical record.
- Only deadline computation shifts.

### Scenario F: Cohort anchor vs cohort start

Setup:
- Cohort C1 start=2026-07-01.
- Cohort timeline anchor manually set=2026-07-08.
- Rule uses `cohort_anchor`, due +60.

What happens:
- Due date computes from 2026-07-08.
- Useful when cohort was created but actual effective timeline starts later.

### Scenario G: Missing duration rule (exception)

Setup:
- Training duration is 6m.
- Activity has only 3m and 4m rules.

What happens:
- System cannot resolve a duration rule.
- Submission preview and submission are blocked with "No activity submission rule configured".

### Scenario H: Provider-level activity with breakdown (exception behavior)

Setup:
- Activity scope is `provider` (for example contract signing).
- Any breakdown exists on trainings/cohorts.

What happens:
- Provider-level activity does not use delivery window enforcement.
- Breakdown does not freeze provider-level activity submission.

---

If needed, a second guide can be added with a suggested default offset set for all 8 PBPS activities.
