# Wholesale Partner Types - Implementation Plan

## Overview
Enhance wholesale partner registration to support two categories with different KYC requirements.

## Database Changes

### 1. Add `wholesale_partner_type` column to customers table
```sql
ALTER TABLE customers 
ADD COLUMN wholesale_partner_type ENUM('local', 'international') NULL 
AFTER account_type;
```

### 2. Create `customer_documents` table for multiple document uploads
```sql
CREATE TABLE customer_documents (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    customer_id BIGINT UNSIGNED NOT NULL,
    document_type VARCHAR(100) NOT NULL,
    document_name VARCHAR(255) NOT NULL,
    file_path VARCHAR(500) NOT NULL,
    file_size INT UNSIGNED,
    mime_type VARCHAR(100),
    odoo_attachment_id INT UNSIGNED NULL,
    uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE,
    INDEX idx_customer_id (customer_id),
    INDEX idx_document_type (document_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
```

## Document Types Configuration

### In-Country Partners (Local)
1. company_profile - Company Profile
2. cr14 - CR14
3. certificate_of_incorporation - Certificate of Incorporation
4. tax_clearance - Tax Clearance
5. director_id_1 - Director National ID #1
6. director_id_2 - Director National ID #2
7. director_residence_1 - Director Proof of Residence #1
8. director_residence_2 - Director Proof of Residence #2
9. zimra_certificate - ZIMRA Registration Certificate
10. potraz_license - POTRAZ License

### International Partners
1. certificate_of_incorporation - Certificate of Incorporation or Business Registration
2. articles_of_association - Articles of Association or Memorandum of Association
3. shareholder_ids - Identification Documents of Shareholders
4. directors_list - List of Directors
5. tax_identification - Tax Identification Number (TIN)
6. nda_document - NDA Document
7. msa_document - MSA Document

## Backend Implementation

### Files to Create/Modify:

1. **Migration**: `database/migrations/xxxx_add_wholesale_partner_types.php`
2. **Model**: `app/Models/CustomerDocument.php` (new)
3. **Controller**: Update `app/Http/Controllers/API/AuthController.php`
4. **Request**: `app/Http/Requests/WholesaleRegistrationRequest.php` (update)
5. **Service**: Update `app/Services/OdooService.php` for document uploads
6. **Email**: Update `app/Mail/WholesaleRegistrationNotification.php`
7. **Email Template**: Update `resources/views/emails/wholesale-registration.blade.php`
8. **Config**: `config/wholesale.php` (new) - document type definitions

## Frontend Implementation

### Files to Create/Modify:

1. **Registration Page**: `afinet-portal/src/app/(auth)/register/page.js`
   - Add tabs for Local/International selection
   - Conditional field rendering based on partner type
   - Multiple document upload component

2. **Document Upload Component**: `afinet-portal/src/components/forms/document-upload.jsx` (new)
   - Reuse KYC modal pattern
   - Support multiple files per document type
   - File validation (size, type)
   - Preview and remove functionality

3. **API Service**: `afinet-portal/src/services/api.js`
   - Update registration endpoint to handle FormData
   - Document upload endpoints

## API Endpoints

### New/Updated Endpoints:

```
POST /api/auth/register/wholesale
- Accepts multipart/form-data
- Fields: all registration fields + wholesale_partner_type
- Files: multiple documents based on partner type

POST /api/customers/{id}/documents
- Upload additional documents after registration

GET /api/customers/{id}/documents
- Retrieve customer documents list

DELETE /api/customers/{id}/documents/{documentId}
- Remove a document
```

## Odoo Integration

### Document Upload to Odoo:
- Use `ir.attachment` model
- Link attachments to partner record
- Set `res_model='res.partner'` and `res_id=partner_id`
- Include document type in attachment name/description

### Partner Type Field:
- Add custom field `x_wholesale_partner_type` to res.partner
- Values: 'local' or 'international'

## Email Template Updates

### Wholesale Registration Email:
- Show partner type (Local/International)
- List all uploaded documents with types
- Include document count
- Add section for missing documents (if any)

## Validation Rules

### File Upload:
- Max file size: 10MB per file
- Allowed types: PDF, JPG, JPEG, PNG, DOC, DOCX
- Required documents based on partner type
- Minimum 1 file per document type

### Form Validation:
- Partner type selection required
- All required documents must be uploaded
- File size and type validation
- Duplicate document type prevention

## UI/UX Flow

### Registration Form:

```
┌─────────────────────────────────────────┐
│  WHOLESALE PARTNER REGISTRATION         │
├─────────────────────────────────────────┤
│                                         │
│  ┌──────────┐  ┌──────────────────┐   │
│  │  LOCAL   │  │  INTERNATIONAL   │   │
│  └──────────┘  └──────────────────┘   │
│     (Active)         (Inactive)        │
│                                         │
│  Company Information                    │
│  ├─ Company Name                       │
│  ├─ Registration Number                │
│  ├─ Email                              │
│  └─ Phone                              │
│                                         │
│  Required Documents                     │
│  ├─ Company Profile        [Upload]    │
│  ├─ CR14                   [Upload]    │
│  ├─ Certificate of Inc.    [Upload]    │
│  └─ ... (based on type)                │
│                                         │
│  [Submit Registration]                  │
└─────────────────────────────────────────┘
```

### Document Upload Modal:
```
┌─────────────────────────────────────────┐
│  Upload: Company Profile                │
├─────────────────────────────────────────┤
│                                         │
│  ┌─────────────────────────────────┐  │
│  │  Drag & drop files here         │  │
│  │  or click to browse             │  │
│  │                                  │  │
│  │  Accepted: PDF, JPG, PNG, DOC   │  │
│  │  Max size: 10MB                 │  │
│  └─────────────────────────────────┘  │
│                                         │
│  Uploaded Files:                        │
│  ✓ company_profile.pdf (2.3 MB)  [×]  │
│                                         │
│  [Cancel]  [Upload]                    │
└─────────────────────────────────────────┘
```

## Implementation Steps

### Phase 1: Database & Backend (Priority)
1. Create migration for wholesale_partner_type column
2. Create customer_documents table migration
3. Create CustomerDocument model
4. Update AuthController registration logic
5. Create document upload service methods
6. Update Odoo integration for documents
7. Update wholesale registration email

### Phase 2: Frontend
1. Update registration form with tabs
2. Create document upload component
3. Implement conditional document requirements
4. Add file validation and preview
5. Update API service calls
6. Test end-to-end flow

### Phase 3: Testing & Refinement
1. Test local partner registration
2. Test international partner registration
3. Verify Odoo document uploads
4. Test email notifications
5. Validate all documents uploaded correctly

## Next Steps

Would you like me to:
1. Start with the database migrations?
2. Create the backend API endpoints first?
3. Build the frontend components?
4. Or proceed with all phases sequentially?
