# Create a Corrective Quotation (Spare Parts)

> **Important Note:** This data is added within the Supply Chain customer quotation at: `https://demo.rzain.com.tr/supplychain/customer-quotations`  
> It applies when the request belongs to the Maintenance department — these fields appear in that context.

---

## User Story

**As** a sales officer  
**I want** to create a quotation for a fault repair  
**So that** I can obtain the client's approval before carrying out the repair

---

## Operational Scenario

### Entry Point

- From within the registered fault report → "Create Quotation" button

### Main Flow

1. The sales officer sees the requests that have completed pricing
2. Clicks "Create Quotation"
3. The system automatically pulls the fault and contract data
4. The required spare parts and purchase prices are displayed
5. The visit cost is entered
6. Clicks "Save"

---

## Fields & Data

### Screen: Corrective Quotation

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

| Field | Type |
|-------|------|
| Related Contract Number | Auto |
| Client Name | Auto |
| Location | Auto |
| Faulty Asset | Auto |
| Fault Description | Auto |
| Fault Photos | Auto |

#### Section 2 — Repair Pricing

**Spare Parts Table:**

| Column | Type |
|--------|------|
| Part Name | Text |
| Part Number | Text |
| Brand | Text |
| Asset Unit Number | Text |
| Quantity | Number |
| Unit Cost | Currency |
| Total | Currency (Auto) |

**Additional Fields:**

| Field | Type |
|-------|------|
| Corrective Visit Cost | Currency |

**Additional Costs Table:**

| Column | Type |
|--------|------|
| Cost Type | Dropdown (Transport / Logistics / Additional Labour Hours) |
| Value | Currency |
| + Add Cost | Button |

**Totals:**

| Field | Type |
|-------|------|
| Subtotal (before tax) | Currency (Auto) |
| Tax (15%) | Currency (Auto) |
| Grand Total | Currency (Auto) |

#### Section 3 — Execution Terms

| Field | Type | Notes |
|-------|------|-------|
| Quotation Validity | Date | |
| Expected Repair Duration | Number + Dropdown | Hours / Days |
| Does the asset need to be shut down during repair? | Toggle | |
| Repair Warranty Terms | Textarea | |

---

## Buttons

| Button | Action |
|--------|--------|
| Save as Draft | |
| Save & Send to Client | |
| Preview PDF | |

---

## Acceptance Criteria

- **AC1:** All Section 1 data is pulled automatically from the fault report and cannot be edited
- **AC2:** The "Total" field for each part is calculated automatically = Quantity × Unit Cost
- **AC3:** "Subtotal" is calculated automatically = sum of parts + visit cost + additional costs
- **AC4:** "Tax" is calculated automatically = Subtotal × 15%
- **AC5:** "Grand Total" is calculated automatically = Subtotal + Tax
- **AC6:** When "Save & Send to Client" is clicked, the quotation is saved with status "Pending Client Approval" and a notification is sent to the client
- **AC7:** The system generates an automatic reminder after 7 days if the client has not responded

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

Listed directory Domains
Listed directory Supply
Listed directory SubDomains
Searched for "PendingCustomerReminder"
Listed directory Maintenance
Listed directory Jobs
Viewed SendPriceOfferReminderJob.php:1-76
Viewed MaintenanceRequest.php:1-502
Searched for "notify"
Listed directory Listeners
Listed directory Services
Searched for "CustomerQuotation"

The audit for the **Corrective Quotation (Spare Parts)** feature is complete. This feature is primarily implemented within the `MaintenancePriceOffer` module, specifically handling "corrective" type offers derived from fault reports.

### Audit Report: Corrective Quotation (Spare Parts)

[Create a Corrective Quotation (Spare Parts)]
✅ **Implemented:**
- **Auto-populated Data (AC1):** The system links the quotation to the original `MaintenanceRequest` (Fault Report), providing access to the client name, location, faulty asset, description, and photos (via relations).
- **Pricing Calculations (AC2 - AC5):** 
    - **Part Totals:** Calculated individually as `Quantity × Unit Cost`.
    - **Subtotal:** Sum of parts, visit cost, and additional costs (logistics/labor) is handled in `MaintenancePriceOfferService::calculateTotals`.
    - **Tax & Grand Total:** Automatic tax calculation (default 15%) and grand total summation are implemented.
- **Additional Costs:** The system supports an additional costs table where types (Transport, Labour, etc.) and values can be added and included in the subtotal.
- **Execution Terms:** Fields for validity date, repair duration, asset shutdown toggle, and warranty terms are present in the model and validated.
- **7-Day Reminder (AC7):** Implemented via `SendPriceOfferReminderJob` and the `scopePendingCustomerReminder` on the model. It automatically tracks reminder counts and sends notifications every 7 days (up to 3 times).

❌ **Missing:**
- **Initial Client Notification (AC6):** While the state transition to `pending_customer_approval` exists, no explicit logic was found to trigger the **initial notification** to the client upon clicking "Save & Send" (unlike the reminder job which is fully implemented).

⚠️ **Partially Implemented:**
- **Status Terminology:** The specification uses "Pending Client Approval", whereas the implementation uses `pending_customer_approval`. 

---

### Audited Files Updated:

I have stored the audit report for this feature in the artifacts directory.

[Corrective_Quotation_Audit.md](file:///C:/Users/rzain/.gemini/antigravity/brain/4c7b187a-0f99-49b6-9cff-3ad0e70da5a0/Corrective_Quotation_Audit.md)

I am waiting for your next feature or request. Please say "Done" when you are finished.

Edited Corrective_Quotation_Audit.md

The audit for the **Corrective Quotation (Spare Parts)** feature is complete.

The implementation successfully handles the complex pricing logic and the automated reminder system (AC7). The main finding is the absence of the initial client notification trigger (AC6) in the backend service.

### Audit Summary: Corrective Quotation (Spare Parts)

[Create a Corrective Quotation (Spare Parts)]

✅ **Implemented:**
- **Automated Pricing:** Part calculations (AC2), subtotal aggregation (AC3), tax application (AC4), and grand total summation (AC5) are all handled automatically in `MaintenancePriceOfferService`.
- **Fault Data Integration:** Section 1 fields (Asset, Description, Photos) are linked via the `maintenanceRequest` model relationship (AC1).
- **Automated Reminders:** A scheduled job (`SendPriceOfferReminderJob`) is implemented to send reminders every 7 days if the client hasn't responded, capped at 3 reminders (AC7).
- **Execution Metadata:** Full support for repair duration, asset shutdown toggles, and warranty terms.

❌ **Missing:**
- **Initial Notification:** While the status logic is present, the specific trigger to notify the client the moment a quotation is sent (AC6) is missing from the service layer.

⚠️ **Partially Implemented:**
- **Status Naming:** The implementation uses `pending_customer_approval` as the status for quotations awaiting client response.

The full report is available here: [Corrective_Quotation_Audit.md](file:///C:/Users/rzain/.gemini/antigravity/brain/4c7b187a-0f99-49b6-9cff-3ad0e70da5a0/Corrective_Quotation_Audit.md)

I am waiting for your next feature or request. Please say "Done" when you are finished.