cats_core 1.5.17 → 1.5.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -7
- data/app/controllers/cats/core/access_controller.rb +4 -4
- data/app/controllers/cats/core/application_controller.rb +4 -4
- data/app/controllers/cats/core/commodities_controller.rb +7 -7
- data/app/controllers/cats/core/commodity_categories_controller.rb +4 -4
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +22 -9
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +4 -4
- data/app/controllers/cats/core/dispatch_plans_controller.rb +10 -10
- data/app/controllers/cats/core/dispatch_transactions_controller.rb +5 -5
- data/app/controllers/cats/core/dispatches_controller.rb +19 -19
- data/app/controllers/cats/core/loans_controller.rb +1 -1
- data/app/controllers/cats/core/locations_controller.rb +4 -4
- data/app/controllers/cats/core/menus_controller.rb +1 -1
- data/app/controllers/cats/core/notifications_controller.rb +5 -5
- data/app/controllers/cats/core/purchase_orders_controller.rb +3 -3
- data/app/controllers/cats/core/receipt_authorizations_controller.rb +29 -17
- data/app/controllers/cats/core/receipt_transactions_controller.rb +4 -4
- data/app/controllers/cats/core/receipts_controller.rb +1 -1
- data/app/controllers/cats/core/roles_controller.rb +3 -3
- data/app/controllers/cats/core/round_beneficiaries_controller.rb +13 -13
- data/app/controllers/cats/core/round_plans_controller.rb +13 -13
- data/app/controllers/cats/core/routes_controller.rb +2 -2
- data/app/controllers/cats/core/spaces_controller.rb +1 -1
- data/app/controllers/cats/core/stack_transactions_controller.rb +3 -3
- data/app/controllers/cats/core/stacks_controller.rb +15 -7
- data/app/controllers/cats/core/stores_controller.rb +14 -14
- data/app/controllers/cats/core/swaps_controller.rb +2 -2
- data/app/controllers/cats/core/transporters_controller.rb +1 -1
- data/app/controllers/cats/core/users_controller.rb +24 -12
- data/app/controllers/concerns/cats/core/common.rb +24 -23
- data/app/helpers/cats/core/document_helper.rb +1 -1
- data/app/models/cats/core/authorization.rb +9 -9
- data/app/models/cats/core/beneficiary.rb +6 -6
- data/app/models/cats/core/beneficiary_plan_item.rb +9 -9
- data/app/models/cats/core/beneficiary_round_plan_item.rb +2 -2
- data/app/models/cats/core/cash_donation.rb +1 -1
- data/app/models/cats/core/commodity.rb +47 -33
- data/app/models/cats/core/commodity_donation.rb +2 -2
- data/app/models/cats/core/commodity_substitution.rb +15 -7
- data/app/models/cats/core/contract_item.rb +2 -2
- data/app/models/cats/core/dispatch.rb +36 -21
- data/app/models/cats/core/dispatch_authorization.rb +31 -5
- data/app/models/cats/core/dispatch_plan.rb +19 -10
- data/app/models/cats/core/dispatch_plan_item.rb +27 -14
- data/app/models/cats/core/dispatch_transaction.rb +15 -5
- data/app/models/cats/core/gift_certificate.rb +3 -3
- data/app/models/cats/core/hub_authorization.rb +7 -7
- data/app/models/cats/core/loan.rb +2 -2
- data/app/models/cats/core/location.rb +12 -8
- data/app/models/cats/core/lost_commodity.rb +2 -2
- data/app/models/cats/core/notification.rb +2 -2
- data/app/models/cats/core/offer_item.rb +4 -4
- data/app/models/cats/core/plan.rb +9 -9
- data/app/models/cats/core/plan_item.rb +5 -5
- data/app/models/cats/core/plan_item_detail.rb +2 -2
- data/app/models/cats/core/project.rb +1 -1
- data/app/models/cats/core/purchase_order.rb +5 -5
- data/app/models/cats/core/ration.rb +1 -1
- data/app/models/cats/core/receipt.rb +5 -5
- data/app/models/cats/core/receipt_authorization.rb +6 -2
- data/app/models/cats/core/receipt_transaction.rb +8 -4
- data/app/models/cats/core/rhn_request.rb +8 -8
- data/app/models/cats/core/role_menu.rb +1 -1
- data/app/models/cats/core/round_beneficiary.rb +10 -2
- data/app/models/cats/core/round_plan.rb +15 -11
- data/app/models/cats/core/round_plan_item.rb +9 -5
- data/app/models/cats/core/round_plan_item_detail.rb +3 -3
- data/app/models/cats/core/round_ration.rb +2 -2
- data/app/models/cats/core/route.rb +12 -8
- data/app/models/cats/core/stack.rb +52 -34
- data/app/models/cats/core/stack_transaction.rb +3 -3
- data/app/models/cats/core/stacking_rule.rb +2 -2
- data/app/models/cats/core/store.rb +29 -7
- data/app/models/cats/core/swap.rb +5 -5
- data/app/models/cats/core/transaction.rb +6 -6
- data/app/models/cats/core/transport_bid.rb +13 -13
- data/app/models/cats/core/transport_bid_item.rb +2 -2
- data/app/models/cats/core/transport_offer.rb +3 -3
- data/app/models/cats/core/transport_order.rb +8 -8
- data/app/models/cats/core/transport_order_item.rb +2 -2
- data/app/models/cats/core/transport_plan.rb +7 -7
- data/app/models/cats/core/transport_plan_item.rb +2 -2
- data/app/models/cats/core/transport_requisition.rb +9 -9
- data/app/models/cats/core/transport_requisition_detail.rb +2 -2
- data/app/models/cats/core/transport_requisition_item.rb +3 -3
- data/app/models/cats/core/transporter.rb +4 -0
- data/app/models/cats/core/unit_conversion.rb +4 -4
- data/app/models/cats/core/unit_of_measure.rb +4 -4
- data/app/models/cats/core/user.rb +11 -11
- data/app/models/concerns/cats/core/dispatchable.rb +3 -3
- data/app/notifications/cats/core/allocation_notification.rb +1 -1
- data/app/notifications/cats/core/dispatch_authorization_notification.rb +5 -1
- data/app/notifications/cats/core/dispatch_notification.rb +1 -1
- data/app/notifications/cats/core/receipt_authorization_notification.rb +1 -1
- data/app/notifications/cats/core/round_plan_notification.rb +1 -1
- data/app/notifications/cats/core/simple_notification.rb +1 -1
- data/app/serializers/cats/core/cash_donation_serializer.rb +1 -1
- data/app/serializers/cats/core/commodity_donation_serializer.rb +2 -2
- data/app/serializers/cats/core/commodity_serializer.rb +2 -2
- data/app/serializers/cats/core/dispatch_authorization_serializer.rb +2 -2
- data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +3 -3
- data/app/serializers/cats/core/dispatch_plan_serializer.rb +1 -1
- data/app/serializers/cats/core/dispatch_serializer.rb +2 -2
- data/app/serializers/cats/core/dispatch_transaction_serializer.rb +1 -1
- data/app/serializers/cats/core/loan_serializer.rb +1 -1
- data/app/serializers/cats/core/purchase_order_serializer.rb +2 -2
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +2 -2
- data/app/serializers/cats/core/receipt_serializer.rb +1 -1
- data/app/serializers/cats/core/receipt_transaction_serializer.rb +2 -2
- data/app/serializers/cats/core/round_beneficiary_serializer.rb +1 -1
- data/app/serializers/cats/core/round_plan_serializer.rb +1 -1
- data/app/serializers/cats/core/stack_serializer.rb +1 -1
- data/app/serializers/cats/core/store_serializer.rb +1 -1
- data/app/serializers/cats/core/swap_serializer.rb +2 -2
- data/app/services/cats/core/authorization_service.rb +22 -21
- data/app/services/cats/core/beneficiary_service.rb +11 -11
- data/app/services/cats/core/dispatch_plan_service.rb +10 -10
- data/app/services/cats/core/dispatch_service.rb +31 -31
- data/app/services/cats/core/notification_service.rb +5 -5
- data/app/services/cats/core/round_plan_service.rb +23 -23
- data/app/services/cats/core/space_service.rb +11 -11
- data/app/services/cats/core/stack_service.rb +10 -10
- data/app/services/cats/core/token_auth_service.rb +4 -4
- data/app/services/cats/core/user_service.rb +19 -0
- data/app/utils/cats/core/util.rb +1 -1
- data/config/routes.rb +110 -105
- data/config/spring.rb +1 -0
- data/db/migrate/20210715114910_create_cats_core_users.rb +3 -3
- data/db/migrate/20210715120018_create_cats_core_roles.rb +14 -14
- data/db/migrate/20210715121244_create_cats_core_menus.rb +3 -3
- data/db/migrate/20210715122141_create_cats_core_menu_items.rb +3 -3
- data/db/migrate/20210715122423_create_cats_core_role_menus.rb +13 -13
- data/db/migrate/20210717031810_create_cats_core_plans.rb +4 -4
- data/db/migrate/20210717032024_create_cats_core_plan_items.rb +18 -18
- data/db/migrate/20210717032260_create_cats_core_beneficiary_categories.rb +3 -3
- data/db/migrate/20210717032270_create_cats_core_rations.rb +10 -10
- data/db/migrate/20210717032290_create_cats_core_beneficiary_plan_items.rb +7 -7
- data/db/migrate/20210717032295_create_cats_core_plan_item_details.rb +7 -7
- data/db/migrate/20210717032330_create_cats_core_commodity_donations.rb +12 -12
- data/db/migrate/20210717032408_create_cats_core_cash_donations.rb +6 -6
- data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +12 -12
- data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +12 -12
- data/db/migrate/20210717032927_create_cats_core_projects.rb +3 -3
- data/db/migrate/20210717033223_create_cats_core_commodities.rb +10 -10
- data/db/migrate/20210717140855_create_cats_core_stores.rb +3 -3
- data/db/migrate/20210717171101_create_cats_core_stacks.rb +11 -11
- data/db/migrate/20210718040129_create_cats_core_routes.rb +9 -9
- data/db/migrate/20210718042755_create_cats_core_rhn_requests.rb +6 -6
- data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +7 -7
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +17 -17
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +13 -13
- data/db/migrate/20210718055414_create_cats_core_dispatch_authorizations.rb +13 -13
- data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +11 -11
- data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +13 -13
- data/db/migrate/20210727105834_create_cats_core_receipts.rb +6 -6
- data/db/migrate/20210728041505_create_cats_core_lost_commodities.rb +6 -6
- data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +10 -10
- data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +10 -10
- data/db/migrate/20211024063240_add_status_to_cats_core_rhn_requests.rb +1 -1
- data/db/migrate/20211030133752_add_status_to_cats_core_commodities.rb +1 -1
- data/db/migrate/20211215114737_create_cats_core_transport_plans.rb +4 -4
- data/db/migrate/20211215114835_create_cats_core_transport_plan_items.rb +9 -9
- data/db/migrate/20211215121151_create_cats_core_transport_bids.rb +4 -4
- data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +10 -10
- data/db/migrate/20211229160125_create_cats_core_transport_offers.rb +7 -7
- data/db/migrate/20211229160126_create_cats_core_offer_items.rb +6 -6
- data/db/migrate/20211229160127_create_cats_core_transport_contracts.rb +6 -6
- data/db/migrate/20211229160128_create_cats_core_contract_items.rb +9 -9
- data/db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb +10 -10
- data/db/migrate/20220103152802_create_cats_core_tenderers.rb +6 -6
- data/db/migrate/20220107121752_create_cats_core_round_plans.rb +7 -7
- data/db/migrate/20220107122280_create_cats_core_round_rations.rb +12 -12
- data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +19 -19
- data/db/migrate/20220107126025_create_cats_core_beneficiary_round_plan_items.rb +8 -8
- data/db/migrate/20220107132433_create_cats_core_round_plan_item_details.rb +9 -9
- data/db/migrate/20220209083928_create_cats_core_hub_authorizations.rb +12 -12
- data/db/migrate/20220416143416_create_cats_core_unit_conversions.rb +6 -6
- data/db/migrate/20220417105839_create_cats_core_transport_requisitions.rb +12 -12
- data/db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb +9 -9
- data/db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb +6 -6
- data/db/migrate/20220506082329_create_cats_core_transport_orders.rb +10 -10
- data/db/migrate/20220506083042_create_cats_core_transport_order_items.rb +13 -13
- data/db/migrate/20220511082354_create_cats_core_beneficiaries.rb +6 -6
- data/db/migrate/20220626063501_create_cats_core_loans.rb +6 -6
- data/db/migrate/20220626063757_create_cats_core_swaps.rb +12 -12
- data/db/migrate/20220626132050_create_cats_core_round_beneficiaries.rb +13 -13
- data/db/migrate/20220923190857_create_cats_core_application_settings.rb +3 -3
- data/lib/cats/core/engine.rb +4 -4
- data/lib/cats/core/version.rb +1 -1
- data/lib/cats_core.rb +8 -8
- data/spec/factories/cats/core/application_modules.rb +1 -1
- data/spec/factories/cats/core/application_settings.rb +1 -1
- data/spec/factories/cats/core/beneficiaries.rb +3 -3
- data/spec/factories/cats/core/beneficiary_categories.rb +1 -1
- data/spec/factories/cats/core/beneficiary_plan_items.rb +1 -1
- data/spec/factories/cats/core/beneficiary_round_plan_items.rb +1 -1
- data/spec/factories/cats/core/cash_donations.rb +1 -1
- data/spec/factories/cats/core/commodities.rb +1 -1
- data/spec/factories/cats/core/commodity_categories.rb +1 -1
- data/spec/factories/cats/core/commodity_donations.rb +1 -1
- data/spec/factories/cats/core/commodity_substitutions.rb +2 -2
- data/spec/factories/cats/core/contract_items.rb +1 -1
- data/spec/factories/cats/core/currencies.rb +1 -1
- data/spec/factories/cats/core/dispatch_authorizations.rb +7 -11
- data/spec/factories/cats/core/dispatch_plan_items.rb +16 -1
- data/spec/factories/cats/core/dispatch_plans.rb +1 -1
- data/spec/factories/cats/core/dispatch_transactions.rb +2 -4
- data/spec/factories/cats/core/dispatches.rb +16 -25
- data/spec/factories/cats/core/donors.rb +1 -1
- data/spec/factories/cats/core/gift_certificates.rb +1 -1
- data/spec/factories/cats/core/hub_authorizations.rb +1 -1
- data/spec/factories/cats/core/loans.rb +1 -1
- data/spec/factories/cats/core/locations.rb +6 -6
- data/spec/factories/cats/core/lost_commodities.rb +1 -1
- data/spec/factories/cats/core/menu_items.rb +1 -1
- data/spec/factories/cats/core/menus.rb +1 -1
- data/spec/factories/cats/core/notification_rules.rb +1 -1
- data/spec/factories/cats/core/notifications.rb +2 -2
- data/spec/factories/cats/core/offer_items.rb +1 -1
- data/spec/factories/cats/core/operators.rb +1 -1
- data/spec/factories/cats/core/plan_item_details.rb +1 -1
- data/spec/factories/cats/core/plan_items.rb +1 -1
- data/spec/factories/cats/core/plans.rb +1 -1
- data/spec/factories/cats/core/programs.rb +1 -1
- data/spec/factories/cats/core/projects.rb +1 -1
- data/spec/factories/cats/core/purchase_orders.rb +1 -1
- data/spec/factories/cats/core/rations.rb +1 -1
- data/spec/factories/cats/core/receipt_authorizations.rb +1 -1
- data/spec/factories/cats/core/receipt_transactions.rb +2 -2
- data/spec/factories/cats/core/receipts.rb +1 -1
- data/spec/factories/cats/core/rhn_requests.rb +1 -1
- data/spec/factories/cats/core/role_menus.rb +1 -1
- data/spec/factories/cats/core/roles.rb +1 -1
- data/spec/factories/cats/core/round_beneficiaries.rb +1 -1
- data/spec/factories/cats/core/round_plan_item_details.rb +3 -3
- data/spec/factories/cats/core/round_plan_items.rb +1 -1
- data/spec/factories/cats/core/round_plans.rb +1 -1
- data/spec/factories/cats/core/round_rations.rb +1 -1
- data/spec/factories/cats/core/routes.rb +1 -1
- data/spec/factories/cats/core/stack_transactions.rb +1 -1
- data/spec/factories/cats/core/stacking_rules.rb +1 -1
- data/spec/factories/cats/core/stacks.rb +1 -1
- data/spec/factories/cats/core/stores.rb +1 -1
- data/spec/factories/cats/core/suppliers.rb +1 -1
- data/spec/factories/cats/core/swaps.rb +1 -1
- data/spec/factories/cats/core/tenderers.rb +1 -1
- data/spec/factories/cats/core/transport_bid_items.rb +1 -1
- data/spec/factories/cats/core/transport_bids.rb +1 -1
- data/spec/factories/cats/core/transport_contracts.rb +1 -1
- data/spec/factories/cats/core/transport_offers.rb +1 -1
- data/spec/factories/cats/core/transport_order_items.rb +1 -1
- data/spec/factories/cats/core/transport_orders.rb +1 -1
- data/spec/factories/cats/core/transport_plan_items.rb +1 -1
- data/spec/factories/cats/core/transport_plans.rb +1 -1
- data/spec/factories/cats/core/transport_requisition_details.rb +1 -1
- data/spec/factories/cats/core/transport_requisition_items.rb +1 -1
- data/spec/factories/cats/core/transport_requisitions.rb +1 -1
- data/spec/factories/cats/core/transporters.rb +1 -1
- data/spec/factories/cats/core/unit_conversions.rb +1 -1
- data/spec/factories/cats/core/unit_of_measures.rb +1 -1
- data/spec/factories/cats/core/users.rb +2 -2
- metadata +18 -2
@@ -4,33 +4,33 @@ module Cats
|
|
4
4
|
def search(user, status, authorized: false)
|
5
5
|
details = user.details
|
6
6
|
|
7
|
-
unless details[
|
8
|
-
raise(StandardError,
|
7
|
+
unless details["stores"] || details["warehouse"] || details["hub"]
|
8
|
+
raise(StandardError, "User does not have associated location.")
|
9
9
|
end
|
10
10
|
|
11
11
|
# Get user's hub
|
12
|
-
hub = if details[
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
hub = if details["stores"]
|
13
|
+
Store.find(details["stores"][0]).warehouse.parent
|
14
|
+
elsif details["warehouse"]
|
15
|
+
Location.find(details["warehouse"]).parent
|
16
|
+
else
|
17
|
+
Location.find(details["hub"])
|
18
|
+
end
|
19
19
|
|
20
20
|
if authorized
|
21
21
|
return Dispatch.joins(:dispatch_plan_item)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
.includes({dispatch_plan_item: :destination}, :transporter, :prepared_by, :unit)
|
23
|
+
.where(
|
24
|
+
dispatch_plan_item: {destination: hub, status: DispatchPlanItem::AUTHORIZED},
|
25
|
+
dispatch_status: status
|
26
|
+
)
|
27
27
|
end
|
28
28
|
Dispatch.joins(:dispatch_plan_item)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
.includes({dispatch_plan_item: :destination}, :transporter, :prepared_by, :unit)
|
30
|
+
.where(
|
31
|
+
dispatch_plan_item: {destination: hub},
|
32
|
+
dispatch_status: status
|
33
|
+
)
|
34
34
|
end
|
35
35
|
|
36
36
|
def start(dispatch)
|
@@ -41,23 +41,23 @@ module Cats
|
|
41
41
|
|
42
42
|
def start_with_pin(dispatch_id, pin)
|
43
43
|
dispatch = Dispatch.includes(
|
44
|
-
{
|
44
|
+
{dispatch_plan_item: :destination},
|
45
45
|
:transporter,
|
46
46
|
:prepared_by,
|
47
47
|
:unit
|
48
48
|
).find(dispatch_id)
|
49
|
-
raise(StandardError,
|
49
|
+
raise(StandardError, "Dispatch is already started.") if dispatch.dispatch_status == Dispatch::STARTED
|
50
50
|
|
51
|
-
raise(StandardError,
|
51
|
+
raise(StandardError, "No pin has been generated for dispatch.") if dispatch.auth_details.nil?
|
52
52
|
|
53
|
-
raise(StandardError,
|
53
|
+
raise(StandardError, "Incorrect pin.") unless pin == dispatch.auth_details["pin"]
|
54
54
|
|
55
|
-
raise(StandardError,
|
55
|
+
raise(StandardError, "Pin is not active.") unless dispatch.auth_details["active"]
|
56
56
|
|
57
|
-
if DateTime.now > dispatch.auth_details[
|
57
|
+
if DateTime.now > dispatch.auth_details["expires_at"]
|
58
58
|
dispatch.auth_details[:active] = false
|
59
59
|
dispatch.save!
|
60
|
-
raise(StandardError,
|
60
|
+
raise(StandardError, "Pin has expired.")
|
61
61
|
end
|
62
62
|
dispatch.start
|
63
63
|
send_notification(dispatch)
|
@@ -67,17 +67,17 @@ module Cats
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def send_notification(dispatch)
|
70
|
-
notification_rule = NotificationRule.find_by(code:
|
71
|
-
raise(StandardError,
|
70
|
+
notification_rule = NotificationRule.find_by(code: "dispatch")
|
71
|
+
raise(StandardError, "Notification rule not found for dispatch notification.") unless notification_rule
|
72
72
|
|
73
|
-
users = User.joins(:roles).where(cats_core_roles: {
|
73
|
+
users = User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
|
74
74
|
location_id = dispatch.dispatch_plan_item.destination_id
|
75
75
|
hub = Location.find(location_id)
|
76
76
|
recipients = users.map do |user|
|
77
77
|
details = user.details
|
78
78
|
|
79
|
-
if (details.key?(
|
80
|
-
|
79
|
+
if (details.key?("warehouse") && hub.child_ids.include?(details["warehouse"])) ||
|
80
|
+
(details.key?("hub") && details["hub"] == location_id)
|
81
81
|
user
|
82
82
|
end
|
83
83
|
end.compact
|
@@ -3,14 +3,14 @@ module Cats
|
|
3
3
|
class NotificationService
|
4
4
|
NOTIFICATION_RULES = {
|
5
5
|
dispatch_plan: {
|
6
|
-
application:
|
7
|
-
notification:
|
6
|
+
application: "CATS-WH",
|
7
|
+
notification: "DispatchPlanNotification",
|
8
8
|
params: [:way_bill],
|
9
9
|
recipients: [:warehouse_manager]
|
10
10
|
},
|
11
11
|
receipt_plan: {
|
12
|
-
application:
|
13
|
-
notification:
|
12
|
+
application: "CATS-WH",
|
13
|
+
notification: "ReceiptPlanNotification",
|
14
14
|
params: [:receipt_plan],
|
15
15
|
recipients: [:store_keeper]
|
16
16
|
}
|
@@ -34,7 +34,7 @@ module Cats
|
|
34
34
|
roles = rule[:recipients]
|
35
35
|
|
36
36
|
users = Cats::Core::User.joins(:application_module)
|
37
|
-
|
37
|
+
.where(application_module: {prefix: app_code}).with_all_roles(*roles)
|
38
38
|
notifier.deliver(users)
|
39
39
|
end
|
40
40
|
end
|
@@ -3,9 +3,9 @@ module Cats
|
|
3
3
|
class RoundPlanService
|
4
4
|
def generate_round_needs(plan_id)
|
5
5
|
round_plan = Cats::Core::RoundPlan.find(plan_id)
|
6
|
-
raise(StandardError,
|
6
|
+
raise(StandardError, "Plan has no rations.") if round_plan.round_rations.count.zero?
|
7
7
|
|
8
|
-
raise(StandardError,
|
8
|
+
raise(StandardError, "Plan has no plan items.") if round_plan.round_plan_items.count.zero?
|
9
9
|
|
10
10
|
clear_needs(round_plan.id)
|
11
11
|
|
@@ -13,15 +13,15 @@ module Cats
|
|
13
13
|
rations = round_plan.round_rations
|
14
14
|
plan = round_plan.plan
|
15
15
|
no_of_days = plan.total_days / plan.rounds
|
16
|
-
mt = UnitOfMeasure.find_by(abbreviation:
|
16
|
+
mt = UnitOfMeasure.find_by(abbreviation: "mt")
|
17
17
|
round_plan.beneficiary_round_plan_items.each do |plan_item|
|
18
18
|
round_rations = rations.select { |r| r.beneficiary_category_id == plan_item.beneficiary_category_id }
|
19
19
|
round_rations.each do |ration|
|
20
20
|
quantity = (no_of_days / ration.no_of_days * ration.quantity) * plan_item.beneficiaries *
|
21
|
-
|
21
|
+
round_plan.rounds.count
|
22
22
|
quantity = quantity.truncate(2)
|
23
23
|
unit = ration.unit
|
24
|
-
if ration.unit.abbreviation.downcase !=
|
24
|
+
if ration.unit.abbreviation.downcase != "pc"
|
25
25
|
quantity = UnitConversion.convert(unit, mt, quantity).truncate(2)
|
26
26
|
unit = mt
|
27
27
|
end
|
@@ -42,7 +42,7 @@ module Cats
|
|
42
42
|
def clear_needs(plan_id)
|
43
43
|
Cats::Core::RoundPlanItemDetail
|
44
44
|
.joins(beneficiary_round_plan_item: :round_plan_item)
|
45
|
-
.where(cats_core_beneficiary_round_plan_items: {
|
45
|
+
.where(cats_core_beneficiary_round_plan_items: {cats_core_round_plan_items: {round_plan_id: plan_id}})
|
46
46
|
.delete_all
|
47
47
|
end
|
48
48
|
|
@@ -54,7 +54,7 @@ module Cats
|
|
54
54
|
status: Cats::Core::Plan::DRAFT,
|
55
55
|
rounds: rounds
|
56
56
|
)
|
57
|
-
rations = Cats::Core::Ration.joins(:beneficiary_category).where(beneficiary_category: {
|
57
|
+
rations = Cats::Core::Ration.joins(:beneficiary_category).where(beneficiary_category: {plan_id: plan_id})
|
58
58
|
round_rations = rations.map do |ration|
|
59
59
|
{
|
60
60
|
beneficiary_category_id: ration.beneficiary_category_id,
|
@@ -111,27 +111,27 @@ module Cats
|
|
111
111
|
# round plan item becomes empty, then it too should be deleted.
|
112
112
|
#
|
113
113
|
def remove_items(plan_id, ids)
|
114
|
-
raise(StandardError,
|
114
|
+
raise(StandardError, "No beneficiary plan items specified.") if ids.count.zero?
|
115
115
|
|
116
116
|
begin
|
117
117
|
plan = Cats::Core::RoundPlan.find(plan_id)
|
118
118
|
rescue ActiveRecord::RecordNotFound
|
119
|
-
raise(StandardError,
|
119
|
+
raise(StandardError, "Round plan not found.") unless plan
|
120
120
|
end
|
121
121
|
|
122
122
|
plans = Cats::Core::RoundPlan.includes(:beneficiary_round_plan_items)
|
123
|
-
|
124
|
-
raise(StandardError,
|
123
|
+
.where(beneficiary_round_plan_items: {id: ids})
|
124
|
+
raise(StandardError, "Round plan items should be from the same plan.") if plans.count > 1
|
125
125
|
|
126
126
|
unless plans.count.positive? && plan.id == plans[0].id
|
127
|
-
raise(StandardError,
|
127
|
+
raise(StandardError, "Round plan items are not from the given round plan.")
|
128
128
|
end
|
129
129
|
|
130
130
|
to_delete = Cats::Core::BeneficiaryRoundPlanItem.where(id: ids)
|
131
131
|
keys = to_delete.map(&:round_plan_item_id).uniq
|
132
132
|
|
133
133
|
item_counts = Cats::Core::BeneficiaryRoundPlanItem.where(round_plan_item_id: keys)
|
134
|
-
|
134
|
+
.group(:round_plan_item_id).count
|
135
135
|
|
136
136
|
delete_hash = {}
|
137
137
|
keys.each { |k| delete_hash[k] = [] }
|
@@ -151,16 +151,16 @@ module Cats
|
|
151
151
|
|
152
152
|
def approve(plan_id)
|
153
153
|
plan = RoundPlan.find(plan_id)
|
154
|
-
if plan.plan.program.code ==
|
154
|
+
if plan.plan.program.code == "PSNP"
|
155
155
|
rounds = plan.rounds.count
|
156
|
-
item_ids = plan.beneficiary_round_plan_items.pluck(
|
156
|
+
item_ids = plan.beneficiary_round_plan_items.pluck("beneficiary_plan_item_id").flatten
|
157
157
|
plan_items = BeneficiaryPlanItem.includes(plan_item: :fdp).where(id: item_ids)
|
158
158
|
invalid = plan_items.select { |pi| pi.rounds - (pi.rounds_served || 0) < rounds }.map do |pi|
|
159
159
|
pi.plan_item.fdp.name
|
160
160
|
end
|
161
161
|
|
162
162
|
if invalid.count.positive?
|
163
|
-
msg = invalid.join(
|
163
|
+
msg = invalid.join(", ")
|
164
164
|
error = "The FDPs [#{msg}] exceeded their allowed number of rounds."
|
165
165
|
raise(StandardError, error)
|
166
166
|
end
|
@@ -169,7 +169,7 @@ module Cats
|
|
169
169
|
rounds_served = plan_item.rounds_served || 0
|
170
170
|
res << "(#{plan_item.id}, #{rounds + rounds_served})"
|
171
171
|
end
|
172
|
-
values = items.join(
|
172
|
+
values = items.join(",")
|
173
173
|
sql = <<-SQL
|
174
174
|
UPDATE cats_core_beneficiary_plan_items AS bpi
|
175
175
|
SET
|
@@ -192,11 +192,11 @@ module Cats
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def send_approval_notification(round_plan)
|
195
|
-
notification_rule = NotificationRule.find_by(code:
|
196
|
-
error =
|
195
|
+
notification_rule = NotificationRule.find_by(code: "round_plan_approval")
|
196
|
+
error = "Notification rule not found for round plan approval notification."
|
197
197
|
raise(StandardError, error) unless notification_rule
|
198
198
|
|
199
|
-
users = User.joins(:roles).where(cats_core_roles: {
|
199
|
+
users = User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
|
200
200
|
return if users.empty?
|
201
201
|
|
202
202
|
notification = RoundPlanNotification.with(round_plan: round_plan)
|
@@ -204,14 +204,14 @@ module Cats
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def send_approved_notification(round_plan)
|
207
|
-
notification_rule = NotificationRule.find_by(code:
|
208
|
-
error =
|
207
|
+
notification_rule = NotificationRule.find_by(code: "round_plan_approved")
|
208
|
+
error = "Notification rule not found for round plan approved notification."
|
209
209
|
raise(StandardError, error) unless notification_rule
|
210
210
|
|
211
211
|
users = User.joins(roles: :application_module).where(
|
212
212
|
cats_core_roles: {
|
213
213
|
name: notification_rule.roles,
|
214
|
-
cats_core_application_modules: {
|
214
|
+
cats_core_application_modules: {prefix: "CATS-TMS"}
|
215
215
|
}
|
216
216
|
)
|
217
217
|
return if users.empty?
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class SpaceService
|
4
|
-
HUB =
|
5
|
-
WAREHOUSE =
|
6
|
-
STORE =
|
4
|
+
HUB = "Hub".freeze
|
5
|
+
WAREHOUSE = "Warehouse".freeze
|
6
|
+
STORE = "Store".freeze
|
7
7
|
|
8
8
|
def available_space(id, level)
|
9
9
|
case level
|
@@ -12,17 +12,17 @@ module Cats
|
|
12
12
|
warehouses = hub.children
|
13
13
|
warehouse_ids = warehouses.map(&:id)
|
14
14
|
stores = Cats::Core::Store.joins(:warehouse)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
.where(
|
16
|
+
cats_core_locations: {
|
17
|
+
location_type: Cats::Core::Location::WAREHOUSE,
|
18
|
+
id: warehouse_ids
|
19
|
+
}
|
20
|
+
).group_by(&:warehouse_id)
|
21
21
|
wh_details = []
|
22
22
|
stores.each do |key, value|
|
23
23
|
total_space = value.inject(0) { |sum, val| sum + val.available_space }
|
24
24
|
details = value.map do |val|
|
25
|
-
{
|
25
|
+
{store_id: val.id, code: val.code, name: val.name, total_space: val.available_space}
|
26
26
|
end
|
27
27
|
warehouse = warehouses.find(key)
|
28
28
|
wh_details << {
|
@@ -45,7 +45,7 @@ module Cats
|
|
45
45
|
warehouse = Cats::Core::Location.find(id)
|
46
46
|
stores = Cats::Core::Store.where(warehouse_id: id)
|
47
47
|
details = stores.map do |store|
|
48
|
-
{
|
48
|
+
{store_id: store.id, code: store.code, name: store.name, total_space: store.available_space}
|
49
49
|
end
|
50
50
|
total_space = stores.inject(0) { |sum, val| sum + val.available_space }
|
51
51
|
space = {
|
@@ -5,20 +5,20 @@ module Cats
|
|
5
5
|
details = user.details
|
6
6
|
|
7
7
|
key_available = details.keys.any? { |key| %w[stores warehouse hub].include?(key) }
|
8
|
-
raise(StandardError,
|
8
|
+
raise(StandardError, "User does not have associated location.") unless key_available
|
9
9
|
|
10
|
-
hub = if details[
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
hub = if details["hub"]
|
11
|
+
Location.find(details["hub"])
|
12
|
+
elsif details["warehouse"]
|
13
|
+
Location.find(details["warehouse"]).parent
|
14
|
+
else
|
15
|
+
Store.find(details["stores"][0]).warehouse.parent
|
16
|
+
end
|
17
17
|
|
18
18
|
allocation_items =
|
19
19
|
DispatchPlanItem
|
20
|
-
|
21
|
-
|
20
|
+
.joins(:dispatch_plan)
|
21
|
+
.where(destination: hub, dispatch_plan: {status: DispatchPlan::APPROVED})
|
22
22
|
|
23
23
|
allocation_items.map do |item|
|
24
24
|
{
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class TokenAuthService
|
4
|
-
AUTH_SECRET =
|
5
|
-
|
4
|
+
AUTH_SECRET = "592fac227e8ee4ff985e376d554604f36c974b4f4605eb8d7ebe4dd1cf8fd8aa8e0cb85df1b48a8ec60cac7bb4117d854" \
|
5
|
+
"5c359123e14f6784dcd88e6e6a1ea8c".freeze
|
6
6
|
|
7
7
|
def self.issue(payload)
|
8
|
-
JWT.encode(payload, auth_secret,
|
8
|
+
JWT.encode(payload, auth_secret, "HS256")
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.decode(token)
|
12
|
-
JWT.decode(token, auth_secret, true, algorithm:
|
12
|
+
JWT.decode(token, auth_secret, true, algorithm: "HS256").first
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.auth_secret
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class UserService
|
4
|
+
def change_password(email, old_password, new_password, password_confirmation)
|
5
|
+
raise(StandardError, "Password and confirmation do not match.") unless new_password == password_confirmation
|
6
|
+
|
7
|
+
user = User.find_by(email:)
|
8
|
+
raise(StandardError, "User with email '#{email}' could not be found.") unless user
|
9
|
+
|
10
|
+
raise(StandardError, "Old password for user '#{email}' is not correct.") unless user.authenticate(old_password)
|
11
|
+
|
12
|
+
user.password = new_password
|
13
|
+
user.password_confirmation = password_confirmation
|
14
|
+
user.save!
|
15
|
+
user
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/app/utils/cats/core/util.rb
CHANGED
@@ -7,7 +7,7 @@ module Cats
|
|
7
7
|
|
8
8
|
def self.generate_pin(obj)
|
9
9
|
pin = SecureRandom.hex(10)
|
10
|
-
obj.auth_details = {
|
10
|
+
obj.auth_details = {pin: pin, active: true, expires_at: DateTime.now + 24.hour}
|
11
11
|
obj.save!
|
12
12
|
end
|
13
13
|
end
|