# AccountingReports License Troubleshooting Guide

## Issue: "License not found" Error

If you're getting the error **"License not found. Please generate a license via License Management or contact support."** even though you've created a license on https://wefnf.com/, follow these steps:

---

## Step 1: Verify License in Database

Check if the license exists in the `module_licenses` table:

```sql
SELECT * FROM module_licenses 
WHERE module_name = 'accountingreports' 
AND license_code = 'YOUR_LICENSE_CODE';
```

**Check these fields:**
- ✅ `license_code` - Must match exactly (case-sensitive)
- ✅ `username` - This is what you need to enter during installation
- ✅ `email` - Can also be used if username doesn't work
- ✅ `status` - Must be 'active' or 'inactive' (not 'expired', 'revoked', or 'suspended')
- ✅ `expiry_date` - Should be 'lifetime' or a future date

---

## Step 2: Check Username/Email Matching

The validation now supports:
- ✅ **Case-insensitive username matching**
- ✅ **Email matching** (if username doesn't match)
- ✅ **License code only** (if username/email don't match)

**What to enter during installation:**
1. **License Code:** `BM-A6DB-5539-39C9-3580` (exact match, case-sensitive)
2. **Username:** Try one of these:
   - The `username` field from the database
   - The `email` field from the database (if username doesn't work)
   - Example: `sashamrat1@gmail.com` (if that's the email in the database)

---

## Step 3: Check License Status

**Status must be 'active' or 'inactive':**
- ✅ `active` - License is active and can be installed
- ✅ `inactive` - License is inactive but can be installed (will become active after installation)
- ❌ `expired` - License has expired (cannot install)
- ❌ `revoked` - License has been revoked (cannot install)
- ❌ `suspended` - License has been suspended (cannot install)

**To activate an inactive license:**
1. Go to License Management on https://wefnf.com/
2. Find your license
3. Change status from 'inactive' to 'active'
4. Or use the "Actions" button to activate it

---

## Step 4: Verify License Code Format

**Your License Code:** `BM-A6DB-5539-39C9-3580`

**During installation, enter:**
- License Code: `BM-A6DB-5539-39C9-3580` (exact match, including dashes and case)
- Username: Try the email `sashamrat1@gmail.com` or the username from database

---

## Step 5: Check Logs

Check Laravel logs for detailed error messages:

```bash
tail -f storage/logs/laravel.log
```

Look for entries like:
- `AccountingReports: Local license validated successfully`
- `AccountingReports: License not found by username, trying with email`
- `Local license validation: License is valid`

---

## Common Issues & Solutions

### Issue 1: Username Doesn't Match

**Problem:** The username you're entering doesn't match what's in the database.

**Solution:**
1. Check the database to see what username is stored:
   ```sql
   SELECT username, email FROM module_licenses 
   WHERE license_code = 'BM-A6DB-5539-39C9-3580';
   ```
2. Use the exact username from the database (case-insensitive now)
3. Or use the email address as username

### Issue 2: License Status is Inactive

**Problem:** License exists but status is 'inactive'.

**Solution:**
- ✅ **Good news:** Inactive licenses are now allowed for installation
- The license will automatically become 'active' after successful installation
- If it still doesn't work, manually activate it in License Management

### Issue 3: License Code Mismatch

**Problem:** License code doesn't match exactly.

**Solution:**
- Copy the license code exactly from License Management
- Check for:
  - Extra spaces
  - Case differences
  - Missing dashes
  - Wrong characters

### Issue 4: License Not in Database

**Problem:** License was created on https://wefnf.com/ but not in local database.

**Solution:**
1. The license should sync automatically
2. If not, manually add it to the database:
   ```sql
   INSERT INTO module_licenses (
       module_name, license_code, username, email, 
       license_type, expiry_date, status, created_at, updated_at
   ) VALUES (
       'accountingreports', 
       'BM-A6DB-5539-39C9-3580', 
       'YOUR_USERNAME', 
       'sashamrat1@gmail.com',
       'single', 
       NULL, 
       'inactive', 
       NOW(), 
       NOW()
   );
   ```

---

## Updated Validation Logic

The system now:

1. ✅ **Tries username first** (case-insensitive)
2. ✅ **Tries email if username doesn't match**
3. ✅ **Tries license code only** (if username/email don't match)
4. ✅ **Allows 'inactive' status** for installation
5. ✅ **Automatically activates** license after installation

---

## Quick Test

To test if your license will work:

1. **Check database:**
   ```sql
   SELECT * FROM module_licenses 
   WHERE module_name = 'accountingreports' 
   AND license_code = 'BM-A6DB-5539-39C9-3580';
   ```

2. **During installation, try:**
   - License Code: `BM-A6DB-5539-39C9-3580`
   - Username: `sashamrat1@gmail.com` (the email from your license)

3. **If still doesn't work:**
   - Check the `username` field in the database
   - Use that exact username (case-insensitive)

---

## Need More Help?

If the issue persists:
1. Check Laravel logs: `storage/logs/laravel.log`
2. Look for "AccountingReports" entries
3. Check the exact error message
4. Verify license exists in database with correct status

---

**Last Updated:** 2025-01-XX

