# Corporate Phase 2: Proposals

## Scope

Phase 2 adds official technical and financial proposals for the B2B workflow. It does not implement agreements. Agreement conversion is intentionally left as a disabled Phase 3 placeholder.

## Canonical Data Model

- `CorporateProposal` is linked to `organizations.id` and/or `b2b_leads.id`.
- `Organization` remains the canonical institution model.
- `EventOffer`, `companies`, `users.company_id`, and `agreement_path` are not used for new corporate features.
- A proposal can be drafted against an unconverted B2B lead, but the UI warns admins that Organization conversion is recommended before contracting.

## Workflow

- `draft -> sent`
- `sent -> accepted`
- `sent -> rejected`
- `sent -> expired`
- `accepted -> converted_to_agreement` is reserved for Phase 3.

When a proposal is marked as sent, the related lead moves to `proposal_sent` if it is still in `new`, `contacted`, `qualified`, or `proposal_needed`.

## Financial Rules

Proposal totals are calculated server-side:

- `subtotal_dzd` is the sum of item totals.
- `discount_dzd` and `tax_dzd` are proposal-level adjustments.
- `total_amount_dzd = subtotal - discount + tax`, with a minimum of zero.

Discount line items are supported, but the proposal-level discount remains the primary field for commercial adjustments.

## PDF Storage

Generated PDFs are stored privately:

`storage/app/private/corporate/proposals/{reference}.pdf`

Downloads go through an authenticated route protected by `corporate_proposals.download_pdf`.

## Permissions

- `corporate_proposals.view`
- `corporate_proposals.create`
- `corporate_proposals.update`
- `corporate_proposals.send`
- `corporate_proposals.accept`
- `corporate_proposals.reject`
- `corporate_proposals.generate_pdf`
- `corporate_proposals.download_pdf`

Admins and super admins receive all proposal permissions. Support users receive view-only access by default.

## Notifications

The workflow logs non-blocking messaging records:

- `admin_corporate_proposal_sent`
- `corporate_proposal_sent`
- `admin_corporate_proposal_accepted`
- `admin_corporate_proposal_rejected`

Messaging failures are reported but do not block the proposal workflow.

## Remaining For Phase 3

- Agreement data model.
- Proposal-to-agreement conversion.
- Contract PDF and signature flow.
- Corporate cohort provisioning from accepted agreements.
