# Transition from K M Global (Lender ID 2) to BlackSoil (Lender ID 20)
---
## Migration Overview — 2026-09-17
### Overview
This document tracks the (rest of the) transition of default logic, filters, and hardcoded conditions from K M Global (Lender ID `2`) to BlackSoil (Lender ID `20`) across the platform. Credit Fair is promoting BlackSoil as the primary/default lender in place of K M Global. The transition involves updating hardcoded fallback IDs for jobs and status updates, expanding dashboard filters to accommodate both lenders, and transferring special access rights (like `avanse_access` visibility) to BlackSoil users.
As modifications are progressively made across the codebase, this document will be updated to reflect the business rules, technical flow, and specific files impacted by the transition.
---
### Business Rules
#### Dashboard Visibility and Access Control
* **Avanse Cases Access:** K M Global historically enjoyed special visibility into applications that had an `avanse_access` relationship, rather than being strictly restricted to applications directly assigned to `lender_id = 2`. BlackSoil users (`lender_id = 20`) are now granted this exact same dashboard visibility rule.
* **BNPL & Avanse Validation:** Specific validation bypasses or checks involving `is_bnpl` and `avanse_da` unique IDs are now shared between Lender 2 and Lender 20.
#### Application State & Status Transitions
* **Default Lender on Approval:** When an application is explicitly marked as `cf approved` through certain manual or programmatic paths where a lender is not pre-determined, the system now assigns BlackSoil (`lender_id = 20`) as the default lender, replacing K M Global.
* **Status Change Payloads:** Background jobs and queued operations triggered by status changes (including manual `nach registered` transitions) now fallback to Lender 20 instead of Lender 2 if the incoming request payload omits a specific lender ID.
#### Customer Documents and Notifications
* **Welcome & CAM Reports:** Text labels on CAM reports and Welcome Letters that conditionally print "Product" & "Merchant" (instead of "Course" & "Institute") are now triggered for both BlackSoil (Lender 20) and K M Global (Lender 2).
* **Statements of Account (SOA):** Service endpoints that fetch SOA or generate payment links for a specific lender now validate `in_array([2, 20])` allowing BlackSoil users to use the internal SOA generation service.
* **E-Sign Success:** E-sign congratulatory messages previously scoped to K M Global are now updated to target BlackSoil.
#### Internal Processes and Workflows
* **Lender Rejection Reasons:** The UI prompt requiring a "Lender Rejection Reason" dropdown upon admin approval of an application is now enforced for both BlackSoil and K M Global.
* **Accounting and Pre-Part Payments:** The ability to log a "Pre-part Payment" in the admin accounting view is now unlocked for BlackSoil alongside K M Global.
* **Tally Bridge & Default Parameters:** Several background command services (like TallyBridge) and API controllers that construct payloads or fetch documents (like `getLoanAgreement`) now use `20` as the default fallback parameter, replacing `2`.
* **Trade Advance Disbursements:** Trade Advance models that relate back to consumer applications now resolve applications for both Lender 2 and Lender 20.
#### Disbursement and Document Validation
* **Disbursement Checklist:** Validation logic for `product_type_details`, Aadhar masking, Loan Agreement non-signing (especially for the Solar Category), and other DCD (Disbursement Checklist Done) blockages now identically target BlackSoil (Lender ID 20) alongside K M Global.
* **Consent Checks:** Co-applicant consent checks and first EMI date validations (ensuring it's > 20 days) strictly apply to BlackSoil just as they did for K M Global.
#### Payment Gateway and Settlements
* **Razorpay Keys:** API integration calls for creating, fetching, or cancelling Razorpay payment links and settlements now evaluate `in_array([2, 20])` to route BlackSoil applications through the appropriate Razorpay credentials (inheriting the `KMRAZORPAYKEY` configuration path).
* **Overdue Payments:** Global queries fetching overdue payments across all lenders (when no specific lender is selected) now explicitly include `20` in the default lender array `[1, 2, 20]`.
#### Financials and Filters
* **NACH Mode Filtering:** The `hdfc_nach` filter in the consumer application list previously scoped strictly to Lender 2. This has been expanded to include applications assigned to both Lender 2 and Lender 20.
* **Tally Settlements:** When fetching subvention and interest applications for Tally integration without an explicit lender parameter, the system now defaults to pulling data for BlackSoil (`lender_id = 20`).
---
### Technical Flow
#### 1. Data Visibility Expansion
In `ConsumerApplicationController@index`, the data fetching logic checks the authenticated user's `lender_id`. If it matches `2` or `20`, it triggers `whereHas('avanse_access')` to override strict application-level lender matching. Similarly, the `nach_mode` filter now uses `whereIn('lender_id', [2, 20])`.
#### 2. Status Updates and Fallbacks
Throughout the `ConsumerApplicationController` status change flows, array payloads prepared for delayed jobs or immediate processing use a ternary operator fallback: `Input::has('lender_id') ? Input::get('lender_id') : 20`. This ensures all unassigned status transitions default to BlackSoil.
#### 3. Settlement Internal Fetches
In `TallySettlementController@fetchSubventionInterestApplicationsInternal`, the initial query parameter parsing has been adjusted to default to `20`.
---
### Data Model and Migrations
*There are no direct database structure migrations required for this phase of the transition, as it relies on updating hardcoded application-level logic to reference the existing `lender_id = 20` record.*
---
### Main Code Impact
| File | Change |
| --- | --- |
| `app/Http/Controllers/Admin/TallySettlementController.php` | Updated `fetchSubventionInterestApplicationsInternal` to use `20` as the fallback `lender_id` when fetching subvention and interest data. |
| `app/Console/Commands/TallyBridge.php` | Updated default parameter `lender_id` to `20`. |
| `app/Http/Controllers/Admin/ConsumerDocument.php` | Updated `getLoanAgreement` default `lender_id` parameter to `20`. |
| `app/Http/Controllers/Service/ServiceController.php` | Allowed `[2, 20]` to pass through SOA (`getAccountStatement`) and payment link endpoints. |
| `app/Http/Controllers/FrontController.php` & `ApiController.php` | Changed hardcoded fallbacks to `20` and arrays to `[2, 20]`. |
| `app/TradeAdvanceDisbursement.php` | Expanded `application()` relationship constraint to `whereIn('lender_id', [2, 20])`. |
| `app/Method/JM/Response/Response.php` | Changed `updateStatus` method signature fallback to `20`. |
| `resources/views/admin/accounting/payment_v1.blade.php` | Enabled "Pre-part Payment" dropdown option for BlackSoil. |
| `resources/views/admin/documents/avanse/cam_report.blade.php` | Applied Product/Merchant terminology logic to BlackSoil. |
| `resources/views/admin/documents/welcome_v2.blade.php` | Applied Product/Merchant terminology logic to BlackSoil. |
| `resources/views/admin/layouts/footer.blade.php` | Rendered Lender Rejection Reason dropdown for BlackSoil on approval. |
| `resources/views/front/esign-congrats.blade.php` | Updated E-sign completion success message to target BlackSoil. |
| `app/Http/Controllers/Admin/ConsumerApplicationController.php` (Phase II) | Added `20` to DCD validation blocks (`product_type_details`, solar category agreement check).
Updated `consent_check`, `co_applicant_consent_check`, and `first_emi_date_validation` to check `in_array([2, 20])`.
Updated Razorpay integration functions (`cancelraazorpaylink`, `callRazorPaySettlementAPI`, etc.) to use KM keys for Lender 20.
Updated global overdue payments query to default to `[1, 2, 20]`. |
| `app/Http/Controllers/Admin/ConsumerApplicationController.php` (Phase I) | Updated `nach_mode` (`hdfc_nach`) query filter to include `[2, 20]`.
Updated data visibility `index` to grant `avanse_access` to `lender_id == 20`.
Updated `avanse_da` validation to allow `in_array([2, 20])`.
Changed fallback `lender_id` assignments from `2` to `20` during `cf approved` state transition.
Changed fallback `lender_id` assignments from `2` to `20` in status-change job payloads (`nach registered` and default). |
---
### Operational Verification Checklist
1. Confirm that a logged-in BlackSoil user (`lender_id = 20`) can see applications associated with `avanse_access` on the admin dashboard, just like K M Global users.
2. Filter applications using `nach_mode = hdfc_nach` and verify that the results contain applications assigned to both Lender 2 and Lender 20.
3. Push an application to `cf approved` through a path that relies on the default fallback, and verify the application's `lender_id` updates to `20`.
4. Trigger a status change (e.g., to `nach registered`) without passing a specific `lender_id` in the request, and confirm the generated job payload defaults to `20`.
5. On the Tally Settlement page, click the "Get Data" button for subvention and interest without explicitly selecting a lender, and verify it retrieves records for BlackSoil (`lender_id = 20`).