# Global Invoice Scheme Prefixes - User Guide

## Overview
The Global Invoice Scheme Prefixes feature allows you to apply consistent invoice prefixes across all business locations for different transaction types (Expense, Purchase, Purchase Return).

## How to Use

### Step 1: Access Business Location Settings
1. Navigate to **Business Settings** → **Business Locations**
2. Click the **Edit** button for any business location
3. Scroll down to the **Global Invoice Scheme Prefixes** section

### Step 2: Enter Prefixes
You will see three rows for different transaction types:

| Transaction Type | Prefix Field | Apply Button |
|-----------------|--------------|--------------|
| Expense | Enter expense prefix (e.g., "EXP-") | Apply |
| Purchase | Enter purchase prefix (e.g., "PUR-") | Apply |
| Purchase Return | Enter purchase return prefix (e.g., "PR-") | Apply |

### Step 3: Apply Prefixes
1. **Enter a prefix** in the desired field (e.g., "EXP-" for expense invoices)
2. **Click the Apply button** next to that field
3. **Confirm the action** when prompted
4. The system will apply this prefix to ALL business locations

## Important Notes

### Prefix Persistence
- **Fixed Issue**: Prefixes now persist and display correctly when you return to edit the page
- Current prefixes are fetched from your existing invoice schemes
- Empty fields indicate no prefix has been set for that transaction type

### Validation
- **Empty Prefix Error**: If you click Apply without entering a prefix, you'll see: "Please enter a prefix for [transaction type] before applying."
- **Visual Feedback**: Empty fields will be highlighted with a red border
- **Auto-focus**: The system will automatically focus on the empty field

### What Happens When You Apply
1. **Existing Schemes**: If invoice schemes already exist, their prefixes are updated
2. **New Schemes**: If no scheme exists, a new one is created with:
   - Name: "[Transaction Type] Scheme - [Your Prefix]"
   - Scheme Type: Blank
   - Start Number: 1
   - Total Digits: 4

### Best Practices
1. **Use Consistent Format**: 
   - Good: "EXP-", "PUR-", "PR-"
   - Avoid: "exp", "Purchase", spaces in prefixes

2. **Unique Prefixes**: Use different prefixes for each transaction type to avoid confusion

3. **Test First**: Apply to a test location first if you're unsure

## Troubleshooting

### Issue: "Please enter a prefix first" Error
**Solution**: Enter a prefix in the field before clicking Apply. The field cannot be empty.

### Issue: Prefix Not Showing After Edit
**Status**: ✅ **FIXED** - Prefixes now correctly display when you return to edit the page.

### Issue: Changes Not Applied to All Locations
**Solution**: The Apply button affects ALL business locations. Make sure you have the necessary permissions.

## Example Usage

### Scenario: Setting Up Invoice Prefixes
1. **Expense Prefix**: Enter "EXP-" → Click Apply
2. **Purchase Prefix**: Enter "PUR-" → Click Apply  
3. **Purchase Return Prefix**: Enter "PR-" → Click Apply

**Result**: 
- Expense invoices will be numbered: EXP-0001, EXP-0002, etc.
- Purchase invoices will be numbered: PUR-0001, PUR-0002, etc.
- Purchase return invoices will be numbered: PR-0001, PR-0002, etc.

## Technical Details

### Database Storage
- Prefixes are stored in the `invoice_schemes` table
- Business locations reference these schemes via foreign keys:
  - `expense_invoice_scheme_id`
  - `purchase_invoice_scheme_id` 
  - `purchase_return_invoice_scheme_id`

### Permissions Required
- `business_settings.access` permission is required to use this feature

---
*Last Updated: April 15, 2026*
