cats_core 1.5.16 → 1.5.18
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.
- 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 +30 -7
- 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 +30 -18
- 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 +35 -0
- 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 +36 -18
- 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 +19 -2
@@ -2,33 +2,33 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class User < ApplicationRecord
|
4
4
|
has_secure_password
|
5
|
-
rolify role_cname:
|
5
|
+
rolify role_cname: "Cats::Core::Role"
|
6
6
|
|
7
7
|
belongs_to :application_module
|
8
8
|
has_many :notifications, as: :recipient
|
9
9
|
|
10
|
-
validates :password, length: {
|
10
|
+
validates :password, length: {minimum: 6}, if: proc { |u| u.password.present? }, on: :update
|
11
11
|
validates :first_name, :last_name, :email, presence: true
|
12
|
-
validates :password, presence: true, length: {
|
13
|
-
validates :email, uniqueness: true, format: {
|
12
|
+
validates :password, presence: true, length: {minimum: 6}, on: :create
|
13
|
+
validates :email, uniqueness: true, format: {with: URI::MailTo::EMAIL_REGEXP}
|
14
14
|
validate :validate_phone_number
|
15
15
|
|
16
16
|
def warehouse
|
17
|
-
return unless details.key?(
|
17
|
+
return unless details.key?("warehouse")
|
18
18
|
|
19
|
-
Cats::Core::Location.find_by(id: details[
|
19
|
+
Cats::Core::Location.find_by(id: details["warehouse"], location_type: Cats::Core::Location::WAREHOUSE)
|
20
20
|
end
|
21
21
|
|
22
22
|
def stores
|
23
|
-
return unless details.key?(
|
23
|
+
return unless details.key?("stores")
|
24
24
|
|
25
|
-
Cats::Core::Store.where(id: details[
|
25
|
+
Cats::Core::Store.where(id: details["stores"])
|
26
26
|
end
|
27
27
|
|
28
28
|
def hub
|
29
|
-
return unless details.key?(
|
29
|
+
return unless details.key?("hub")
|
30
30
|
|
31
|
-
Cats::Core::Location.find_by(id: details[
|
31
|
+
Cats::Core::Location.find_by(id: details["hub"], location_type: Cats::Core::Location::HUB)
|
32
32
|
end
|
33
33
|
|
34
34
|
def add_detail(key, value)
|
@@ -48,7 +48,7 @@ module Cats
|
|
48
48
|
|
49
49
|
return if phone_number.length == 12 && /251\d{9}/.match(phone_number)
|
50
50
|
|
51
|
-
errors.add(:phone_number,
|
51
|
+
errors.add(:phone_number, "must be 10 or 12 digits and should match with local phone pattern")
|
52
52
|
end
|
53
53
|
|
54
54
|
def full_name
|
@@ -7,9 +7,9 @@ module Cats
|
|
7
7
|
module Dispatchable
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
DRAFT =
|
11
|
-
APPROVED =
|
12
|
-
COMPLETED =
|
10
|
+
DRAFT = "Draft".freeze
|
11
|
+
APPROVED = "Approved".freeze
|
12
|
+
COMPLETED = "Completed".freeze
|
13
13
|
|
14
14
|
# rubocop:disable Style/MutableConstant
|
15
15
|
STATUSES = [DRAFT, APPROVED, COMPLETED]
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class DispatchAuthorizationNotification < Noticed::Base
|
4
|
+
deliver_by :database
|
5
|
+
|
6
|
+
param :dispatch_authorization
|
7
|
+
|
8
|
+
def message
|
9
|
+
authorization = params[:dispatch_authorization]
|
10
|
+
dispatch = authorization.dispatch
|
11
|
+
plan_item_ref = dispatch.dispatch_plan_item.reference_no
|
12
|
+
plan_ref = dispatch.dispatch_plan_item.dispatch_plan.reference_no
|
13
|
+
commodity = dispatch.dispatch_plan_item.commodity
|
14
|
+
title = "Dispatch Authorization Notification - #{commodity.name}"
|
15
|
+
date = Date.today
|
16
|
+
|
17
|
+
body = <<~BODY
|
18
|
+
Commodity with the following details is ordered to be dispatched from your store:
|
19
|
+
Authorization no. = #{dispatch.dispatch_plan_item.reference_no}
|
20
|
+
Dispatch Ref. = #{dispatch.reference_no}
|
21
|
+
Dispatch Plan Ref. = #{plan_ref}
|
22
|
+
Dispatch Plan Item Ref. = #{plan_item_ref}
|
23
|
+
Batch No. = #{commodity.batch_no}
|
24
|
+
Commodity = #{commodity.name}
|
25
|
+
Quantity = #{authorization.quantity}
|
26
|
+
Unit = #{authorization.unit.abbreviation}
|
27
|
+
Truck Plate No. = #{dispatch.plate_no}
|
28
|
+
Driver Name = #{dispatch.driver_name}
|
29
|
+
Driver Phone = #{dispatch.driver_phone}
|
30
|
+
BODY
|
31
|
+
{title: title, date: date, body: body}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class CommodityDonationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :donated_on, :donor_id, :donor_name, :plan_id, :plan_reference_no,
|
5
|
-
|
6
|
-
|
5
|
+
:quantity, :unit_id, :unit_abbreviation, :description, :commodity_category_id,
|
6
|
+
:commodity_category_name, :shipping_reference
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class CommoditySerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_abbreviation, :project_id,
|
5
|
-
|
6
|
-
|
5
|
+
:project_code, :quantity, :best_use_before, :volume_per_metric_ton, :arrival_status, :status,
|
6
|
+
:shipping_reference, :commodity_grade, :package_unit_id, :package_unit_abbreviation
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :authorized_by_id,
|
5
|
-
|
6
|
-
|
5
|
+
:authorizer_full_name, :dispatch_status, :plate_no, :driver_name, :status, :unit_id,
|
6
|
+
:unit_abbreviation
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,9 +2,9 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchPlanItemSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
:destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
|
6
|
+
:status, :commodity_id, :commodity_name, :commodity_batch_no, :unit_abbreviation,
|
7
|
+
:commodity_shipping_reference, :unit_id
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :dispatch_plan_item_id, :transporter_id, :transporter_name, :plate_no,
|
5
|
-
|
6
|
-
|
5
|
+
:driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
|
6
|
+
:dispatch_status, :destination, :auth_details, :unit_id, :unit_abbreviation, :commodity_status
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchTransactionSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :source_id, :source_code, :dispatch_authorization_id, :quantity, :transaction_date, :status,
|
5
|
-
|
5
|
+
:unit_id, :unit_abbreviation, :reference_no
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class LoanSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :lender, :agreement_date, :repayment_date, :commodity_category_id,
|
5
|
-
|
5
|
+
:commodity_category_name, :quantity, :unit_id, :unit_abbreviation
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class PurchaseOrderSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :order_date, :requisition_no, :supplier, :cash_donation_id, :purchase_type,
|
5
|
-
|
6
|
-
|
5
|
+
:commodity_category_id, :commodity_category_name, :quantity, :unit_id, :unit_name, :currency_id,
|
6
|
+
:currency_code, :price
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class ReceiptAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
|
5
|
-
|
6
|
-
|
5
|
+
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details, :plate_no, :driver_name,
|
6
|
+
:dispatch_status, :unit_id, :unit_abbreviation, :driver_confirmed
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class ReceiptSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :receipt_authorization_id, :commodity_status, :commodity_grade, :quantity, :remark,
|
5
|
-
|
5
|
+
:unit_id, :unit_abbreviation, :reference_no
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class ReceiptTransactionSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :receipt_authorization_id, :receipt_number,
|
5
|
-
|
6
|
-
|
5
|
+
:dispatch_reference_no, :destination_id, :destination_code, :quantity,
|
6
|
+
:transaction_date, :status, :unit_id, :unit_abbreviation
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class RoundBeneficiarySerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :beneficiary_id, :beneficiary_full_name, :round_plan_item_id, :commodity_category_id,
|
5
|
-
|
5
|
+
:commodity_category_name, :quantity, :unit_id, :unit_abbreviation, :received
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class StackSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :code, :length, :width, :height, :start_x, :start_y, :commodity_id, :store_id, :commodity_status,
|
5
|
-
|
5
|
+
:stack_status, :quantity, :commodity_batch_no, :unit_id, :unit_abbreviation
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class StoreSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :code, :name, :length, :width, :height, :temporary, :has_gangway, :gangway_length,
|
5
|
-
|
5
|
+
:gangway_width, :gangway_corner_dist, :warehouse_id
|
6
6
|
|
7
7
|
has_many :stacks
|
8
8
|
end
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class SwapSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :swapper, :agreement_date, :issued_commodity_id, :issued_commodity_name,
|
5
|
-
|
6
|
-
|
5
|
+
:issued_quantity, :received_commodity_id, :received_commodity_name, :received_quantity,
|
6
|
+
:issued_unit_id, :issued_unit_abbreviation, :received_unit_id, :received_unit_abbreviation
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class AuthorizationService
|
4
|
-
def driver_confirm(authorization_id, pin)
|
4
|
+
def driver_confirm(authorization_id, pin, receipt_number)
|
5
5
|
authorization = ReceiptAuthorization.find(authorization_id)
|
6
6
|
if authorization.status == Authorization::AUTHORIZED
|
7
|
-
raise(StandardError,
|
7
|
+
raise(StandardError, "Authorization not confirmed by storekeeper.")
|
8
8
|
end
|
9
9
|
|
10
|
-
raise(StandardError,
|
10
|
+
raise(StandardError, "No pin has been generated for receipt.") if authorization.auth_details.nil?
|
11
11
|
|
12
|
-
raise(StandardError,
|
12
|
+
raise(StandardError, "Incorrect pin.") unless pin == authorization.auth_details["pin"]
|
13
13
|
|
14
|
-
raise(StandardError,
|
14
|
+
raise(StandardError, "Pin is not active.") unless authorization.auth_details["active"]
|
15
15
|
|
16
|
-
if DateTime.now > authorization.auth_details[
|
16
|
+
if DateTime.now > authorization.auth_details["expires_at"]
|
17
17
|
authorization.auth_details[:active] = false
|
18
18
|
authorization.save!
|
19
|
-
raise(StandardError,
|
19
|
+
raise(StandardError, "Pin has expired.")
|
20
20
|
end
|
21
21
|
|
22
22
|
authorization.driver_confirmed = true
|
@@ -27,7 +27,7 @@ module Cats
|
|
27
27
|
# Create destination stack and transaction for FDP
|
28
28
|
location = authorization.dispatch.dispatch_plan_item.destination
|
29
29
|
if location.location_type == Location::FDP
|
30
|
-
create_stack(authorization_id)
|
30
|
+
create_stack(authorization_id, receipt_number)
|
31
31
|
stack(authorization_id)
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ module Cats
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# A method to create stack and stack transactions for FDP
|
38
|
-
def create_stack(authorization_id)
|
38
|
+
def create_stack(authorization_id, receipt_number)
|
39
39
|
authorization = ReceiptAuthorization.find(authorization_id)
|
40
40
|
commodity = authorization.dispatch.dispatch_plan_item.commodity
|
41
41
|
stack = Stack.create!(
|
@@ -57,7 +57,8 @@ module Cats
|
|
57
57
|
quantity: authorization.received_quantity,
|
58
58
|
unit: authorization.unit,
|
59
59
|
status: Transaction::DRAFT,
|
60
|
-
transaction_date: Date.today
|
60
|
+
transaction_date: Date.today,
|
61
|
+
receipt_number: receipt_number
|
61
62
|
)
|
62
63
|
stack
|
63
64
|
end
|
@@ -65,12 +66,12 @@ module Cats
|
|
65
66
|
def stack(authorization_id)
|
66
67
|
authorization = ReceiptAuthorization.find(authorization_id)
|
67
68
|
unless authorization.dispatch.dispatch_status == Dispatch::RECEIVED
|
68
|
-
raise(StandardError,
|
69
|
+
raise(StandardError, "Dispatch is not received.")
|
69
70
|
end
|
70
71
|
|
71
72
|
total = authorization.transactions.sum(:quantity)
|
72
73
|
if total != authorization.received_quantity
|
73
|
-
raise(StandardError,
|
74
|
+
raise(StandardError, "Received quantity is not the same as quantity to be stacked.")
|
74
75
|
end
|
75
76
|
|
76
77
|
authorization.transactions.each(&:commit)
|
@@ -83,7 +84,7 @@ module Cats
|
|
83
84
|
item = DispatchPlanItem.find(id).includes(
|
84
85
|
:destination,
|
85
86
|
:unit,
|
86
|
-
commodity: {
|
87
|
+
commodity: {project: :source}
|
87
88
|
)
|
88
89
|
{
|
89
90
|
date: Date.today,
|
@@ -96,22 +97,39 @@ module Cats
|
|
96
97
|
}
|
97
98
|
end
|
98
99
|
|
99
|
-
def
|
100
|
-
notification_rule = NotificationRule.find_by(code:
|
101
|
-
error =
|
100
|
+
def send_receipt_notification(authorization)
|
101
|
+
notification_rule = NotificationRule.find_by(code: "receipt_authorization")
|
102
|
+
error = "Notification rule not found for receipt authorization notification."
|
102
103
|
raise(StandardError, error) unless notification_rule
|
103
104
|
|
104
|
-
users = User.joins(:roles).where(cats_core_roles: {
|
105
|
+
users = User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
|
105
106
|
recipients = users.map do |user|
|
106
107
|
details = user.details
|
107
108
|
|
108
|
-
user if details.key?(
|
109
|
+
user if details.key?("stores") && details["stores"].include?(authorization.store_id)
|
109
110
|
end.compact
|
110
111
|
return if recipients.empty?
|
111
112
|
|
112
113
|
notification = ReceiptAuthorizationNotification.with(receipt_authorization: authorization)
|
113
114
|
notification.deliver(recipients)
|
114
115
|
end
|
116
|
+
|
117
|
+
def send_dispatch_notification(authorization)
|
118
|
+
notification_rule = NotificationRule.find_by(code: "dispatch_authorization")
|
119
|
+
error = "Notification rule not found for dispatch authorization notification."
|
120
|
+
raise(StandardError, error) unless notification_rule
|
121
|
+
|
122
|
+
users = User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
|
123
|
+
recipients = users.map do |user|
|
124
|
+
details = user.details
|
125
|
+
|
126
|
+
user if details.key?("stores") && details["stores"].include?(authorization.store_id)
|
127
|
+
end.compact
|
128
|
+
return if recipients.empty?
|
129
|
+
|
130
|
+
notification = DispatchAuthorizationNotification.with(dispatch_authorization: authorization)
|
131
|
+
notification.deliver(recipients)
|
132
|
+
end
|
115
133
|
end
|
116
134
|
end
|
117
135
|
end
|
@@ -3,9 +3,9 @@ module Cats
|
|
3
3
|
class BeneficiaryService
|
4
4
|
def clear_distribution_list(id)
|
5
5
|
round_plan = RoundPlan.find(id)
|
6
|
-
raise(StandardError,
|
6
|
+
raise(StandardError, "Round plan is not in draft state.") unless round_plan.status == RoundPlan::DRAFT
|
7
7
|
|
8
|
-
RoundBeneficiary.joins(:round_plan_item).where(round_plan_item: {
|
8
|
+
RoundBeneficiary.joins(:round_plan_item).where(round_plan_item: {round_plan_id: id}).delete_all
|
9
9
|
end
|
10
10
|
|
11
11
|
def generate_distribution_list(id)
|
@@ -14,7 +14,7 @@ module Cats
|
|
14
14
|
plan_days = round_plan.plan.no_of_round_days
|
15
15
|
rounds = round_plan.rounds.count
|
16
16
|
beneficiaries = Beneficiary.joins(:beneficiary_category).where(
|
17
|
-
beneficiary_category: {
|
17
|
+
beneficiary_category: {plan_id: round_plan.plan_id}
|
18
18
|
).group_by(&:fdp_id)
|
19
19
|
beneficiaries.each_key do |key|
|
20
20
|
beneficiaries[key] = beneficiaries[key].group_by(&:beneficiary_category_id)
|
@@ -48,38 +48,38 @@ module Cats
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def remove_items(plan_id, ids)
|
51
|
-
raise(StandardError,
|
51
|
+
raise(StandardError, "No beneficiaries specified.") if ids.count.zero?
|
52
52
|
|
53
53
|
begin
|
54
54
|
plan = RoundPlan.find(plan_id)
|
55
55
|
rescue ActiveRecord::RecordNotFound
|
56
|
-
raise(StandardError,
|
56
|
+
raise(StandardError, "Round plan not found.") unless plan
|
57
57
|
end
|
58
58
|
|
59
59
|
beneficiaries = RoundBeneficiary.joins(:round_plan_item)
|
60
|
-
|
60
|
+
.where(round_plan_item: {round_plan_id: plan_id})
|
61
61
|
to_delete = RoundBeneficiary.where(id: ids)
|
62
62
|
diff = to_delete - beneficiaries
|
63
|
-
raise(StandardError,
|
63
|
+
raise(StandardError, "Round plan beneficiaries should be from the same plan.") if diff.count.positive?
|
64
64
|
|
65
65
|
to_delete.delete_all
|
66
66
|
true
|
67
67
|
end
|
68
68
|
|
69
69
|
def confirm_receipt(plan_id, ids)
|
70
|
-
raise(StandardError,
|
70
|
+
raise(StandardError, "No beneficiaries specified.") if ids.count.zero?
|
71
71
|
|
72
72
|
begin
|
73
73
|
plan = RoundPlan.find(plan_id)
|
74
74
|
rescue ActiveRecord::RecordNotFound
|
75
|
-
raise(StandardError,
|
75
|
+
raise(StandardError, "Round plan not found.") unless plan
|
76
76
|
end
|
77
77
|
|
78
78
|
beneficiaries = RoundBeneficiary.joins(:round_plan_item)
|
79
|
-
|
79
|
+
.where(round_plan_item: {round_plan_id: plan_id})
|
80
80
|
to_confirm = RoundBeneficiary.where(id: ids)
|
81
81
|
diff = to_confirm - beneficiaries
|
82
|
-
raise(StandardError,
|
82
|
+
raise(StandardError, "Round plan beneficiaries should be from the same plan.") if diff.count.positive?
|
83
83
|
|
84
84
|
to_confirm.update_all(received: true)
|
85
85
|
true
|
@@ -7,8 +7,8 @@ module Cats
|
|
7
7
|
if plan.upstream
|
8
8
|
# Create source hub authorizations for each item and
|
9
9
|
# put them in a `Source Authorized` state
|
10
|
-
store = Store.find_by(code:
|
11
|
-
keeper = User.find_by(first_name:
|
10
|
+
store = Store.find_by(code: "SUP-STORE")
|
11
|
+
keeper = User.find_by(first_name: "SUP-Storekeeper")
|
12
12
|
authorizations = []
|
13
13
|
plan.dispatch_plan_items.each do |item|
|
14
14
|
authorizations << {
|
@@ -40,17 +40,17 @@ module Cats
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def send_notification(allocation)
|
43
|
-
notification_rule = Cats::Core::NotificationRule.find_by(code:
|
44
|
-
raise(StandardError,
|
43
|
+
notification_rule = Cats::Core::NotificationRule.find_by(code: "allocation")
|
44
|
+
raise(StandardError, "Notification rule not found for allocation notification.") unless notification_rule
|
45
45
|
|
46
|
-
users = Cats::Core::User.joins(:roles).where(cats_core_roles: {
|
46
|
+
users = Cats::Core::User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
|
47
47
|
allocation.dispatch_plan_items.each do |item|
|
48
48
|
location_id = item.destination_id
|
49
49
|
|
50
50
|
recipients = users.map do |user|
|
51
51
|
details = user.details
|
52
|
-
if (details.key?(
|
53
|
-
|
52
|
+
if (details.key?("warehouse") && details["warehouse"] == location_id) ||
|
53
|
+
(details.key?("hub") && details["hub"] == location_id)
|
54
54
|
user
|
55
55
|
end
|
56
56
|
end.compact
|
@@ -69,9 +69,9 @@ module Cats
|
|
69
69
|
#
|
70
70
|
def generate(id)
|
71
71
|
details = RoundPlanItemDetail.joins(
|
72
|
-
beneficiary_round_plan_item: {
|
72
|
+
beneficiary_round_plan_item: {round_plan_item: :round_plan}
|
73
73
|
).where(
|
74
|
-
beneficiary_round_plan_item: {
|
74
|
+
beneficiary_round_plan_item: {cats_core_round_plan_items: {round_plan_id: id}}
|
75
75
|
).includes(
|
76
76
|
beneficiary_round_plan_item: {
|
77
77
|
round_plan_item: %i[round_plan region zone woreda fdp]
|
@@ -99,7 +99,7 @@ module Cats
|
|
99
99
|
{
|
100
100
|
reference_no: nil,
|
101
101
|
dispatchable_id: id,
|
102
|
-
dispatchable_type:
|
102
|
+
dispatchable_type: "Cats::Core::RoundPlan",
|
103
103
|
items: items
|
104
104
|
}
|
105
105
|
end
|