cats_core 1.0.10 → 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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/menus_controller.rb +19 -0
  3. data/app/controllers/cats/core/roles_controller.rb +1 -1
  4. data/app/models/cats/core/commodity.rb +1 -0
  5. data/app/models/cats/core/commodity_allocation.rb +19 -0
  6. data/app/models/cats/core/dispatch.rb +14 -0
  7. data/app/models/cats/core/dispatch_transaction.rb +8 -0
  8. data/app/models/cats/core/gift_certificate.rb +11 -0
  9. data/app/models/cats/core/notification.rb +1 -1
  10. data/app/models/cats/core/receipt.rb +19 -0
  11. data/app/models/cats/core/receipt_transaction.rb +8 -0
  12. data/app/models/cats/core/role_menu.rb +3 -0
  13. data/app/models/cats/core/stack.rb +2 -2
  14. data/app/models/cats/core/stack_transaction.rb +8 -0
  15. data/app/models/cats/core/store.rb +8 -2
  16. data/app/models/cats/core/transaction.rb +32 -0
  17. data/app/models/cats/core/user.rb +13 -1
  18. data/app/notifications/cats/core/simple_notification.rb +15 -4
  19. data/app/serializers/cats/core/role_menu_serializer.rb +11 -0
  20. data/app/services/cats/core/menu_service.rb +9 -0
  21. data/app/services/cats/core/notification_service.rb +3 -6
  22. data/config/routes.rb +3 -2
  23. data/db/migrate/20210715114910_create_cats_core_users.rb +1 -0
  24. data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +27 -0
  25. data/db/migrate/20210717033223_create_cats_core_commodities.rb +1 -0
  26. data/db/migrate/20210717140855_create_cats_core_stores.rb +4 -3
  27. data/db/migrate/20210718042823_create_cats_core_commodity_allocations.rb +23 -0
  28. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +27 -0
  29. data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +19 -0
  30. data/db/migrate/20210727074646_create_cats_core_receipts.rb +20 -0
  31. data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +19 -0
  32. data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +19 -0
  33. data/lib/cats/core/version.rb +1 -1
  34. data/spec/factories/cats/core/commodities.rb +5 -4
  35. data/spec/factories/cats/core/commodity_allocations.rb +10 -0
  36. data/spec/factories/cats/core/dispatch_transactions.rb +9 -0
  37. data/spec/factories/cats/core/dispatches.rb +13 -0
  38. data/spec/factories/cats/core/gift_certificates.rb +17 -0
  39. data/spec/factories/cats/core/receipt_transactions.rb +9 -0
  40. data/spec/factories/cats/core/receipts.rb +10 -0
  41. data/spec/factories/cats/core/stack_transactions.rb +9 -0
  42. data/spec/factories/cats/core/stores.rb +2 -2
  43. data/spec/factories/cats/core/users.rb +1 -0
  44. metadata +27 -14
  45. data/app/models/cats/core/commodity_transaction.rb +0 -55
  46. data/app/models/cats/core/receipt_plan.rb +0 -24
  47. data/app/models/cats/core/way_bill.rb +0 -12
  48. data/app/models/cats/core/way_bill_item.rb +0 -15
  49. data/db/migrate/20210718045516_create_cats_core_way_bills.rb +0 -25
  50. data/db/migrate/20210718050751_create_cats_core_way_bill_items.rb +0 -18
  51. data/db/migrate/20210718202957_create_cats_core_commodity_transactions.rb +0 -14
  52. data/db/migrate/20210727074646_create_cats_core_receipt_plans.rb +0 -16
  53. data/spec/factories/cats/core/commodity_transactions.rb +0 -10
  54. data/spec/factories/cats/core/receipt_plans.rb +0 -9
  55. data/spec/factories/cats/core/way_bill_items.rb +0 -8
  56. 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: c511fd3cb4ee9da3373af2685f3d0afc00b5398c8e4383aaa0fe3d07ddfe5ffc
4
- data.tar.gz: dc4d3bc44ef05e623f02456574e1c038efaca0d0fe001c75023717afe4e2ba71
3
+ metadata.gz: 4811ffba4bc939ced12590d2166bf82fdb9b7de3bc273994c46c5a122bf878fa
4
+ data.tar.gz: 361b0230470cfd0145009394d7f1c3e78bb15054aa2b5cc6dbc2ec9e04e0174d
5
5
  SHA512:
6
- metadata.gz: 04c8d868354002f73de37919c6fa4acf069bc4f88dfe7c471dd1b54253ce7bc23721b0c2ba351a8860a8998e2aa8967581fbe8ddf4e198c011dff1125e41cfcb
7
- data.tar.gz: 44a86aaf44b09fcb2bfcc44d38d19220dbcb04f59303508bc308d54535da0d60c4b020b992291a5cc8702d8d3501d935d89332aa3f92407e3c8563b990ad4e8e
6
+ metadata.gz: 54f3f4bdcb66b057e1d46d1f4df1ee9ef51be56b24d574bbe79be0c718a4e846778e4f0e66a7400e8cc25d5040d8487977ec837046fc373d02d2777cd05e0f04
7
+ data.tar.gz: 26da239fa55604b7d1090e8a5fd0b6d5b2eb3945491c73b225e25ca98f543eb3dcbceab88ac1c0a298a2676e3402136ddad517a302c08e421dbd44c7fee7db25
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class MenusController < ApplicationController
4
+ before_action :set_service
5
+
6
+ def index
7
+ menu = @service.fetch_menu(current_user)
8
+ data = ActiveModelSerializers::SerializableResource.new(menu, each_serializer: RoleMenuSerializer)
9
+ render json: { success: true, data: data }
10
+ end
11
+
12
+ private
13
+
14
+ def set_service
15
+ @service = MenuService.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,7 @@ module Cats
11
11
  private
12
12
 
13
13
  def set_role
14
- @role = Role.find(params[:id])
14
+ @role = Role.find_by(name: params[:name])
15
15
  end
16
16
  end
17
17
  end
@@ -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
@@ -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? }.merge(to_notification.message)
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
@@ -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
@@ -14,6 +14,9 @@ module Cats
14
14
 
15
15
  errors.add(:base, 'Application module does not match for role and menu')
16
16
  end
17
+
18
+ delegate(:label, to: :menu, prefix: false)
19
+ delegate(:icon, to: :menu, prefix: false)
17
20
  end
18
21
  end
19
22
  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
@@ -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, :store_keeper_name, :length, :width, :height, presence: true
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,
@@ -20,6 +20,12 @@ module Cats
20
20
 
21
21
  errors.add(:warehouse, 'must be a valid warehouse') unless warehouse.location_type == Location::WAREHOUSE
22
22
  end
23
+
24
+ def store_keeper_name
25
+ "#{store_keeper.first_name} #{store_keeper.last_name}"
26
+ end
27
+
28
+ delegate(:phone_number, to: :store_keeper, prefix: true)
23
29
  end
24
30
  end
25
31
  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
@@ -1,9 +1,20 @@
1
1
  # This is a simple notification class which delivers a
2
2
  # message via database delivery method. It requires a
3
- # +msg+ parameter to instantiate, which represents the
3
+ # +body+ and +title+ parameter to instantiate, which represents the
4
4
  # text message to deliver.
5
- class SimpleNotification < Noticed::Base
6
- deliver_by :database
5
+ module Cats
6
+ module Core
7
+ class SimpleNotification < Noticed::Base
8
+ deliver_by :database
7
9
 
8
- param :msg
10
+ param :body
11
+ param :title
12
+
13
+ def message
14
+ title = params[:title]
15
+ body = params[:body]
16
+ { title: title, body: body }
17
+ end
18
+ end
19
+ end
9
20
  end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class RoleMenuSerializer < ActiveModel::Serializer
4
+ attributes :id, :label, :icon, :description, :menu_items
5
+
6
+ def menu_items
7
+ object.menu.menu_items
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Cats
2
+ module Core
3
+ class MenuService
4
+ def fetch_menu(user)
5
+ user.roles.map(&:role_menus).flatten
6
+ end
7
+ end
8
+ end
9
+ 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 = notification_rules[@code]
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
@@ -2,14 +2,15 @@ Cats::Core::Engine.routes.draw do
2
2
  post '/login', controller: :access, action: :login
3
3
  get '/notifications/unread', controller: :notifications, action: :unread
4
4
  get '/notifications/read', controller: :notifications, action: :read
5
-
5
+
6
+ resources :menus, only: [:index]
6
7
  resources :notifications, only: [:index] do
7
8
  member do
8
9
  post 'mark_as_read', controller: :notifications, action: :mark_as_read
9
10
  post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
10
11
  end
11
12
  end
12
- resources :roles do
13
+ resources :roles, param: :name do
13
14
  member do
14
15
  get 'users', controller: :roles, action: :users
15
16
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.10'.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
@@ -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
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  first_name { FFaker::Name.name }
4
4
  last_name { FFaker::Name.name }
5
5
  email { FFaker::Internet.email }
6
+ phone_number { '0913345678' }
6
7
  active { true }
7
8
  password { FFaker::Internet.password }
8
9
  details { {} }
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.10
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-05 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
@@ -218,6 +218,7 @@ files:
218
218
  - Rakefile
219
219
  - app/controllers/cats/core/access_controller.rb
220
220
  - app/controllers/cats/core/application_controller.rb
221
+ - app/controllers/cats/core/menus_controller.rb
221
222
  - app/controllers/cats/core/notifications_controller.rb
222
223
  - app/controllers/cats/core/roles_controller.rb
223
224
  - app/controllers/cats/core/users_controller.rb
@@ -225,26 +226,32 @@ files:
225
226
  - app/models/cats/core/application_module.rb
226
227
  - app/models/cats/core/application_record.rb
227
228
  - app/models/cats/core/commodity.rb
229
+ - app/models/cats/core/commodity_allocation.rb
228
230
  - app/models/cats/core/commodity_category.rb
229
- - app/models/cats/core/commodity_transaction.rb
231
+ - app/models/cats/core/dispatch.rb
232
+ - app/models/cats/core/dispatch_transaction.rb
230
233
  - app/models/cats/core/donor.rb
234
+ - app/models/cats/core/gift_certificate.rb
231
235
  - app/models/cats/core/location.rb
232
236
  - app/models/cats/core/menu.rb
233
237
  - app/models/cats/core/menu_item.rb
234
238
  - app/models/cats/core/notification.rb
235
239
  - app/models/cats/core/program.rb
236
- - app/models/cats/core/receipt_plan.rb
240
+ - app/models/cats/core/receipt.rb
241
+ - app/models/cats/core/receipt_transaction.rb
237
242
  - app/models/cats/core/role.rb
238
243
  - app/models/cats/core/role_menu.rb
239
244
  - app/models/cats/core/stack.rb
245
+ - app/models/cats/core/stack_transaction.rb
240
246
  - app/models/cats/core/stacking_rule.rb
241
247
  - app/models/cats/core/store.rb
248
+ - app/models/cats/core/transaction.rb
242
249
  - app/models/cats/core/transporter.rb
243
250
  - app/models/cats/core/unit_of_measure.rb
244
251
  - app/models/cats/core/user.rb
245
- - app/models/cats/core/way_bill.rb
246
- - app/models/cats/core/way_bill_item.rb
247
252
  - app/notifications/cats/core/simple_notification.rb
253
+ - app/serializers/cats/core/role_menu_serializer.rb
254
+ - app/services/cats/core/menu_service.rb
248
255
  - app/services/cats/core/notification_service.rb
249
256
  - app/services/cats/core/token_auth_service.rb
250
257
  - config/routes.rb
@@ -258,17 +265,20 @@ files:
258
265
  - db/migrate/20210716145125_create_cats_core_unit_of_measures.rb
259
266
  - db/migrate/20210716151230_create_cats_core_programs.rb
260
267
  - db/migrate/20210717031108_create_cats_core_donors.rb
268
+ - db/migrate/20210717032602_create_cats_core_gift_certificates.rb
261
269
  - db/migrate/20210717033223_create_cats_core_commodities.rb
262
270
  - db/migrate/20210717043620_create_cats_core_locations.rb
263
271
  - db/migrate/20210717140855_create_cats_core_stores.rb
264
272
  - db/migrate/20210717171101_create_cats_core_stacks.rb
265
273
  - db/migrate/20210718042749_create_cats_core_transporters.rb
266
- - db/migrate/20210718045516_create_cats_core_way_bills.rb
267
- - db/migrate/20210718050751_create_cats_core_way_bill_items.rb
268
- - 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
269
277
  - db/migrate/20210719133710_create_cats_core_stacking_rules.rb
270
278
  - db/migrate/20210724074657_create_cats_core_notifications.rb
271
- - 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
272
282
  - lib/cats/core.rb
273
283
  - lib/cats/core/engine.rb
274
284
  - lib/cats/core/version.rb
@@ -276,25 +286,28 @@ files:
276
286
  - lib/tasks/cats_core_tasks.rake
277
287
  - spec/factories/cats/core/application_modules.rb
278
288
  - spec/factories/cats/core/commodities.rb
289
+ - spec/factories/cats/core/commodity_allocations.rb
279
290
  - spec/factories/cats/core/commodity_categories.rb
280
- - spec/factories/cats/core/commodity_transactions.rb
291
+ - spec/factories/cats/core/dispatch_transactions.rb
292
+ - spec/factories/cats/core/dispatches.rb
281
293
  - spec/factories/cats/core/donors.rb
294
+ - spec/factories/cats/core/gift_certificates.rb
282
295
  - spec/factories/cats/core/locations.rb
283
296
  - spec/factories/cats/core/menu_items.rb
284
297
  - spec/factories/cats/core/menus.rb
285
298
  - spec/factories/cats/core/notifications.rb
286
299
  - spec/factories/cats/core/programs.rb
287
- - spec/factories/cats/core/receipt_plans.rb
300
+ - spec/factories/cats/core/receipt_transactions.rb
301
+ - spec/factories/cats/core/receipts.rb
288
302
  - spec/factories/cats/core/role_menus.rb
289
303
  - spec/factories/cats/core/roles.rb
304
+ - spec/factories/cats/core/stack_transactions.rb
290
305
  - spec/factories/cats/core/stacking_rules.rb
291
306
  - spec/factories/cats/core/stacks.rb
292
307
  - spec/factories/cats/core/stores.rb
293
308
  - spec/factories/cats/core/transporters.rb
294
309
  - spec/factories/cats/core/unit_of_measures.rb
295
310
  - spec/factories/cats/core/users.rb
296
- - spec/factories/cats/core/way_bill_items.rb
297
- - spec/factories/cats/core/way_bills.rb
298
311
  homepage: http://cats.ndrmcapps.org
299
312
  licenses:
300
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