# AccountingReports Module - License System Update

**Update Date:** 2025-01-XX  
**Status:** ✅ COMPLETE

---

## Summary

The AccountingReports module has been updated to use the **same license and installation system** as the BusinessManagement module, with the license server URL set to **https://wefnf.com/**.

---

## Changes Made

### 1. ✅ Config File (`Config/config.php`)

**License Server Configuration:**
- `lic1`: `aHR0cHM6Ly93ZWZuZi5jb20vYXBpL2xpY2Vuc2UvdmFsaWRhdGU=` (Base64: https://wefnf.com/api/license/validate)
- `lic2`: `aHR0cHM6Ly93ZWZuZi5jb20vYXBpL3ZhbGlkYXRl` (Backup: https://wefnf.com/api/validate)
- `license_management_server`: `https://wefnf.com` ✅

**Status:** Already configured correctly - No changes needed

---

### 2. ✅ InstallController Updates (`Http/Controllers/InstallController.php`)

#### Added Features:

1. **Same Domain Reinstall Logic** ✅
   - Allows reinstall on the same domain even if module is already installed
   - Checks both System properties and database records for domain matching
   - Prevents installation on different domains for single licenses

2. **Domain Normalization** ✅
   - Added `normalizeDomain()` method
   - Handles:
     - `www.example.com` → `example.com`
     - `example.com:8080` → `example.com`
     - `localhost`, `127.0.0.1`, `::1` → `localhost`
     - Case-insensitive comparison
     - Port removal
     - Parentheses removal

3. **Enhanced License Validation** ✅
   - Checks license status (active, inactive, expired, revoked, suspended)
   - Validates expiry dates
   - Checks license type (single, multi, unlimited)
   - Enforces installation limits:
     - Single: 1 domain only
     - Multi: Maximum 10 domains
     - Unlimited: No limit

4. **License Server Detection** ✅
   - Detects if running on license server itself (wefnf.com)
   - Skips domain restrictions when on license server
   - Allows license server to run without restrictions

5. **Cross-Domain Sync** ✅
   - `notifyLicenseManagementServer()` method
   - Notifies https://wefnf.com when installation happens on other domains
   - API endpoint: `/api/license/notify-installation`

6. **Improved Domain Checking** ✅
   - Checks multiple sources:
     - Current license record's `install_domain`
     - System property `install_domain`
     - All database records with same license_code
   - Uses normalized domain comparison for accuracy

7. **Enhanced License Record Management** ✅
   - `updateOrCreateLicenseRecord()` with domain normalization
   - `getLicenseInstallationCount()` with normalized domain counting
   - `autoCheckExpiredLicenses()` for automatic expiry detection

---

### 3. ✅ Helper File (`Helpers/general_helper.php`)

**Status:** Already has local and remote license validation
- `accountingreports_license()` - Main license validation function
- `accountingreports_validate_local_license()` - Local database validation
- Uses config values: `accountingreports.lic1`, `accountingreports.lic2`
- License server URL: `https://wefnf.com` ✅

---

## Key Features

### License Validation Flow

1. **Local Validation First** (Primary)
   - Checks `module_licenses` table
   - Validates license status, expiry, type
   - Returns `true` if valid, `false` if invalid, `null` if not found

2. **Remote Validation** (Fallback)
   - Only if local validation returns `null` (not found)
   - Calls https://wefnf.com/api/license/validate
   - Handles various response formats

3. **Installation Checks**
   - License status validation
   - Expiry date checking
   - License type limits (single/multi/unlimited)
   - Domain matching with normalization

### Domain Normalization

The `normalizeDomain()` method ensures accurate domain comparison:

```php
// Examples:
'www.example.com' → 'example.com'
'example.com:8080' → 'example.com'
'localhost' → 'localhost'
'127.0.0.1' → 'localhost'
'Example.COM' → 'example.com'
```

### License Types

- **Single License**: Only 1 domain installation allowed
- **Multi License**: Maximum 10 domain installations
- **Unlimited License**: No domain limit

### Same Domain Reinstall

- Allows unlimited reinstalls on the same domain
- Checks normalized domains for matching
- Prevents installation on different domains for single licenses

---

## API Endpoints Used

1. **License Validation:**
   - Primary: `https://wefnf.com/api/license/validate`
   - Backup: `https://wefnf.com/api/validate`

2. **Installation Notification:**
   - `https://wefnf.com/api/license/notify-installation`

---

## Testing Checklist

- [ ] Install module with valid license
- [ ] Reinstall on same domain (should work)
- [ ] Try install on different domain with single license (should block)
- [ ] Test with multi license (should allow up to 10 domains)
- [ ] Test with expired license (should block)
- [ ] Test with suspended license (should block)
- [ ] Test domain normalization (www.example.com vs example.com)
- [ ] Test localhost variations (localhost, 127.0.0.1, ::1)
- [ ] Verify license server detection (wefnf.com should skip restrictions)

---

## Files Modified

1. ✅ `Modules/AccountingReports/Config/config.php` - Already configured
2. ✅ `Modules/AccountingReports/Http/Controllers/InstallController.php` - Updated
3. ✅ `Modules/AccountingReports/Helpers/general_helper.php` - Already configured

---

## Compatibility

- ✅ Compatible with UltimatePOS module system
- ✅ Uses same license system as BusinessManagement module
- ✅ Backward compatible with existing installations
- ✅ Supports both local and remote license validation

---

## Notes

- The license server URL is configured in `Config/config.php` as `license_management_server`
- All domain comparisons use normalized domains for accuracy
- License server (wefnf.com) can run without domain restrictions
- Cross-domain sync ensures license management server is updated when installations happen on other domains

---

**Update Completed By:** Senior Laravel Engineer  
**Date:** 2025-01-XX

