dscf-credit 0.1.1 → 0.1.2

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/dscf/credit/reviewable.rb +112 -0
  3. data/app/controllers/dscf/credit/categories_controller.rb +3 -2
  4. data/app/controllers/dscf/credit/credit_lines_controller.rb +11 -38
  5. data/app/controllers/dscf/credit/facilitators_controller.rb +39 -150
  6. data/app/controllers/dscf/credit/scoring_param_types_controller.rb +31 -0
  7. data/app/controllers/dscf/credit/scoring_parameters_controller.rb +13 -8
  8. data/app/controllers/dscf/credit/system_configs_controller.rb +10 -7
  9. data/app/models/dscf/credit/category.rb +1 -1
  10. data/app/models/dscf/credit/credit_line.rb +7 -4
  11. data/app/models/dscf/credit/facilitator.rb +5 -4
  12. data/app/models/dscf/credit/facilitator_performance.rb +1 -2
  13. data/app/models/dscf/credit/loan_profile.rb +4 -3
  14. data/app/models/dscf/credit/loan_profile_scoring_spec.rb +3 -4
  15. data/app/models/dscf/credit/scoring_param_type.rb +17 -0
  16. data/app/models/dscf/credit/scoring_parameter.rb +7 -6
  17. data/app/models/dscf/credit/system_config.rb +5 -4
  18. data/app/serializers/dscf/credit/category_serializer.rb +1 -1
  19. data/app/serializers/dscf/credit/credit_line_serializer.rb +2 -2
  20. data/app/serializers/dscf/credit/facilitator_performance_serializer.rb +1 -1
  21. data/app/serializers/dscf/credit/facilitator_serializer.rb +2 -2
  22. data/app/serializers/dscf/credit/scoring_param_type_serializer.rb +7 -0
  23. data/app/serializers/dscf/credit/scoring_parameter_serializer.rb +4 -3
  24. data/app/serializers/dscf/credit/system_config_serializer.rb +2 -2
  25. data/app/services/dscf/credit/facilitator_approval_service.rb +4 -3
  26. data/app/services/dscf/credit/facilitator_creation_service.rb +157 -0
  27. data/config/locales/en.yml +46 -8
  28. data/config/routes.rb +23 -6
  29. data/db/migrate/20250822091011_create_dscf_credit_categories.rb +2 -0
  30. data/db/migrate/20250822091131_create_dscf_credit_credit_lines.rb +7 -4
  31. data/db/migrate/20250822091820_create_dscf_credit_system_configs.rb +5 -2
  32. data/db/migrate/20250822092040_create_dscf_credit_scoring_param_types.rb +12 -0
  33. data/db/migrate/20250822092050_create_dscf_credit_scoring_parameters.rb +11 -6
  34. data/db/migrate/20250822092246_create_dscf_credit_loan_profiles.rb +5 -3
  35. data/db/migrate/20250822092417_create_dscf_credit_loan_profile_scoring_specs.rb +5 -4
  36. data/db/migrate/20250822092436_create_dscf_credit_facilitators.rb +5 -2
  37. data/db/migrate/20250822092528_create_dscf_credit_facilitator_performances.rb +0 -3
  38. data/db/seeds.rb +48 -20
  39. data/lib/dscf/credit/version.rb +1 -1
  40. data/spec/factories/dscf/credit/categories.rb +1 -0
  41. data/spec/factories/dscf/credit/credit_lines.rb +7 -5
  42. data/spec/factories/dscf/credit/facilitator_performances.rb +0 -5
  43. data/spec/factories/dscf/credit/facilitators.rb +6 -1
  44. data/spec/factories/dscf/credit/loan_profile_scoring_specs.rb +3 -6
  45. data/spec/factories/dscf/credit/loan_profiles.rb +10 -6
  46. data/spec/factories/dscf/credit/scoring_param_types.rb +31 -0
  47. data/spec/factories/dscf/credit/scoring_parameters.rb +26 -4
  48. data/spec/factories/dscf/credit/system_configs.rb +8 -2
  49. metadata +23 -2
@@ -8,8 +8,10 @@ class CreateDscfCreditCreditLines < ActiveRecord::Migration[8.0]
8
8
  t.text :description
9
9
  t.string :status, default: 'pending'
10
10
  t.references :created_by, polymorphic: true, null: false
11
- t.references :approved_by, polymorphic: true, null: true
12
- t.datetime :approval_date
11
+ t.references :reviewed_by, polymorphic: true, null: true
12
+ t.datetime :review_date
13
+ t.jsonb :review_feedback, default: {}
14
+ t.string :document_reference
13
15
 
14
16
  t.timestamps
15
17
  end
@@ -18,8 +20,9 @@ class CreateDscfCreditCreditLines < ActiveRecord::Migration[8.0]
18
20
  add_index :dscf_credit_credit_lines, :code
19
21
  add_index :dscf_credit_credit_lines, :status
20
22
  add_index :dscf_credit_credit_lines, [ :created_by_type, :created_by_id ]
21
- add_index :dscf_credit_credit_lines, [ :approved_by_type, :approved_by_id ]
22
- add_index :dscf_credit_credit_lines, :approval_date
23
+ add_index :dscf_credit_credit_lines, [ :reviewed_by_type, :reviewed_by_id ]
24
+ add_index :dscf_credit_credit_lines, :review_date
25
+ add_index :dscf_credit_credit_lines, :document_reference
23
26
  add_index :dscf_credit_credit_lines, [ :bank_id, :code ], unique: true
24
27
  end
25
28
  end
@@ -5,13 +5,16 @@ class CreateDscfCreditSystemConfigs < ActiveRecord::Migration[8.0]
5
5
  t.text :config_value, null: false
6
6
  t.string :status, default: 'pending'
7
7
  t.references :last_updated_by, polymorphic: true, null: false
8
- t.references :approved_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: {}
9
11
 
10
12
  t.timestamps
11
13
  end
12
14
 
13
15
  add_index :dscf_credit_system_configs, [ :last_updated_by_type, :last_updated_by_id ]
14
- add_index :dscf_credit_system_configs, [ :approved_by_type, :approved_by_id ]
16
+ add_index :dscf_credit_system_configs, [ :reviewed_by_type, :reviewed_by_id ]
15
17
  add_index :dscf_credit_system_configs, :status
18
+ add_index :dscf_credit_system_configs, :review_date
16
19
  end
17
20
  end
@@ -0,0 +1,12 @@
1
+ class CreateDscfCreditScoringParamTypes < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :dscf_credit_scoring_param_types do |t|
4
+ t.string :name, null: false
5
+ t.text :description
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :dscf_credit_scoring_param_types, :name, unique: true
11
+ end
12
+ end
@@ -5,26 +5,31 @@ class CreateDscfCreditScoringParameters < ActiveRecord::Migration[8.0]
5
5
  t.string :name, null: false
6
6
  t.text :description
7
7
  t.string :data_type, null: false
8
- t.string :type, null: false
9
8
  t.decimal :weight, precision: 5, scale: 4, null: false
10
9
  t.decimal :min_value, precision: 15, scale: 2
11
10
  t.decimal :max_value, precision: 15, scale: 2
12
11
  t.boolean :active, default: true
13
12
  t.references :previous_version, foreign_key: { to_table: :dscf_credit_scoring_parameters }, null: true
14
13
  t.references :created_by, polymorphic: true, null: false
15
- t.references :approved_by, polymorphic: true, null: false
16
- t.datetime :expires_at
14
+ t.references :reviewed_by, polymorphic: true, null: false
15
+ t.datetime :review_date
16
+ t.jsonb :review_feedback, default: {}
17
+ t.string :source
18
+ t.references :scoring_param_type, null: false, foreign_key: { to_table: :dscf_credit_scoring_param_types }
19
+ t.string :document_reference
20
+ t.string :status, default: 'pending'
17
21
 
18
22
  t.timestamps
19
23
  end
20
24
 
21
25
  add_index :dscf_credit_scoring_parameters, :name
22
26
  add_index :dscf_credit_scoring_parameters, :data_type
23
- add_index :dscf_credit_scoring_parameters, :type
24
27
  add_index :dscf_credit_scoring_parameters, :active
25
28
  add_index :dscf_credit_scoring_parameters, [ :created_by_type, :created_by_id ]
26
- add_index :dscf_credit_scoring_parameters, [ :approved_by_type, :approved_by_id ]
27
- add_index :dscf_credit_scoring_parameters, :expires_at
29
+ add_index :dscf_credit_scoring_parameters, [ :reviewed_by_type, :reviewed_by_id ]
30
+ add_index :dscf_credit_scoring_parameters, :review_date
31
+ add_index :dscf_credit_scoring_parameters, :source
32
+ add_index :dscf_credit_scoring_parameters, :document_reference
28
33
  add_index :dscf_credit_scoring_parameters, [ :bank_id, :name, :active ]
29
34
  end
30
35
  end
@@ -7,8 +7,9 @@ class CreateDscfCreditLoanProfiles < ActiveRecord::Migration[8.0]
7
7
  t.string :status, default: 'pending'
8
8
  t.decimal :total_amount, precision: 15, scale: 2, default: 0
9
9
  t.decimal :available_amount, precision: 15, scale: 2, default: 0
10
- t.references :approved_by, polymorphic: true, null: false
11
- t.text :rejection_reason
10
+ t.references :reviewed_by, polymorphic: true, null: false
11
+ t.datetime :review_date
12
+ t.jsonb :review_feedback, default: {}
12
13
 
13
14
  t.timestamps
14
15
  end
@@ -17,7 +18,8 @@ class CreateDscfCreditLoanProfiles < ActiveRecord::Migration[8.0]
17
18
  add_index :dscf_credit_loan_profiles, :total_amount
18
19
  add_index :dscf_credit_loan_profiles, :available_amount
19
20
  add_index :dscf_credit_loan_profiles, [ :backer_type, :backer_id ]
20
- add_index :dscf_credit_loan_profiles, [ :approved_by_type, :approved_by_id ]
21
+ add_index :dscf_credit_loan_profiles, [ :reviewed_by_type, :reviewed_by_id ]
22
+ add_index :dscf_credit_loan_profiles, :review_date
21
23
  add_index :dscf_credit_loan_profiles, [ :bank_id, :user_id, :status ]
22
24
  add_index :dscf_credit_loan_profiles, [ :user_id, :status ]
23
25
  add_index :dscf_credit_loan_profiles, [ :total_amount, :available_amount ]
@@ -6,8 +6,9 @@ class CreateDscfCreditLoanProfileScoringSpecs < ActiveRecord::Migration[8.0]
6
6
  t.decimal :score, precision: 5, scale: 2, null: false
7
7
  t.boolean :active, default: true
8
8
  t.references :created_by, polymorphic: true, null: false
9
- t.references :approved_by, polymorphic: true, null: false
10
- t.datetime :expires_at
9
+ t.references :reviewed_by, polymorphic: true, null: false
10
+ t.datetime :review_date
11
+ t.jsonb :review_feedback, default: {}
11
12
 
12
13
  t.timestamps
13
14
  end
@@ -15,8 +16,8 @@ class CreateDscfCreditLoanProfileScoringSpecs < ActiveRecord::Migration[8.0]
15
16
  add_index :dscf_credit_loan_profile_scoring_specs, :score
16
17
  add_index :dscf_credit_loan_profile_scoring_specs, :active
17
18
  add_index :dscf_credit_loan_profile_scoring_specs, [ :created_by_type, :created_by_id ]
18
- add_index :dscf_credit_loan_profile_scoring_specs, [ :approved_by_type, :approved_by_id ]
19
- add_index :dscf_credit_loan_profile_scoring_specs, :expires_at
19
+ add_index :dscf_credit_loan_profile_scoring_specs, [ :reviewed_by_type, :reviewed_by_id ]
20
+ add_index :dscf_credit_loan_profile_scoring_specs, :review_date
20
21
  add_index :dscf_credit_loan_profile_scoring_specs, :scoring_input_data, using: :gin
21
22
  add_index :dscf_credit_loan_profile_scoring_specs, [ :loan_profile_id, :active ]
22
23
  end
@@ -7,7 +7,9 @@ class CreateDscfCreditFacilitators < ActiveRecord::Migration[8.0]
7
7
  t.string :type, null: false
8
8
  t.decimal :total_limit, precision: 15, scale: 2
9
9
  t.string :kyc_status, default: 'pending'
10
- t.references :kyc_approved_by, polymorphic: true, null: false
10
+ t.references :kyc_reviewed_by, polymorphic: true, null: false
11
+ t.datetime :kyc_review_date
12
+ t.jsonb :review_feedback, default: {}
11
13
 
12
14
  t.timestamps
13
15
  end
@@ -15,7 +17,8 @@ class CreateDscfCreditFacilitators < ActiveRecord::Migration[8.0]
15
17
  add_index :dscf_credit_facilitators, :name
16
18
  add_index :dscf_credit_facilitators, :type
17
19
  add_index :dscf_credit_facilitators, :kyc_status
18
- add_index :dscf_credit_facilitators, [ :kyc_approved_by_type, :kyc_approved_by_id ]
20
+ add_index :dscf_credit_facilitators, [ :kyc_reviewed_by_type, :kyc_reviewed_by_id ]
21
+ add_index :dscf_credit_facilitators, :kyc_review_date
19
22
  add_index :dscf_credit_facilitators, [ :bank_id, :user_id ], unique: true
20
23
  add_index :dscf_credit_facilitators, [ :user_id, :kyc_status ]
21
24
  end
@@ -9,7 +9,6 @@ class CreateDscfCreditFacilitatorPerformances < ActiveRecord::Migration[8.0]
9
9
  t.integer :previous_performance_id
10
10
  t.jsonb :input_data
11
11
  t.references :created_by, polymorphic: true, null: false
12
- t.datetime :expires_at
13
12
 
14
13
  t.timestamps
15
14
  end
@@ -19,8 +18,6 @@ class CreateDscfCreditFacilitatorPerformances < ActiveRecord::Migration[8.0]
19
18
  add_index :dscf_credit_facilitator_performances, :total_outstanding_amount
20
19
  add_index :dscf_credit_facilitator_performances, :approval_required
21
20
  add_index :dscf_credit_facilitator_performances, [ :created_by_type, :created_by_id ]
22
- add_index :dscf_credit_facilitator_performances, :expires_at
23
21
  add_index :dscf_credit_facilitator_performances, :input_data, using: :gin
24
- add_index :dscf_credit_facilitator_performances, [ :facilitator_id, :expires_at ]
25
22
  end
26
23
  end
data/db/seeds.rb CHANGED
@@ -306,14 +306,16 @@ puts "Seeding system configs..."
306
306
  Dscf::Credit::SystemConfig.find_or_create_by(config_definition: config_def1) do |config|
307
307
  config.config_value = '500000.00'
308
308
  config.status = 'approved'
309
- config.approved_by = admin_user
309
+ config.reviewed_by = admin_user
310
+ config.review_date = Time.current
310
311
  config.last_updated_by = admin_user
311
312
  end
312
313
 
313
314
  Dscf::Credit::SystemConfig.find_or_create_by(config_definition: config_def2) do |config|
314
315
  config.config_value = 'daily'
315
316
  config.status = 'approved'
316
- config.approved_by = admin_user
317
+ config.reviewed_by = admin_user
318
+ config.review_date = Time.current
317
319
  config.last_updated_by = admin_user
318
320
  end
319
321
 
@@ -341,6 +343,28 @@ corporate_category = Dscf::Credit::Category.find_or_create_by(type: 'credit_line
341
343
  category.description = 'Corporate credit category for large businesses'
342
344
  end
343
345
 
346
+ # 4.6. Scoring Param Types (independent)
347
+ puts "Seeding scoring param types..."
348
+ consumer_type = Dscf::Credit::ScoringParamType.find_or_create_by(name: 'Consumer') do |type|
349
+ type.description = 'Parameters for consumer credit scoring'
350
+ end
351
+
352
+ facilitator_type = Dscf::Credit::ScoringParamType.find_or_create_by(name: 'Facilitator') do |type|
353
+ type.description = 'Parameters for facilitator credit scoring'
354
+ end
355
+
356
+ wholesaler_type = Dscf::Credit::ScoringParamType.find_or_create_by(name: 'Wholesaler') do |type|
357
+ type.description = 'Parameters for wholesaler credit scoring'
358
+ end
359
+
360
+ retailer_type = Dscf::Credit::ScoringParamType.find_or_create_by(name: 'Retailer') do |type|
361
+ type.description = 'Parameters for retailer credit scoring'
362
+ end
363
+
364
+ manufacturer_type = Dscf::Credit::ScoringParamType.find_or_create_by(name: 'Manufacturer') do |type|
365
+ type.description = 'Parameters for manufacturer credit scoring'
366
+ end
367
+
344
368
  # 5. Credit Lines (depends on banks, users, and categories)
345
369
  puts "Seeding credit lines..."
346
370
  credit_line1 = Dscf::Credit::CreditLine.find_or_create_by(bank: bank1, name: 'SME Credit Line') do |line|
@@ -349,8 +373,8 @@ credit_line1 = Dscf::Credit::CreditLine.find_or_create_by(bank: bank1, name: 'SM
349
373
  line.description = 'Credit line for Small and Medium Enterprises'
350
374
  line.status = 'approved'
351
375
  line.created_by = admin_user
352
- line.approved_by = bank_admin
353
- line.approval_date = 1.week.ago
376
+ line.reviewed_by = bank_admin
377
+ line.review_date = 1.week.ago
354
378
  end
355
379
 
356
380
  credit_line2 = Dscf::Credit::CreditLine.find_or_create_by(bank: bank1, name: 'Personal Credit Line') do |line|
@@ -359,8 +383,8 @@ credit_line2 = Dscf::Credit::CreditLine.find_or_create_by(bank: bank1, name: 'Pe
359
383
  line.description = 'Personal credit line for individuals'
360
384
  line.status = 'approved'
361
385
  line.created_by = admin_user
362
- line.approved_by = bank_admin
363
- line.approval_date = 5.days.ago
386
+ line.reviewed_by = bank_admin
387
+ line.review_date = 5.days.ago
364
388
  end
365
389
 
366
390
  Dscf::Credit::CreditLine.find_or_create_by(bank: bank2, name: 'Agricultural Credit Line') do |line|
@@ -369,7 +393,7 @@ Dscf::Credit::CreditLine.find_or_create_by(bank: bank2, name: 'Agricultural Cred
369
393
  line.description = 'Credit line for agricultural sector'
370
394
  line.status = 'pending'
371
395
  line.created_by = bank_admin
372
- line.approved_by = admin_user
396
+ line.reviewed_by = admin_user
373
397
  end
374
398
 
375
399
  # 6. Credit Line Specs (depends on credit lines)
@@ -420,14 +444,15 @@ scoring_param1 = Dscf::Credit::ScoringParameter.find_or_create_by(
420
444
  ) do |param|
421
445
  param.description = 'Monthly income of the applicant'
422
446
  param.data_type = 'decimal'
423
- param.type = 'financial'
424
447
  param.weight = 0.3
425
448
  param.min_value = 0
426
449
  param.max_value = 1000000
427
450
  param.active = true
428
- param.approved_by = admin_user
451
+ param.reviewed_by = admin_user
452
+ param.review_date = Time.current
429
453
  param.created_by = admin_user
430
- param.expires_at = 1.year.from_now
454
+ param.source = 'internal'
455
+ param.document_reference = 'DOC-SP-001'
431
456
  end
432
457
 
433
458
  scoring_param2 = Dscf::Credit::ScoringParameter.find_or_create_by(
@@ -436,14 +461,15 @@ scoring_param2 = Dscf::Credit::ScoringParameter.find_or_create_by(
436
461
  ) do |param|
437
462
  param.description = 'Credit history score from credit bureau'
438
463
  param.data_type = 'integer'
439
- param.type = 'credit_history'
440
464
  param.weight = 0.4
441
465
  param.min_value = 300
442
466
  param.max_value = 850
443
467
  param.active = true
444
- param.approved_by = admin_user
468
+ param.reviewed_by = admin_user
469
+ param.review_date = Time.current
445
470
  param.created_by = admin_user
446
- param.expires_at = 1.year.from_now
471
+ param.source = 'external'
472
+ param.document_reference = 'DOC-SP-002'
447
473
  end
448
474
 
449
475
  scoring_param3 = Dscf::Credit::ScoringParameter.find_or_create_by(
@@ -452,12 +478,13 @@ scoring_param3 = Dscf::Credit::ScoringParameter.find_or_create_by(
452
478
  ) do |param|
453
479
  param.description = 'Type of employment (permanent, contract, self-employed)'
454
480
  param.data_type = 'string'
455
- param.type = 'employment'
456
481
  param.weight = 0.2
457
482
  param.active = true
458
- param.approved_by = bank_admin
483
+ param.reviewed_by = bank_admin
484
+ param.review_date = Time.current
459
485
  param.created_by = admin_user
460
- param.expires_at = 1.year.from_now
486
+ param.source = 'internal'
487
+ param.document_reference = 'DOC-SP-003'
461
488
  end
462
489
 
463
490
  # 8. Parameter Normalizers (depends on scoring parameters)
@@ -576,7 +603,8 @@ loan_profile1 = Dscf::Credit::LoanProfile.find_or_create_by(
576
603
  profile.status = 'approved'
577
604
  profile.total_amount = 100000.00
578
605
  profile.available_amount = 75000.00
579
- profile.approved_by = bank_admin
606
+ profile.reviewed_by = bank_admin
607
+ profile.review_date = Time.current
580
608
  # Note: backer will be set when facilitators are created via API
581
609
  end
582
610
 
@@ -593,9 +621,9 @@ Dscf::Credit::LoanProfileScoringSpec.create!(
593
621
  },
594
622
  score: 78.5,
595
623
  active: true,
596
- approved_by: admin_user,
597
- created_by: admin_user,
598
- expires_at: 6.months.from_now
624
+ reviewed_by: admin_user,
625
+ review_date: Time.current,
626
+ created_by: admin_user
599
627
  )
600
628
 
601
629
  # 13. Payment Requests (depends on users)
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Credit
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  type { %w[scoring loan_profile payment risk_assessment].sample }
4
4
  sequence(:name) { |n| "#{type.humanize} Category #{n}" }
5
5
  description { Faker::Lorem.paragraph }
6
+ document_reference { Faker::Alphanumeric.alphanumeric(number: 10).upcase }
6
7
 
7
8
  trait :scoring do
8
9
  type { "scoring" }
@@ -3,26 +3,28 @@ FactoryBot.define do
3
3
  association :bank, factory: :bank
4
4
  association :category, factory: :category
5
5
  association :created_by, factory: :user if defined?(Dscf::Core::User)
6
- association :approved_by, factory: :user if defined?(Dscf::Core::User)
6
+ association :reviewed_by, factory: :user if defined?(Dscf::Core::User)
7
7
  name { "#{Faker::Finance.credit_card(:visa)} Credit Line" }
8
8
  sequence(:code) { |n| "CL#{n.to_s.rjust(4, '0')}" }
9
9
  description { Faker::Lorem.paragraph }
10
10
  status { %w[pending approved active suspended].sample }
11
- approval_date { Faker::Date.between(from: 6.months.ago, to: Date.current) if status.in?(%w[approved active]) }
11
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) if status.in?(%w[approved active]) }
12
+ document_reference { Faker::Alphanumeric.alphanumeric(number: 10).upcase }
13
+ review_feedback { {} }
12
14
 
13
15
  trait :pending do
14
16
  status { "pending" }
15
- approval_date { nil }
17
+ review_date { nil }
16
18
  end
17
19
 
18
20
  trait :approved do
19
21
  status { "approved" }
20
- approval_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
22
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
21
23
  end
22
24
 
23
25
  trait :active do
24
26
  status { "active" }
25
- approval_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
27
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
26
28
  end
27
29
 
28
30
  trait :suspended do
@@ -7,7 +7,6 @@ FactoryBot.define do
7
7
  total_outstanding_amount { Faker::Number.decimal(l_digits: 6, r_digits: 2) }
8
8
  approval_required { [ true, false ].sample }
9
9
  input_data { Faker::Json.shallow_json(width: 3, options: { key: 'Name.name', value: 'Number.number' }) }
10
- expires_at { Faker::Date.between(from: 1.month.from_now, to: 1.year.from_now) }
11
10
 
12
11
  trait :high_performance do
13
12
  score { Faker::Number.between(from: 80.0, to: 100.0) }
@@ -22,9 +21,5 @@ FactoryBot.define do
22
21
  trait :requiring_approval do
23
22
  approval_required { true }
24
23
  end
25
-
26
- trait :expired do
27
- expires_at { Faker::Date.between(from: 1.year.ago, to: 1.month.ago) }
28
- end
29
24
  end
30
25
  end
@@ -2,22 +2,27 @@ FactoryBot.define do
2
2
  factory :facilitator, class: "Dscf::Credit::Facilitator" do
3
3
  association :bank, factory: :bank
4
4
  association :user, factory: :user if defined?(Dscf::Core::User)
5
- association :kyc_approved_by, factory: :user if defined?(Dscf::Core::User)
5
+ association :kyc_reviewed_by, factory: :user if defined?(Dscf::Core::User)
6
6
  name { Faker::Name.name }
7
7
  type { %w[individual corporate agent].sample }
8
8
  total_limit { Faker::Number.decimal(l_digits: 6, r_digits: 2) }
9
9
  kyc_status { %w[pending approved rejected].sample }
10
+ kyc_review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) if kyc_status == "approved" }
11
+ review_feedback { {} }
10
12
 
11
13
  trait :pending_kyc do
12
14
  kyc_status { "pending" }
15
+ kyc_review_date { nil }
13
16
  end
14
17
 
15
18
  trait :approved do
16
19
  kyc_status { "approved" }
20
+ kyc_review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
17
21
  end
18
22
 
19
23
  trait :rejected do
20
24
  kyc_status { "rejected" }
25
+ kyc_review_date { nil }
21
26
  end
22
27
 
23
28
  trait :individual do
@@ -2,11 +2,12 @@ FactoryBot.define do
2
2
  factory :loan_profile_scoring_spec, class: "Dscf::Credit::LoanProfileScoringSpec" do
3
3
  association :loan_profile, factory: :loan_profile
4
4
  association :created_by, factory: :user if defined?(Dscf::Core::User)
5
- association :approved_by, factory: :user if defined?(Dscf::Core::User)
5
+ association :reviewed_by, factory: :user if defined?(Dscf::Core::User)
6
6
  scoring_input_data { Faker::Json.shallow_json(width: 5, options: { key: 'Name.name', value: 'Number.number' }) }
7
7
  score { Faker::Number.decimal(l_digits: 2, r_digits: 2) }
8
8
  active { true }
9
- expires_at { Faker::Date.between(from: 3.months.from_now, to: 1.year.from_now) }
9
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
10
+ review_feedback { {} }
10
11
 
11
12
  trait :active do
12
13
  active { true }
@@ -23,9 +24,5 @@ FactoryBot.define do
23
24
  trait :low_score do
24
25
  score { Faker::Number.between(from: 0.0, to: 30.0) }
25
26
  end
26
-
27
- trait :expired do
28
- expires_at { Faker::Date.between(from: 1.year.ago, to: 1.month.ago) }
29
- end
30
27
  end
31
28
  end
@@ -1,27 +1,31 @@
1
1
  FactoryBot.define do
2
2
  factory :loan_profile, class: "Dscf::Credit::LoanProfile" do
3
3
  association :bank, factory: :bank
4
- association :approved_by, factory: :user if defined?(Dscf::Core::User)
4
+ association :reviewed_by, factory: :user if defined?(Dscf::Core::User)
5
5
  association :user, factory: :user if defined?(Dscf::Core::User)
6
6
  association :backer, factory: :user if defined?(Dscf::Core::User)
7
- status { %w[pending approved rejected].sample }
7
+ status { %w[pending approved rejected kyc_approved kyc_rejected].sample }
8
8
  total_amount { Faker::Number.decimal(l_digits: 6, r_digits: 2).to_f }
9
9
  available_amount { total_amount - Faker::Number.decimal(l_digits: 4, r_digits: 2).to_f }
10
- rejection_reason { Faker::Lorem.sentence if status == "rejected" }
10
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) if status == "approved" }
11
+ review_feedback { status == "rejected" ? { reason: Faker::Lorem.sentence } : {} }
11
12
 
12
13
  trait :pending do
13
14
  status { "pending" }
14
- rejection_reason { nil }
15
+ review_feedback { {} }
16
+ review_date { nil }
15
17
  end
16
18
 
17
19
  trait :approved do
18
20
  status { "approved" }
19
- rejection_reason { nil }
21
+ review_feedback { {} }
22
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
20
23
  end
21
24
 
22
25
  trait :rejected do
23
26
  status { "rejected" }
24
- rejection_reason { Faker::Lorem.sentence }
27
+ review_feedback { { reason: Faker::Lorem.sentence } }
28
+ review_date { nil }
25
29
  end
26
30
 
27
31
  trait :fully_available do
@@ -0,0 +1,31 @@
1
+ FactoryBot.define do
2
+ factory :scoring_param_type, class: "Dscf::Credit::ScoringParamType" do
3
+ name { Faker::Lorem.word.capitalize }
4
+ description { Faker::Lorem.paragraph }
5
+
6
+ trait :consumer do
7
+ name { "Consumer" }
8
+ description { "Parameters for consumer credit scoring" }
9
+ end
10
+
11
+ trait :facilitator do
12
+ name { "Facilitator" }
13
+ description { "Parameters for facilitator credit scoring" }
14
+ end
15
+
16
+ trait :wholesaler do
17
+ name { "Wholesaler" }
18
+ description { "Parameters for wholesaler credit scoring" }
19
+ end
20
+
21
+ trait :retailer do
22
+ name { "Retailer" }
23
+ description { "Parameters for retailer credit scoring" }
24
+ end
25
+
26
+ trait :manufacturer do
27
+ name { "Manufacturer" }
28
+ description { "Parameters for manufacturer credit scoring" }
29
+ end
30
+ end
31
+ end
@@ -2,16 +2,20 @@ FactoryBot.define do
2
2
  factory :scoring_parameter, class: "Dscf::Credit::ScoringParameter" do
3
3
  association :bank, factory: :bank
4
4
  association :created_by, factory: :user if defined?(Dscf::Core::User)
5
- association :approved_by, factory: :user if defined?(Dscf::Core::User)
6
- name { Faker::Lorem.words(number: 2).join('_').downcase }
5
+ association :reviewed_by, factory: :user if defined?(Dscf::Core::User)
6
+ association :scoring_param_type, factory: :scoring_param_type
7
+ sequence(:name) { |n| "#{Faker::Lorem.words(number: 2).join('_').downcase}_#{n}" }
7
8
  description { Faker::Lorem.paragraph }
8
9
  data_type { %w[integer decimal boolean string].sample }
9
- type { %w[income credit_history employment_status collateral].sample }
10
10
  weight { Faker::Number.decimal(l_digits: 0, r_digits: 4) }
11
11
  min_value { Faker::Number.decimal(l_digits: 2, r_digits: 2) }
12
12
  max_value { min_value + Faker::Number.decimal(l_digits: 3, r_digits: 2) }
13
13
  active { true }
14
- expires_at { Faker::Date.between(from: 6.months.from_now, to: 2.years.from_now) }
14
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
15
+ source { Faker::Lorem.word }
16
+ document_reference { Faker::Alphanumeric.alphanumeric(number: 10).upcase }
17
+ status { "pending" }
18
+ review_feedback { {} }
15
19
 
16
20
  trait :active do
17
21
  active { true }
@@ -44,5 +48,23 @@ FactoryBot.define do
44
48
  min_value { nil }
45
49
  max_value { nil }
46
50
  end
51
+
52
+ trait :pending do
53
+ status { "pending" }
54
+ end
55
+
56
+ trait :approved do
57
+ status { "approved" }
58
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
59
+ end
60
+
61
+ trait :rejected do
62
+ status { "rejected" }
63
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) }
64
+ end
65
+
66
+ trait :modify do
67
+ status { "modify" }
68
+ end
47
69
  end
48
70
  end
@@ -2,9 +2,11 @@ FactoryBot.define do
2
2
  factory :system_config, class: "Dscf::Credit::SystemConfig" do
3
3
  association :config_definition, factory: :system_config_definition
4
4
  association :last_updated_by, factory: :user if defined?(Dscf::Core::User)
5
- association :approved_by, factory: :user if defined?(Dscf::Core::User)
5
+ association :reviewed_by, factory: :user if defined?(Dscf::Core::User)
6
6
  config_value { Faker::Lorem.word }
7
- status { %w[pending approved rejected].sample }
7
+ status { %w[pending approved rejected modify].sample }
8
+ review_date { Faker::Date.between(from: 6.months.ago, to: Date.current) if status == 'approved' }
9
+ review_feedback { {} }
8
10
 
9
11
  trait :string_value do
10
12
  config_value { Faker::Lorem.sentence }
@@ -25,5 +27,9 @@ FactoryBot.define do
25
27
  trait :json_value do
26
28
  value { { key: Faker::Lorem.word, value: Faker::Number.number(digits: 3) }.to_json }
27
29
  end
30
+
31
+ trait :modify do
32
+ status { "modify" }
33
+ end
28
34
  end
29
35
  end