# EMI Date Calculation Centralization --- ## CRED-6188 — 2026-04-27 ### Overview Centralized the core logic of first EMI date calculation, which was previously scattered across three different methods within two distinct controllers. Consolidated the implementation into a single highly reusable method `calculateFirstEMIDate` inside `ConsumerApplicationController` to ensure uniform EMI starting dates starting precisely with index 0 across varying processes and dynamically checking constraints, removing duplicate and depreciated loop configurations like the hardcoded day 18. --- ### Logic Changed - **Created New Strategy**: - `ConsumerApplicationController::calculateFirstEMIDate($application, $isAvanse = false, $offer_details = null)` - Encapsulates `subvention_type_id`, `is_bnpl`, and dynamic days handling explicitly computing available dates. Drops the `$i=1` offset utilizing `$i=0` inline with new logic bounds, restricting acceptable loop generation checks strictly to generic days `[5]` or isolated arrays for 'avanse' records `[7]`. - **Impacted Workflows Refactored**: - **`generateRPSforBPI`**: Replaced inline EMI construction logic. Now calls `$this->calculateFirstEMIDate(...)` locally and returns formatting mapped appropriately. - **`GradeController::generateEMIForDecision`**: Binds its `$arrayDate` finding structure by sending arguments into the injected `$consumerApplicationController->calculateFirstEMIDate($application, $request->has('avanse'), clone $offer)` utilizing exact `d/m/Y` string mappings securely. - **`GradeController::regenerateEMIAfterDecision`**: Cleans up duplicate iteration, creates an explicit `ConsumerApplicationController` instance contextually to utilize `calculateFirstEMIDate`, preserving fallback checking over `$offer_details`. --- ### Impact — Files Changed / Added | File | Type | Change | |------|------|--------| | `app/Http/Controllers/Admin/ConsumerApplicationController.php` | Modified | Added `calculateFirstEMIDate()` core functionality; Reduced duplicated calculation scripts returning natively inside `generateRPSforBPI()` | | `app/Http/Controllers/Grade/GradeController.php` | Modified | Reduced iteration implementations returning securely mapped calls mapping `$this` references backwards properly across `regenerateEMIAfterDecision()` and `generateEMIForDecision()` | ---