cats_core 1.5.19 → 1.5.21
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/app/controllers/cats/core/commodities_controller.rb +3 -3
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +4 -4
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +1 -1
- data/app/controllers/cats/core/dispatch_plans_controller.rb +2 -2
- data/app/controllers/cats/core/dispatch_transactions_controller.rb +1 -1
- data/app/controllers/cats/core/dispatches_controller.rb +5 -5
- data/app/controllers/cats/core/loans_controller.rb +1 -1
- data/app/controllers/cats/core/purchase_orders_controller.rb +2 -2
- data/app/controllers/cats/core/receipt_authorizations_controller.rb +5 -5
- data/app/controllers/cats/core/receipt_transactions_controller.rb +2 -2
- data/app/controllers/cats/core/receipts_controller.rb +1 -1
- data/app/controllers/cats/core/roles_controller.rb +1 -1
- data/app/controllers/cats/core/round_beneficiaries_controller.rb +5 -5
- data/app/controllers/cats/core/round_plans_controller.rb +3 -3
- data/app/controllers/cats/core/stack_transactions_controller.rb +1 -1
- data/app/controllers/cats/core/stacks_controller.rb +2 -2
- data/app/controllers/cats/core/stores_controller.rb +1 -1
- data/app/controllers/cats/core/swaps_controller.rb +2 -2
- data/app/controllers/cats/core/users_controller.rb +1 -1
- data/app/controllers/concerns/cats/core/common.rb +15 -16
- data/app/models/cats/core/authorization.rb +1 -1
- data/app/models/cats/core/beneficiary_plan_item.rb +1 -1
- data/app/models/cats/core/commodity.rb +12 -12
- data/app/models/cats/core/commodity_substitution.rb +2 -2
- data/app/models/cats/core/dispatch.rb +16 -16
- data/app/models/cats/core/dispatch_authorization.rb +3 -3
- data/app/models/cats/core/dispatch_plan.rb +6 -6
- data/app/models/cats/core/dispatch_plan_item.rb +10 -10
- data/app/models/cats/core/dispatch_transaction.rb +8 -8
- data/app/models/cats/core/location.rb +2 -2
- data/app/models/cats/core/receipt_authorization.rb +2 -2
- data/app/models/cats/core/receipt_transaction.rb +2 -2
- data/app/models/cats/core/round_beneficiary.rb +4 -4
- data/app/models/cats/core/round_plan.rb +2 -2
- data/app/models/cats/core/round_plan_item.rb +2 -2
- data/app/models/cats/core/route.rb +2 -2
- data/app/models/cats/core/stack.rb +30 -30
- data/app/models/cats/core/stacking_rule.rb +2 -2
- data/app/models/cats/core/store.rb +21 -21
- data/app/models/cats/core/transporter.rb +2 -2
- data/app/models/cats/core/unit_conversion.rb +1 -3
- 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 +3 -9
- data/app/services/cats/core/beneficiary_service.rb +2 -2
- data/app/services/cats/core/dispatch_plan_service.rb +1 -1
- data/app/services/cats/core/dispatch_service.rb +18 -20
- data/app/services/cats/core/notification_service.rb +1 -1
- data/app/services/cats/core/round_plan_service.rb +4 -6
- data/app/services/cats/core/space_service.rb +6 -6
- data/app/services/cats/core/stack_service.rb +8 -8
- data/app/services/cats/core/user_service.rb +1 -1
- data/db/migrate/20210715114910_create_cats_core_users.rb +3 -3
- data/db/migrate/20210715120018_create_cats_core_roles.rb +11 -11
- 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 +12 -12
- data/db/migrate/20210717031810_create_cats_core_plans.rb +3 -3
- data/db/migrate/20210717032024_create_cats_core_plan_items.rb +19 -19
- data/db/migrate/20210717032260_create_cats_core_beneficiary_categories.rb +3 -3
- data/db/migrate/20210717032270_create_cats_core_rations.rb +9 -9
- 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 +9 -9
- data/db/migrate/20210717140855_create_cats_core_stores.rb +3 -3
- data/db/migrate/20210717171101_create_cats_core_stacks.rb +9 -9
- 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 +6 -6
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +15 -15
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +12 -12
- data/db/migrate/20210718055414_create_cats_core_dispatch_authorizations.rb +12 -12
- data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +10 -10
- data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +12 -12
- 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 +9 -9
- data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +9 -9
- data/db/migrate/20211215114737_create_cats_core_transport_plans.rb +3 -3
- data/db/migrate/20211215114835_create_cats_core_transport_plan_items.rb +9 -9
- data/db/migrate/20211215121151_create_cats_core_transport_bids.rb +3 -3
- data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +9 -9
- 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 +6 -6
- data/db/migrate/20220107122280_create_cats_core_round_rations.rb +12 -12
- data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +18 -18
- data/db/migrate/20220107126025_create_cats_core_beneficiary_round_plan_items.rb +7 -7
- 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 +7 -7
- 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 +9 -9
- data/db/migrate/20220506083042_create_cats_core_transport_order_items.rb +12 -12
- 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 +12 -12
- data/db/migrate/20220923190857_create_cats_core_application_settings.rb +3 -3
- data/lib/cats/core/engine.rb +1 -3
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_authorizations.rb +1 -1
- data/spec/factories/cats/core/dispatch_plan_items.rb +1 -1
- data/spec/factories/cats/core/dispatches.rb +4 -4
- data/spec/factories/cats/core/round_plan_item_details.rb +1 -1
- metadata +41 -13
@@ -54,8 +54,8 @@ module Cats
|
|
54
54
|
Store.find_by(code: "FDP-ST-#{code}")
|
55
55
|
end
|
56
56
|
|
57
|
-
def self.ransackable_attributes(
|
58
|
-
[
|
57
|
+
def self.ransackable_attributes(_auth_object = nil)
|
58
|
+
%w[code location_type name]
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -15,8 +15,8 @@ module Cats
|
|
15
15
|
ValidationUtil.validate_quantity(self, "dispatch", authorizations, "dispatch")
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.ransackable_attributes(
|
19
|
-
[
|
18
|
+
def self.ransackable_attributes(_auth_object = nil)
|
19
|
+
%w[authorized_by_id dispatch_id received_quantity quantity status store_id unit_id]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -46,8 +46,8 @@ module Cats
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.ransackable_attributes(
|
50
|
-
[
|
49
|
+
def self.ransackable_attributes(_auth_object = nil)
|
50
|
+
%w[destination_id quantity receipt_authorization_id receipt_number status transaction_date unit_id]
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -12,12 +12,12 @@ module Cats
|
|
12
12
|
delegate(:name, to: :commodity_category, prefix: true)
|
13
13
|
delegate(:abbreviation, to: :unit, prefix: true)
|
14
14
|
|
15
|
-
def self.ransackable_attributes(
|
16
|
-
[
|
15
|
+
def self.ransackable_attributes(_auth_object = nil)
|
16
|
+
%w[beneficiary_id commodity_category_id quantity received round_plan_item_id unit_id]
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.ransackable_associations(
|
20
|
-
[
|
19
|
+
def self.ransackable_associations(_auth_object = nil)
|
20
|
+
%w[beneficiary commodity_category round_plan_item unit]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -72,8 +72,8 @@ module Cats
|
|
72
72
|
errors.add(:region, "is not valid.") unless region.location_type == Location::REGION
|
73
73
|
end
|
74
74
|
|
75
|
-
def self.ransackable_attributes(
|
76
|
-
[
|
75
|
+
def self.ransackable_attributes(_auth_object = nil)
|
76
|
+
%w[plan_id reference_no region_id rounds status]
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -22,8 +22,8 @@ module Cats
|
|
22
22
|
delegate(:name, to: :fdp, prefix: true)
|
23
23
|
delegate(:name, to: :operator, prefix: true)
|
24
24
|
|
25
|
-
def self.ransackable_attributes(
|
26
|
-
[
|
25
|
+
def self.ransackable_attributes(_auth_object = nil)
|
26
|
+
%w[fdp_id operator_id plan_item_id region_id round_plan_id woreda_id zone_id]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -44,8 +44,8 @@ module Cats
|
|
44
44
|
errors.add(:base, "Source and destination cannot be the same") if source == destination
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.ransackable_attributes(
|
48
|
-
[
|
47
|
+
def self.ransackable_attributes(_auth_object = nil)
|
48
|
+
%w[destination_id name region_id source_id]
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -15,16 +15,16 @@ module Cats
|
|
15
15
|
has_many :receipt_transactions, foreign_key: :destination_id
|
16
16
|
|
17
17
|
validates :code, :length, :width, :height, :start_x, :start_y, :commodity_status, :stack_status,
|
18
|
-
|
18
|
+
:quantity, presence: true
|
19
19
|
validates :code, uniqueness: true
|
20
20
|
validates :length, :width, :height, :start_x, :start_y, numericality: {greater_than: 0}
|
21
21
|
validates :quantity, numericality: {greater_than_or_equal_to: 0}
|
22
22
|
validates :commodity_status, inclusion: {in: Cats::Core::Commodity::COMMODITY_STATUSES}
|
23
23
|
validates :stack_status, inclusion: {in: STACK_STATUSES}
|
24
24
|
validate :validate_coordinates, :validate_dimensions, :validate_distance_from_wall, :validate_overlap,
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
:validate_space_between_stack, :validate_max_height, :validate_max_length, :validate_max_width,
|
26
|
+
:validate_distance_from_ceiling,
|
27
|
+
unless: -> { store && (store.code == "SUP-STORE" || store.code.start_with?("FDP-ST")) }
|
28
28
|
|
29
29
|
delegate :batch_no, to: :commodity, prefix: true
|
30
30
|
delegate :abbreviation, to: :unit, prefix: true
|
@@ -66,9 +66,9 @@ module Cats
|
|
66
66
|
|
67
67
|
rule = stacking_rules
|
68
68
|
if start_x < rule.distance_from_wall || store.length - (start_x + length) < rule.distance_from_wall ||
|
69
|
-
|
69
|
+
store.width - (start_y + width) < rule.distance_from_wall || start_y < rule.distance_from_wall
|
70
70
|
errors.add(:base,
|
71
|
-
|
71
|
+
message: "The stack must be placed #{rule.distance_from_wall} meter away from a store wall")
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -89,9 +89,9 @@ module Cats
|
|
89
89
|
rule = stacking_rules
|
90
90
|
new_stack = dup
|
91
91
|
new_stack.assign_attributes(start_x: start_x - rule.space_between_stack,
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
start_y: start_y - rule.space_between_stack,
|
93
|
+
length: length + (2 * rule.space_between_stack),
|
94
|
+
width: width + (2 * rule.space_between_stack))
|
95
95
|
stacks.each do |s|
|
96
96
|
errors.add(:base, message: "#{code} overlaps with #{s.code}") if overlaps?(new_stack, s)
|
97
97
|
end
|
@@ -140,10 +140,10 @@ module Cats
|
|
140
140
|
return unless length_previously_changed? || width_previously_changed? || stack_status_previously_changed?
|
141
141
|
|
142
142
|
old_area = if length_previously_was.nil? && width_previously_was.nil?
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
143
|
+
0
|
144
|
+
else
|
145
|
+
length_previously_was * width_previously_was
|
146
|
+
end
|
147
147
|
|
148
148
|
store.available_space += old_area
|
149
149
|
store.available_space -= length * width unless stack_status == DESTROYED
|
@@ -171,27 +171,27 @@ module Cats
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def destroy_stack
|
174
|
-
|
175
|
-
self.stack_status = Cats::Core::Stack::DESTROYED
|
176
|
-
save!
|
177
|
-
else
|
174
|
+
unless stack_status == Cats::Core::Stack::RESERVED || quantity.zero?
|
178
175
|
raise(StandardError, "Stack has to be either RESERVED or with zero quantity to be destroyed.")
|
179
176
|
end
|
177
|
+
|
178
|
+
self.stack_status = Cats::Core::Stack::DESTROYED
|
179
|
+
save!
|
180
180
|
end
|
181
181
|
|
182
|
-
def self.ransackable_attributes(
|
183
|
-
[
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
182
|
+
def self.ransackable_attributes(_auth_object = nil)
|
183
|
+
%w[
|
184
|
+
commodity_id
|
185
|
+
commodity_status
|
186
|
+
height
|
187
|
+
length
|
188
|
+
quantity
|
189
|
+
stack_status
|
190
|
+
start_x
|
191
|
+
start_y
|
192
|
+
store_id
|
193
|
+
unit_id
|
194
|
+
width
|
195
195
|
]
|
196
196
|
end
|
197
197
|
end
|
@@ -2,14 +2,14 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class StackingRule < ApplicationRecord
|
4
4
|
validates :distance_from_wall, :space_between_stack, :distance_from_ceiling, :maximum_height, :maximum_length,
|
5
|
-
|
5
|
+
:maximum_width, :distance_from_gangway, presence: true, numericality: {greater_than: 0}
|
6
6
|
validate :validate_only_a_record_exist
|
7
7
|
|
8
8
|
def validate_only_a_record_exist
|
9
9
|
return unless StackingRule.count > 1
|
10
10
|
|
11
11
|
errors.add(:base,
|
12
|
-
|
12
|
+
"There is already a stacking rule entry. A new rule can not be added")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -9,10 +9,10 @@ module Cats
|
|
9
9
|
validates :length, :width, :height, numericality: {greater_than: 0}
|
10
10
|
validates :gangway_length, :gangway_width, :gangway_corner_dist, presence: true, if: :has_gangway?
|
11
11
|
validates :gangway_length,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
:gangway_width,
|
13
|
+
:gangway_corner_dist,
|
14
|
+
numericality: {greater_than: 0},
|
15
|
+
allow_nil: true
|
16
16
|
validate :validate_location
|
17
17
|
|
18
18
|
before_create :update_usable_space
|
@@ -29,26 +29,26 @@ module Cats
|
|
29
29
|
self.available_space = self.usable_space
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.ransackable_attributes(
|
33
|
-
[
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
def self.ransackable_attributes(_auth_object = nil)
|
33
|
+
%w[
|
34
|
+
available_space
|
35
|
+
code
|
36
|
+
gangway_corner_dist
|
37
|
+
gangway_length
|
38
|
+
gangway_width
|
39
|
+
has_gangway
|
40
|
+
height
|
41
|
+
length
|
42
|
+
name
|
43
|
+
temporary
|
44
|
+
usable_space
|
45
|
+
warehouse_id
|
46
|
+
width
|
47
47
|
]
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.ransackable_associations(
|
51
|
-
[
|
50
|
+
def self.ransackable_associations(_auth_object = nil)
|
51
|
+
%w[stacks warehouse]
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -4,8 +4,8 @@ module Cats
|
|
4
4
|
validates :code, :name, :address, :contact_phone, presence: true
|
5
5
|
validates :code, uniqueness: true
|
6
6
|
|
7
|
-
def self.ransackable_attributes(
|
8
|
-
[
|
7
|
+
def self.ransackable_attributes(_auth_object = nil)
|
8
|
+
%w[address code contact_phone name]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -19,9 +19,7 @@ module Cats
|
|
19
19
|
|
20
20
|
# Check if there is reverse conversion entry defined
|
21
21
|
conversion = find_by(from: to, to: from)
|
22
|
-
unless conversion
|
23
|
-
raise(StandardError, "Conversion factor between #{from.abbreviation} and #{to.abbreviation} not found.")
|
24
|
-
end
|
22
|
+
raise(StandardError, "Conversion factor between #{from.abbreviation} and #{to.abbreviation} not found.") unless conversion
|
25
23
|
|
26
24
|
(value / conversion.factor).round(2)
|
27
25
|
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
|
@@ -3,9 +3,7 @@ module Cats
|
|
3
3
|
class AuthorizationService
|
4
4
|
def driver_confirm(authorization_id, pin, receipt_number)
|
5
5
|
authorization = ReceiptAuthorization.find(authorization_id)
|
6
|
-
if authorization.status == Authorization::AUTHORIZED
|
7
|
-
raise(StandardError, "Authorization not confirmed by storekeeper.")
|
8
|
-
end
|
6
|
+
raise(StandardError, "Authorization not confirmed by storekeeper.") if authorization.status == Authorization::AUTHORIZED
|
9
7
|
|
10
8
|
raise(StandardError, "No pin has been generated for receipt.") if authorization.auth_details.nil?
|
11
9
|
|
@@ -65,14 +63,10 @@ module Cats
|
|
65
63
|
|
66
64
|
def stack(authorization_id)
|
67
65
|
authorization = ReceiptAuthorization.find(authorization_id)
|
68
|
-
unless authorization.dispatch.dispatch_status == Dispatch::RECEIVED
|
69
|
-
raise(StandardError, "Dispatch is not received.")
|
70
|
-
end
|
66
|
+
raise(StandardError, "Dispatch is not received.") unless authorization.dispatch.dispatch_status == Dispatch::RECEIVED
|
71
67
|
|
72
68
|
total = authorization.transactions.sum(:quantity)
|
73
|
-
if total != authorization.received_quantity
|
74
|
-
raise(StandardError, "Received quantity is not the same as quantity to be stacked.")
|
75
|
-
end
|
69
|
+
raise(StandardError, "Received quantity is not the same as quantity to be stacked.") if total != authorization.received_quantity
|
76
70
|
|
77
71
|
authorization.transactions.each(&:commit)
|
78
72
|
|
@@ -57,7 +57,7 @@ module Cats
|
|
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
63
|
raise(StandardError, "Round plan beneficiaries should be from the same plan.") if diff.count.positive?
|
@@ -76,7 +76,7 @@ module Cats
|
|
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
82
|
raise(StandardError, "Round plan beneficiaries should be from the same plan.") if diff.count.positive?
|
@@ -50,7 +50,7 @@ module Cats
|
|
50
50
|
recipients = users.map do |user|
|
51
51
|
details = user.details
|
52
52
|
if (details.key?("warehouse") && details["warehouse"] == location_id) ||
|
53
|
-
|
53
|
+
(details.key?("hub") && details["hub"] == location_id)
|
54
54
|
user
|
55
55
|
end
|
56
56
|
end.compact
|
@@ -4,33 +4,31 @@ module Cats
|
|
4
4
|
def search(user, status, authorized: false)
|
5
5
|
details = user.details
|
6
6
|
|
7
|
-
unless details["stores"] || details["warehouse"] || details["hub"]
|
8
|
-
raise(StandardError, "User does not have associated location.")
|
9
|
-
end
|
7
|
+
raise(StandardError, "User does not have associated location.") unless details["stores"] || details["warehouse"] || details["hub"]
|
10
8
|
|
11
9
|
# Get user's hub
|
12
10
|
hub = if details["stores"]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
Store.find(details["stores"][0]).warehouse.parent
|
12
|
+
elsif details["warehouse"]
|
13
|
+
Location.find(details["warehouse"]).parent
|
14
|
+
else
|
15
|
+
Location.find(details["hub"])
|
16
|
+
end
|
19
17
|
|
20
18
|
if authorized
|
21
19
|
return Dispatch.joins(:dispatch_plan_item)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
.includes({dispatch_plan_item: :destination}, :transporter, :prepared_by, :unit)
|
21
|
+
.where(
|
22
|
+
dispatch_plan_item: {destination: hub, status: DispatchPlanItem::AUTHORIZED},
|
23
|
+
dispatch_status: status
|
24
|
+
)
|
27
25
|
end
|
28
26
|
Dispatch.joins(:dispatch_plan_item)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
.includes({dispatch_plan_item: :destination}, :transporter, :prepared_by, :unit)
|
28
|
+
.where(
|
29
|
+
dispatch_plan_item: {destination: hub},
|
30
|
+
dispatch_status: status
|
31
|
+
)
|
34
32
|
end
|
35
33
|
|
36
34
|
def start(dispatch)
|
@@ -77,7 +75,7 @@ module Cats
|
|
77
75
|
details = user.details
|
78
76
|
|
79
77
|
if (details.key?("warehouse") && hub.child_ids.include?(details["warehouse"])) ||
|
80
|
-
|
78
|
+
(details.key?("hub") && details["hub"] == location_id)
|
81
79
|
user
|
82
80
|
end
|
83
81
|
end.compact
|
@@ -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
|