cats_core 1.4.13 → 1.4.16

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/{monthly_plans_controller.rb → round_plans_controller.rb} +11 -10
  3. data/app/models/cats/core/beneficiary.rb +15 -0
  4. data/app/models/cats/core/beneficiary_category.rb +11 -0
  5. data/app/models/cats/core/beneficiary_plan_item.rb +12 -0
  6. data/app/models/cats/core/beneficiary_round_plan_item.rb +14 -0
  7. data/app/models/cats/core/plan.rb +5 -2
  8. data/app/models/cats/core/plan_item.rb +10 -3
  9. data/app/models/cats/core/plan_item_detail.rb +4 -4
  10. data/app/models/cats/core/ration.rb +8 -1
  11. data/app/models/cats/core/{monthly_plan.rb → round_plan.rb} +22 -11
  12. data/app/models/cats/core/round_plan_item.rb +25 -0
  13. data/app/models/cats/core/round_plan_item_detail.rb +11 -0
  14. data/app/models/cats/core/round_ration.rb +17 -0
  15. data/app/serializers/cats/core/round_plan_serializer.rb +7 -0
  16. data/app/services/cats/core/round_plan_service.rb +108 -0
  17. data/config/routes.rb +5 -5
  18. data/db/migrate/20210717031810_create_cats_core_plans.rb +0 -4
  19. data/db/migrate/20210717032024_create_cats_core_plan_items.rb +13 -2
  20. data/db/migrate/20210717032260_create_cats_core_beneficiary_categories.rb +14 -0
  21. data/db/migrate/{20210717031343_create_cats_core_ration_items.rb → 20210717032270_create_cats_core_rations.rb} +9 -8
  22. data/db/migrate/20210717032290_create_cats_core_beneficiary_plan_items.rb +23 -0
  23. data/db/migrate/20210717032295_create_cats_core_plan_item_details.rb +18 -0
  24. data/db/migrate/{20220107121752_create_cats_core_monthly_plans.rb → 20220107121752_create_cats_core_round_plans.rb} +3 -4
  25. data/db/migrate/20220107122280_create_cats_core_round_rations.rb +26 -0
  26. data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +33 -0
  27. data/db/migrate/20220107126025_create_cats_core_beneficiary_round_plan_items.rb +24 -0
  28. data/db/migrate/20220107132433_create_cats_core_round_plan_item_details.rb +17 -0
  29. data/db/migrate/20220511082354_create_cats_core_beneficiaries.rb +16 -0
  30. data/lib/cats/core/version.rb +1 -1
  31. data/spec/factories/cats/core/beneficiaries.rb +9 -0
  32. data/spec/factories/cats/core/beneficiary_categories.rb +7 -0
  33. data/spec/factories/cats/core/beneficiary_plan_items.rb +7 -0
  34. data/spec/factories/cats/core/beneficiary_round_plan_items.rb +8 -0
  35. data/spec/factories/cats/core/dispatch_plans.rb +3 -3
  36. data/spec/factories/cats/core/locations.rb +4 -4
  37. data/spec/factories/cats/core/plan_item_details.rb +3 -3
  38. data/spec/factories/cats/core/plan_items.rb +4 -2
  39. data/spec/factories/cats/core/plans.rb +0 -1
  40. data/spec/factories/cats/core/rations.rb +5 -2
  41. data/spec/factories/cats/core/round_plan_item_details.rb +7 -0
  42. data/spec/factories/cats/core/round_plan_items.rb +11 -0
  43. data/spec/factories/cats/core/{monthly_plans.rb → round_plans.rb} +2 -3
  44. data/spec/factories/cats/core/round_rations.rb +10 -0
  45. metadata +31 -22
  46. data/app/models/cats/core/monthly_plan_item.rb +0 -15
  47. data/app/models/cats/core/monthly_plan_item_detail.rb +0 -14
  48. data/app/models/cats/core/monthly_ration.rb +0 -15
  49. data/app/models/cats/core/ration_item.rb +0 -14
  50. data/app/serializers/cats/core/monthly_plan_serializer.rb +0 -8
  51. data/app/services/cats/core/monthly_plan_service.rb +0 -86
  52. data/db/migrate/20210717031216_create_cats_core_rations.rb +0 -14
  53. data/db/migrate/20210717032240_create_cats_core_plan_item_details.rb +0 -18
  54. data/db/migrate/20220107124630_create_cats_core_monthly_rations.rb +0 -22
  55. data/db/migrate/20220107125025_create_cats_core_monthly_plan_items.rb +0 -17
  56. data/db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb +0 -17
  57. data/spec/factories/cats/core/monthly_plan_item_details.rb +0 -7
  58. data/spec/factories/cats/core/monthly_plan_items.rb +0 -7
  59. data/spec/factories/cats/core/monthly_rations.rb +0 -9
  60. data/spec/factories/cats/core/ration_items.rb +0 -9
@@ -0,0 +1,33 @@
1
+ class CreateCatsCoreRoundPlanItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_round_plan_items do |t|
4
+ t.references :round_plan,
5
+ null: false,
6
+ index: { name: 'mp_on_mpi_indx' },
7
+ foreign_key: { to_table: :cats_core_round_plans }
8
+ t.references :region,
9
+ null: false,
10
+ index: { name: 'region_on_round_plan_items_indx' },
11
+ foreign_key: { to_table: :cats_core_locations }
12
+ t.references :zone,
13
+ null: false,
14
+ index: { name: 'zone_on_round_plan_items_indx' },
15
+ foreign_key: { to_table: :cats_core_locations }
16
+ t.references :woreda,
17
+ null: false,
18
+ index: { name: 'woreda_on_round_plan_items_idnx' },
19
+ foreign_key: { to_table: :cats_core_locations }
20
+ t.references :fdp,
21
+ null: false,
22
+ index: { name: 'fdp_on_round_plan_items_indx' },
23
+ foreign_key: { to_table: :cats_core_locations }
24
+ t.references :operator,
25
+ null: false,
26
+ index: { name: 'operator_on_rpi_indx' },
27
+ foreign_key: { to_table: :cats_core_operators }
28
+ t.integer :plan_item_id, null: false
29
+
30
+ t.timestamps
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ class CreateCatsCoreBeneficiaryRoundPlanItems < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_beneficiary_round_plan_items do |t|
4
+ t.references :round_plan_item,
5
+ null: false,
6
+ index: { name: 'rpi_on_brpi_indx' },
7
+ foreign_key: { to_table: :cats_core_round_plan_items }
8
+ t.references :beneficiary_category,
9
+ null: false,
10
+ index: { name: 'bc_on_brpi_indx' },
11
+ foreign_key: { to_table: :cats_core_beneficiary_categories }
12
+ t.integer :planned_beneficiaries, null: false
13
+ t.integer :beneficiaries, null: false
14
+
15
+ t.timestamps
16
+ end
17
+ add_index(
18
+ :cats_core_beneficiary_round_plan_items,
19
+ [ :round_plan_item_id, :beneficiary_category_id ],
20
+ unique: true,
21
+ name: 'rpii_on_bci_uniq_indx'
22
+ )
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ class CreateCatsCoreRoundPlanItemDetails < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_round_plan_item_details do |t|
4
+ t.references :beneficiary_round_plan_item,
5
+ null: false,
6
+ index: { name: 'brpi_on_rpid_indx' },
7
+ foreign_key: { to_table: :cats_core_beneficiary_round_plan_items }
8
+ t.references :round_ration,
9
+ null: false,
10
+ index: { name: 'rr_on_rpid_indx' },
11
+ foreign_key: { to_table: :cats_core_round_rations }
12
+ t.float :quantity, null: false
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ class CreateCatsCoreBeneficiaries < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_beneficiaries do |t|
4
+ t.string :full_name, null: false
5
+ t.integer :age, null: false
6
+ t.string :gender, null: false
7
+ t.string :phone
8
+ t.references :beneficiary_category,
9
+ null: false,
10
+ index: { name: 'bc_on_beneficiaries_indx' },
11
+ foreign_key: { to_table: :cats_core_beneficiary_categories }
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.13'.freeze
3
+ VERSION = '1.4.16'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :beneficiary, class: 'Cats::Core::Beneficiary' do
3
+ full_name { FFaker::Name.name }
4
+ age { 30 }
5
+ gender { 'M' }
6
+ phone { '0911121212' }
7
+ beneficiary_category
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :beneficiary_category, class: 'Cats::Core::BeneficiaryCategory' do
3
+ code { FFaker::Name.name }
4
+ name { FFaker::Name.name }
5
+ plan
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :beneficiary_plan_item, class: 'Cats::Core::BeneficiaryPlanItem' do
3
+ plan_item
4
+ beneficiary_category
5
+ beneficiaries { 100 }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :beneficiary_round_plan_item, class: 'Cats::Core::BeneficiaryRoundPlanItem' do
3
+ round_plan_item
4
+ beneficiary_category
5
+ planned_beneficiaries { 100 }
6
+ beneficiaries { 50 }
7
+ end
8
+ end
@@ -15,10 +15,10 @@ FactoryBot.define do
15
15
  end
16
16
  end
17
17
 
18
- trait :with_monthly_plan do
18
+ trait :with_round_plan do
19
19
  dispatchable do
20
- disp = create(:monthly_plan)
21
- 3.times { create(:monthly_plan_item, monthly_plan: disp) }
20
+ disp = create(:round_plan)
21
+ 3.times { create(:round_plan_item, round_plan: disp) }
22
22
  disp.approve
23
23
  disp
24
24
  end
@@ -13,21 +13,21 @@ FactoryBot.define do
13
13
 
14
14
  factory :woreda, parent: :location, class: 'Cats::Core::Location' do
15
15
  location_type { Cats::Core::Location::WOREDA }
16
- parent
16
+ parent factory: :zone
17
17
  end
18
18
 
19
19
  factory :fdp, parent: :woreda, class: 'Cats::Core::Location' do
20
20
  location_type { Cats::Core::Location::FDP }
21
- parent
21
+ parent factory: :woreda
22
22
  end
23
23
 
24
24
  factory :hub, parent: :location, class: 'Cats::Core::Location' do
25
25
  location_type { Cats::Core::Location::HUB }
26
- parent
26
+ parent factory: :woreda
27
27
  end
28
28
 
29
29
  factory :warehouse, parent: :location, class: 'Cats::Core::Location' do
30
30
  location_type { Cats::Core::Location::WAREHOUSE }
31
- parent
31
+ parent factory: :hub
32
32
  end
33
33
  end
@@ -1,7 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :plan_item_detail, class: 'Cats::Core::PlanItemDetail' do
3
- plan_item
4
- ration_item
5
- amount { 150 }
3
+ beneficiary_plan_item
4
+ ration
5
+ quantity { 150 }
6
6
  end
7
7
  end
@@ -1,8 +1,10 @@
1
1
  FactoryBot.define do
2
2
  factory :plan_item, class: 'Cats::Core::PlanItem' do
3
3
  plan
4
- woreda
5
- beneficiaries { 100 }
4
+ fdp
5
+ woreda { fdp.parent }
6
+ zone { woreda.parent }
7
+ region { zone.parent }
6
8
  operator
7
9
  end
8
10
  end
@@ -7,6 +7,5 @@ FactoryBot.define do
7
7
  rounds { 6 }
8
8
  status { Cats::Core::Plan::DRAFT }
9
9
  program
10
- ration
11
10
  end
12
11
  end
@@ -1,7 +1,10 @@
1
1
  FactoryBot.define do
2
2
  factory :ration, class: 'Cats::Core::Ration' do
3
3
  reference_no { FFaker::Name.name }
4
- program
5
- current { false }
4
+ beneficiary_category
5
+ commodity_category
6
+ quantity { 150 }
7
+ unit_of_measure
8
+ no_of_days { 10 }
6
9
  end
7
10
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :round_plan_item_detail, class: 'Cats::Core::RoundPlanItemDetail' do
3
+ beneficiary_round_plan_item
4
+ round_ration
5
+ quantity { 150 }
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ FactoryBot.define do
2
+ factory :round_plan_item, class: 'Cats::Core::RoundPlanItem' do
3
+ round_plan
4
+ fdp
5
+ woreda { fdp.parent }
6
+ zone { woreda.parent }
7
+ region { zone.parent }
8
+ operator
9
+ plan_item_id { 1 }
10
+ end
11
+ end
@@ -1,10 +1,9 @@
1
1
  FactoryBot.define do
2
- factory :monthly_plan, class: 'Cats::Core::MonthlyPlan' do
2
+ factory :round_plan, class: 'Cats::Core::RoundPlan' do
3
3
  reference_no { FFaker::Name.name }
4
+ rounds { [1] }
4
5
  status { Cats::Core::Plan::DRAFT }
5
6
  plan
6
7
  region factory: :location
7
- month { 1 }
8
- no_of_days { 30 }
9
8
  end
10
9
  end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :round_ration, class: 'Cats::Core::RoundRation' do
3
+ beneficiary_category
4
+ commodity_category
5
+ quantity { 100 }
6
+ unit_of_measure
7
+ round_plan
8
+ no_of_days { 30 }
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.13
4
+ version: 1.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-10 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -242,11 +242,11 @@ files:
242
242
  - app/controllers/cats/core/locations_controller.rb
243
243
  - app/controllers/cats/core/lost_commodities_controller.rb
244
244
  - app/controllers/cats/core/menus_controller.rb
245
- - app/controllers/cats/core/monthly_plans_controller.rb
246
245
  - app/controllers/cats/core/notifications_controller.rb
247
246
  - app/controllers/cats/core/receipt_transactions_controller.rb
248
247
  - app/controllers/cats/core/receipts_controller.rb
249
248
  - app/controllers/cats/core/roles_controller.rb
249
+ - app/controllers/cats/core/round_plans_controller.rb
250
250
  - app/controllers/cats/core/routes_controller.rb
251
251
  - app/controllers/cats/core/spaces_controller.rb
252
252
  - app/controllers/cats/core/stacks_controller.rb
@@ -258,6 +258,10 @@ files:
258
258
  - app/jobs/cats/core/application_job.rb
259
259
  - app/models/cats/core/application_module.rb
260
260
  - app/models/cats/core/application_record.rb
261
+ - app/models/cats/core/beneficiary.rb
262
+ - app/models/cats/core/beneficiary_category.rb
263
+ - app/models/cats/core/beneficiary_plan_item.rb
264
+ - app/models/cats/core/beneficiary_round_plan_item.rb
261
265
  - app/models/cats/core/commodity.rb
262
266
  - app/models/cats/core/commodity_category.rb
263
267
  - app/models/cats/core/commodity_substitution.rb
@@ -275,10 +279,6 @@ files:
275
279
  - app/models/cats/core/lost_commodity.rb
276
280
  - app/models/cats/core/menu.rb
277
281
  - app/models/cats/core/menu_item.rb
278
- - app/models/cats/core/monthly_plan.rb
279
- - app/models/cats/core/monthly_plan_item.rb
280
- - app/models/cats/core/monthly_plan_item_detail.rb
281
- - app/models/cats/core/monthly_ration.rb
282
282
  - app/models/cats/core/notification.rb
283
283
  - app/models/cats/core/notification_rule.rb
284
284
  - app/models/cats/core/offer_item.rb
@@ -289,12 +289,15 @@ files:
289
289
  - app/models/cats/core/program.rb
290
290
  - app/models/cats/core/purchase_order.rb
291
291
  - app/models/cats/core/ration.rb
292
- - app/models/cats/core/ration_item.rb
293
292
  - app/models/cats/core/receipt.rb
294
293
  - app/models/cats/core/receipt_transaction.rb
295
294
  - app/models/cats/core/rhn_request.rb
296
295
  - app/models/cats/core/role.rb
297
296
  - app/models/cats/core/role_menu.rb
297
+ - app/models/cats/core/round_plan.rb
298
+ - app/models/cats/core/round_plan_item.rb
299
+ - app/models/cats/core/round_plan_item_detail.rb
300
+ - app/models/cats/core/round_ration.rb
298
301
  - app/models/cats/core/route.rb
299
302
  - app/models/cats/core/stack.rb
300
303
  - app/models/cats/core/stack_transaction.rb
@@ -331,11 +334,11 @@ files:
331
334
  - app/serializers/cats/core/dispatch_transaction_serializer.rb
332
335
  - app/serializers/cats/core/location_serializer.rb
333
336
  - app/serializers/cats/core/lost_commodity_serializer.rb
334
- - app/serializers/cats/core/monthly_plan_serializer.rb
335
337
  - app/serializers/cats/core/receipt_serializer.rb
336
338
  - app/serializers/cats/core/receipt_transaction_serializer.rb
337
339
  - app/serializers/cats/core/role_menu_serializer.rb
338
340
  - app/serializers/cats/core/role_serializer.rb
341
+ - app/serializers/cats/core/round_plan_serializer.rb
339
342
  - app/serializers/cats/core/route_serializer.rb
340
343
  - app/serializers/cats/core/stack_serializer.rb
341
344
  - app/serializers/cats/core/transporter_serializer.rb
@@ -345,9 +348,9 @@ files:
345
348
  - app/services/cats/core/dispatch_plan_service.rb
346
349
  - app/services/cats/core/dispatch_service.rb
347
350
  - app/services/cats/core/menu_service.rb
348
- - app/services/cats/core/monthly_plan_service.rb
349
351
  - app/services/cats/core/notification_service.rb
350
352
  - app/services/cats/core/receipt_service.rb
353
+ - app/services/cats/core/round_plan_service.rb
351
354
  - app/services/cats/core/space_service.rb
352
355
  - app/services/cats/core/stack_service.rb
353
356
  - app/services/cats/core/token_auth_service.rb
@@ -366,11 +369,12 @@ files:
366
369
  - db/migrate/20210716210635_create_cats_core_operators.rb
367
370
  - db/migrate/20210716210905_create_cats_core_suppliers.rb
368
371
  - db/migrate/20210717031108_create_cats_core_donors.rb
369
- - db/migrate/20210717031216_create_cats_core_rations.rb
370
- - db/migrate/20210717031343_create_cats_core_ration_items.rb
371
372
  - db/migrate/20210717031810_create_cats_core_plans.rb
372
373
  - db/migrate/20210717032024_create_cats_core_plan_items.rb
373
- - db/migrate/20210717032240_create_cats_core_plan_item_details.rb
374
+ - db/migrate/20210717032260_create_cats_core_beneficiary_categories.rb
375
+ - db/migrate/20210717032270_create_cats_core_rations.rb
376
+ - db/migrate/20210717032290_create_cats_core_beneficiary_plan_items.rb
377
+ - db/migrate/20210717032295_create_cats_core_plan_item_details.rb
374
378
  - db/migrate/20210717032330_create_cats_core_donations.rb
375
379
  - db/migrate/20210717032602_create_cats_core_gift_certificates.rb
376
380
  - db/migrate/20210717032855_create_cats_core_purchase_orders.rb
@@ -403,10 +407,11 @@ files:
403
407
  - db/migrate/20211229160128_create_cats_core_contract_items.rb
404
408
  - db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb
405
409
  - db/migrate/20220103152802_create_cats_core_tenderers.rb
406
- - db/migrate/20220107121752_create_cats_core_monthly_plans.rb
407
- - db/migrate/20220107124630_create_cats_core_monthly_rations.rb
408
- - db/migrate/20220107125025_create_cats_core_monthly_plan_items.rb
409
- - db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb
410
+ - db/migrate/20220107121752_create_cats_core_round_plans.rb
411
+ - db/migrate/20220107122280_create_cats_core_round_rations.rb
412
+ - db/migrate/20220107125025_create_cats_core_round_plan_items.rb
413
+ - db/migrate/20220107126025_create_cats_core_beneficiary_round_plan_items.rb
414
+ - db/migrate/20220107132433_create_cats_core_round_plan_item_details.rb
410
415
  - db/migrate/20220209083928_create_cats_core_hub_authorizations.rb
411
416
  - db/migrate/20220416143416_create_cats_core_unit_conversions.rb
412
417
  - db/migrate/20220417105839_create_cats_core_transport_requisitions.rb
@@ -414,12 +419,17 @@ files:
414
419
  - db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb
415
420
  - db/migrate/20220506082329_create_cats_core_transport_orders.rb
416
421
  - db/migrate/20220506083042_create_cats_core_transport_order_items.rb
422
+ - db/migrate/20220511082354_create_cats_core_beneficiaries.rb
417
423
  - lib/cats/core.rb
418
424
  - lib/cats/core/engine.rb
419
425
  - lib/cats/core/version.rb
420
426
  - lib/cats_core.rb
421
427
  - lib/tasks/cats_core_tasks.rake
422
428
  - spec/factories/cats/core/application_modules.rb
429
+ - spec/factories/cats/core/beneficiaries.rb
430
+ - spec/factories/cats/core/beneficiary_categories.rb
431
+ - spec/factories/cats/core/beneficiary_plan_items.rb
432
+ - spec/factories/cats/core/beneficiary_round_plan_items.rb
423
433
  - spec/factories/cats/core/commodities.rb
424
434
  - spec/factories/cats/core/commodity_categories.rb
425
435
  - spec/factories/cats/core/commodity_substitutions.rb
@@ -437,10 +447,6 @@ files:
437
447
  - spec/factories/cats/core/lost_commodities.rb
438
448
  - spec/factories/cats/core/menu_items.rb
439
449
  - spec/factories/cats/core/menus.rb
440
- - spec/factories/cats/core/monthly_plan_item_details.rb
441
- - spec/factories/cats/core/monthly_plan_items.rb
442
- - spec/factories/cats/core/monthly_plans.rb
443
- - spec/factories/cats/core/monthly_rations.rb
444
450
  - spec/factories/cats/core/notification_rules.rb
445
451
  - spec/factories/cats/core/notifications.rb
446
452
  - spec/factories/cats/core/offer_items.rb
@@ -450,13 +456,16 @@ files:
450
456
  - spec/factories/cats/core/plans.rb
451
457
  - spec/factories/cats/core/programs.rb
452
458
  - spec/factories/cats/core/purchase_orders.rb
453
- - spec/factories/cats/core/ration_items.rb
454
459
  - spec/factories/cats/core/rations.rb
455
460
  - spec/factories/cats/core/receipt_transactions.rb
456
461
  - spec/factories/cats/core/receipts.rb
457
462
  - spec/factories/cats/core/rhn_requests.rb
458
463
  - spec/factories/cats/core/role_menus.rb
459
464
  - spec/factories/cats/core/roles.rb
465
+ - spec/factories/cats/core/round_plan_item_details.rb
466
+ - spec/factories/cats/core/round_plan_items.rb
467
+ - spec/factories/cats/core/round_plans.rb
468
+ - spec/factories/cats/core/round_rations.rb
460
469
  - spec/factories/cats/core/routes.rb
461
470
  - spec/factories/cats/core/stack_transactions.rb
462
471
  - spec/factories/cats/core/stacking_rules.rb
@@ -1,15 +0,0 @@
1
- module Cats
2
- module Core
3
- class MonthlyPlanItem < ApplicationRecord
4
- belongs_to :monthly_plan
5
- belongs_to :plan_item
6
-
7
- has_many :monthly_plan_item_details
8
-
9
- validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
10
-
11
- delegate(:reference_no, to: :monthly_plan, prefix: 'plan')
12
- delegate(:woreda_name, to: :plan_item)
13
- end
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- module Cats
2
- module Core
3
- class MonthlyPlanItemDetail < ApplicationRecord
4
- belongs_to :monthly_plan_item
5
- belongs_to :monthly_ration
6
-
7
- validates :amount, presence: true, numericality: { greater_than: 0 }
8
-
9
- delegate(:commodity_category_name, to: :monthly_ration)
10
- delegate(:unit_of_measure_abbreviation, to: :monthly_ration)
11
- delegate(:no_of_days, to: :monthly_ration)
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- module Cats
2
- module Core
3
- class MonthlyRation < ApplicationRecord
4
- belongs_to :commodity_category
5
- belongs_to :unit_of_measure
6
- belongs_to :monthly_plan
7
-
8
- validates :amount, :no_of_days, presence: true, numericality: { greater_than: 0 }
9
-
10
- delegate(:name, to: :commodity_category, prefix: true)
11
- delegate(:abbreviation, to: :unit_of_measure, prefix: true)
12
- delegate(:reference_no, to: :monthly_plan, prefix: true)
13
- end
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- module Cats
2
- module Core
3
- class RationItem < ApplicationRecord
4
- belongs_to :commodity_category
5
- belongs_to :ration
6
- belongs_to :unit_of_measure
7
-
8
- validates :amount, :no_of_days, presence: true, numericality: { greater_than: 0 }
9
-
10
- delegate(:name, to: :commodity_category, prefix: true)
11
- delegate(:abbreviation, to: :unit_of_measure, prefix: true)
12
- end
13
- end
14
- end
@@ -1,8 +0,0 @@
1
- module Cats
2
- module Core
3
- class MonthlyPlanSerializer < ActiveModel::Serializer
4
- attributes :id, :reference_no, :status, :plan_id, :plan_reference_no, :region_id, :region_name, :month,
5
- :no_of_days
6
- end
7
- end
8
- end
@@ -1,86 +0,0 @@
1
- module Cats
2
- module Core
3
- class MonthlyPlanService
4
- def generate_monthly_needs(plan_id)
5
- plan = Cats::Core::MonthlyPlan.find(plan_id)
6
- raise(StandardError, 'Plan has no rations.') if plan.monthly_rations.count.zero?
7
-
8
- raise(StandardError, 'Plan has no plan items.') if plan.monthly_plan_items.count.zero?
9
-
10
- plan.monthly_plan_item_details.delete_all if plan.monthly_plan_item_details.count.positive?
11
-
12
- details = []
13
- plan.monthly_plan_items.each do |plan_item|
14
- plan.monthly_rations.each do |ration|
15
- details << {
16
- monthly_plan_item_id: plan_item.id,
17
- monthly_ration_id: ration.id,
18
- amount: (plan.no_of_days / ration.no_of_days * ration.amount) * plan_item.beneficiaries,
19
- created_at: Date.today,
20
- updated_at: Date.today
21
- }
22
- end
23
- end
24
-
25
- Cats::Core::MonthlyPlanItemDetail.insert_all!(details)
26
- plan
27
- end
28
-
29
- def generate_monthly_plan(params)
30
- region = Cats::Core::Location.find(params[:region_id])
31
- plan = Cats::Core::Plan.includes(plan_items: :plan_item_details).find(params[:plan_id])
32
- rations = Cats::Core::RationItem.where(ration_id: plan.ration_id)
33
- monthly_plan = Cats::Core::MonthlyPlan.create!(
34
- plan_id: plan.id,
35
- reference_no: params[:reference_no],
36
- region_id: params[:region_id],
37
- status: Cats::Core::Plan::DRAFT,
38
- month: params[:month],
39
- no_of_days: params[:no_of_days]
40
- )
41
- ration_items = rations.map do |ration|
42
- {
43
- commodity_category_id: ration.commodity_category_id,
44
- amount: ration.amount,
45
- unit_of_measure_id: ration.unit_of_measure_id,
46
- no_of_days: ration.no_of_days,
47
- monthly_plan_id: monthly_plan.id,
48
- created_at: Date.today,
49
- updated_at: Date.today
50
- }
51
- end
52
- Cats::Core::MonthlyRation.insert_all!(ration_items)
53
-
54
- plan_items = plan.plan_items.where(woreda_id: region.descendant_ids).map do |plan_item|
55
- {
56
- monthly_plan_id: monthly_plan.id,
57
- beneficiaries: plan_item.beneficiaries,
58
- plan_item_id: plan_item.id,
59
- created_at: Date.today,
60
- updated_at: Date.today
61
- }
62
- end
63
- Cats::Core::MonthlyPlanItem.insert_all!(plan_items)
64
- monthly_plan
65
- end
66
-
67
- def remove_items(plan_id, ids)
68
- raise(StandardError, 'No plan items specified.') if ids.count.zero?
69
-
70
- begin
71
- plan = Cats::Core::MonthlyPlan.find(plan_id)
72
- rescue ActiveRecord::RecordNotFound
73
- raise(StandardError, 'Monthly plan not found.') unless plan
74
- end
75
-
76
- plans = Cats::Core::MonthlyPlan.includes(:monthly_plan_items).where(monthly_plan_items: { id: ids })
77
- raise(StandardError, 'Plan items should be from the same plan.') if plans.count > 1
78
-
79
- raise(StandardError, 'Items are not from the given monthly plan.') unless plan_id == plans[0].id
80
-
81
- Cats::Core::MonthlyPlanItem.delete_by(id: ids)
82
- plan
83
- end
84
- end
85
- end
86
- end
@@ -1,14 +0,0 @@
1
- class CreateCatsCoreRations < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_rations do |t|
4
- t.string :reference_no, unique: true
5
- t.references :program,
6
- null: false,
7
- index: { name: 'program_on_ration_indx' },
8
- foreign_key: { to_table: :cats_core_programs }
9
- t.boolean :current, null: false, default: true
10
-
11
- t.timestamps
12
- end
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- class CreateCatsCorePlanItemDetails < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_plan_item_details do |t|
4
- t.references :plan_item,
5
- null: false,
6
- index: { name: 'pi_on_pid_indx' },
7
- foreign_key: { to_table: :cats_core_plan_items }
8
- t.references :ration_item,
9
- null: false,
10
- index: { name: 'ri_on_pid_indx' },
11
- foreign_key: { to_table: :cats_core_ration_items }
12
- t.float :amount, null: false
13
-
14
- t.timestamps
15
- end
16
- add_index(:cats_core_plan_item_details, [:plan_item_id, :ration_item_id], unique: true, name: 'pii_rii_on_pid_indx')
17
- end
18
- end