# US-002: Create a Preventive Maintenance Quotation

> **Note:** Same as the current maintenance quotations, but with the missing fields added.

---

## User Story

**As** a sales officer  
**I want** to create a preventive maintenance quotation from an approved pricing request  
**So that** I can send a complete financial offer to the client

---

## Operational Scenario

### Main Flow

1. The technical supervisor approves the pricing request
2. The sales officer opens the approved request
3. Clicks "Create Quotation"
4. The system automatically pulls the request data
5. The sales officer fills in the pricing details
6. Specifies what is and is not included in the quotation
7. Specifies contract terms
8. Clicks "Save" or "Export PDF"

---

## Fields & Data

### Screen: Create Preventive Quotation

#### Section 1 — Auto-Populated Data (Read Only)

| Field | Type |
|-------|------|
| Pricing Request Number | Auto |
| Client Name | Auto |
| Location(s) | Auto |
| System Type | Auto |
| Does it include chiller or package unit? | Auto |
| Number of Units | Auto |
| Required Frequency | Auto |
| Contract Duration | Auto |

#### Section 2 — Pricing

| Field | Type | Notes |
|-------|------|-------|
| Package Unit / Chiller Visit Cost | Currency | Priced per client's unit type. Chiller is priced under a separate contract from the package unit. |
| Annual Number of Visits | Number | Auto-calculated from frequency = visits × units |
| Total Visit Cost | Currency | Auto |
| Are consumables included? | Toggle | |
| If Yes → Consumables Cost | Currency | |

#### Section 3 — Contract Terms

| Field | Type | Notes |
|-------|------|-------|
| Payment Method | Dropdown | Upfront / Monthly / Quarterly / Upon Execution |
| Payment Schedule | Table | Amount — Due Date (optional) |
| Quotation Validity | Date | |

---

## Buttons

| Button | Action |
|--------|--------|
| Save as Draft | Saves without submitting for approval |
| Save & Submit for Approval | Saves and sends notification to approver |
| Preview PDF | Opens instant preview without saving |
| Export PDF | Exports a downloadable PDF file |

---

## Acceptance Criteria

- **AC1:** All Section 1 data is pulled automatically from the pricing request and cannot be edited
- **AC2:** "Annual Number of Visits" is calculated automatically based on the selected frequency
- **AC3:** "Total Visit Cost" is calculated automatically = (visit cost × number of visits × number of units)
- **AC4:** "Chiller Visit Cost" field appears only if "Does it include chiller? = Yes"
- **AC5:** The consumables section appears only if the "Are consumables included?" toggle = Yes
- **AC6:** When "Save as Draft" is clicked, the quotation is saved with status "Draft" and is not submitted for approval
- **AC7:** When "Save & Submit for Approval" is clicked, the quotation is saved with status "Pending Approval" and a notification is sent to the approver
- **AC8:** After each edit to the quotation post-save, the system creates a new version (Version) while retaining previous versions
- **AC9:** "Preview PDF" opens an instant preview of the quotation without saving
- **AC10:** "Export PDF" exports a downloadable PDF file
- **AC11:** The "Quotation Validity" field cannot be set to a past date
- **AC12:** The system prevents deletion of any quotation that has been sent to the client, and only allows creating a new version

===================================

# Audit Report: US-002 - Create Preventive Quotation

[US-002: Create a Preventive Maintenance Quotation]

✅ **Implemented:**
- **AC1 (Auto-Population):** Snapshot logic in `createPreventivePriceOffer` pulls all required fields from the Technical Offer.
- **AC2 (Visits Calculation):** `annual_visits_count` is calculated automatically: `Frequency Factor (12/4/2/1) * Unit Count`.
- **AC3 (Visit Cost Calculation):** `total_visits_cost` correctly multiplies unit visit costs by unit count and frequency.
- **AC5 (Consumables Toggle):** `is_consumables_included` logic is integrated into total calculations.
- **AC7 (Submit for Approval):** Status transition to `pending_approval` exists with workflow support.
- **AC8 (Versioning):** `createNewVersion` method implementation provides full sequence tracking and history.
- **AC9/10 (PDF Support):** `generatePdf` and `downloadPdf` methods are fully functional.
- **AC11 (Validity Date):** Validation rule `after_or_equal:today` prevents past dates.

❌ **Missing:**
- **AC12 (Delete Restriction):** No guard logic exists in the `delete` method or controller to prevent deleting "Sent" or "Approved" quotations.

⚠️ **Partially Implemented / Differently:**
- **AC6 (Status Naming):** The code uses `pending_pricing` as the draft status instead of "Draft".
- **AC4 (Conditional Pricing):** Backend allows pricing fields for chillers regardless of flags, though calculation logic handles the specific cases correctly.
