cats_core 1.0.34 → 1.0.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/spaces_controller.rb +11 -0
- data/app/models/cats/core/hrp_item.rb +0 -1
- data/app/models/cats/core/hrp_item_detail.rb +12 -0
- data/app/models/cats/core/hrp_ration.rb +10 -0
- data/app/models/cats/core/ration.rb +1 -4
- data/app/models/cats/core/ration_item.rb +14 -0
- data/app/services/cats/core/space_service.rb +40 -0
- data/config/routes.rb +14 -0
- data/db/migrate/20210717031216_create_cats_core_rations.rb +0 -5
- data/db/migrate/20210717031343_create_cats_core_ration_items.rb +21 -0
- data/db/migrate/20210717032024_create_cats_core_hrp_items.rb +0 -1
- data/db/migrate/20210717032106_create_cats_core_hrp_rations.rb +17 -0
- data/db/migrate/20210717032240_create_cats_core_hrp_item_details.rb +22 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/hrp_item_details.rb +8 -0
- data/spec/factories/cats/core/hrp_items.rb +0 -1
- data/spec/factories/cats/core/hrp_rations.rb +6 -0
- data/spec/factories/cats/core/locations.rb +5 -0
- data/spec/factories/cats/core/ration_items.rb +8 -0
- data/spec/factories/cats/core/rations.rb +0 -2
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f003ab02e18c4d6748354703954b989a2854beb06d6cedde9a1417dd033b6b0d
|
4
|
+
data.tar.gz: ec1a54e9e760cf5a8c84109d526b7a6da50696b31bd3647a82b910e108dca482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d21df2b1e4f3052deda19c879fbc0d3c4f4d5bf9754a7c91e6b7260a7ff1cf64292a68da01d847a9caec74d933cded52952d3de3c627afcd9b6a0bd426019cd0
|
7
|
+
data.tar.gz: 2afec4b8dedd8eb129bd3ad61cc3bcf766c69eb1fbc0d45ef12f18085b62db3856bbc298720be52cc63f040451904cd966cfc6b64fcf6d57037b76254b63f54b
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class SpacesController < ApplicationController
|
4
|
+
def available_space
|
5
|
+
service = SpaceService.new
|
6
|
+
space = service.available_space(params[:id], params[:level])
|
7
|
+
render json: { success: true, data: space }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -6,7 +6,6 @@ module Cats
|
|
6
6
|
belongs_to :operator
|
7
7
|
|
8
8
|
validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
|
9
|
-
validates :commodity_amount, presence: true, numericality: { greater_than: 0 }
|
10
9
|
validates :hrp_id, uniqueness: { scope: :woreda_id }
|
11
10
|
|
12
11
|
delegate(:name, to: :woreda, prefix: true)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class HrpItemDetail < ApplicationRecord
|
4
|
+
belongs_to :hrp_item
|
5
|
+
belongs_to :hrp_ration
|
6
|
+
belongs_to :ration_item
|
7
|
+
|
8
|
+
validates :amount, presence: true, numericality: { greater_than: 0 }
|
9
|
+
validates :hrp_item_id, uniqueness: { scope: :ration_item_id }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -2,11 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class Ration < ApplicationRecord
|
4
4
|
belongs_to :program
|
5
|
-
belongs_to :commodity_category
|
6
5
|
|
7
|
-
validates :reference_no, :
|
8
|
-
validates :reference_no, uniqueness: true
|
9
|
-
validates :amount, numericality: { greater_than: 0 }
|
6
|
+
validates :reference_no, presence: true, uniqueness: true
|
10
7
|
end
|
11
8
|
end
|
12
9
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class RationItem < ApplicationRecord
|
4
|
+
belongs_to :commodity_category
|
5
|
+
belongs_to :ration
|
6
|
+
belongs_to :unit_of_measure
|
7
|
+
|
8
|
+
validates :amount, presence: true, numericality: { greater_than: 0 }
|
9
|
+
|
10
|
+
delegate(:name, to: :commodity_category, prefix: true)
|
11
|
+
delegate(:abbreviation, to: :unit_of_measure, prefix: true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class SpaceService
|
4
|
+
HUB = 'Hub'.freeze
|
5
|
+
WAREHOUSE = 'Warehouse'.freeze
|
6
|
+
STORE = 'Store'.freeze
|
7
|
+
|
8
|
+
def available_space(id, level)
|
9
|
+
case level
|
10
|
+
when HUB
|
11
|
+
warehouse_ids = Cats::Core::Location.find(id).children.map(&:id)
|
12
|
+
stores = Cats::Core::Store.joins(:warehouse)
|
13
|
+
.where(
|
14
|
+
cats_core_locations: {
|
15
|
+
location_type: Cats::Core::Location::WAREHOUSE,
|
16
|
+
id: warehouse_ids
|
17
|
+
}
|
18
|
+
).group_by(&:warehouse_id)
|
19
|
+
wh_details = []
|
20
|
+
stores.each do |key, value|
|
21
|
+
total_space = value.inject(0) { |sum, val| sum + val.available_space }
|
22
|
+
details = value.map { |val| { store_id: val.id, total_space: val.available_space } }
|
23
|
+
wh_details << { warehouse_id: key, total_space: total_space, details: details }
|
24
|
+
end
|
25
|
+
hub_space = wh_details.inject(0) { |sum, val| sum + val[:total_space] }
|
26
|
+
space = { hub_id: id, total_space: hub_space, details: wh_details }
|
27
|
+
when WAREHOUSE
|
28
|
+
stores = Cats::Core::Store.where(warehouse_id: id)
|
29
|
+
details = stores.map { |store| { store_id: store.id, total_space: store.available_space } }
|
30
|
+
total_space = stores.inject(0) { |sum, val| sum + val.available_space }
|
31
|
+
space = { warehouse_id: id, total_space: total_space, details: details }
|
32
|
+
when STORE
|
33
|
+
store = Cats::Core::Store.find(id)
|
34
|
+
space = { store_id: store.id, total_space: store.available_space }
|
35
|
+
end
|
36
|
+
space
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/config/routes.rb
CHANGED
@@ -28,6 +28,20 @@ Cats::Core::Engine.routes.draw do
|
|
28
28
|
get 'children'
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
get '/hubs/:id/space',
|
33
|
+
to: 'spaces#available_space',
|
34
|
+
as: :hub_space,
|
35
|
+
defaults: { level: Cats::Core::SpaceService::HUB }
|
36
|
+
get '/warehousess/:id/space',
|
37
|
+
to: 'spaces#available_space',
|
38
|
+
as: :warehouse_space,
|
39
|
+
defaults: { level: Cats::Core::SpaceService::WAREHOUSE }
|
40
|
+
get '/store/:id/space',
|
41
|
+
to: 'spaces#available_space',
|
42
|
+
as: :store_space,
|
43
|
+
defaults: { level: Cats::Core::SpaceService::STORE }
|
44
|
+
|
31
45
|
resources :commodity_categories, except: %i[destroy] do
|
32
46
|
member do
|
33
47
|
get 'children'
|
@@ -6,11 +6,6 @@ class CreateCatsCoreRations < ActiveRecord::Migration[6.1]
|
|
6
6
|
null: false,
|
7
7
|
index: { name: 'program_on_ration_indx' },
|
8
8
|
foreign_key: { to_table: :cats_core_programs }
|
9
|
-
t.references :commodity_category,
|
10
|
-
null: false,
|
11
|
-
index: { name: 'cc_on_ration_indx' },
|
12
|
-
foreign_key: { to_table: :cats_core_commodity_categories }
|
13
|
-
t.float :amount, null: false
|
14
9
|
t.boolean :current, null: false, default: true
|
15
10
|
|
16
11
|
t.timestamps
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreateCatsCoreRationItems < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_ration_items do |t|
|
4
|
+
t.references :commodity_category,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'cc_on_ration_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_commodity_categories }
|
8
|
+
t.references :ration,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'ri_on_ration_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_rations }
|
12
|
+
t.references :unit_of_measure,
|
13
|
+
null: false,
|
14
|
+
index: { name: 'uom_on_ration_indx' },
|
15
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
16
|
+
t.float :amount, null: false
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -10,7 +10,6 @@ class CreateCatsCoreHrpItems < ActiveRecord::Migration[6.1]
|
|
10
10
|
index: { name: 'woreda_on_hrp_items_idnx' },
|
11
11
|
foreign_key: { to_table: :cats_core_locations }
|
12
12
|
t.integer :beneficiaries, null: false
|
13
|
-
t.float :commodity_amount, null: false
|
14
13
|
t.references :operator,
|
15
14
|
null: false,
|
16
15
|
index: { name: 'operator_on_hrp_items_indx' },
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateCatsCoreHrpRations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_hrp_rations do |t|
|
4
|
+
t.references :hrp,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'hrp_on_hr_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_hrps }
|
8
|
+
t.references :ration,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'ration_on_hr_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_rations }
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
add_index(:cats_core_hrp_rations, :hrp_id, unique: true)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateCatsCoreHrpItemDetails < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_hrp_item_details do |t|
|
4
|
+
t.references :hrp_item,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'hi_on_hid_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_hrp_items }
|
8
|
+
t.references :hrp_ration,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'hr_on_hid_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_hrp_rations }
|
12
|
+
t.references :ration_item,
|
13
|
+
null: false,
|
14
|
+
index: { name: 'ri_on_hid_indx' },
|
15
|
+
foreign_key: { to_table: :cats_core_ration_items }
|
16
|
+
t.float :amount, null: false
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
add_index(:cats_core_hrp_item_details, [:hrp_item_id, :ration_item_id], unique: true, name: 'hii_rii_on_hid_indx')
|
21
|
+
end
|
22
|
+
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -5,6 +5,11 @@ FactoryBot.define do
|
|
5
5
|
ancestry { nil }
|
6
6
|
end
|
7
7
|
|
8
|
+
factory :hub, parent: :location, class: 'Cats::Core::Location' do
|
9
|
+
location_type { Cats::Core::Location::HUB }
|
10
|
+
parent
|
11
|
+
end
|
12
|
+
|
8
13
|
factory :warehouse, parent: :location, class: 'Cats::Core::Location' do
|
9
14
|
location_type { Cats::Core::Location::WAREHOUSE }
|
10
15
|
parent
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- app/controllers/cats/core/menus_controller.rb
|
225
225
|
- app/controllers/cats/core/notifications_controller.rb
|
226
226
|
- app/controllers/cats/core/roles_controller.rb
|
227
|
+
- app/controllers/cats/core/spaces_controller.rb
|
227
228
|
- app/controllers/cats/core/unit_of_measures_controller.rb
|
228
229
|
- app/controllers/cats/core/users_controller.rb
|
229
230
|
- app/jobs/cats/core/application_job.rb
|
@@ -241,6 +242,8 @@ files:
|
|
241
242
|
- app/models/cats/core/gift_certificate.rb
|
242
243
|
- app/models/cats/core/hrp.rb
|
243
244
|
- app/models/cats/core/hrp_item.rb
|
245
|
+
- app/models/cats/core/hrp_item_detail.rb
|
246
|
+
- app/models/cats/core/hrp_ration.rb
|
244
247
|
- app/models/cats/core/location.rb
|
245
248
|
- app/models/cats/core/menu.rb
|
246
249
|
- app/models/cats/core/menu_item.rb
|
@@ -249,6 +252,7 @@ files:
|
|
249
252
|
- app/models/cats/core/program.rb
|
250
253
|
- app/models/cats/core/purchase_order.rb
|
251
254
|
- app/models/cats/core/ration.rb
|
255
|
+
- app/models/cats/core/ration_item.rb
|
252
256
|
- app/models/cats/core/receipt.rb
|
253
257
|
- app/models/cats/core/receipt_transaction.rb
|
254
258
|
- app/models/cats/core/rhn_request.rb
|
@@ -271,6 +275,7 @@ files:
|
|
271
275
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
272
276
|
- app/services/cats/core/menu_service.rb
|
273
277
|
- app/services/cats/core/notification_service.rb
|
278
|
+
- app/services/cats/core/space_service.rb
|
274
279
|
- app/services/cats/core/token_auth_service.rb
|
275
280
|
- config/routes.rb
|
276
281
|
- db/migrate/20210715114238_create_cats_core_application_modules.rb
|
@@ -288,8 +293,11 @@ files:
|
|
288
293
|
- db/migrate/20210716210905_create_cats_core_suppliers.rb
|
289
294
|
- db/migrate/20210717031108_create_cats_core_donors.rb
|
290
295
|
- db/migrate/20210717031216_create_cats_core_rations.rb
|
296
|
+
- db/migrate/20210717031343_create_cats_core_ration_items.rb
|
291
297
|
- db/migrate/20210717031810_create_cats_core_hrps.rb
|
292
298
|
- db/migrate/20210717032024_create_cats_core_hrp_items.rb
|
299
|
+
- db/migrate/20210717032106_create_cats_core_hrp_rations.rb
|
300
|
+
- db/migrate/20210717032240_create_cats_core_hrp_item_details.rb
|
293
301
|
- db/migrate/20210717032330_create_cats_core_donations.rb
|
294
302
|
- db/migrate/20210717032602_create_cats_core_gift_certificates.rb
|
295
303
|
- db/migrate/20210717032855_create_cats_core_purchase_orders.rb
|
@@ -323,7 +331,9 @@ files:
|
|
323
331
|
- spec/factories/cats/core/donations.rb
|
324
332
|
- spec/factories/cats/core/donors.rb
|
325
333
|
- spec/factories/cats/core/gift_certificates.rb
|
334
|
+
- spec/factories/cats/core/hrp_item_details.rb
|
326
335
|
- spec/factories/cats/core/hrp_items.rb
|
336
|
+
- spec/factories/cats/core/hrp_rations.rb
|
327
337
|
- spec/factories/cats/core/hrps.rb
|
328
338
|
- spec/factories/cats/core/locations.rb
|
329
339
|
- spec/factories/cats/core/menu_items.rb
|
@@ -332,6 +342,7 @@ files:
|
|
332
342
|
- spec/factories/cats/core/operators.rb
|
333
343
|
- spec/factories/cats/core/programs.rb
|
334
344
|
- spec/factories/cats/core/purchase_orders.rb
|
345
|
+
- spec/factories/cats/core/ration_items.rb
|
335
346
|
- spec/factories/cats/core/rations.rb
|
336
347
|
- spec/factories/cats/core/receipt_transactions.rb
|
337
348
|
- spec/factories/cats/core/receipts.rb
|