# Lumina Invoicing - Project Documentation & Changelog

## 1. Bulk Customer & Vehicle Import Feature

### Overview
A seamless CSV/Excel bulk import functionality designed to ingest complex multi-field customer data (80+ parameters) straight into the database without requiring distinct schema columns for every possible field.

### Key Components

*   **Database Schema (`customers` table):**
    *   Added standard columns: `email`, `phone`, `company_name`, `gstin`.
    *   Added a `JSON` column named `extended_data` to store the vast array of unstructured CSV data (e.g., Vehicle specs, VAH columns, Pricing ledgers).
*   **Customer Model (`app/Models/Customer.php`):**
    *   Configured the `$casts` property for `extended_data` to cast to `array`.
    *   This ensures the raw JSON string is effortlessly transformed into a queryable PHP array for Blade and Vue to consume.
*   **Import Logic (`app/Imports/CustomersImport.php`):**
    *   Utilizes `Maatwebsite\Excel` to read uploaded `.csv` or `.xlsx` files via the `ToCollection` and `WithHeadingRow` traits.
    *   Dynamically maps specific standard keys (like Name, Phone, Email, Company, GSTIN, Address).
    *   Dumps the complete row structure into the `extended_data` JSON payload so no data point is lost during the import, future-proofing against shifting CSV headers.

---

## 2. Customer Profile Dashboard (UI/UX)

### Overview
A comprehensive single-page dashboard built using **Vue.js**, **Inertia.js**, and **Tailwind CSS**. It segments over 80 customer-related data points into logical, navigable tabs without requiring a page reload.

### Structure (`resources/js/Pages/Customers/Show.vue`)
*   **Tab System:**
    *   *Profile Details:* Core contact and billing info.
    *   *General Details:* Sales metrics, outlet codes, invoice parameters.
    *   *Vehicle Details:* Model specs, VIN, Chassis, and Engine values.
    *   *VAH Details:* Registration authority data, finance records.
    *   *Pricing & Tax Details:* GST arrays, CESS %, Taxable values.
    *   *Discounts & Finance:* Hypothecation logs, CRM charges, corp discounts.
    *   *Enquiry Details:* Lead sources, old car trade-in valuations.
*   **`getExtendedVal()` Helper Function:**
    *   Implemented a robust JavaScript dictionary lookup that performs **case-insensitive** and **space-insensitive** matching against the `extended_data` object.
    *   *Why this matters:* If a CSV import creates a key `CUST GST NUMBER`, but a user types `cust_gst_number` or the export tool alters formatting, the UI will successfully bind the data.
*   **Live Saving:**
    *   Vue reactive `useForm()` sends a `PUT` request directly to `CustomerController@update` so that any changes made within the segmented tabs are preserved instantly.

---

## 3. Subdirectory Deployment Configuration (Fixing the 404 Bug)

### Overview
When deploying a Laravel + Vite + Inertia application into a subdirectory environment (e.g. `http://localhost/Invoice/public` under XAMPP), the frontend asset compiler and the client-side SPA router miscalculate the document root.

### The Problem
*   **Vite Assets 404:** Vite compiled JavaScript/CSS to the root domain (`http://localhost/build/...`) instead of the correct subdirectory path.
*   **Inertia URL Doubling 404:** The `inertia-laravel` library mistakenly concatenated `$request->getBaseUrl()` with `$request->getRequestUri()`, causing the client-side router to attempt navigation to `http://localhost/Invoice/public/Invoice/public/customers`.

### The Fixes
1.  **Vite Configuration (`vite.config.js`):**
    *   Explicitly defined `base: '/Invoice/public/build/'` to ensure all asset manifests construct absolute paths relative to the XAMPP directory root.
2.  **Inertia Package Patch (`vendor/inertiajs/inertia-laravel/src/Response.php`):**
    *   Adjusted line 102 from:
        `'url' => $request->getBaseUrl().$request->getRequestUri(),`
    *   To precisely reference the request boundary:
        `'url' => $request->getRequestUri(),`
    *   *Result:* SPA routing in XAMPP seamlessly hydrates without duplicate URI segments. 

---
*Documentation automatically generated and appended at current milestone.*
