Pre-Sale Module

Quotations & Sales Pipeline

v2.0
Module Documentation Pre-Sale

Pre-Sale Management Module

This module covers the entire customer engagement lifecycle before a sale is finalized, from initial inquiry to sales booking, with distinct flows for cash and lease customers.

Data Structure (ERD)

erDiagram
    %% --- MAIN DOCUMENTS ---
    sale_quotations {
        bigint id PK
        string quotation_number
        enum quotation_type "CASH_SALE, LEASE_SALE"
        date quotation_date
        date valid_until
        foreignId branch_id FK
        string customer_name
        decimal grand_total
        enum quotation_status "DRAFT, PENDING, APPROVED, CONVERTED..."
        timestamp created_at
    }

    sale_quotation_items {
        bigint id PK
        foreignId quotation_id FK
        foreignId item_variant_id FK
        decimal quoted_qty
        foreignId quoted_unit_id FK
        decimal unit_price
        decimal line_total
    }

    sale_bookings {
        bigint id PK
        string booking_number
        enum booking_type "CASH_SALE, LEASE_SALE"
        enum reference_type "SALE_QUOTATION, DEFAULT"
        bigint reference_id "Nullable FK to Quotation"
        date booking_date
        foreignId branch_id FK
        string customer_name
        decimal total_amount
        enum booking_status "DRAFT, APPROVED, CONVERTED..."
        timestamp created_at
    }

    sale_booking_items {
        bigint id PK
        foreignId booking_id FK
        foreignId item_variant_id FK
        decimal booking_qty
        foreignId booking_unit_id FK
        decimal unit_price
        decimal line_total
    }

    %% --- CONFIGURATION & MASTER DATA ---
    customer_groups {
        bigint id PK
        string group_name
        text description
        boolean is_active
    }

    item_cash_sale_prices {
        bigint id PK
        foreignId item_variant_id FK
        foreignId branch_id FK
        string price_list_code
        decimal salesman_price
        decimal retail_price
        decimal fixed_price
        enum default_price_type "salesman, retail, fixed"
        boolean change_price
        datetime effective_date
    }

    item_plans {
        bigint id PK
        foreignId item_variant_id FK
        foreignId branch_id FK
        string item_plan_code
        string name
        decimal installment_price
        decimal installment_advance
        integer duration_months
        decimal monthly_installment
        boolean is_active
    }

    %% --- RELATIONSHIPS ---
    sale_quotations ||--o{ sale_quotation_items : "contains"
    sale_bookings   ||--o{ sale_booking_items : "contains"
    
    sale_quotations ||--o| sale_bookings : "converts to"
    
    %% Implicit Relationships (Master Data usage)
    item_cash_sale_prices ||--o{ sale_quotation_items : "provides rate for Cash Sale"
    item_cash_sale_prices ||--o{ sale_booking_items : "provides rate for Cash Sale"
    
    item_plans ||--o{ sale_quotation_items : "provides terms for Lease Sale"
    item_plans ||--o{ sale_booking_items : "provides terms for Lease Sale"

    %% Grouping (Logical)
    customer_groups }|..|{ sale_quotations : "can apply discount rules"
                            

Quotation to Booking Flow

sequenceDiagram
    autonumber
    actor Sales as Sales Officer
    participant GUI as Livewire
(CreateQuotation) participant Svc as PreSaleService participant Repo as QuotationRepository participant BKRepo as BookingRepository participant Appr as ApprovalEngine participant DB as Database Sales->>GUI: Create Quotation GUI->>Svc: create(data) activate Svc Svc->>Repo: create(data) Svc->>Appr: checkSetupExists('CREATE', SaleQuotation::class) alt Approval Needed Svc->>Repo: updateStatus(PENDING) else Auto Approved Svc->>Repo: updateStatus(APPROVED) end Svc-->>GUI: Quotation Created deactivate Svc Sales->>GUI: Convert to Booking GUI->>Svc: convertToBooking(quotation_id) activate Svc Svc->>DB: Begin Transaction Svc->>Repo: find(quotation_id) Svc->>BKRepo: create(from_quotation_data) Svc->>Repo: updateStatus(CONVERTED) Svc->>DB: Commit Transaction Svc-->>GUI: Booking Created deactivate Svc

Lifecycle State

stateDiagram-v2
    state Quotation {
        [*] --> Draft_Q : Created
        Draft_Q --> Pending_Q : Submitted
        Pending_Q --> Approved_Q : Manager Approves
        Pending_Q --> Rejected_Q : Manager Rejects
        Approved_Q --> Converted : Booking Created
        Approved_Q --> Cancelled_Q : Expired/Cancelled
    }

    state Booking {
        [*] --> Draft_B : From Quotation/Direct
        Draft_B --> Pending_B : Submitted
        Pending_B --> Approved_B : Confirmed
        Pending_B --> Rejected_B : Denied
        Approved_B --> Completed : Fulfilled (Sale/Lease)
        Approved_B --> Cancelled_B : Customer Cancelled
    }
                            

Business Process Flowchart

flowchart TD
    Start([Start]) --> Lead{New Enquiry}
    
    Lead -- Direct Booking --> NewBooking
    Lead -- Needs Quote --> NewQuote
    
    subgraph Quotation Process
        NewQuote[Create Sale Quotation]
        NewQuote --> CalcTax[Calculate Tax & Totals]
        CalcTax --> ApprQuote{Approval?}
        ApprQuote -- Yes --> WaitAppr[Wait for Approval]
        ApprQuote -- No --> SendQuote[Send to Customer]
        WaitAppr -- Approved --> SendQuote
        
        SendQuote --> CustAction{Customer Decision}
        CustAction -- Reject --> Lost([Lost Lead])
        CustAction -- Accept --> Convert[Convert to Booking]
    end

    subgraph Booking Process
        Convert --> NewBooking[Create Sale Booking]
        NewBooking --> CheckStock[Check Stock Availability]
        CheckStock -- Available --> Confirm[Confirm Booking]
        CheckStock -- Low Stock --> Backorder[Backorder / Wait]
        
        Confirm --> OrderType{Order Type}
        OrderType -- Cash Sale --> CashInv[Generate Cash Invoice]
        OrderType -- Lease --> LeaseProc[Start Lease Processing]
    end
    
    CashInv --> End([End])
    LeaseProc --> End