149 lines
4.2 KiB
Markdown
149 lines
4.2 KiB
Markdown
# Electricity Bill Compliance Validator
|
|
|
|
## Overview
|
|
This application validates electricity bills according to ANEEL Resolution 1000/2021 (REN 1000/2021). It ensures that bills issued by electricity distributors comply with all regulatory requirements, tariff calculations, and consumer rights.
|
|
|
|
## Regulatory Compliance
|
|
This validator implements the rules defined in [ANEEL Resolution 1000/2021](https://www2.aneel.gov.br/cedoc/ren20211000.html), which establishes the General Conditions for Electricity Supply. The validation covers all aspects of billing as defined in Chapter VIII of the resolution.
|
|
|
|
## Features
|
|
- ✅ Basic Validation
|
|
- ✅ Consumption Calculation
|
|
- ✅ Demand Charges
|
|
- ✅ Reactive Energy
|
|
- ✅ Seasonal Tariffs
|
|
- ✅ Public Lighting
|
|
- ✅ ICMS Tax
|
|
- ✅ Municipal Taxes
|
|
- ✅ Flag System
|
|
- ✅ Subsidies and Discounts
|
|
- ✅ Additional Charges
|
|
- ✅ Payment Terms
|
|
- ✅ Emergency Situations (Art. 350-354)
|
|
|
|
## Input
|
|
The system accepts a `BillComplianceRequest` containing:
|
|
- Bill identification (SmartCode)
|
|
- Distributor information
|
|
- Consumer group and subgroup
|
|
- Reading dates and values
|
|
- Consumption details
|
|
- Tariff components (TUSD, TE)
|
|
- Charges and adjustments
|
|
- Tax amounts
|
|
- Payment information
|
|
|
|
Example:
|
|
```csharp
|
|
var request = new BillComplianceRequest
|
|
{
|
|
SmartCode = "123456789",
|
|
DistributorName = "ENERGY_DIST",
|
|
ConsumerGroup = "B1",
|
|
Subgroup = "RESIDENTIAL",
|
|
ConsumptionAmount = 150.5m,
|
|
TUSDAmount = 100.25m,
|
|
TEAmount = 80.15m,
|
|
// ... other properties
|
|
};
|
|
```
|
|
|
|
## Output
|
|
The system returns a `ValidationResult` containing:
|
|
- Validation status (IsValid)
|
|
- Rule name that was validated
|
|
- Detailed message explaining any violations
|
|
|
|
Example:
|
|
```csharp
|
|
{
|
|
"IsValid": false,
|
|
"RuleName": "Consumption Validation",
|
|
"Message": "Consumption amount doesn't match readings difference"
|
|
}
|
|
```
|
|
|
|
## Validation Rules
|
|
Each validation rule implements the `IValidationRule` interface and follows a specific priority order:
|
|
|
|
1. **Basic Validation** (Priority: 1)
|
|
- Validates fundamental bill information
|
|
- Checks data consistency
|
|
|
|
2. **Consumption Validation** (Priority: 2)
|
|
- Verifies reading periods
|
|
- Validates consumption calculations
|
|
- Checks peak/off-peak totals
|
|
|
|
3. **Tariff Component Validation** (Priority: 3)
|
|
- Validates TUSD and TE calculations
|
|
- Checks power factor adjustments
|
|
|
|
4. **Seasonal Tariff Validation** (Priority: 4)
|
|
- Applies to rural/irrigation consumers
|
|
- Validates dry/wet season multipliers
|
|
|
|
5. **Flag System Validation** (Priority: 5)
|
|
- Validates flag colors and values
|
|
- Checks exemptions
|
|
|
|
6. **Subsidy Validation** (Priority: 6)
|
|
- Validates discount eligibility
|
|
- Checks consumption ranges
|
|
- Calculates correct discount amounts
|
|
|
|
7. **Additional Charges Validation** (Priority: 8)
|
|
- Validates mandatory charges
|
|
- Checks justifications
|
|
- Enforces maximum limits
|
|
|
|
8. **Payment Terms Validation** (Priority: 9)
|
|
- Validates due dates
|
|
- Calculates late fees
|
|
- Checks partial payment eligibility
|
|
|
|
## Dependencies
|
|
The system relies on an `IDistributorRepository` to fetch:
|
|
- Tariff information
|
|
- Subsidy rules
|
|
- Additional charge configurations
|
|
- Payment terms
|
|
- Seasonal tariff parameters
|
|
|
|
## Error Handling
|
|
- All validation errors are clearly documented
|
|
- Tolerance of 0.01 for decimal comparisons
|
|
- Detailed error messages for troubleshooting
|
|
|
|
## Usage Example
|
|
```csharp
|
|
var validator = new BillComplianceValidator(distributorRepository);
|
|
var result = await validator.ValidateAsync(billRequest);
|
|
|
|
if (!result.IsValid)
|
|
{
|
|
Console.WriteLine($"Validation failed: {result.Message}");
|
|
}
|
|
```
|
|
|
|
## Best Practices
|
|
- All monetary values are handled as decimal
|
|
- Date comparisons account for time zones
|
|
- Consumer groups are case-insensitive
|
|
- Validation rules are independent and maintainable
|
|
|
|
## Contributing
|
|
When adding new validation rules:
|
|
1. Implement IValidationRule interface
|
|
2. Define appropriate priority
|
|
3. Add corresponding model classes
|
|
4. Update repository interfaces
|
|
|
|
## Regulatory Updates
|
|
This validator is based on ANEEL Resolution 1000/2021. When regulatory updates occur:
|
|
1. Review affected validation rules
|
|
2. Update calculation parameters
|
|
3. Modify validation logic as needed
|
|
4. Update documentation
|
|
```
|