cats_core 1.0.11 → 1.0.15
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/roles_controller.rb +1 -1
- data/app/models/cats/core/commodity.rb +1 -0
- data/app/models/cats/core/commodity_allocation.rb +19 -0
- data/app/models/cats/core/dispatch.rb +14 -0
- data/app/models/cats/core/dispatch_transaction.rb +8 -0
- data/app/models/cats/core/gift_certificate.rb +11 -0
- data/app/models/cats/core/notification.rb +1 -1
- data/app/models/cats/core/receipt.rb +19 -0
- data/app/models/cats/core/receipt_transaction.rb +8 -0
- data/app/models/cats/core/stack.rb +2 -2
- data/app/models/cats/core/stack_transaction.rb +8 -0
- data/app/models/cats/core/store.rb +26 -2
- data/app/models/cats/core/transaction.rb +32 -0
- data/app/models/cats/core/user.rb +13 -1
- data/app/services/cats/core/notification_service.rb +3 -6
- data/config/routes.rb +1 -1
- data/db/migrate/20210715114910_create_cats_core_users.rb +1 -0
- data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +27 -0
- data/db/migrate/20210717033223_create_cats_core_commodities.rb +1 -0
- data/db/migrate/20210717140855_create_cats_core_stores.rb +4 -3
- data/db/migrate/20210718042823_create_cats_core_commodity_allocations.rb +23 -0
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +27 -0
- data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +19 -0
- data/db/migrate/20210727074646_create_cats_core_receipts.rb +20 -0
- data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +19 -0
- data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +19 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/commodities.rb +5 -4
- data/spec/factories/cats/core/commodity_allocations.rb +10 -0
- data/spec/factories/cats/core/dispatch_transactions.rb +9 -0
- data/spec/factories/cats/core/dispatches.rb +13 -0
- data/spec/factories/cats/core/gift_certificates.rb +17 -0
- data/spec/factories/cats/core/receipt_transactions.rb +9 -0
- data/spec/factories/cats/core/receipts.rb +10 -0
- data/spec/factories/cats/core/stack_transactions.rb +9 -0
- data/spec/factories/cats/core/stores.rb +2 -2
- data/spec/factories/cats/core/users.rb +1 -0
- metadata +24 -14
- data/app/models/cats/core/commodity_transaction.rb +0 -55
- data/app/models/cats/core/receipt_plan.rb +0 -24
- data/app/models/cats/core/way_bill.rb +0 -12
- data/app/models/cats/core/way_bill_item.rb +0 -15
- data/db/migrate/20210718045516_create_cats_core_way_bills.rb +0 -25
- data/db/migrate/20210718050751_create_cats_core_way_bill_items.rb +0 -18
- data/db/migrate/20210718202957_create_cats_core_commodity_transactions.rb +0 -14
- data/db/migrate/20210727074646_create_cats_core_receipt_plans.rb +0 -16
- data/spec/factories/cats/core/commodity_transactions.rb +0 -10
- data/spec/factories/cats/core/receipt_plans.rb +0 -9
- data/spec/factories/cats/core/way_bill_items.rb +0 -8
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83b352120340d746a9cdd10bb03f065b560d88ec99857b3e4f297c959918b0ac
|
4
|
+
data.tar.gz: 9433d430ece366eaae1a8ccae7ea5b3f2121f1675e96ab7540cb8a48e32a49f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8019ad075a42c451fb67f96e668a2522ad2d70a37e1359d3d373b939f1f54a81645a411eac0fff361a9815334db2ab6fc659279201239d4e7e1ef9fdddf29898
|
7
|
+
data.tar.gz: c066e25b734a56afe9a7c9558204dcd8b42107ab7e858c74275211ad46439aaee7829f48a2d4941a1f62eaf9f51763b804107c8d40344ab7a92d7433b35edf94
|
@@ -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
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
belongs_to :recipient, polymorphic: true
|
7
7
|
|
8
8
|
def message
|
9
|
-
{ id: id, read: !read_at.nil
|
9
|
+
{ id: id, read: !read_at.nil?, created_at: created_at }.merge(to_notification.message)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.messages(notifications)
|
@@ -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
|
@@ -9,8 +9,8 @@ module Cats
|
|
9
9
|
|
10
10
|
belongs_to :commodity
|
11
11
|
belongs_to :store
|
12
|
-
has_many :
|
13
|
-
has_many :
|
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
|
@@ -2,10 +2,10 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class Store < ApplicationRecord
|
4
4
|
belongs_to :warehouse, class_name: 'Cats::Core::Location'
|
5
|
+
belongs_to :store_keeper, class_name: 'Cats::Core::User'
|
5
6
|
has_many :stacks
|
6
|
-
has_many :receipt_plans, as: :receivable
|
7
7
|
|
8
|
-
validates :name, :
|
8
|
+
validates :name, :length, :width, :height, presence: true
|
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,
|
@@ -15,11 +15,35 @@ module Cats
|
|
15
15
|
allow_nil: true
|
16
16
|
validate :validate_location
|
17
17
|
|
18
|
+
after_save :update_store_keeper
|
19
|
+
|
18
20
|
def validate_location
|
19
21
|
return if warehouse.nil?
|
20
22
|
|
21
23
|
errors.add(:warehouse, 'must be a valid warehouse') unless warehouse.location_type == Location::WAREHOUSE
|
22
24
|
end
|
25
|
+
|
26
|
+
def store_keeper_name
|
27
|
+
"#{store_keeper.first_name} #{store_keeper.last_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_store_keeper
|
31
|
+
return unless store_keeper_id_previously_changed?
|
32
|
+
|
33
|
+
unless id_previously_changed?
|
34
|
+
old_storekeeper = Cats::Core::User.find(store_keeper_id_previously_was)
|
35
|
+
old_storekeeper.details['stores'].delete(id)
|
36
|
+
old_storekeeper.save
|
37
|
+
end
|
38
|
+
if store_keeper.details.key?('stores')
|
39
|
+
store_keeper.details['stores'] << id
|
40
|
+
else
|
41
|
+
store_keeper.details['stores'] = [id]
|
42
|
+
end
|
43
|
+
store_keeper.save
|
44
|
+
end
|
45
|
+
|
46
|
+
delegate(:phone_number, to: :store_keeper, prefix: true)
|
23
47
|
end
|
24
48
|
end
|
25
49
|
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
|
@@ -8,9 +8,11 @@ module Cats
|
|
8
8
|
has_and_belongs_to_many :roles, join_table: :cats_core_users_cats_core_roles
|
9
9
|
has_many :notifications, as: :recipient
|
10
10
|
|
11
|
+
validates :password, length: { minimum: 6 }, if: proc { |u| u.password.present? }, on: :update
|
11
12
|
validates :first_name, :last_name, :email, presence: true
|
12
|
-
validates :password, length: { minimum: 6 }
|
13
|
+
validates :password, presence: true, length: { minimum: 6 }, on: :create
|
13
14
|
validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
15
|
+
validate :validate_phone_number
|
14
16
|
|
15
17
|
def warehouses
|
16
18
|
return unless details.key?('warehouses')
|
@@ -23,6 +25,16 @@ module Cats
|
|
23
25
|
|
24
26
|
Cats::Core::Store.where(id: details['stores'])
|
25
27
|
end
|
28
|
+
|
29
|
+
def validate_phone_number
|
30
|
+
return unless phone_number.present?
|
31
|
+
|
32
|
+
return if phone_number.length == 10 && /0\d{9}/.match(phone_number)
|
33
|
+
|
34
|
+
return if phone_number.length == 12 && /251\d{9}/.match(phone_number)
|
35
|
+
|
36
|
+
errors.add(:phone_number, 'must be 10 or 12 digits and should match with local phone pattern')
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
@@ -16,22 +16,19 @@ module Cats
|
|
16
16
|
}
|
17
17
|
}.freeze
|
18
18
|
|
19
|
-
def initialize(code, params)
|
19
|
+
def initialize(rules, code, params)
|
20
|
+
@rules = rules
|
20
21
|
@code = code
|
21
22
|
@params = params
|
22
23
|
end
|
23
24
|
|
24
|
-
def notification_rules
|
25
|
-
NOTIFICATION_RULES
|
26
|
-
end
|
27
|
-
|
28
25
|
def create_notifier(rule)
|
29
26
|
clazz = rule[:notification].constantize
|
30
27
|
clazz.with(**@params)
|
31
28
|
end
|
32
29
|
|
33
30
|
def notify
|
34
|
-
rule =
|
31
|
+
rule = @rules[@code]
|
35
32
|
notifier = create_notifier(rule)
|
36
33
|
app_code = rule[:application]
|
37
34
|
roles = rule[:recipients]
|
data/config/routes.rb
CHANGED
@@ -7,6 +7,7 @@ class CreateCatsCoreUsers < ActiveRecord::Migration[6.1]
|
|
7
7
|
t.boolean :active, null: false, default: true
|
8
8
|
t.string :password_digest
|
9
9
|
t.jsonb :details
|
10
|
+
t.string :phone_number
|
10
11
|
t.references :application_module,
|
11
12
|
null: false,
|
12
13
|
index: { name: 'am_on_users_indx' },
|
@@ -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
|
@@ -2,8 +2,6 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
|
|
2
2
|
def change
|
3
3
|
create_table :cats_core_stores do |t|
|
4
4
|
t.string :name, null: false
|
5
|
-
t.string :store_keeper_name, null: false
|
6
|
-
t.string :store_keeper_phone
|
7
5
|
t.float :length, null: false
|
8
6
|
t.float :width, null: false
|
9
7
|
t.float :height, null: false
|
@@ -16,7 +14,10 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
|
|
16
14
|
null: false,
|
17
15
|
index: { name: 'warehouse_on_stores_indx' },
|
18
16
|
foreign_key: { to_table: :cats_core_locations }
|
19
|
-
|
17
|
+
t.references :store_keeper,
|
18
|
+
null: false,
|
19
|
+
index: { name: 'store_keeper_on_store_indx' },
|
20
|
+
foreign_key: { to_table: :cats_core_users }
|
20
21
|
t.timestamps
|
21
22
|
end
|
22
23
|
end
|
@@ -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
|
data/lib/cats/core/version.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :commodity, class: 'Cats::Core::Commodity' do
|
3
|
-
|
3
|
+
commodity_category
|
4
4
|
description { FFaker::Name.name }
|
5
|
-
|
6
|
-
|
7
|
-
|
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,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,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
|
@@ -1,8 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :store, class: 'Cats::Core::Store' do
|
3
3
|
name { FFaker::Name.name }
|
4
|
-
store_keeper_name { FFaker::Name.name }
|
5
|
-
store_keeper_phone { FFaker::Name.name }
|
6
4
|
length { 50 }
|
7
5
|
width { 40 }
|
8
6
|
height { 10 }
|
@@ -12,5 +10,7 @@ FactoryBot.define do
|
|
12
10
|
gangway_width { 4 }
|
13
11
|
gangway_corner_dist { 18 }
|
14
12
|
warehouse
|
13
|
+
store_keeper factory: :user
|
14
|
+
store_keeper_id { create(:user).id }
|
15
15
|
end
|
16
16
|
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.
|
4
|
+
version: 1.0.15
|
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-
|
11
|
+
date: 2021-08-16 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/
|
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/
|
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/
|
270
|
-
- db/migrate/
|
271
|
-
- db/migrate/
|
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/
|
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/
|
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/
|
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,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
|