# Corporate Wallets Overview

The corporate expense manager supports dedicated wallets that hold funds at the account level. These wallets are used when issuing and topping up employee wallets so that every disbursement is traceable back to a corporate-controlled balance.

## Data model

- **CorporateAccountWallet** (`backend/app/Models/CorporateAccountWallet.php`) links a corporate account to its underlying `Wallet` model.
- The migration `2025_10_01_000500_create_corporate_account_wallets_table.php` seeds a wallet for each existing corporate account and ensures future accounts can create funding wallets.
- All transactions generated when issuing or topping up employee wallets are written to the shared `transactions` table with metadata describing the employee recipient and administrator that initiated the action.

## Funding flow

1. Administrators load funds into a corporate wallet through the admin portal (`backend/app/Http/Controllers/AdminController.php`).
2. When a corporate portal user issues a new employee wallet or performs a top-up (`backend/app/Http/Controllers/Corporate/EmployeeWalletController.php`), the requested amount is deducted from the corporate wallet and credited to the employee wallet inside a single database transaction.
3. Both the corporate wallet and the employee wallet receive mirrored transaction records so statements stay in sync.

## Portal capabilities

The Vue-based corporate portal exposes these capabilities:

- **Corporate dashboard** (`expense-manager/src/views/DashboardView.vue`) lists recent disbursements and allows exporting a CSV of the corporate wallet statement.
- **Wallet detail pages** (`expense-manager/src/views/WalletDetailView.vue`) display employee wallet statements with export support.
- **Employees view** (`expense-manager/src/views/EmployeesView.vue`) enables issuing wallets and performing top-ups, automatically debiting the corporate wallet.
- **Login** (`expense-manager/src/views/LoginView.vue`) authenticates users via email and password only.

## Exporting statements

Both corporate and employee wallet statements are downloadable in CSV format:

- Corporate export endpoint: `GET /api/corporate/account-wallets/{wallet}/statement/export` handled by `AccountWalletController::export`.
- Employee export endpoint: `GET /api/corporate/employees/{employee}/wallets/{wallet}/statement/export` handled by `EmployeeWalletController::statementExport`.
- The frontend calls these endpoints and uses `expense-manager/src/utils/download.js` to trigger the file download.

## Operational checklist

- Run Laravel migrations (`php artisan migrate`) after deploying updates that include wallet changes.
- Verify admin funding workflows and CSV exports in staging to confirm statement formatting and balances.

