# Trust Preview Document - Complete Sections Guide

## Overview
The Trust Preview template now displays ALL trust-related information from the database, covering all 11 trust tables available in the system.

## Sections Displayed in Trust Preview

### 1. **Document Header & Client Info**
- Trust Document ID and Status
- Client Name and Creation Date
- Document Type (Trust Deed)
- Action buttons (Back, Print)

### 2. **FIRST: TRUST ESTABLISHMENT**
- Establishes and creates the Trust
- Governed by Malaysian law

### 3. **SECOND: BENEFICIARIES AND DISTRIBUTION**
- Lists all trust beneficiaries
- Full Name, Type (Individual/Entity), and IC/Reg Number
- **Database Table**: `trust_beneficiaries`

### 4. **THIRD: SPECIFIC BEQUESTS OF ASSETS**
- All trust assets listed with descriptions
- Asset types, locations, and values
- Total aggregate value calculated
- **Database Table**: `trust_assets`

### 5. **FOURTH: TRUSTEES**
- Appointed trustees of the trust
- Trustee type and identification numbers
- **Database Table**: `trust_trustees`

### 6. **FOURTH-A: CARETAKERS** *(if applicable)*
- Trust caretakers/managers
- Roles and contact information
- **Database Table**: `trust_caretakers`

### 7. **FIFTH: ALLOWANCES**
- Regular allowances for beneficiaries
- Amount and frequency (Monthly/Quarterly/Annually)
- **Database Table**: `trust_allowances`

### 8. **FIFTH-A: ADMINISTRATOR ALLOWANCES** *(if applicable)*
- Special allowances for trust administrators
- Management fees or compensation
- **Database Table**: `trust_administrator_allowances`

### 9. **FIFTH-B: GUARDIAN ALLOWANCES** *(if applicable)*
- Allowances for appointed guardians
- Frequency of payment
- **Database Table**: `trust_guardian_allowances`

### 10. **SIXTH: GIFTS**
- Specific gifts bequeathed by the trust
- Recipients and gift descriptions
- Values of each gift
- **Database Table**: `trust_gifts`

### 11. **SEVENTH: DONATIONS**
- Charitable donations directed
- Organization names
- Donation amounts and purposes
- **Database Table**: `trust_donations`

### 12. **EIGHTH: RESIDUAL ESTATE**
- All remaining estate not specifically bequeathed
- Distribution to beneficiaries as specified

### 13. **Signature Block**
- Testator/Settlor signature line
- Date and formal attestation

### 14. **Footer**
- Document reference number
- Generation timestamp

## Database Tables Covered

| # | Table | Records Displayed |
|---|-------|------------------|
| 1 | `trusts` | Main trust document |
| 2 | `trust_beneficiaries` | Beneficiary listings |
| 3 | `trust_assets` | Asset details |
| 4 | `trust_trustees` | Trustee information |
| 5 | `trust_caretakers` | Caretaker details |
| 6 | `trust_allowances` | Regular allowances |
| 7 | `trust_administrator_allowances` | Admin compensation |
| 8 | `trust_guardian_allowances` | Guardian payments |
| 9 | `trust_gifts` | Gift bequests |
| 10 | `trust_donations` | Charitable donations |
| 11 | `trust_version_history` | (Versioning tracked) |

## Data Handling

- **Null Safety**: All sections check for data existence before rendering
- **Collections**: Properly converts database collections to arrays for template display
- **Conditional Display**: Sections only show if data exists (count > 0)
- **Safe Field Access**: Uses null coalescing operators (??) to handle missing fields
- **Formatting**: Currency values formatted as RM with 2 decimal places

## Controller Integration

The `LawyerController::previewDocument()` method:
1. Determines if document is Will or Trust
2. Loads ALL required relationships for trusts
3. Passes data as both collections and arrays for template compatibility
4. Handles authorization checks
5. Routes to appropriate template based on document type

## Features

✅ Unified preview format for both Wills and Trusts
✅ All trust-specific sections included
✅ Professional legal document layout
✅ Print-friendly formatting
✅ Proper null/empty checks throughout
✅ Supports all trust data from 11 database tables
✅ Date handling for trust creation vs will dates
