cats_core 1.0.13 → 1.0.14

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/cats/core/commodity.rb +1 -0
  3. data/app/models/cats/core/commodity_allocation.rb +19 -0
  4. data/app/models/cats/core/dispatch.rb +14 -0
  5. data/app/models/cats/core/dispatch_transaction.rb +8 -0
  6. data/app/models/cats/core/gift_certificate.rb +11 -0
  7. data/app/models/cats/core/receipt.rb +19 -0
  8. data/app/models/cats/core/receipt_transaction.rb +8 -0
  9. data/app/models/cats/core/stack.rb +2 -2
  10. data/app/models/cats/core/stack_transaction.rb +8 -0
  11. data/app/models/cats/core/transaction.rb +32 -0
  12. data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +27 -0
  13. data/db/migrate/20210717033223_create_cats_core_commodities.rb +1 -0
  14. data/db/migrate/20210718042823_create_cats_core_commodity_allocations.rb +23 -0
  15. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +27 -0
  16. data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +19 -0
  17. data/db/migrate/20210727074646_create_cats_core_receipts.rb +20 -0
  18. data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +19 -0
  19. data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +19 -0
  20. data/lib/cats/core/version.rb +1 -1
  21. data/spec/factories/cats/core/commodities.rb +5 -4
  22. data/spec/factories/cats/core/commodity_allocations.rb +10 -0
  23. data/spec/factories/cats/core/dispatch_transactions.rb +9 -0
  24. data/spec/factories/cats/core/dispatches.rb +13 -0
  25. data/spec/factories/cats/core/gift_certificates.rb +17 -0
  26. data/spec/factories/cats/core/receipt_transactions.rb +9 -0
  27. data/spec/factories/cats/core/receipts.rb +10 -0
  28. data/spec/factories/cats/core/stack_transactions.rb +9 -0
  29. metadata +24 -14
  30. data/app/models/cats/core/commodity_transaction.rb +0 -55
  31. data/app/models/cats/core/receipt_plan.rb +0 -24
  32. data/app/models/cats/core/way_bill.rb +0 -12
  33. data/app/models/cats/core/way_bill_item.rb +0 -15
  34. data/db/migrate/20210718045516_create_cats_core_way_bills.rb +0 -25
  35. data/db/migrate/20210718050751_create_cats_core_way_bill_items.rb +0 -18
  36. data/db/migrate/20210718202957_create_cats_core_commodity_transactions.rb +0 -14
  37. data/db/migrate/20210727074646_create_cats_core_receipt_plans.rb +0 -16
  38. data/spec/factories/cats/core/commodity_transactions.rb +0 -10
  39. data/spec/factories/cats/core/receipt_plans.rb +0 -9
  40. data/spec/factories/cats/core/way_bill_items.rb +0 -8
  41. data/spec/factories/cats/core/way_bills.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c166b58630fc770c2447694d5d57f59edd26ab7bee0caf07f762fc16d21f4069
4
- data.tar.gz: 7cc6aead85c41426225eb4d306e92cf85ac7024b4690324a62985b7c6b163756
3
+ metadata.gz: 4811ffba4bc939ced12590d2166bf82fdb9b7de3bc273994c46c5a122bf878fa
4
+ data.tar.gz: 361b0230470cfd0145009394d7f1c3e78bb15054aa2b5cc6dbc2ec9e04e0174d
5
5
  SHA512:
6
- metadata.gz: 8a6c48372747e4c159c7fae9d51af746740fe7d556fc9b0cee36d9ba814ccd33aa25be298681729ad474b63c7c30881b79dcdb5da2a2da47d9962f6b3df325a2
7
- data.tar.gz: 30805a86c89f24e1472a177c7cedf1c18a5ccbc18756bf316eca62138d63247a05ee42c18004b06a1ce898ac4343341045eff7f59921d16ea70a22ac2c33d4d9
6
+ metadata.gz: 54f3f4bdcb66b057e1d46d1f4df1ee9ef51be56b24d574bbe79be0c718a4e846778e4f0e66a7400e8cc25d5040d8487977ec837046fc373d02d2777cd05e0f04
7
+ data.tar.gz: 26da239fa55604b7d1090e8a5fd0b6d5b2eb3945491c73b225e25ca98f543eb3dcbceab88ac1c0a298a2676e3402136ddad517a302c08e421dbd44c7fee7db25
@@ -10,6 +10,7 @@ module Cats
10
10
  belongs_to :donor
11
11
  belongs_to :program
12
12
  belongs_to :unit_of_measure
13
+ belongs_to :source, polymorphic: true
13
14
 
14
15
  validates :quantity, presence: true, numericality: { greater_than: 0 }
15
16
  validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityAllocation < ApplicationRecord
4
+ belongs_to :commodity
5
+ belongs_to :source, class_name: 'Cats::Core::Location'
6
+ belongs_to :destination, class_name: 'Cats::Core::Location'
7
+
8
+ validates :quantity, :commodity_status, presence: true
9
+ validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
10
+ validate :validate_source_and_destination
11
+
12
+ def validate_source_and_destination
13
+ return unless source.present? && destination.present?
14
+
15
+ errors.add(:base, 'source and destination cannot be the same') if source == destination
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Cats
2
+ module Core
3
+ class Dispatch < ApplicationRecord
4
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
5
+ belongs_to :transporter
6
+ belongs_to :commodity_allocation
7
+
8
+ validates :reference_no, :plate_no, :driver_name, :driver_phone, :quantity, :commodity_status, presence: true
9
+ validates :reference_no, uniqueness: true
10
+ validates :quantity, numericality: { greater_than: 0 }
11
+ validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchTransaction < Transaction
4
+ belongs_to :source, class_name: 'Cats::Core::Stack'
5
+ belongs_to :destination, class_name: 'Cats::Core::Dispatch'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class GiftCertificate < ApplicationRecord
4
+ belongs_to :program
5
+ belongs_to :donor
6
+
7
+ validates :reference_no, presence: true, uniqueness: true
8
+ validates :gift_date, presence: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class Receipt < ApplicationRecord
4
+ # Receipt status
5
+ DRAFT = 'Draft'.freeze
6
+ ACCEPTED = 'Accepted'.freeze
7
+ DECLINED = 'Declined'.freeze
8
+ RECEIPT_STATUSES = [DRAFT, ACCEPTED, DECLINED].freeze
9
+
10
+ belongs_to :dispatch
11
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
12
+
13
+ validates :quantity, :commodity_status, :status, presence: true
14
+ validates :quantity, numericality: { greater_than: 0 }
15
+ validates :status, inclusion: { in: RECEIPT_STATUSES }
16
+ validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class ReceiptTransaction < Transaction
4
+ belongs_to :source, class_name: 'Cats::Core::Receipt'
5
+ belongs_to :destination, class_name: 'Cats::Core::Stack'
6
+ end
7
+ end
8
+ end
@@ -9,8 +9,8 @@ module Cats
9
9
 
10
10
  belongs_to :commodity
11
11
  belongs_to :store
12
- has_many :source_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :source
13
- has_many :destination_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :destination
12
+ has_many :dispatch_transactions, foreign_key: :source_id
13
+ has_many :receipt_transactions, foreign_key: :destination_id
14
14
 
15
15
  validates :code, :length, :width, :height, :start_x, :start_y, :commodity_status, :stack_status,
16
16
  :quantity, presence: true
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class StackTransaction < Transaction
4
+ belongs_to :source, class_name: 'Cats::Core::Stack'
5
+ belongs_to :destination, class_name: 'Cats::Core::Stack'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ module Cats
2
+ module Core
3
+ class Transaction < ApplicationRecord
4
+ self.abstract_class = true
5
+
6
+ # Transaction statuses
7
+ DRAFT = 'Draft'.freeze
8
+ COMMITTED = 'Committed'.freeze
9
+ STATUSES = [DRAFT, COMMITTED].freeze
10
+
11
+ validates :transaction_date, :quantity, :status, presence: true
12
+ validates :quantity, numericality: { greater_than: 0 }
13
+ validates :status, inclusion: { in: STATUSES }
14
+ validate :validate_quantity
15
+
16
+ def validate_quantity
17
+ return unless quantity.present? && source.present?
18
+
19
+ errors.add(:quantity, 'cannot be more than source quantity') if quantity > source.quantity
20
+ end
21
+
22
+ def commit
23
+ Transaction.transaction do
24
+ source.quantity -= quantity
25
+ destination.quantity += quantity
26
+ source.save
27
+ destination.save
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_gift_certificates do |t|
4
+ t.string :reference_no, unique: true
5
+ t.date :gift_date, null: false
6
+ t.references :program,
7
+ null: false,
8
+ index: { name: 'gc_on_program_indx' },
9
+ foreign_key: { to_table: :cats_core_programs }
10
+ t.references :donor,
11
+ null: false,
12
+ index: { name: 'gc_on_donor_indx' },
13
+ foreign_key: { to_table: :cats_core_donors }
14
+ t.string :vessel
15
+ t.string :port
16
+ t.string :customs_declaration_no
17
+ t.integer :purchase_year
18
+ t.date :expiry_date
19
+ t.string :bill_of_lading_no
20
+ t.float :amount, null: false
21
+ t.float :estimated_price
22
+ t.float :estimated_tax
23
+
24
+ t.timestamps
25
+ end
26
+ end
27
+ end
@@ -17,6 +17,7 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
17
17
  null: false,
18
18
  index: { name: 'uom_on_commodities_indx' },
19
19
  foreign_key: { to_table: :cats_core_unit_of_measures }
20
+ t.references :source, polymorphic: true
20
21
  t.float :quantity, null: false
21
22
  t.string :description
22
23
  t.boolean :hazardous, null: false, default: false
@@ -0,0 +1,23 @@
1
+ class CreateCatsCoreCommodityAllocations < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_commodity_allocations do |t|
4
+ t.references :commodity,
5
+ null: false,
6
+ index: { name: 'ca_on_commodity_indx' },
7
+ foreign_key: { to_table: :cats_core_commodities }
8
+ t.references :source,
9
+ null: false,
10
+ index: { name: 'ca_on_source_indx' },
11
+ foreign_key: { to_table: :cats_core_locations }
12
+ t.references :destination,
13
+ null: false,
14
+ index: { name: 'ca_on_destination_indx' },
15
+ foreign_key: { to_table: :cats_core_locations }
16
+ t.float :quantity, null: false
17
+ t.string :commodity_status, null: false, default: 'Good'
18
+ t.string :remark
19
+
20
+ t.timestamps
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ class CreateCatsCoreDispatches < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_dispatches do |t|
4
+ t.string :reference_no, unique: true
5
+ t.references :commodity_allocation,
6
+ null: false,
7
+ index: { name: 'ca_on_dispatches_indx' },
8
+ foreign_key: { to_table: :cats_core_commodity_allocations }
9
+ t.references :transporter,
10
+ null: false,
11
+ index: { name: 'transporter_on_dispatches_indx' },
12
+ foreign_key: { to_table: :cats_core_transporters }
13
+ t.string :plate_no, null: false
14
+ t.string :driver_name, null: false
15
+ t.string :driver_phone, null: false
16
+ t.float :quantity, null: false
17
+ t.string :commodity_status, null: false, default: 'Good'
18
+ t.string :remark
19
+ t.references :prepared_by,
20
+ null: false,
21
+ index: { name: 'pb_on_dispatches_indx' },
22
+ foreign_key: { to_table: :cats_core_users }
23
+
24
+ t.timestamps
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreDispatchTransactions < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_dispatch_transactions do |t|
4
+ t.references :source,
5
+ null: false,
6
+ index: { name: 'stack_on_dt_indx' },
7
+ foreign_key: { to_table: :cats_core_stacks }
8
+ t.references :destination,
9
+ null: false,
10
+ index: { name: 'dispatch_on_dt_indx' },
11
+ foreign_key: { to_table: :cats_core_dispatches }
12
+ t.date :transaction_date, null: false
13
+ t.float :quantity, null: false
14
+ t.string :status, null: false, default: 'Draft'
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ class CreateCatsCoreReceipts < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_receipts do |t|
4
+ t.references :dispatch,
5
+ null: false,
6
+ index: { name: 'dispatch_on_receipts_indx' },
7
+ foreign_key: { to_table: :cats_core_dispatches }
8
+ t.float :quantity, null: false
9
+ t.string :commodity_status, null: false, default: 'Good'
10
+ t.string :status, null: false, default: 'Draft'
11
+ t.string :remark
12
+ t.references :prepared_by,
13
+ null: false,
14
+ index: { name: 'pb_on_receipts_indx' },
15
+ foreign_key: { to_table: :cats_core_users }
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreReceiptTransactions < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_receipt_transactions do |t|
4
+ t.references :source,
5
+ null: false,
6
+ index: { name: 'receipt_on_rt_indx' },
7
+ foreign_key: { to_table: :cats_core_receipts }
8
+ t.references :destination,
9
+ null: false,
10
+ index: { name: 'stack_on_rt_indx' },
11
+ foreign_key: { to_table: :cats_core_stacks }
12
+ t.date :transaction_date, null: false
13
+ t.float :quantity, null: false
14
+ t.string :status, null: false, default: 'Draft'
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreStackTransactions < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_stack_transactions do |t|
4
+ t.references :source,
5
+ null: false,
6
+ index: { name: 'source_on_st_indx' },
7
+ foreign_key: { to_table: :cats_core_stacks }
8
+ t.references :destination,
9
+ null: false,
10
+ index: { name: 'destination_on_st_indx' },
11
+ foreign_key: { to_table: :cats_core_stacks }
12
+ t.date :transaction_date, null: false
13
+ t.float :quantity, null: false
14
+ t.string :status, null: false, default: 'Draft'
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.13'.freeze
3
+ VERSION = '1.0.14'.freeze
4
4
  end
5
5
  end
@@ -1,10 +1,11 @@
1
1
  FactoryBot.define do
2
2
  factory :commodity, class: 'Cats::Core::Commodity' do
3
- association :commodity_category
3
+ commodity_category
4
4
  description { FFaker::Name.name }
5
- association :donor
6
- association :program
7
- association :unit_of_measure
5
+ donor
6
+ program
7
+ unit_of_measure
8
+ source factory: :gift_certificate
8
9
  quantity { 100 }
9
10
  hazardous { false }
10
11
  best_use_before { Date.today + 2.month }
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :commodity_allocation, class: 'Cats::Core::CommodityAllocation' do
3
+ commodity
4
+ source factory: :location
5
+ destination factory: :location
6
+ quantity { 50 }
7
+ commodity_status { Cats::Core::Commodity::GOOD }
8
+ remark { FFaker::Name.name }
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :dispatch_transaction, class: 'Cats::Core::DispatchTransaction' do
3
+ source factory: :stack
4
+ destination factory: :dispatch
5
+ transaction_date { Date.today }
6
+ quantity { 10 }
7
+ status { Cats::Core::Transaction::DRAFT }
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :dispatch, class: 'Cats::Core::Dispatch' do
3
+ reference_no { FFaker::Name.name }
4
+ commodity_allocation
5
+ transporter
6
+ plate_no { FFaker::Name.name }
7
+ driver_name { FFaker::Name.name }
8
+ driver_phone { FFaker::Name.name }
9
+ quantity { 50 }
10
+ remark { FFaker::Name.name }
11
+ prepared_by factory: :user
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ FactoryBot.define do
2
+ factory :gift_certificate, class: 'Cats::Core::GiftCertificate' do
3
+ reference_no { FFaker::Name.name }
4
+ gift_date { Date.today - 1.month }
5
+ program
6
+ donor
7
+ vessel { FFaker::Name.name }
8
+ port { FFaker::Name.name }
9
+ customs_declaration_no { FFaker::Name.name }
10
+ purchase_year { 1 }
11
+ expiry_date { Date.today + 6.month }
12
+ bill_of_lading_no { FFaker::Name.name }
13
+ amount { 1.5 }
14
+ estimated_price { 1.5 }
15
+ estimated_tax { 1.5 }
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :receipt_transaction do
3
+ source factory: :receipt
4
+ destination factory: :stack
5
+ transaction_date { Date.today }
6
+ quantity { 10 }
7
+ status { Cats::Core::Transaction::DRAFT }
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :receipt, class: 'Cats::Core::Receipt' do
3
+ dispatch
4
+ quantity { 1.5 }
5
+ commodity_status { Cats::Core::Commodity::GOOD }
6
+ status { Cats::Core::Receipt::DRAFT }
7
+ remark { FFaker::Name.name }
8
+ prepared_by factory: :user
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :stack_transaction, class: 'Cats::Core::StackTransaction' do
3
+ source factory: :stack
4
+ destination factory: :stack
5
+ transaction_date { Date.today }
6
+ quantity { 25 }
7
+ status { Cats::Core::Transaction::DRAFT }
8
+ end
9
+ end
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.13
4
+ version: 1.0.14
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-08-09 00:00:00.000000000 Z
11
+ date: 2021-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -226,25 +226,29 @@ files:
226
226
  - app/models/cats/core/application_module.rb
227
227
  - app/models/cats/core/application_record.rb
228
228
  - app/models/cats/core/commodity.rb
229
+ - app/models/cats/core/commodity_allocation.rb
229
230
  - app/models/cats/core/commodity_category.rb
230
- - app/models/cats/core/commodity_transaction.rb
231
+ - app/models/cats/core/dispatch.rb
232
+ - app/models/cats/core/dispatch_transaction.rb
231
233
  - app/models/cats/core/donor.rb
234
+ - app/models/cats/core/gift_certificate.rb
232
235
  - app/models/cats/core/location.rb
233
236
  - app/models/cats/core/menu.rb
234
237
  - app/models/cats/core/menu_item.rb
235
238
  - app/models/cats/core/notification.rb
236
239
  - app/models/cats/core/program.rb
237
- - app/models/cats/core/receipt_plan.rb
240
+ - app/models/cats/core/receipt.rb
241
+ - app/models/cats/core/receipt_transaction.rb
238
242
  - app/models/cats/core/role.rb
239
243
  - app/models/cats/core/role_menu.rb
240
244
  - app/models/cats/core/stack.rb
245
+ - app/models/cats/core/stack_transaction.rb
241
246
  - app/models/cats/core/stacking_rule.rb
242
247
  - app/models/cats/core/store.rb
248
+ - app/models/cats/core/transaction.rb
243
249
  - app/models/cats/core/transporter.rb
244
250
  - app/models/cats/core/unit_of_measure.rb
245
251
  - app/models/cats/core/user.rb
246
- - app/models/cats/core/way_bill.rb
247
- - app/models/cats/core/way_bill_item.rb
248
252
  - app/notifications/cats/core/simple_notification.rb
249
253
  - app/serializers/cats/core/role_menu_serializer.rb
250
254
  - app/services/cats/core/menu_service.rb
@@ -261,17 +265,20 @@ files:
261
265
  - db/migrate/20210716145125_create_cats_core_unit_of_measures.rb
262
266
  - db/migrate/20210716151230_create_cats_core_programs.rb
263
267
  - db/migrate/20210717031108_create_cats_core_donors.rb
268
+ - db/migrate/20210717032602_create_cats_core_gift_certificates.rb
264
269
  - db/migrate/20210717033223_create_cats_core_commodities.rb
265
270
  - db/migrate/20210717043620_create_cats_core_locations.rb
266
271
  - db/migrate/20210717140855_create_cats_core_stores.rb
267
272
  - db/migrate/20210717171101_create_cats_core_stacks.rb
268
273
  - db/migrate/20210718042749_create_cats_core_transporters.rb
269
- - db/migrate/20210718045516_create_cats_core_way_bills.rb
270
- - db/migrate/20210718050751_create_cats_core_way_bill_items.rb
271
- - db/migrate/20210718202957_create_cats_core_commodity_transactions.rb
274
+ - db/migrate/20210718042823_create_cats_core_commodity_allocations.rb
275
+ - db/migrate/20210718045516_create_cats_core_dispatches.rb
276
+ - db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb
272
277
  - db/migrate/20210719133710_create_cats_core_stacking_rules.rb
273
278
  - db/migrate/20210724074657_create_cats_core_notifications.rb
274
- - db/migrate/20210727074646_create_cats_core_receipt_plans.rb
279
+ - db/migrate/20210727074646_create_cats_core_receipts.rb
280
+ - db/migrate/20210814160628_create_cats_core_receipt_transactions.rb
281
+ - db/migrate/20210814175406_create_cats_core_stack_transactions.rb
275
282
  - lib/cats/core.rb
276
283
  - lib/cats/core/engine.rb
277
284
  - lib/cats/core/version.rb
@@ -279,25 +286,28 @@ files:
279
286
  - lib/tasks/cats_core_tasks.rake
280
287
  - spec/factories/cats/core/application_modules.rb
281
288
  - spec/factories/cats/core/commodities.rb
289
+ - spec/factories/cats/core/commodity_allocations.rb
282
290
  - spec/factories/cats/core/commodity_categories.rb
283
- - spec/factories/cats/core/commodity_transactions.rb
291
+ - spec/factories/cats/core/dispatch_transactions.rb
292
+ - spec/factories/cats/core/dispatches.rb
284
293
  - spec/factories/cats/core/donors.rb
294
+ - spec/factories/cats/core/gift_certificates.rb
285
295
  - spec/factories/cats/core/locations.rb
286
296
  - spec/factories/cats/core/menu_items.rb
287
297
  - spec/factories/cats/core/menus.rb
288
298
  - spec/factories/cats/core/notifications.rb
289
299
  - spec/factories/cats/core/programs.rb
290
- - spec/factories/cats/core/receipt_plans.rb
300
+ - spec/factories/cats/core/receipt_transactions.rb
301
+ - spec/factories/cats/core/receipts.rb
291
302
  - spec/factories/cats/core/role_menus.rb
292
303
  - spec/factories/cats/core/roles.rb
304
+ - spec/factories/cats/core/stack_transactions.rb
293
305
  - spec/factories/cats/core/stacking_rules.rb
294
306
  - spec/factories/cats/core/stacks.rb
295
307
  - spec/factories/cats/core/stores.rb
296
308
  - spec/factories/cats/core/transporters.rb
297
309
  - spec/factories/cats/core/unit_of_measures.rb
298
310
  - spec/factories/cats/core/users.rb
299
- - spec/factories/cats/core/way_bill_items.rb
300
- - spec/factories/cats/core/way_bills.rb
301
311
  homepage: http://cats.ndrmcapps.org
302
312
  licenses:
303
313
  - MIT
@@ -1,55 +0,0 @@
1
- module Cats
2
- module Core
3
- class CommodityTransaction < ApplicationRecord
4
- # Transaction statuses
5
- DRAFT = 'Draft'.freeze
6
- COMMITTED = 'Committed'.freeze
7
- STATUSES = [DRAFT, COMMITTED].freeze
8
-
9
- # Transaction types
10
- STACK_TO_STACK = 'Stack to Stack'.freeze
11
- STACK_TO_WAY_BILL = 'Stack to Way Bill'.freeze
12
- WAY_BILL_TO_STACK = 'Way Bill to Stack'.freeze
13
- TRANSACTION_TYPES = [STACK_TO_STACK, STACK_TO_WAY_BILL, WAY_BILL_TO_STACK].freeze
14
-
15
- belongs_to :source, polymorphic: true
16
- belongs_to :destination, polymorphic: true
17
-
18
- validates :transaction_date, :quantity, :status, presence: true
19
- validates :quantity, numericality: { greater_than: 0 }
20
- validates :status, inclusion: { in: STATUSES }
21
- validate :validate_quantity
22
-
23
- before_validation :set_transaction_type
24
-
25
- def validate_quantity
26
- return unless quantity.present? && source.present?
27
-
28
- errors.add(:quantity, 'cannot be more than source quantity') if quantity > source.quantity
29
- end
30
-
31
- def commit
32
- CommodityTransaction.transaction do
33
- source.quantity -= quantity
34
- destination.quantity += quantity
35
- source.save
36
- destination.save
37
- end
38
- end
39
-
40
- private
41
-
42
- def set_transaction_type
43
- return unless transaction_type.nil? && source.present? && destination.present?
44
-
45
- if source.instance_of?(Cats::Core::Stack) && destination.instance_of?(Cats::Core::Stack)
46
- self.transaction_type = STACK_TO_STACK
47
- elsif source.instance_of?(Cats::Core::Stack) && destination.instance_of?(Cats::Core::WayBillItem)
48
- self.transaction_type = STACK_TO_WAY_BILL
49
- else
50
- self.transaction_type = WAY_BILL_TO_STACK
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,24 +0,0 @@
1
- module Cats
2
- module Core
3
- class ReceiptPlan < ApplicationRecord
4
- # receipt plan status
5
- DRAFT = 'Draft'.freeze
6
- ACCEPTED = 'Accepted'.freeze
7
- DECLINED = 'Declined'.freeze
8
- RECEIPT_PLAN_STATUSES = [DRAFT, ACCEPTED, DECLINED].freeze
9
-
10
- validates :quantity, :status, presence: true
11
- belongs_to :commodity
12
- belongs_to :plan_recipient, polymorphic: true
13
- validates :quantity, numericality: { greater_than: 0 }
14
- validates :status, inclusion: { in: RECEIPT_PLAN_STATUSES }
15
- validate :validate_reason_for_decline
16
-
17
- def validate_reason_for_decline
18
- return unless reason_for_decline.nil? || reason_for_decline == 'Accepted'
19
-
20
- errors.add(:reason_for_decline, 'must be specified')
21
- end
22
- end
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- module Cats
2
- module Core
3
- class WayBill < ApplicationRecord
4
- belongs_to :source, class_name: 'Cats::Core::Location'
5
- belongs_to :destination, class_name: 'Cats::Core::Location'
6
- belongs_to :transporter
7
-
8
- validates :ref_no, :plate_no, :driver_name, :driver_phone, :date_prepared, presence: true
9
- validates :ref_no, uniqueness: true
10
- end
11
- end
12
- end
@@ -1,15 +0,0 @@
1
- module Cats
2
- module Core
3
- class WayBillItem < ApplicationRecord
4
- belongs_to :way_bill
5
- belongs_to :commodity
6
-
7
- has_many :source_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :source
8
- has_many :destination_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :destination
9
-
10
- validates :quantity, :commodity_status, presence: true
11
- validates :quantity, numericality: { greater_than: 0 }
12
- validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
13
- end
14
- end
15
- end
@@ -1,25 +0,0 @@
1
- class CreateCatsCoreWayBills < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_way_bills do |t|
4
- t.string :ref_no, unique: true
5
- t.references :source,
6
- null: false,
7
- index: { name: 'source_on_wb_indx' },
8
- foreign_key: { to_table: :cats_core_locations }
9
- t.references :destination,
10
- null: false,
11
- index: { name: 'destination_on_wb_indx' },
12
- foreign_key: { to_table: :cats_core_locations }
13
- t.references :transporter,
14
- null: false,
15
- index: { name: 'transporter_on_wb_indx' },
16
- foreign_key: { to_table: :cats_core_transporters }
17
- t.string :plate_no, null: false
18
- t.string :driver_name, null: false
19
- t.string :driver_phone, null: false
20
- t.date :date_prepared, null: false
21
-
22
- t.timestamps
23
- end
24
- end
25
- end
@@ -1,18 +0,0 @@
1
- class CreateCatsCoreWayBillItems < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_way_bill_items do |t|
4
- t.references :way_bill,
5
- null: false,
6
- index: { name: 'wb_on_wbi_indx' },
7
- foreign_key: { to_table: :cats_core_way_bills }
8
- t.references :commodity,
9
- null: false,
10
- index: { name: 'commodity_on_wbi_indx' },
11
- foreign_key: { to_table: :cats_core_commodities }
12
- t.float :quantity, null: false
13
- t.string :commodity_status, null: false
14
-
15
- t.timestamps
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- class CreateCatsCoreCommodityTransactions < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_commodity_transactions do |t|
4
- t.references :source, polymorphic: true
5
- t.references :destination, polymorphic: true
6
- t.date :transaction_date, null: false
7
- t.float :quantity, null: false
8
- t.string :status, null: false, default: 'Draft'
9
- t.string :transaction_type, null: false, default: 'Stack to Stack'
10
-
11
- t.timestamps
12
- end
13
- end
14
- end
@@ -1,16 +0,0 @@
1
- class CreateCatsCoreReceiptPlans < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_receipt_plans do |t|
4
- t.float :quantity, null: false
5
- t.string :status, default: 'Draft'
6
- t.references :commodity,
7
- null: false,
8
- index: { name: 'commodity_on_receipt_plan_indx' },
9
- foreign_key: { to_table: :cats_core_commodities }
10
- t.string :reason_for_decline
11
- t.references :plan_recipient, polymorphic: true
12
-
13
- t.timestamps
14
- end
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- FactoryBot.define do
2
- factory :commodity_transaction, class: 'Cats::Core::CommodityTransaction' do
3
- source factory: :stack
4
- destination factory: :stack
5
- transaction_date { Date.today }
6
- quantity { 10 }
7
- status { Cats::Core::CommodityTransaction::DRAFT }
8
- transaction_type { Cats::Core::CommodityTransaction::STACK_TO_STACK }
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- FactoryBot.define do
2
- factory :receipt_plan, class: 'Cats::Core::ReceiptPlan' do
3
- plan_recipient factory: :store
4
- commodity
5
- quantity { 1.5 }
6
- status { 'Accepted' }
7
- reason_for_decline { FFaker::Name.name }
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :way_bill_item, class: 'Cats::Core::WayBillItem' do
3
- way_bill
4
- commodity
5
- quantity { 20 }
6
- commodity_status { Cats::Core::Commodity::GOOD }
7
- end
8
- end
@@ -1,12 +0,0 @@
1
- FactoryBot.define do
2
- factory :way_bill, class: 'Cats::Core::WayBill' do
3
- ref_no { FFaker::Name.name }
4
- source factory: :location
5
- destination factory: :location
6
- transporter
7
- plate_no { FFaker::Name.name }
8
- driver_name { FFaker::Name.name }
9
- driver_phone { FFaker::Name.name }
10
- date_prepared { Date.today }
11
- end
12
- end