# Test Data Seeding Guide

## Overview

This guide explains how to seed your database with test data for testing purposes. Two seed scripts are available:

1. **seeds.js** - Creates initial super admin user
2. **seed-test-data.js** - Creates 1000 test records for each main table

## Prerequisites

- Backend server stopped or not interfering
- Database connection configured in `.env`
- Tables already created in the database

## Usage

### Step 1: Create Super Admin (First Time Only)

```bash
npm run seed
```

This will:

- Create a super admin user with credentials:
  - Email: `admin@erp.local`
  - Password: `Admin@123456`

### Step 2: Seed 1000 Test Records (For Testing)

```bash
npm run seed:test
```

This will create:

- **10 Fiscal Years** - Multiple years for testing
- **50 Designations** - Various job titles
- **30 Departments** - Multiple departments
- **1000 Clients** - Full batch of test clients with:
  - Random designations and departments
  - Auto-generated serial numbers (CLIENT-0001 to CLIENT-1000)
  - Auto-generated account numbers (ACC-000001 to ACC-001000)
  - Active status
- **1000 Transactions** - One per client with:
  - Random fiscal years
  - Pending status
  - Created by admin user
- **1000+ Transaction Details** - Multiple entries per transaction with:
  - Random purposes (Salary, Bonus, Travel, etc.)
  - Random amounts (1000-51000 TK)
  - Random dates (within last 90 days)
- **4 User Requests** - Sample approval requests for testing

## Expected Output

```
🌱 Seeding 1000 test records for each table...

📅 Seeding Fiscal Years...
✅ Fiscal Years seeded (10 records)

👔 Seeding Designations...
✅ Designations seeded (50 records)

🏢 Seeding Departments...
✅ Departments seeded (30 records)

👥 Seeding Clients (1000 records)...
  100/1000 clients created...
  200/1000 clients created...
  [... continues ...]
✅ Clients seeded (1000 records)

💳 Seeding Transactions (1000 records)...
  [... progress ...]
✅ Transactions seeded (1000 records)

📝 Seeding Transaction Details (1000+ records)...
  [... progress ...]
✅ Transaction Details seeded (2500+ records)

✨ ALL TEST DATA SEEDED SUCCESSFULLY! ✨
```

## Testing in Frontend

After seeding:

1. Start your frontend: `npm run dev`
2. Login with admin credentials:
   - Email: `admin@erp.local`
   - Password: `Admin@123456`
3. Select a fiscal year
4. Navigate to:
   - **Dashboard** - See aggregated data
   - **Transactions** - View 1000 transaction records
   - **Clients** - View 1000 clients
   - **Designations** - View 50 designations
   - **Departments** - View 30 departments

## Notes

- Test data uses realistic names and values
- All clients are marked as "active"
- All transactions are marked as "pending" (not approved)
- Transaction amounts range from 1,000 to 51,000 TK
- Multiple entries per transaction for realistic testing
- Companies are auto-generated with names like "Tech Solutions", "Global Services", etc.

## Reset Data (Optional)

To completely reset the database:

1. Drop all tables (or delete the database)
2. Re-run database migrations/schema creation
3. Run `npm run seed`
4. Run `npm run seed:test`

## Troubleshooting

If you encounter errors:

1. **Connection Error** - Check `.env` file database credentials
2. **Table Not Found** - Ensure database schema is created first
3. **Foreign Key Error** - Tables must exist in correct order
4. **Duplicate Entry** - Don't run seed twice without resetting

## Performance Notes

- Seeding 1000 records typically takes 30-60 seconds
- Progress indicators displayed every 100 records
- Can be run multiple times (may cause duplicates)
