# Task D.6 Implementation Report - 2026-07-01

## Scope
- Separate CRM business `Activity` semantics from system-generated audit history.
- Rename CRM detail tabs that currently show system history from `Activity` to `Audit Log`.
- Improve follow-up date input UX with the shared calendar picker and stable `YYYY-MM-DD` display.
- Introduce a contract-first CRM Activity foundation without migrating existing follow-up storage in this phase.

## Review Summary
Reviewed before implementation:
- [AGENTS.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/AGENTS.md)
- [plans/task-d.6.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/plans/task-d.6.md)
- [docs/standards/project-foundations.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/project-foundations.md)
- [docs/standards/architecture-rules.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/architecture-rules.md)
- [docs/standards/ui-ux-rules.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/ui-ux-rules.md)
- [docs/standards/task-review-checklist.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/task-review-checklist.md)
- Related CRM detail, follow-up, and audit-log foundations under `src/features/crm/**` and `src/features/foundation/audit-log/**`

## Changes
- Added shared [audit-log-tab.tsx](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/crm/components/audit-log-tab.tsx) and [types.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/crm/audit-log/types.ts) for consistent CRM audit history rendering.
- Updated lead, opportunity, customer, and quotation detail views to label system history as `Audit Log`.
- Enriched CRM audit-log records in lead, opportunity, customer, and quotation services so UI can consume `beforeData`, `afterData`, and `requestId`.
- Standardized [crm-form-controls.tsx](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/crm/components/crm-form-controls.tsx) and [date-picker-field.tsx](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/components/forms/fields/date-picker-field.tsx) to show `YYYY-MM-DD` and allow clearing optional dates.
- Rebuilt [lead-followup-panel.tsx](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/crm/leads/components/lead-followup-panel.tsx) to use the shared date-picker field instead of plain text date entry.
- Added [src/features/crm/activity/types.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/crm/activity/types.ts) to define future activity entity scope, types, statuses, priorities, permission contracts, and overdue-status derivation.
- Added activity and audit-log permission keys in [rbac.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/lib/auth/rbac.ts).

## Verification
- `npm run typecheck` -> PASS
- `npm run build` -> PASS
- `npm run audit:pdf` -> PASS

## Known Follow-up
- Historical lead/opportunity/quotation follow-up rows still live in their existing tables and APIs; only the UX and activity contracts were prepared in this phase.
- `npm run build` still emits pre-existing Turbopack warnings about workspace root lockfile detection and NFT tracing around PDF audit/template validation paths. No new blocking build issue was introduced by D.6.

## Outcome
Task D.6 now reserves `Activity` for future MK/Sales business work, presents current system history as `Audit Log`, improves lead follow-up date entry with a proper calendar picker, and establishes the first reusable contracts for a future CRM activity module.
