Purpose
The Business Rules Layer (BRL) serves as the intermediary tier between the Presentation Layer and the Data Access Layer (DAL) in SMAF’s three-tier architecture. This layer encapsulates all business logic, validation rules, and domain-specific operations for expense and travel allowance management.Key Responsibilities
Business Logic Enforcement
Implements Mexican Federal Public Administration expense policies and validation rules
Data Orchestration
Coordinates complex operations across multiple DAL components
Authorization Workflows
Manages approval chains and status transitions for commissions and expenses
Calculation Engine
Computes travel allowances, reimbursements, and budget allocations
Architecture Pattern
The BRL implements a Manager-based pattern where each domain entity has a dedicated manager class:Core Manager Classes
| Manager Class | Domain Responsibility |
|---|---|
MngNegocioComision | Commission lifecycle management and CRUD operations |
MngNegocioComprobacion | Expense verification and fiscal compliance validation |
MngNegocioPago | Payment processing and disbursement logic |
MngNegocioMinistracion | Budget allocation and fund release management |
MngNegocioViaticos | Travel allowance rate calculations |
MngNegocioXml | CFDI invoice XML processing and validation |
MngNegocioGenerarRef | Bank reference generation for payments |
Design Principles
1. Stateless Operations
All BRL methods are static and stateless, enabling simplified invocation from the presentation layer:2. Separation of Concerns
The BRL never accesses the database directly. All data persistence operations are delegated to the DAL:3. Validation Before Persistence
Business rules are enforced in the BRL before data reaches the DAL:Commission Date Overlap Validation
Commission Date Overlap Validation
The BRL validates that commission dates do not overlap for the same employee:
Continuous Day Accumulation
Continuous Day Accumulation
Enforces SAT regulations on continuous travel day limits:
UUID Uniqueness for CFDI Invoices
UUID Uniqueness for CFDI Invoices
Prevents duplicate invoice submission:
Parameter Naming Convention
The BRL uses Hungarian notation with prefixes indicating data types:String parameters (e.g.,
psUsuario, psFolio, psEstatus)Integer parameters (e.g.,
piOpcion, piSecuencia)Boolean parameters (e.g.,
pbBandera, pbUsuarioPagador)Object parameters (e.g.,
poComision, poEntidad)Status Transition Management
The BRL orchestrates complex state machines for commission workflows:Status Update Method
Transaction Coordination
While individual BRL methods are stateless, complex operations require coordinated calls:Error Handling Philosophy
BRL methods typically return:- Boolean for success/failure operations
- String for calculated values or validation messages
- Entity objects for data retrieval
- Lists for collection queries
Exceptions are not caught in the BRL - they bubble up to the presentation layer for user-facing error messages.
Integration with Entities
The BRL heavily uses entity classes fromInapescaWeb.Entidades namespace:
Common Entity Types
- Comision: Full commission details with nested properties
- Entidad: Generic key-value entity for dropdowns and catalogs
- GridView: Specialized entity for data table binding
- comprobacion: Expense verification details
- Ministracion: Budget allocation records
Performance Considerations
Thin Layer Pattern
Most methods are simple pass-through calls, minimizing overhead
Dataset Returns
Some methods return
DataSet for complex multi-table resultsOptional Parameters
Extensive use of optional parameters reduces method proliferation
String-based Logic
Calculations return strings to avoid decimal precision issues
Best Practices for BRL Development
- Always validate inputs before passing to DAL
- Use descriptive parameter names following Hungarian notation
- Return meaningful values - empty strings, nulls, or zero for invalid states
- Keep methods stateless - no class-level variables
- Delegate all database operations to the DAL layer
- Document business rules in code comments
Related Documentation
Commission Management
Deep dive into MngNegocioComision methods
Verification Management
Expense validation and reimbursement logic
Payment Management
Payment processing and bank reference generation
Data Access Layer
Understanding the DAL that BRL depends on