# Client Information Import Feature

## Overview
This feature allows you to import and update client information in bulk using Excel files. You can update any column from either the `clients` table or the `clientsinfo` table by uploading an Excel file with usernames and the corresponding data.

## How to Access
Navigate to: `/client-info-import`

## How It Works

### 1. **Excel File Format**
The Excel file must have exactly 2 columns:
- **Column 1 (username)**: The client's username (userid) in the system
- **Column 2 (information)**: The value you want to update for that client

Example:
```
| username | information        |
|----------|--------------------|
| user001  | John Doe          |
| user002  | Jane Smith        |
| user003  | Bob Johnson       |
```

### 2. **Column Selection**
Before uploading, select which field you want to update from the dropdown menu. The dropdown is organized into two groups:

#### Client Table Fields:
- POP ID
- Billing Cycle
- Package ID
- MAC Address
- Password
- IP Address
- Expire Date
- Required Cable
- Client Approval
- Client Status
- Marketed By
- Sub Package ID
- Customer ID
- Payment Deadline
- Permanent Discount

#### Client Information Table Fields:
- Client Name
- Father Name
- Mother Name
- Flat No
- Building Name
- Road No
- Block/Sector
- Area
- District
- Thana
- Contact No
- National ID
- Email
- Passport No
- Owner Name
- Owner Number
- OLT PON
- OTC
- Building No
- Remarks
- Date of Birth
- Cable Type
- Road Name
- OTC Due
- Other Contact
- Box
- Join Date
- Latitude
- Longitude
- Client Door
- CAT Type
- CAT Length
- OLT No
- PON Port
- ONU Serial
- Cable ID
- Customer Package Name
- BTRC Package Bandwidth
- Source Name

### 3. **Import Process**
1. Download the sample Excel file
2. Fill in your data (username and information columns)
3. Select the target column from the dropdown
4. Upload your Excel file
5. Click "Import Data"

### 4. **Results**
After import, you'll see:
- **Success Count**: Number of records successfully updated
- **Error List**: Detailed list of any errors encountered (with row numbers)

## Important Notes

### Data Format Guidelines:
- **Usernames**: Must exactly match the client's username in the system
- **Date Fields**: Use format YYYY-MM-DD (e.g., 2026-01-29)
- **Numeric Fields**: Use numbers only, no special characters
- **Text Fields**: Plain text without special formatting

### Error Handling:
- If a username is not found, that row will be skipped
- If the information value is empty, that row will be skipped
- Rows with errors are skipped, but other valid rows are still processed
- All errors are reported with specific row numbers

### Security:
- The import validates that the username exists before updating
- Only the specified column is updated (no other fields are modified)
- The system automatically determines if the column belongs to the `clients` or `clientsinfo` table

## Files Created

1. **Import Class**: `app/Imports/ClientInfoImport.php`
   - Handles the Excel file processing
   - Validates data
   - Updates the appropriate table

2. **Controller**: `app/Http/Controllers/ClientInfoImportController.php`
   - Displays the import form
   - Processes the import
   - Generates sample Excel file

3. **View**: `resources/views/clients/clientInfoImport.blade.php`
   - User interface for the import feature
   - Shows import results
   - Provides instructions and help

4. **Routes**: Added to `routes/web.php`
   - GET `/client-info-import` - Show import form
   - POST `/client-info-import` - Process import
   - GET `/client-info-import/download-sample` - Download sample file

## Usage Examples

### Example 1: Update Client Names
1. Select "Client Name" from dropdown
2. Upload Excel with:
```
| username | information  |
|----------|-------------|
| user001  | John Doe    |
| user002  | Jane Smith  |
```

### Example 2: Update Contact Numbers
1. Select "Contact No" from dropdown
2. Upload Excel with:
```
| username | information   |
|----------|--------------|
| user001  | 01712345678  |
| user002  | 01812345678  |
```

### Example 3: Update Email Addresses
1. Select "Email" from dropdown
2. Upload Excel with:
```
| username | information           |
|----------|-----------------------|
| user001  | john@example.com     |
| user002  | jane@example.com     |
```

## Troubleshooting

### Common Issues:

1. **"Client with username 'xxx' not found"**
   - The username doesn't exist in the system
   - Check for typos in the username
   - Verify the username is correct

2. **"Information value is required"**
   - The second column is empty
   - Make sure all rows have data in both columns

3. **"Invalid column mapping"**
   - The selected column doesn't exist
   - This shouldn't happen if using the dropdown

4. **File upload fails**
   - Check file format (.xlsx, .xls, or .csv only)
   - Ensure file is not corrupted
   - Try re-saving the Excel file

## Support
For any issues or questions, please contact the development team.
