dscf-credit 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/dscf/core/copilot-instructions.md +683 -0
  3. data/app/controllers/concerns/dscf/core/reviewable_controller.rb +347 -0
  4. data/app/controllers/dscf/credit/categories_controller.rb +3 -3
  5. data/app/controllers/dscf/credit/credit_lines_controller.rb +21 -13
  6. data/app/controllers/dscf/credit/disbursements_controller.rb +15 -16
  7. data/app/controllers/dscf/credit/eligible_credit_lines_controller.rb +50 -8
  8. data/app/controllers/dscf/credit/facilitator_applications_controller.rb +35 -0
  9. data/app/controllers/dscf/credit/facilitators_controller.rb +8 -96
  10. data/app/controllers/dscf/credit/loan_applications_controller.rb +252 -0
  11. data/app/controllers/dscf/credit/loan_profiles_controller.rb +61 -68
  12. data/app/controllers/dscf/credit/loans_controller.rb +7 -7
  13. data/app/controllers/dscf/credit/scoring_parameters_controller.rb +59 -13
  14. data/app/controllers/dscf/credit/system_configs_controller.rb +30 -12
  15. data/app/models/concerns/core/reviewable_model.rb +31 -0
  16. data/app/models/dscf/credit/bank.rb +3 -3
  17. data/app/models/dscf/credit/bank_branch.rb +1 -1
  18. data/app/models/dscf/credit/category.rb +1 -2
  19. data/app/models/dscf/credit/credit_line.rb +4 -10
  20. data/app/models/dscf/credit/eligible_credit_line.rb +2 -2
  21. data/app/models/dscf/credit/facilitator.rb +6 -17
  22. data/app/models/dscf/credit/facilitator_application.rb +20 -0
  23. data/app/models/dscf/credit/loan.rb +4 -4
  24. data/app/models/dscf/credit/loan_application.rb +30 -0
  25. data/app/models/dscf/credit/loan_profile.rb +10 -30
  26. data/app/models/dscf/credit/parameter_normalizer.rb +1 -1
  27. data/app/models/dscf/credit/scoring_parameter.rb +5 -7
  28. data/app/models/dscf/credit/system_config.rb +4 -9
  29. data/app/serializers/dscf/credit/category_serializer.rb +0 -1
  30. data/app/serializers/dscf/credit/credit_line_serializer.rb +2 -2
  31. data/app/serializers/dscf/credit/facilitator_application_serializer.rb +7 -0
  32. data/app/serializers/dscf/credit/facilitator_serializer.rb +3 -6
  33. data/app/serializers/dscf/credit/loan_application_serializer.rb +12 -0
  34. data/app/serializers/dscf/credit/loan_profile_serializer.rb +3 -6
  35. data/app/serializers/dscf/credit/loan_serializer.rb +1 -2
  36. data/app/serializers/dscf/credit/scoring_parameter_serializer.rb +3 -4
  37. data/app/serializers/dscf/credit/system_config_serializer.rb +2 -2
  38. data/app/services/dscf/credit/credit_scoring_engine.rb +258 -0
  39. data/app/services/dscf/credit/disbursement_service.rb +39 -84
  40. data/app/services/dscf/credit/facility_limit_calculation_engine.rb +159 -0
  41. data/app/services/dscf/credit/loan_profile_creation_service.rb +91 -0
  42. data/app/services/dscf/credit/risk_application_service.rb +61 -11
  43. data/config/locales/en.yml +65 -50
  44. data/config/routes.rb +30 -18
  45. data/db/migrate/20250822091131_create_dscf_credit_credit_lines.rb +1 -8
  46. data/db/migrate/20250822091820_create_dscf_credit_system_configs.rb +0 -7
  47. data/db/migrate/20250822092050_create_dscf_credit_scoring_parameters.rb +2 -6
  48. data/db/migrate/20250822092225_create_dscf_credit_parameter_normalizers.rb +1 -1
  49. data/db/migrate/20250822092236_create_dscf_credit_loan_applications.rb +20 -0
  50. data/db/migrate/20250822092246_create_dscf_credit_loan_profiles.rb +7 -19
  51. data/db/migrate/20250822092426_create_dscf_credit_facilitator_applications.rb +10 -0
  52. data/db/migrate/20250822092436_create_dscf_credit_facilitators.rb +1 -16
  53. data/db/migrate/20250822092654_create_dscf_credit_loans.rb +3 -1
  54. data/db/seeds.rb +321 -290
  55. data/lib/dscf/credit/version.rb +1 -1
  56. data/spec/factories/dscf/credit/banks.rb +1 -1
  57. data/spec/factories/dscf/credit/credit_lines.rb +0 -23
  58. data/spec/factories/dscf/credit/facilitator_applications.rb +37 -0
  59. data/spec/factories/dscf/credit/facilitators.rb +8 -30
  60. data/spec/factories/dscf/credit/loan_applications.rb +42 -0
  61. data/spec/factories/dscf/credit/loan_profiles.rb +20 -34
  62. data/spec/factories/dscf/credit/loans.rb +5 -1
  63. data/spec/factories/dscf/credit/parameter_normalizers.rb +4 -4
  64. data/spec/factories/dscf/credit/scoring_parameters.rb +14 -11
  65. data/spec/factories/dscf/credit/system_configs.rb +21 -5
  66. metadata +20 -20
  67. data/app/controllers/concerns/dscf/credit/reviewable.rb +0 -112
  68. data/app/controllers/dscf/credit/payment_requests_controller.rb +0 -87
  69. data/app/controllers/dscf/credit/payments_controller.rb +0 -36
  70. data/app/controllers/dscf/credit/scoring_tables_controller.rb +0 -63
  71. data/app/models/dscf/credit/payment.rb +0 -22
  72. data/app/models/dscf/credit/payment_request.rb +0 -29
  73. data/app/models/dscf/credit/scoring_table.rb +0 -24
  74. data/app/serializers/dscf/credit/payment_request_serializer.rb +0 -10
  75. data/app/serializers/dscf/credit/payment_serializer.rb +0 -8
  76. data/app/serializers/dscf/credit/scoring_table_serializer.rb +0 -9
  77. data/db/migrate/20250822092608_create_dscf_credit_payment_requests.rb +0 -26
  78. data/db/migrate/20250822092843_create_dscf_credit_payments.rb +0 -23
  79. data/db/migrate/20250901172842_create_dscf_credit_scoring_tables.rb +0 -18
  80. data/spec/factories/dscf/credit/payment_requests.rb +0 -40
  81. data/spec/factories/dscf/credit/payments.rb +0 -39
  82. data/spec/factories/dscf/credit/scoring_tables.rb +0 -25
@@ -0,0 +1,91 @@
1
+ module Dscf::Credit
2
+ class LoanProfileCreationService
3
+ attr_reader :loan_application, :score, :errors
4
+
5
+ def initialize(loan_application, score)
6
+ @loan_application = loan_application
7
+ @score = score
8
+ @errors = []
9
+ end
10
+
11
+ def create_loan_profile
12
+ return error_result("Loan application is required") unless loan_application
13
+ return error_result("Score is required") unless score
14
+
15
+ if loan_application.loan_profile.present?
16
+ return success_result(loan_application.loan_profile, "Loan profile already exists")
17
+ end
18
+
19
+ begin
20
+ ActiveRecord::Base.transaction do
21
+ loan_profile = build_loan_profile
22
+ loan_profile.save!
23
+
24
+ create_initial_review(loan_profile)
25
+
26
+ success_result(loan_profile, "Loan profile created successfully")
27
+ end
28
+ rescue StandardError => e
29
+ Rails.logger.error "Loan profile creation failed: #{e.message}"
30
+ Rails.logger.error e.backtrace.join("\n")
31
+ error_result("Failed to create loan profile: #{e.message}")
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def build_loan_profile
38
+ loan_application.build_loan_profile(
39
+ code: generate_loan_profile_code,
40
+ score: score,
41
+ total_limit: calculate_total_limit
42
+ )
43
+ end
44
+
45
+ def generate_loan_profile_code
46
+ # Generate unique code starting with "BB" followed by up to 6 digits
47
+ loop do
48
+ # Generate a random 6-digit number
49
+ random_digits = sprintf("%06d", rand(1000000))
50
+ code = "BB#{random_digits}"
51
+
52
+ unless Dscf::Credit::LoanProfile.exists?(code: code)
53
+ return code
54
+ end
55
+ end
56
+ end
57
+
58
+ def calculate_total_limit
59
+ 0.0
60
+ end
61
+
62
+ def create_initial_review(loan_profile)
63
+ loan_profile.reviews.create!(
64
+ context: "default",
65
+ status: "approved",
66
+ reviewed_by: nil, # System created
67
+ reviewed_at: Time.current,
68
+ feedback: {
69
+ message: "Loan profile automatically created for approved loan application"
70
+ }
71
+ )
72
+ end
73
+
74
+ def success_result(loan_profile, message)
75
+ {
76
+ success: true,
77
+ loan_profile: loan_profile,
78
+ message: message
79
+ }
80
+ end
81
+
82
+ def error_result(message)
83
+ @errors << message
84
+ {
85
+ success: false,
86
+ error: message,
87
+ errors: @errors
88
+ }
89
+ end
90
+ end
91
+ end
@@ -1,27 +1,77 @@
1
1
  module Dscf::Credit
2
2
  class RiskApplicationService
3
- def initialize(eligible_credit_line, risk_value)
3
+ attr_reader :eligible_credit_line, :risk_factor, :errors
4
+
5
+ def initialize(eligible_credit_line, risk_factor)
4
6
  @eligible_credit_line = eligible_credit_line
5
- @risk_value = risk_value.to_f
7
+ @risk_factor = risk_factor.nil? ? nil : risk_factor.to_f
8
+ @errors = []
6
9
  end
7
10
 
8
11
  def apply_risk
9
- return { success: false, errors: @eligible_credit_line.errors.full_messages } unless @eligible_credit_line.valid?
12
+ return error_result("Eligible credit line is required") unless eligible_credit_line
13
+ return error_result("Risk factor is required") if risk_factor.nil?
14
+ return error_result("Risk factor must be between 0.0 and 0.9") unless valid_risk_factor?
15
+
16
+ begin
17
+ ActiveRecord::Base.transaction do
18
+ eligible_credit_line.risk = risk_factor
19
+
20
+ new_available_limit = calculate_available_limit_with_risk
21
+ eligible_credit_line.available_limit = new_available_limit
22
+
23
+ eligible_credit_line.save!
10
24
 
11
- @eligible_credit_line.risk = @risk_value
12
- @eligible_credit_line.available_limit = calculate_available_limit
25
+ update_loan_profile_total_limit
13
26
 
14
- if @eligible_credit_line.save
15
- { success: true, data: @eligible_credit_line }
16
- else
17
- { success: false, errors: @eligible_credit_line.errors.full_messages }
27
+ success_result(eligible_credit_line, "Risk factor applied successfully")
28
+ end
29
+ rescue StandardError => e
30
+ Rails.logger.error "Risk application failed: #{e.message}"
31
+ Rails.logger.error e.backtrace.join("\n")
32
+ error_result("Failed to apply risk factor: #{e.message}")
18
33
  end
19
34
  end
20
35
 
21
36
  private
22
37
 
23
- def calculate_available_limit
24
- @eligible_credit_line.credit_limit * (1 - @risk_value)
38
+ def valid_risk_factor?
39
+ risk_factor >= 0.0 && risk_factor <= 0.9
40
+ end
41
+
42
+ def calculate_available_limit_with_risk
43
+ # available_limit = credit_limit × (1 - risk_factor)
44
+ # If risk_factor is 0.0 (0%), available_limit = credit_limit
45
+ # If risk_factor is 0.9 (90%), available_limit = credit_limit × 0.1
46
+ result = eligible_credit_line.credit_limit * (1 - risk_factor)
47
+ result.round(2)
48
+ end
49
+
50
+ def update_loan_profile_total_limit
51
+ loan_profile = eligible_credit_line.loan_profile
52
+ return unless loan_profile
53
+
54
+ total_available_limit = loan_profile.eligible_credit_lines.sum(:available_limit)
55
+
56
+ loan_profile.update!(total_limit: total_available_limit)
57
+
58
+ Rails.logger.info "Updated loan profile #{loan_profile.id} total limit to #{total_available_limit}"
59
+ end
60
+
61
+ def success_result(data, message)
62
+ {
63
+ success: true,
64
+ data: data,
65
+ message: message
66
+ }
67
+ end
68
+
69
+ def error_result(message)
70
+ {
71
+ success: false,
72
+ error: message,
73
+ errors: [ message ]
74
+ }
25
75
  end
26
76
  end
27
77
  end
@@ -85,7 +85,10 @@ en:
85
85
  update: "Loan profile updated successfully"
86
86
  approve: "Loan profile approved successfully"
87
87
  reject: "Loan profile rejected successfully"
88
- calculate_score: "Credit score calculated successfully"
88
+ request_modification: "Modification requested for loan profile successfully"
89
+ resubmit: "Loan profile resubmitted successfully"
90
+ calculate_facility_limits: "Facility limits calculated successfully"
91
+ apply_risk_factor: "Risk factor applied successfully"
89
92
  errors:
90
93
  index: "Failed to retrieve loan profiles"
91
94
  show: "Failed to retrieve loan profile details"
@@ -93,8 +96,11 @@ en:
93
96
  update: "Failed to update loan profile"
94
97
  approve: "Failed to approve loan profile"
95
98
  reject: "Failed to reject loan profile"
96
- calculate_score: "Failed to calculate credit score"
99
+ request_modification: "Failed to request modification for loan profile"
100
+ resubmit: "Failed to resubmit loan profile"
97
101
  not_found: "Loan profile not found"
102
+ calculate_facility_limits: "Failed to calculate facility limits"
103
+ apply_risk_factor: "Failed to apply risk factor"
98
104
 
99
105
  parameter_normalizer:
100
106
  success:
@@ -118,27 +124,18 @@ en:
118
124
  update: "Facilitator updated successfully"
119
125
  approve: "Facilitator approved successfully"
120
126
  reject: "Facilitator rejected successfully"
121
- set_limit: "Facilitator limit updated successfully"
122
- submit_additional_info: "Additional information submitted successfully"
123
127
  request_modification: "Modification requested for facilitator successfully"
124
128
  resubmit: "Facilitator resubmitted successfully"
125
- batch_created_all: "All facilitators created successfully"
126
- batch_created_partial: "Batch processing completed with partial success"
127
129
  errors:
130
+ index: "Failed to retrieve facilitators"
131
+ show: "Failed to retrieve facilitator details"
128
132
  create: "Failed to create facilitator"
129
133
  update: "Failed to update facilitator"
130
- show: "Failed to retrieve facilitator details"
131
134
  approve: "Failed to approve facilitator"
132
135
  reject: "Failed to reject facilitator"
133
- set_limit: "Failed to update facilitator limit"
134
- submit_additional_info: "Failed to submit additional information"
135
136
  request_modification: "Failed to request modification for facilitator"
136
137
  resubmit: "Failed to resubmit facilitator"
137
- no_business: "User must have a business associated to become a facilitator"
138
- invalid_batch_format: "Invalid batch format"
139
- empty_batch: "Empty batch provided"
140
- batch_too_large: "Batch size exceeds maximum allowed"
141
- batch_failed_all: "All facilitators failed to create"
138
+ not_found: "Facilitator not found"
142
139
 
143
140
  credit_line_spec:
144
141
  success:
@@ -189,6 +186,7 @@ en:
189
186
  create: "Failed to create eligible credit line"
190
187
  update: "Failed to update eligible credit line"
191
188
  apply_risk: "Failed to apply risk"
189
+ not_found: "Eligible credit line not found"
192
190
 
193
191
  system_config_definition:
194
192
  success:
@@ -240,24 +238,6 @@ en:
240
238
  update: "Failed to update category"
241
239
  destroy: "Failed to delete category"
242
240
 
243
- scoring_table:
244
- success:
245
- index: "Scoring tables retrieved successfully"
246
- show: "Scoring table details retrieved successfully"
247
- create: "Scoring table created successfully"
248
- update: "Scoring table updated successfully"
249
- activate: "Scoring table activated successfully"
250
- deactivate: "Scoring table deactivated successfully"
251
- destroy: "Scoring table deleted successfully"
252
- errors:
253
- index: "Failed to retrieve scoring tables"
254
- show: "Failed to retrieve scoring table details"
255
- create: "Failed to create scoring table"
256
- update: "Failed to update scoring table"
257
- activate: "Failed to activate scoring table"
258
- deactivate: "Failed to deactivate scoring table"
259
- destroy: "Failed to delete scoring table"
260
-
261
241
  payment_request:
262
242
  success:
263
243
  index: "Payment requests retrieved successfully"
@@ -276,17 +256,59 @@ en:
276
256
  eligible_credit_lines: "Failed to retrieve eligible credit lines"
277
257
  destroy: "Failed to delete payment request"
278
258
 
279
- user:
259
+ loan_application:
280
260
  success:
281
- index: "Users retrieved successfully"
282
- show: "User details retrieved successfully"
283
- create: "User created successfully"
284
- update: "User updated successfully"
261
+ index: "Loan applications retrieved successfully"
262
+ show: "Loan application details retrieved successfully"
263
+ create: "Loan application created successfully"
264
+ update: "Loan application updated successfully"
265
+ update_bank_info: "Bank information updated successfully"
266
+ update_facilitator_info: "Facilitator information updated successfully"
267
+ update_field_assessment: "Field assessment updated successfully"
268
+ calculate_credit_score: "Credit score calculated successfully"
269
+ apply_risk_factor: "Risk factor applied successfully"
270
+ approve: "Loan application approved successfully"
271
+ reject: "Loan application rejected successfully"
272
+ request_modification: "Modification requested for loan application successfully"
273
+ resubmit: "Loan application resubmitted successfully"
285
274
  errors:
286
- index: "Failed to retrieve Users"
287
- show: "Failed to retrieve User details"
288
- create: "Failed to create User"
289
- update: "Failed to update User"
275
+ index: "Failed to retrieve loan applications"
276
+ show: "Failed to retrieve loan application details"
277
+ create: "Failed to create loan application"
278
+ update: "Failed to update loan application"
279
+ update_bank_info: "Failed to update bank information"
280
+ update_facilitator_info: "Failed to update facilitator information"
281
+ update_field_assessment: "Failed to update field assessment"
282
+ calculate_credit_score: "Failed to calculate credit score"
283
+ apply_risk_factor: "Failed to apply risk factor"
284
+ invalid_risk_percentage: "Invalid risk percentage provided"
285
+ no_loan_profile: "No loan profile found for this application"
286
+ approve: "Failed to approve loan application"
287
+ reject: "Failed to reject loan application"
288
+ request_modification: "Failed to request modification for loan application"
289
+ resubmit: "Failed to resubmit loan application"
290
+ not_found: "Loan application not found"
291
+
292
+ facilitator_application:
293
+ success:
294
+ index: "Facilitator applications retrieved successfully"
295
+ show: "Facilitator application details retrieved successfully"
296
+ create: "Facilitator application created successfully"
297
+ update: "Facilitator application updated successfully"
298
+ approve: "Facilitator application approved successfully"
299
+ reject: "Facilitator application rejected successfully"
300
+ request_modification: "Modification requested for facilitator application successfully"
301
+ resubmit: "Facilitator application resubmitted successfully"
302
+ errors:
303
+ index: "Failed to retrieve facilitator applications"
304
+ show: "Failed to retrieve facilitator application details"
305
+ create: "Failed to create facilitator application"
306
+ update: "Failed to update facilitator application"
307
+ approve: "Failed to approve facilitator application"
308
+ reject: "Failed to reject facilitator application"
309
+ request_modification: "Failed to request modification for facilitator application"
310
+ resubmit: "Failed to resubmit facilitator application"
311
+ not_found: "Facilitator application not found"
290
312
 
291
313
  # Global messages
292
314
  operations:
@@ -297,13 +319,6 @@ en:
297
319
  failed: "Operation failed"
298
320
  not_found: "Resource not found"
299
321
 
300
- loan_profile:
301
- success:
302
- calculate_score: "Credit score calculated successfully"
303
- errors:
304
- calculate_score: "Failed to calculate credit score"
305
- not_found: "Loan profile not found"
306
-
307
322
  credit_limit_calculation:
308
323
  success:
309
324
  create: "Credit limits calculated successfully"
@@ -313,10 +328,10 @@ en:
313
328
 
314
329
  disbursement:
315
330
  success:
316
- create: "Disbursement processed successfully"
331
+ create: "Disbursement processed successfully. Loan created and credit limit updated."
317
332
  errors:
318
333
  create: "Failed to process disbursement"
319
- not_found: "Credit line or payment request not found"
334
+ not_found: "Loan profile or eligible credit line not found"
320
335
 
321
336
  repayment:
322
337
  success:
data/config/routes.rb CHANGED
@@ -1,19 +1,16 @@
1
1
  Dscf::Credit::Engine.routes.draw do
2
- # Main API endpoints
3
- resources :banks, only: [ :index, :show, :create, :update, :destroy ]
2
+ resources :banks
4
3
  resources :bank_branches
5
- resources :payments, only: [ :index, :show, :create, :update, :destroy ]
6
- resources :loans, only: [ :index, :show, :create, :update, :destroy ]
4
+ resources :payments
5
+ resources :loans
7
6
  resources :scoring_param_types
8
7
 
9
- resources :facilitators, only: [ :index, :show, :create, :update, :destroy ] do
10
- collection do
11
- post "batch_create", to: "facilitators#batch_create"
12
- post "additional_info", to: "facilitators#submit_additional_info"
13
- end
8
+ resources :facilitators do
14
9
  member do
15
- patch "approve", to: "facilitators#approve"
16
- patch "reject", to: "facilitators#reject"
10
+ patch "approve"
11
+ patch "reject"
12
+ patch "request_modification"
13
+ patch "resubmit"
17
14
  end
18
15
  end
19
16
 
@@ -21,7 +18,7 @@ Dscf::Credit::Engine.routes.draw do
21
18
  member do
22
19
  patch "approve"
23
20
  patch "reject"
24
- post "calculate_score"
21
+ post "calculate_facility_limits"
25
22
  end
26
23
  end
27
24
  resources :payment_requests do
@@ -63,12 +60,6 @@ Dscf::Credit::Engine.routes.draw do
63
60
  end
64
61
  end
65
62
  resources :categories
66
- resources :scoring_tables do
67
- member do
68
- patch "activate", to: "scoring_tables#activate"
69
- patch "deactivate", to: "scoring_tables#deactivate"
70
- end
71
- end
72
63
  resources :users
73
64
  resources :kyc_reviews, only: [ :index, :show ]
74
65
  resources :bank_staffs
@@ -76,4 +67,25 @@ Dscf::Credit::Engine.routes.draw do
76
67
  resources :credit_limit_calculations, only: [ :create ]
77
68
  resources :disbursements, only: [ :create ]
78
69
  resources :repayments, only: [ :create ]
70
+ resources :loan_applications do
71
+ member do
72
+ patch "approve"
73
+ patch "reject"
74
+ patch "request_modification"
75
+ patch "resubmit"
76
+ patch "update_bank_info"
77
+ patch "update_facilitator_info"
78
+ patch "update_field_assessment"
79
+ post "calculate_credit_score"
80
+ end
81
+ end
82
+
83
+ resources :facilitator_applications do
84
+ member do
85
+ patch "approve"
86
+ patch "reject"
87
+ patch "request_modification"
88
+ patch "resubmit"
89
+ end
90
+ end
79
91
  end
@@ -6,11 +6,7 @@ class CreateDscfCreditCreditLines < ActiveRecord::Migration[8.0]
6
6
  t.string :name, null: false
7
7
  t.string :code
8
8
  t.text :description
9
- t.string :status, default: 'pending'
10
9
  t.references :created_by, polymorphic: true, null: false
11
- t.references :reviewed_by, polymorphic: true, null: true
12
- t.datetime :review_date
13
- t.jsonb :review_feedback, default: {}
14
10
  t.string :document_reference
15
11
 
16
12
  t.timestamps
@@ -18,11 +14,8 @@ class CreateDscfCreditCreditLines < ActiveRecord::Migration[8.0]
18
14
 
19
15
  add_index :dscf_credit_credit_lines, :name
20
16
  add_index :dscf_credit_credit_lines, :code
21
- add_index :dscf_credit_credit_lines, :status
22
- add_index :dscf_credit_credit_lines, [ :created_by_type, :created_by_id ]
23
- add_index :dscf_credit_credit_lines, [ :reviewed_by_type, :reviewed_by_id ]
24
- add_index :dscf_credit_credit_lines, :review_date
25
17
  add_index :dscf_credit_credit_lines, :document_reference
18
+ add_index :dscf_credit_credit_lines, [ :created_by_type, :created_by_id ]
26
19
  add_index :dscf_credit_credit_lines, [ :bank_id, :code ], unique: true
27
20
  end
28
21
  end
@@ -3,18 +3,11 @@ class CreateDscfCreditSystemConfigs < ActiveRecord::Migration[8.0]
3
3
  create_table :dscf_credit_system_configs do |t|
4
4
  t.references :config_definition, null: false, foreign_key: { to_table: :dscf_credit_system_config_definitions }, index: { unique: true }
5
5
  t.text :config_value, null: false
6
- t.string :status, default: 'pending'
7
6
  t.references :last_updated_by, polymorphic: true, null: false
8
- t.references :reviewed_by, polymorphic: true, null: false
9
- t.datetime :review_date
10
- t.jsonb :review_feedback, default: {}
11
7
 
12
8
  t.timestamps
13
9
  end
14
10
 
15
11
  add_index :dscf_credit_system_configs, [ :last_updated_by_type, :last_updated_by_id ]
16
- add_index :dscf_credit_system_configs, [ :reviewed_by_type, :reviewed_by_id ]
17
- add_index :dscf_credit_system_configs, :status
18
- add_index :dscf_credit_system_configs, :review_date
19
12
  end
20
13
  end
@@ -2,6 +2,7 @@ class CreateDscfCreditScoringParameters < ActiveRecord::Migration[8.0]
2
2
  def change
3
3
  create_table :dscf_credit_scoring_parameters do |t|
4
4
  t.references :bank, null: false, foreign_key: { to_table: :dscf_credit_banks }
5
+ t.references :category, null: false, foreign_key: { to_table: :dscf_credit_categories }
5
6
  t.string :name, null: false
6
7
  t.text :description
7
8
  t.string :data_type, null: false
@@ -11,13 +12,9 @@ class CreateDscfCreditScoringParameters < ActiveRecord::Migration[8.0]
11
12
  t.boolean :active, default: true
12
13
  t.references :previous_version, foreign_key: { to_table: :dscf_credit_scoring_parameters }, null: true
13
14
  t.references :created_by, polymorphic: true, null: false
14
- t.references :reviewed_by, polymorphic: true, null: false
15
- t.datetime :review_date
16
- t.jsonb :review_feedback, default: {}
17
15
  t.string :source
18
16
  t.references :scoring_param_type, null: false, foreign_key: { to_table: :dscf_credit_scoring_param_types }
19
17
  t.string :document_reference
20
- t.string :status, default: 'pending'
21
18
 
22
19
  t.timestamps
23
20
  end
@@ -26,10 +23,9 @@ class CreateDscfCreditScoringParameters < ActiveRecord::Migration[8.0]
26
23
  add_index :dscf_credit_scoring_parameters, :data_type
27
24
  add_index :dscf_credit_scoring_parameters, :active
28
25
  add_index :dscf_credit_scoring_parameters, [ :created_by_type, :created_by_id ]
29
- add_index :dscf_credit_scoring_parameters, [ :reviewed_by_type, :reviewed_by_id ]
30
- add_index :dscf_credit_scoring_parameters, :review_date
31
26
  add_index :dscf_credit_scoring_parameters, :source
32
27
  add_index :dscf_credit_scoring_parameters, :document_reference
33
28
  add_index :dscf_credit_scoring_parameters, [ :bank_id, :name, :active ]
29
+ add_index :dscf_credit_scoring_parameters, [ :category_id, :name ]
34
30
  end
35
31
  end
@@ -5,7 +5,7 @@ class CreateDscfCreditParameterNormalizers < ActiveRecord::Migration[8.0]
5
5
  t.string :name, null: false
6
6
  t.text :description
7
7
  t.string :raw_value, null: false
8
- t.integer :normalized_value, null: false
8
+ t.decimal :normalized_value, precision: 5, scale: 4, null: false
9
9
 
10
10
  t.timestamps
11
11
  end
@@ -0,0 +1,20 @@
1
+ class CreateDscfCreditLoanApplications < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :dscf_credit_loan_applications do |t|
4
+ t.references :bank, null: false, foreign_key: { to_table: :dscf_credit_banks }
5
+ t.references :user, null: false, foreign_key: { to_table: :dscf_core_users }
6
+ t.references :backer, polymorphic: true
7
+ t.references :review_branch, null: false, foreign_key: { to_table: :dscf_credit_bank_branches }
8
+ t.string :bank_statement_source
9
+ t.jsonb :user_info, default: {}
10
+ t.jsonb :facilitator_info, default: {}
11
+ t.jsonb :bank_info, default: {}
12
+ t.jsonb :field_assessment, default: {}
13
+ t.decimal :score, precision: 15, scale: 2
14
+
15
+ t.timestamps
16
+ end
17
+
18
+ add_index :dscf_credit_loan_applications, :bank_statement_source
19
+ end
20
+ end
@@ -1,28 +1,16 @@
1
1
  class CreateDscfCreditLoanProfiles < ActiveRecord::Migration[8.0]
2
2
  def change
3
3
  create_table :dscf_credit_loan_profiles do |t|
4
- t.references :bank, null: false, foreign_key: { to_table: :dscf_credit_banks }
5
- t.references :user, null: false, foreign_key: { to_table: :dscf_core_users }
6
- t.references :backer, polymorphic: true, null: true
7
- t.string :status, default: 'pending'
8
- t.decimal :total_amount, precision: 15, scale: 2, default: 0
9
- t.decimal :available_amount, precision: 15, scale: 2, default: 0
10
- t.references :reviewed_by, polymorphic: true
11
- t.datetime :review_date
12
- t.jsonb :review_feedback, default: {}
13
- t.references :review_branch, null: true, foreign_key: { to_table: :dscf_credit_bank_branches }
4
+ t.references :loan_application, null: false, foreign_key: { to_table: :dscf_credit_loan_applications }
5
+ t.string :code, null: false, limit: 8
6
+ t.decimal :score, precision: 8, scale: 2
7
+ t.decimal :total_limit, precision: 15, scale: 2, default: 0
14
8
 
15
9
  t.timestamps
16
10
  end
17
11
 
18
- add_index :dscf_credit_loan_profiles, :status
19
- add_index :dscf_credit_loan_profiles, :total_amount
20
- add_index :dscf_credit_loan_profiles, :available_amount
21
- add_index :dscf_credit_loan_profiles, [ :backer_type, :backer_id ]
22
- add_index :dscf_credit_loan_profiles, [ :reviewed_by_type, :reviewed_by_id ]
23
- add_index :dscf_credit_loan_profiles, :review_date
24
- add_index :dscf_credit_loan_profiles, [ :bank_id, :user_id, :status ]
25
- add_index :dscf_credit_loan_profiles, [ :user_id, :status ]
26
- add_index :dscf_credit_loan_profiles, [ :total_amount, :available_amount ]
12
+ add_index :dscf_credit_loan_profiles, :code, unique: true
13
+ add_index :dscf_credit_loan_profiles, :score
14
+ add_index :dscf_credit_loan_profiles, :total_limit
27
15
  end
28
16
  end
@@ -0,0 +1,10 @@
1
+ class CreateDscfCreditFacilitatorApplications < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :dscf_credit_facilitator_applications do |t|
4
+ t.references :user, null: false, foreign_key: { to_table: :dscf_core_users }
5
+ t.references :bank, null: false, foreign_key: { to_table: :dscf_credit_banks }
6
+ t.jsonb :facilitator_info, null: false, default: {}
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,25 +1,10 @@
1
1
  class CreateDscfCreditFacilitators < ActiveRecord::Migration[8.0]
2
2
  def change
3
3
  create_table :dscf_credit_facilitators do |t|
4
- t.references :user, null: false, foreign_key: { to_table: :dscf_core_users }
5
- t.references :bank, null: false, foreign_key: { to_table: :dscf_credit_banks }
6
- t.string :name, null: false
7
- t.string :type, null: false
4
+ t.references :facilitator_application, null: false, foreign_key: { to_table: :dscf_credit_facilitator_applications }
8
5
  t.decimal :total_limit, precision: 15, scale: 2
9
- t.string :kyc_status, default: 'pending'
10
- t.references :kyc_reviewed_by, polymorphic: true, null: false
11
- t.datetime :kyc_review_date
12
- t.jsonb :review_feedback, default: {}
13
6
 
14
7
  t.timestamps
15
8
  end
16
-
17
- add_index :dscf_credit_facilitators, :name
18
- add_index :dscf_credit_facilitators, :type
19
- add_index :dscf_credit_facilitators, :kyc_status
20
- add_index :dscf_credit_facilitators, [ :kyc_reviewed_by_type, :kyc_reviewed_by_id ]
21
- add_index :dscf_credit_facilitators, :kyc_review_date
22
- add_index :dscf_credit_facilitators, [ :bank_id, :user_id ], unique: true
23
- add_index :dscf_credit_facilitators, [ :user_id, :kyc_status ]
24
9
  end
25
10
  end
@@ -3,7 +3,6 @@ class CreateDscfCreditLoans < ActiveRecord::Migration[8.0]
3
3
  create_table :dscf_credit_loans do |t|
4
4
  t.references :loan_profile, null: false, foreign_key: { to_table: :dscf_credit_loan_profiles }
5
5
  t.references :credit_line, null: false, foreign_key: { to_table: :dscf_credit_credit_lines }
6
- t.references :payment_request, null: false, foreign_key: { to_table: :dscf_credit_payment_requests }
7
6
  t.string :status, default: 'pending'
8
7
  t.decimal :principal_amount, precision: 15, scale: 2, null: false
9
8
  t.decimal :accrued_interest, precision: 15, scale: 2, default: 0
@@ -13,6 +12,7 @@ class CreateDscfCreditLoans < ActiveRecord::Migration[8.0]
13
12
  t.decimal :remaining_amount, precision: 15, scale: 2, null: false
14
13
  t.date :due_date, null: false
15
14
  t.datetime :disbursed_at
15
+ t.boolean :active, default: true, null: false
16
16
 
17
17
  t.timestamps
18
18
  end
@@ -22,8 +22,10 @@ class CreateDscfCreditLoans < ActiveRecord::Migration[8.0]
22
22
  add_index :dscf_credit_loans, :disbursed_at
23
23
  add_index :dscf_credit_loans, :principal_amount
24
24
  add_index :dscf_credit_loans, :remaining_amount
25
+ add_index :dscf_credit_loans, :active
25
26
  add_index :dscf_credit_loans, [ :loan_profile_id, :status ]
26
27
  add_index :dscf_credit_loans, [ :credit_line_id, :status ]
27
28
  add_index :dscf_credit_loans, [ :status, :due_date ]
29
+ add_index :dscf_credit_loans, [ :active, :status ]
28
30
  end
29
31
  end