# Corporate Operational Readiness

## Status

Corporate module is ready for controlled production usage after Phase 7.5 QA hardening.

Covered scope:

- B2B lead intake and conversion to `Organization`
- proposals
- agreements
- corporate cohorts
- trainees
- sessions and attendance
- final reports
- invoices
- corporate payments
- payment allocations
- credit notes
- allocation reversals
- private receipt/PDF downloads
- executive corporate dashboard

## End-to-End Workflow

1. Public user submits `/corporate` or `/b2b`.
2. Admin reviews the B2B lead.
3. Admin converts the lead to an `Organization`.
4. Admin creates and sends a corporate proposal.
5. Proposal is accepted or rejected.
6. Accepted proposal is converted into an agreement.
7. Agreement PDF is generated, sent for signature, signed, and activated.
8. Active agreement produces a corporate cohort.
9. Admin imports or adds corporate trainees.
10. Admin generates sessions.
11. Teacher/admin marks attendance.
12. Admin generates the final report PDF.
13. Admin creates and issues an invoice.
14. Admin confirms corporate payment.
15. Admin allocates payment to invoice.
16. Admin applies a credit note when a safe unpaid-balance adjustment is needed.
17. Admin reverses allocation only through auditable reversal, never deletion.
18. Admin monitors receivables.
19. Organization portal members see only their own reports and invoices.

## Roles and Permissions

Key admin permissions:

- `corporate_dashboard.view`
- `b2b.leads.view`
- `corporate_proposals.*`
- `corporate_agreements.*`
- `corporate_cohorts.*`
- `corporate_reports.*`
- `corporate_invoices.*`
- `corporate_payments.*`
- `corporate_credit_notes.*`
- `corporate_receivables.view`

Finance visibility:

- `corporate_finance.view` is required for sensitive financial dashboard values.
- Support can view operational records by default but cannot review payments, allocate payments, reverse allocations, or view finance widgets unless explicitly granted.

Org portal:

- organization members must have active membership in the selected organization,
- reports require `org.reports.view`,
- invoices and receipt downloads require `org.invoices.view`,
- tenancy middleware rejects stale or cross-organization session selections.

## Daily Operational Checklist

Morning:

- Review new B2B leads.
- Check leads without follow-up.
- Review proposals expiring soon.
- Check agreements waiting for signature.
- Review payments pending finance approval.

During training delivery:

- Confirm trainees are imported.
- Confirm sessions are generated.
- Confirm attendance is being marked.
- Watch corporate cohort readiness checklists.

Finance:

- Issue invoices only after validating line items.
- Confirm payment only after finance review.
- Allocate payments only to invoices from the same organization.
- Use credit notes only against unpaid balances.
- Use allocation reversal for corrections; never delete allocations or revenue transactions silently.
- Monitor receivables and overdue invoices.

## Finance Safety Rules

- Revenue is recognized only when a confirmed payment allocation is created.
- Allocation reversals create negative financial transactions with `source_type=corporate_payment_allocation_reversal`.
- Credit notes reduce invoice net total and balance only within unpaid balance.
- Original allocations and financial transactions remain auditable.
- Invoice, report, agreement, proposal, credit note, and receipt files remain private.

## Production-Ready Areas

- Route and permission coverage for corporate admin and org portal pages.
- Organization is the canonical B2B customer model.
- Private file delivery through controllers and policies.
- End-to-end regression coverage for the complete corporate workflow.
- Executive dashboard with finance-aware visibility.
- Operational checklists on lead, proposal, agreement, cohort, and invoice detail pages.

## Known Limitations

- No payment gateway for corporate invoices yet.
- No public expiring download links.
- No partial allocation reversal.
- No advanced VAT/tax credit note accounting.
- No full ERP ledger or credit note line-item accounting.
- No automated PDF final delivery signature workflow.

## Verification

Phase 7.5 adds:

- `tests/Feature/Corporate/CorporateEndToEndOperationalTest.php`
- `tests/Feature/Corporate/CorporateDashboardTest.php`

These tests verify the full workflow, dashboard permissions, finance visibility, and legacy Company avoidance in active corporate code.
