# Supplier Quick Add Feature

## Overview
Added inline supplier creation capability to Purchase Order forms, similar to how customer quick-add works in Quotes and Invoices.

## Changes Made

### 1. Updated Views

#### `/views/purchaseorders/create.php`
- Replaced form generator with explicit HTML form
- Added supplier dropdown with "New" button
- Included quick-add supplier modal

#### `/views/purchaseorders/edit.php`
- Added "New" button next to supplier dropdown
- Included quick-add supplier modal

### 2. Created Modal Component

#### `/views/partials/quick_add_supplier_modal.php`
- Bootstrap modal for quick supplier creation
- Fields included:
  - Company Name (required)
  - Contact Person
  - Email (required)
  - Phone
  - Payment Terms (dropdown)
- JavaScript function `saveQuickSupplier()` to handle AJAX submission
- Auto-populates supplier dropdown after successful creation
- Shows success notification

### 3. Added Controller Endpoint

#### `SupplierController::quickAdd()`
- Location: `/controllers/SupplierController.php`
- Route: `POST /suppliers/quick-add`
- Features:
  - Authentication check
  - Permission check (`purchases.create`)
  - CSRF validation
  - Creates supplier with minimal required fields
  - Returns JSON response with supplier data
  - Status defaults to 'active'

### 4. Added Route

#### `/public/index.php`
- Added route: `$router->post('/suppliers/quick-add', 'SupplierController@quickAdd');`

## Usage

### For Users
1. Go to **Purchases > Orders > Create** (or Edit)
2. Click the **"New"** button next to the Supplier dropdown
3. Fill in the quick-add form:
   - **Company Name** (required)
   - **Email** (required)
   - Contact Person (optional)
   - Phone (optional)
   - Payment Terms (optional)
4. Click **"Add Supplier"**
5. The new supplier is automatically added to the dropdown and selected

### For Developers
The quick-add modal can be included in any view that needs supplier selection:
```php
<?php include BASE_PATH . '/views/partials/quick_add_supplier_modal.php'; ?>
```

The supplier dropdown must have an `id` of one of:
- `supplierSelect`
- `supplier_id`
- Or the name attribute `supplier_id`

## Technical Details

### API Endpoint
- **URL**: `/suppliers/quick-add`
- **Method**: POST
- **Authentication**: Required
- **Permission**: `purchases.create`
- **Request Format**: FormData
  ```
  company_name: string (required)
  contact_person: string (optional)
  email: string (required)
  phone: string (optional)
  payment_terms: string (optional)
  ```
- **Response Format**: JSON
  ```json
  {
    "success": true,
    "supplier": {
      "id": 123,
      "company_name": "ABC Corp",
      "email": "contact@abc.com",
      ...
    }
  }
  ```

### Dependencies
- Bootstrap 5 (for modal)
- JavaScript Fetch API
- CSRF token validation
- Database model: `Supplier::create()` and `Supplier::getById()`

## Benefits
1. **Improved workflow**: No need to leave the purchase order form to add suppliers
2. **Faster data entry**: Quick form with only essential fields
3. **Consistent UX**: Matches the customer quick-add pattern in quotes/invoices
4. **Full record creation**: Can add complete details later in supplier management

## Future Enhancements
- Add address fields to quick-add form
- Support for tax ID entry
- Duplicate detection based on email/company name
- Recent suppliers quick-select
