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
@@ -8,7 +8,7 @@ module Cats
|
|
8
8
|
def index
|
9
9
|
super do
|
10
10
|
Role.joins(:application_module)
|
11
|
-
|
11
|
+
.where(cats_core_application_modules: {prefix: params[:prefix]})
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,11 +16,11 @@ module Cats
|
|
16
16
|
user = User.find(params[:id])
|
17
17
|
roles = Role.where(application_module_id: user.application_module_id)
|
18
18
|
unassigned = roles - user.roles
|
19
|
-
render json: {
|
19
|
+
render json: {success: true, data: serialize(unassigned)}
|
20
20
|
end
|
21
21
|
|
22
22
|
def users
|
23
|
-
render json: {
|
23
|
+
render json: {success: true, data: serialize(@role.users)}
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
@@ -5,38 +5,38 @@ module Cats
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
beneficiaries = RoundBeneficiary.joins(:round_plan_item)
|
8
|
-
|
9
|
-
|
10
|
-
render json: {
|
8
|
+
.where(round_plan_item: {round_plan_id: params[:id]})
|
9
|
+
.includes(:beneficiary, :commodity_category, :unit)
|
10
|
+
render json: {success: true, data: serialize(beneficiaries)}
|
11
11
|
end
|
12
12
|
|
13
13
|
def generate
|
14
14
|
service = BeneficiaryService.new
|
15
15
|
result = service.generate_distribution_list(params[:id])
|
16
|
-
render json: {
|
17
|
-
rescue
|
18
|
-
render json: {
|
16
|
+
render json: {success: result}
|
17
|
+
rescue => e
|
18
|
+
render json: {success: false, error: e.message}
|
19
19
|
end
|
20
20
|
|
21
21
|
def filter
|
22
22
|
query = RoundBeneficiary.includes(:beneficiary, :commodity_category, :unit).ransack(params[:q])
|
23
|
-
render json: {
|
23
|
+
render json: {success: true, data: serialize(query.result)}
|
24
24
|
end
|
25
25
|
|
26
26
|
def remove_beneficiaries
|
27
27
|
service = BeneficiaryService.new
|
28
28
|
result = service.remove_items(params[:id], common_params[:ids])
|
29
|
-
render json: {
|
30
|
-
rescue
|
31
|
-
render json: {
|
29
|
+
render json: {success: result}
|
30
|
+
rescue => e
|
31
|
+
render json: {success: false, error: e.message}
|
32
32
|
end
|
33
33
|
|
34
34
|
def confirm_receipt
|
35
35
|
service = BeneficiaryService.new
|
36
36
|
result = service.confirm_receipt(params[:id], common_params[:ids])
|
37
|
-
render json: {
|
38
|
-
rescue
|
39
|
-
render json: {
|
37
|
+
render json: {success: result}
|
38
|
+
rescue => e
|
39
|
+
render json: {success: false, error: e.message}
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
@@ -8,40 +8,40 @@ module Cats
|
|
8
8
|
|
9
9
|
def index
|
10
10
|
super do
|
11
|
-
RoundPlan.includes({
|
11
|
+
RoundPlan.includes({plan: :program}, :region).where(plan: params[:id])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def filter
|
16
|
-
query = RoundPlan.includes({
|
17
|
-
render json: {
|
16
|
+
query = RoundPlan.includes({plan: :program}, :region).ransack(params[:q])
|
17
|
+
render json: {success: true, data: serialize(query.result)}
|
18
18
|
end
|
19
19
|
|
20
20
|
def approve
|
21
21
|
plan = @service.approve(params[:id])
|
22
|
-
render json: {
|
23
|
-
rescue
|
24
|
-
render json: {
|
22
|
+
render json: {success: true, data: serialize(plan)}
|
23
|
+
rescue => e
|
24
|
+
render json: {success: false, error: e.message}, status: :unprocessable_entity
|
25
25
|
end
|
26
26
|
|
27
27
|
def generate
|
28
28
|
p = model_params
|
29
29
|
plan = @service.generate_round_plan(p[:reference_no], p[:rounds], p[:plan_id], p[:region_id])
|
30
|
-
render json: {
|
30
|
+
render json: {success: true, data: serialize(plan)}
|
31
31
|
end
|
32
32
|
|
33
33
|
def generate_round_needs
|
34
34
|
plan = @service.generate_round_needs(params[:id])
|
35
|
-
render json: {
|
36
|
-
rescue
|
37
|
-
render json: {
|
35
|
+
render json: {success: true, data: serialize(plan)}
|
36
|
+
rescue => e
|
37
|
+
render json: {success: false, error: e.message}
|
38
38
|
end
|
39
39
|
|
40
40
|
def remove_items
|
41
41
|
plan = @service.remove_items(params[:id], remove_params[:ids])
|
42
|
-
render json: {
|
43
|
-
rescue
|
44
|
-
render json: {
|
42
|
+
render json: {success: true, data: serialize(plan)}
|
43
|
+
rescue => e
|
44
|
+
render json: {success: false, error: e.message}
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
@@ -11,7 +11,7 @@ module Cats
|
|
11
11
|
|
12
12
|
def filter
|
13
13
|
query = Route.includes(:region).ransack(params[:q])
|
14
|
-
render json: {
|
14
|
+
render json: {success: true, data: serialize(query.result)}
|
15
15
|
end
|
16
16
|
|
17
17
|
def bulk_create
|
@@ -30,7 +30,7 @@ module Cats
|
|
30
30
|
|
31
31
|
result = Route.insert_all!(data, record_timestamps: true)
|
32
32
|
routes = Route.includes(:region).where(id: result.rows.flatten)
|
33
|
-
render json: {
|
33
|
+
render json: {success: true, data: serialize(routes)}
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
@@ -5,14 +5,14 @@ module Cats
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
super do
|
8
|
-
StackTransaction.joins({
|
9
|
-
|
8
|
+
StackTransaction.joins({source: :store}, :unit)
|
9
|
+
.where(cats_core_stacks: {cats_core_stores: {warehouse_id: params[:id]}})
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def filter
|
14
14
|
query = StackTransaction.ransack(params[:q])
|
15
|
-
render json: {
|
15
|
+
render json: {success: true, data: serialize(query.result)}
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -11,13 +11,13 @@ module Cats
|
|
11
11
|
|
12
12
|
def filter
|
13
13
|
query = Stack.includes(:commodity, :unit).where(store_id: params[:id]).ransack(params[:q])
|
14
|
-
render json: {
|
14
|
+
render json: {success: true, data: serialize(query.result)}
|
15
15
|
end
|
16
16
|
|
17
17
|
def items_for_location
|
18
18
|
service = StackService.new
|
19
19
|
commodities = service.items_for_location(current_user)
|
20
|
-
render json: {
|
20
|
+
render json: {success: true, data: serialize(commodities)}
|
21
21
|
end
|
22
22
|
|
23
23
|
def dispatch_stacks
|
@@ -26,25 +26,33 @@ module Cats
|
|
26
26
|
stacks = service.dispatch_stacks(dispatch)
|
27
27
|
|
28
28
|
# Filter for current user
|
29
|
-
if current_user.details.key?(
|
30
|
-
stores = current_user.details[
|
29
|
+
if current_user.details.key?("stores")
|
30
|
+
stores = current_user.details["stores"]
|
31
31
|
stacks = stacks.select { |stack| stores.include?(stack.store_id) }
|
32
32
|
end
|
33
|
-
render json: {
|
33
|
+
render json: {success: true, data: serialize(stacks)}
|
34
34
|
end
|
35
35
|
|
36
36
|
def receipt_stacks
|
37
37
|
service = StackService.new
|
38
38
|
authorization = ReceiptAuthorization.find(params[:id])
|
39
39
|
stacks = service.receipt_stacks(authorization.id)
|
40
|
-
render json: {
|
40
|
+
render json: {success: true, data: serialize(stacks)}
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy
|
44
|
+
stack = set_object
|
45
|
+
stack.destroy_stack
|
46
|
+
render json: {success: true, data: serialize(stack)}
|
47
|
+
rescue => e
|
48
|
+
render json: {success: false, error: e}
|
41
49
|
end
|
42
50
|
|
43
51
|
private
|
44
52
|
|
45
53
|
def model_params
|
46
54
|
params.require(:payload).permit(:code, :length, :width, :height, :start_x, :start_y, :commodity_id, :store_id,
|
47
|
-
|
55
|
+
:commodity_status, :stack_status, :quantity, :unit_id)
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
@@ -5,38 +5,38 @@ module Cats
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
stores = Store.includes(:stacks).where(warehouse_id: params[:id])
|
8
|
-
render json: {
|
8
|
+
render json: {success: true, data: serialize(stores)}
|
9
9
|
end
|
10
10
|
|
11
11
|
def filter
|
12
12
|
query = Store.includes(:stacks).ransack(params[:q])
|
13
|
-
render json: {
|
13
|
+
render json: {success: true, data: serialize(query.result)}
|
14
14
|
end
|
15
15
|
|
16
16
|
def stores_for_hub
|
17
17
|
warehouses = Location.find(params[:id]).children
|
18
18
|
ids = warehouses.map(&:id)
|
19
19
|
stores = Store.includes(:stacks).where(warehouse_id: ids)
|
20
|
-
render json: {
|
20
|
+
render json: {success: true, data: serialize(stores)}
|
21
21
|
end
|
22
22
|
|
23
23
|
def assign_store
|
24
24
|
store_keeper = User.find(params[:id])
|
25
|
-
store_keeper.details[
|
26
|
-
store_keeper.details[
|
25
|
+
store_keeper.details["stores"] ||= []
|
26
|
+
store_keeper.details["stores"] += store_params[:store_ids]
|
27
27
|
store_keeper.save!
|
28
28
|
|
29
|
-
render json: {
|
29
|
+
render json: {success: true, data: serialize(store_keeper)}
|
30
30
|
end
|
31
31
|
|
32
32
|
def unassign_store
|
33
33
|
store_keeper = User.find(params[:id])
|
34
|
-
if store_keeper.details.key?(
|
35
|
-
store_keeper.details[
|
34
|
+
if store_keeper.details.key?("stores")
|
35
|
+
store_keeper.details["stores"] -= store_params[:store_ids]
|
36
36
|
store_keeper.save!
|
37
|
-
render json: {
|
37
|
+
render json: {success: true, data: serialize(store_keeper)}
|
38
38
|
else
|
39
|
-
render json: {
|
39
|
+
render json: {success: false, error: "User has no stores assigned."}
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -44,17 +44,17 @@ module Cats
|
|
44
44
|
store = Store.find(params[:id])
|
45
45
|
location = store.warehouse.parent
|
46
46
|
if location.location_type == Location::FDP
|
47
|
-
render json: {
|
47
|
+
render json: {success: true, data: serialize(location)}
|
48
48
|
else
|
49
|
-
render json: {
|
49
|
+
render json: {success: false, error: "No FDP is associated with store."}
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
private
|
54
54
|
|
55
55
|
def model_params
|
56
|
-
params.require(
|
57
|
-
|
56
|
+
params.require("payload").permit(:id, :code, :name, :length, :width, :height, :temporary, :has_gangway,
|
57
|
+
:gangway_length, :gangway_width, :gangway_corner_dist, :warehouse_id)
|
58
58
|
end
|
59
59
|
|
60
60
|
def store_params
|
@@ -13,8 +13,8 @@ module Cats
|
|
13
13
|
|
14
14
|
def model_params
|
15
15
|
params.require(:payload).permit(:reference_no, :swapper, :agreement_date, :issued_commodity_id, :description,
|
16
|
-
|
17
|
-
|
16
|
+
:issued_quantity, :received_commodity_id, :received_quantity, :issued_unit_id,
|
17
|
+
:received_unit_id)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -3,11 +3,12 @@ module Cats
|
|
3
3
|
class UsersController < ApplicationController
|
4
4
|
include Common
|
5
5
|
|
6
|
+
skip_before_action :authenticate, only: [:change_password]
|
6
7
|
around_action :skip_bullet, if: -> { defined?(Bullet) }, only: %i[stores]
|
7
8
|
|
8
9
|
def index
|
9
10
|
super do
|
10
|
-
User.joins(:application_module).where(cats_core_application_modules: {
|
11
|
+
User.joins(:application_module).where(cats_core_application_modules: {prefix: params[:prefix]})
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -34,14 +35,25 @@ module Cats
|
|
34
35
|
end
|
35
36
|
|
36
37
|
if user.save
|
37
|
-
render json: {
|
38
|
+
render json: {success: true, data: serialize(user)}
|
38
39
|
else
|
39
|
-
render json: {
|
40
|
+
render json: {success: false, error: user.errors.full_messages[0]}, status: :unprocessable_entity
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
44
|
+
def change_password
|
45
|
+
service = UserService.new
|
46
|
+
payload = params.require(:payload).permit(:email, :old_password, :password, :password_confirmation)
|
47
|
+
email, old_pass, new_pass, confirmation = *payload.values
|
48
|
+
user = service.change_password(email, old_pass, new_pass, confirmation)
|
49
|
+
|
50
|
+
render json: {success: true, data: serialize(user)}
|
51
|
+
rescue => e
|
52
|
+
render json: {success: false, error: e}
|
53
|
+
end
|
54
|
+
|
43
55
|
def roles
|
44
|
-
render json: {
|
56
|
+
render json: {success: true, data: serialize(set_object.roles)}
|
45
57
|
end
|
46
58
|
|
47
59
|
def assign_role
|
@@ -50,15 +62,15 @@ module Cats
|
|
50
62
|
user.roles << role
|
51
63
|
|
52
64
|
case role.name
|
53
|
-
when
|
65
|
+
when "warehouse_manager"
|
54
66
|
user.add_detail(:warehouse, params[:warehouse_id])
|
55
|
-
when
|
67
|
+
when "hub_manager"
|
56
68
|
user.add_detail(:hub, params[:hub_id])
|
57
|
-
when
|
69
|
+
when "regional_manager"
|
58
70
|
user.add_detail(:region, params[:region_id])
|
59
71
|
end
|
60
72
|
|
61
|
-
render json: {
|
73
|
+
render json: {success: true, data: serialize(role)}
|
62
74
|
end
|
63
75
|
|
64
76
|
def revoke_role
|
@@ -66,19 +78,19 @@ module Cats
|
|
66
78
|
role = Role.find(params[:role_id])
|
67
79
|
user.roles.delete(role)
|
68
80
|
user.remove_detail(role.name) if %w[warehouse_manager hub_manager regional_manager].include?(role.name)
|
69
|
-
render json: {
|
81
|
+
render json: {success: true, data: serialize(role)}
|
70
82
|
end
|
71
83
|
|
72
84
|
def stores
|
73
|
-
render json: {
|
85
|
+
render json: {success: true, data: serialize(set_object.stores)}
|
74
86
|
end
|
75
87
|
|
76
88
|
def warehouse
|
77
|
-
render json: {
|
89
|
+
render json: {success: true, data: serialize(set_object.warehouse)}
|
78
90
|
end
|
79
91
|
|
80
92
|
def hub
|
81
|
-
render json: {
|
93
|
+
render json: {success: true, data: serialize(set_object.hub)}
|
82
94
|
end
|
83
95
|
|
84
96
|
private
|
@@ -10,45 +10,45 @@ module Cats
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
data = if block_given?
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
render json: {
|
13
|
+
yield
|
14
|
+
else
|
15
|
+
@clazz.all
|
16
|
+
end
|
17
|
+
render json: {success: true, data: serialize(data)}
|
18
18
|
end
|
19
19
|
|
20
20
|
def show
|
21
|
-
render json: {
|
21
|
+
render json: {success: true, data: serialize(@obj)}
|
22
22
|
end
|
23
23
|
|
24
24
|
def create
|
25
25
|
obj = if block_given?
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
yield
|
27
|
+
else
|
28
|
+
@clazz.new(model_params)
|
29
|
+
end
|
30
30
|
if obj.save
|
31
|
-
render json: {
|
31
|
+
render json: {success: true, data: serialize(obj)}, status: :created
|
32
32
|
else
|
33
|
-
render json: {
|
33
|
+
render json: {success: false, error: obj.errors.full_messages[0]}, status: :unprocessable_entity
|
34
34
|
end
|
35
|
-
rescue
|
36
|
-
render json: {
|
35
|
+
rescue => e
|
36
|
+
render json: {success: false, error: e.message}
|
37
37
|
end
|
38
38
|
|
39
39
|
def update
|
40
40
|
obj = if block_given?
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
yield
|
42
|
+
else
|
43
|
+
obj = @obj
|
44
|
+
end
|
45
45
|
if obj.update(model_params)
|
46
|
-
render json: {
|
46
|
+
render json: {success: true, data: serialize(obj)}
|
47
47
|
else
|
48
|
-
render json: {
|
48
|
+
render json: {success: false, error: obj.errors.full_messages[0]}, status: :unprocessable_entity
|
49
49
|
end
|
50
|
-
rescue
|
51
|
-
render json: {
|
50
|
+
rescue => e
|
51
|
+
render json: {success: false, error: e.message}
|
52
52
|
end
|
53
53
|
|
54
54
|
private
|
@@ -66,7 +66,8 @@ module Cats
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# This class should be overridden by respective child controllers
|
69
|
-
def model_params
|
69
|
+
def model_params
|
70
|
+
end
|
70
71
|
end
|
71
72
|
end
|
72
73
|
end
|
@@ -6,17 +6,17 @@ module Cats
|
|
6
6
|
before_validation :set_unit
|
7
7
|
|
8
8
|
# Authorization statuses
|
9
|
-
AUTHORIZED =
|
10
|
-
CONFIRMED =
|
9
|
+
AUTHORIZED = "Authorized".freeze
|
10
|
+
CONFIRMED = "Confirmed".freeze
|
11
11
|
STATUSES = [AUTHORIZED, CONFIRMED].freeze
|
12
12
|
|
13
13
|
belongs_to :dispatch
|
14
14
|
belongs_to :store
|
15
|
-
belongs_to :unit, class_name:
|
16
|
-
belongs_to :authorized_by, class_name:
|
15
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
16
|
+
belongs_to :authorized_by, class_name: "Cats::Core::User"
|
17
17
|
|
18
|
-
validates :quantity, presence: true, numericality: {
|
19
|
-
validates :status, presence: true, inclusion: {
|
18
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
19
|
+
validates :status, presence: true, inclusion: {in: STATUSES}
|
20
20
|
validate :validate_dispatch_status, if: -> { status == AUTHORIZED }
|
21
21
|
|
22
22
|
delegate(:full_name, to: :authorized_by, prefix: :authorizer)
|
@@ -39,7 +39,7 @@ module Cats
|
|
39
39
|
return unless dispatch
|
40
40
|
|
41
41
|
if instance_of?(DispatchAuthorization)
|
42
|
-
errors.add(:dispatch,
|
42
|
+
errors.add(:dispatch, "is not in draft state.") unless dispatch.dispatch_status == Dispatch::DRAFT
|
43
43
|
else
|
44
44
|
return if dispatch.dispatch_status == Cats::Core::Dispatch::STARTED
|
45
45
|
|
@@ -58,7 +58,7 @@ module Cats
|
|
58
58
|
def confirm
|
59
59
|
if instance_of?(DispatchAuthorization)
|
60
60
|
ActiveRecord::Base.transaction do
|
61
|
-
raise(StandardError,
|
61
|
+
raise(StandardError, "Authorization does not have transactions.") if transactions.blank?
|
62
62
|
|
63
63
|
transactions.each(&:commit)
|
64
64
|
self.status = CONFIRMED
|
@@ -72,7 +72,7 @@ module Cats
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
elsif instance_of?(ReceiptAuthorization)
|
75
|
-
raise(StandardError,
|
75
|
+
raise(StandardError, "Authorization does not have receipts.") unless receipts.count.positive?
|
76
76
|
|
77
77
|
total_received = receipts.sum(:quantity)
|
78
78
|
total_lost = lost_commodities.sum(:quantity)
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Beneficiary < ApplicationRecord
|
4
|
-
MALE =
|
5
|
-
FEMALE =
|
4
|
+
MALE = "M".freeze
|
5
|
+
FEMALE = "F".freeze
|
6
6
|
GENDERS = [MALE, FEMALE].freeze
|
7
7
|
|
8
8
|
belongs_to :beneficiary_category
|
9
|
-
belongs_to :fdp, class_name:
|
9
|
+
belongs_to :fdp, class_name: "Location"
|
10
10
|
|
11
11
|
validates :full_name, :age, :gender, presence: true
|
12
|
-
validates :gender, inclusion: {
|
13
|
-
validates :age, numericality: {
|
12
|
+
validates :gender, inclusion: {in: GENDERS}
|
13
|
+
validates :age, numericality: {greater_than: 0, less_than: 100}
|
14
14
|
validate :validate_fdp
|
15
15
|
|
16
16
|
delegate(:name, to: :beneficiary_category, prefix: true)
|
@@ -19,7 +19,7 @@ module Cats
|
|
19
19
|
def validate_fdp
|
20
20
|
return unless fdp
|
21
21
|
|
22
|
-
errors.add(:fdp,
|
22
|
+
errors.add(:fdp, "should be a valid distribution point.") unless fdp.location_type == Location::FDP
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -5,12 +5,12 @@ module Cats
|
|
5
5
|
belongs_to :beneficiary_category
|
6
6
|
has_many :plan_item_details
|
7
7
|
|
8
|
-
validates :beneficiaries, presence: true, numericality: {
|
9
|
-
validates :plan_item_id, uniqueness: {
|
8
|
+
validates :beneficiaries, presence: true, numericality: {greater_than: 0}
|
9
|
+
validates :plan_item_id, uniqueness: {scope: :beneficiary_category_id}
|
10
10
|
|
11
|
-
validates :rounds, presence: true, numericality: {
|
12
|
-
validates :rounds_served, presence: true, numericality: {
|
13
|
-
|
11
|
+
validates :rounds, presence: true, numericality: {greater_than: 0}, if: :psnp?
|
12
|
+
validates :rounds_served, presence: true, numericality: {greater_than_or_equal_to: 0}, allow_nil: true,
|
13
|
+
if: :psnp?
|
14
14
|
validates :rounds, :rounds_served, absence: true, unless: :psnp?
|
15
15
|
validate :validate_rounds
|
16
16
|
|
@@ -19,17 +19,17 @@ module Cats
|
|
19
19
|
def psnp?
|
20
20
|
return false unless plan_item
|
21
21
|
|
22
|
-
plan_item.plan.program.code ==
|
22
|
+
plan_item.plan.program.code == "PSNP"
|
23
23
|
end
|
24
24
|
|
25
25
|
def validate_rounds
|
26
26
|
return unless rounds && rounds_served
|
27
27
|
|
28
|
-
errors.add(:rounds,
|
28
|
+
errors.add(:rounds, "should not be set for non PSNP plans.") unless psnp?
|
29
29
|
|
30
|
-
errors.add(:rounds_served,
|
30
|
+
errors.add(:rounds_served, "should not be set for non PSNP plans.") unless psnp?
|
31
31
|
|
32
|
-
errors.add(:rounds,
|
32
|
+
errors.add(:rounds, "cannot be lower than rounds served.") if rounds < rounds_served
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -5,8 +5,8 @@ module Cats
|
|
5
5
|
belongs_to :beneficiary_category
|
6
6
|
has_many :round_plan_item_details
|
7
7
|
|
8
|
-
validates :beneficiaries, presence: true, numericality: {
|
9
|
-
validates :round_plan_item_id, uniqueness: {
|
8
|
+
validates :beneficiaries, presence: true, numericality: {greater_than_or_equal_to: 0}
|
9
|
+
validates :round_plan_item_id, uniqueness: {scope: :beneficiary_category_id}
|
10
10
|
validates :beneficiary_plan_item_id, presence: true
|
11
11
|
|
12
12
|
delegate(:name, to: :beneficiary_category, prefix: true)
|