# BO Signature Setup Controller Documentation

## Overview
The BO Signature Setup Controller provides functionality to generate BO Signature setup files according to the specified format requirements.

## Function: generateBoSignatureSetupFile

### Purpose
Generates BO Signature setup files with the following structure:
- File naming format: `06<DP ID (6)><date (8)>.<Running Serial Number (2)>`
- Example: `0606090016012017.01`, `0606090016012017.02`, etc.

### File Format

#### Control Record
- **Total Number of Records**: 7 digits (M - Mandatory)
- **Operator Id**: 6 characters (M - Mandatory) 
- **DP Id**: 6 digits (M - Mandatory)

#### Detail Record
- **BO ID**: 16 digits (M - Mandatory)
- **Purpose Code**: 2 digits (M - Mandatory)
  - 01: Individual
  - 02: Company
  - 03: Clearing
  - 04: Power of Attorney
  - 05: Heir
  - 06: Nominee
  - 07: Guardian
- **Serial Number**: 2 digits (M - Mandatory)
- **File Name**: 50 characters (M - Mandatory)

### API Endpoint
```
GET /api/file-gen/bo-signature-setup-file-generate
```

### Request Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| bo_in_id | integer | Yes | BO Initial Info ID |
| client_user_id | integer | Yes | Client User ID |
| bo_id | integer | Yes | BO ID |
| client_code | string | Yes | Client Code |
| purpose_code | numeric | Yes | Purpose Code (1-7) |
| users_id | integer | Yes | User ID for authentication |
| name | string | Yes | User name for authentication |
| email | string | Yes | User email for authentication |
| role | string | Yes | User role for authentication |
| post | string | Yes | User post for authentication |

### Response
- **Success**: Downloads a ZIP file containing:
  - Text file with the setup data
  - Images ZIP file containing signature images
- **Error**: JSON response with error details

### File Structure
The generated ZIP file contains:
```
{fileName}/
├── {fileName} (text file)
└── {uploadId}{dpId}{date}.zip (images zip)
```

### Image Naming Convention
Images are named using the format: `{bo_id}{purpose_code}{serial_number}.{extension}`

### Example Usage
```bash
curl -X GET "http://your-domain/api/file-gen/bo-signature-setup-file-generate" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "bo_in_id": 123,
    "client_user_id": 456,
    "bo_id": 7890123456789012,
    "client_code": "CL001",
    "purpose_code": 1,
    "users_id": 789,
    "name": "John Doe",
    "email": "john@example.com",
    "role": "admin",
    "post": "manager"
  }'
```

### Error Handling
- **422**: Validation failed
- **400**: User data missing
- **401**: Unauthenticated
- **403**: Token mismatch or user ID mismatch
- **404**: BO record not found or file not found

### Dependencies
- Laravel Storage
- ZipArchive
- Carbon for date formatting
- JWT Authentication

### Storage Location
Files are stored in: `storage/app/public/bo-signature-setup-files/`

### Notes
- The function automatically generates unique serial numbers for each file
- Signature images are downloaded from the specified URL and included in the ZIP
- The main ZIP file contains both the text file and images ZIP
- Temporary files are cleaned up after ZIP creation
