ecom_core 1.0.4

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 (90) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +24 -0
  5. data/app/controllers/concerns/ecom/core/lookupable.rb +44 -0
  6. data/app/controllers/concerns/ecom/core/resource_typeable.rb +43 -0
  7. data/app/controllers/ecom/core/application_controller.rb +7 -0
  8. data/app/controllers/ecom/core/crew_types_controller.rb +7 -0
  9. data/app/controllers/ecom/core/equipment_types_controller.rb +7 -0
  10. data/app/controllers/ecom/core/material_types_controller.rb +7 -0
  11. data/app/models/ecom/core/application_module.rb +7 -0
  12. data/app/models/ecom/core/application_record.rb +7 -0
  13. data/app/models/ecom/core/crew.rb +14 -0
  14. data/app/models/ecom/core/crew_time.rb +10 -0
  15. data/app/models/ecom/core/crew_type.rb +6 -0
  16. data/app/models/ecom/core/currency.rb +7 -0
  17. data/app/models/ecom/core/equipment_type.rb +6 -0
  18. data/app/models/ecom/core/lookup.rb +7 -0
  19. data/app/models/ecom/core/material_type.rb +6 -0
  20. data/app/models/ecom/core/menu.rb +10 -0
  21. data/app/models/ecom/core/overtime_type.rb +6 -0
  22. data/app/models/ecom/core/product_type.rb +10 -0
  23. data/app/models/ecom/core/project.rb +15 -0
  24. data/app/models/ecom/core/resource_type.rb +9 -0
  25. data/app/models/ecom/core/stakeholder.rb +11 -0
  26. data/app/models/ecom/core/stakeholder_type.rb +7 -0
  27. data/app/models/ecom/core/task.rb +10 -0
  28. data/app/models/ecom/core/task_template.rb +34 -0
  29. data/app/models/ecom/core/task_template_type.rb +7 -0
  30. data/app/models/ecom/core/user.rb +18 -0
  31. data/app/models/ecom/core/user_role.rb +12 -0
  32. data/app/models/ecom/core/work_component.rb +14 -0
  33. data/app/models/ecom/core/work_component_template.rb +11 -0
  34. data/app/models/ecom/core/work_product.rb +70 -0
  35. data/app/models/ecom/core/work_product_template.rb +14 -0
  36. data/app/serializers/ecom/core/lookup_serializer.rb +8 -0
  37. data/app/serializers/ecom/core/resource_type_serializer.rb +8 -0
  38. data/config/database.ci.yml +12 -0
  39. data/config/routes.rb +5 -0
  40. data/db/migrate/20190101112620_create_ecom_core_lookups.rb +10 -0
  41. data/db/migrate/20191119010518_create_ecom_core_task_template_types.rb +13 -0
  42. data/db/migrate/20191119012030_create_ecom_core_task_templates.rb +15 -0
  43. data/db/migrate/20191119013236_create_ecom_core_work_product_templates.rb +15 -0
  44. data/db/migrate/20191119144141_create_ecom_core_stakeholder_types.rb +10 -0
  45. data/db/migrate/20191119144618_create_ecom_core_stakeholders.rb +19 -0
  46. data/db/migrate/20191119145711_create_ecom_core_resource_types.rb +15 -0
  47. data/db/migrate/20191201131341_create_ecom_core_product_types.rb +14 -0
  48. data/db/migrate/20191201134420_create_ecom_core_work_component_templates.rb +23 -0
  49. data/db/migrate/20191201145816_create_ecom_core_currencies.rb +10 -0
  50. data/db/migrate/20191201145848_create_ecom_core_projects.rb +34 -0
  51. data/db/migrate/20191202103735_create_ecom_core_tasks.rb +17 -0
  52. data/db/migrate/20191202105355_create_task_templates_resource_types.rb +16 -0
  53. data/db/migrate/20191202220752_create_ecom_core_application_modules.rb +10 -0
  54. data/db/migrate/20191202220832_create_ecom_core_users.rb +24 -0
  55. data/db/migrate/20191202220953_create_ecom_core_user_roles.rb +22 -0
  56. data/db/migrate/20191202221423_create_ecom_core_menus.rb +25 -0
  57. data/db/migrate/20191202235434_create_ecom_core_work_products.rb +35 -0
  58. data/db/migrate/20191206104247_create_ecom_core_work_components.rb +30 -0
  59. data/db/migrate/20191225100054_create_ecom_core_crews.rb +17 -0
  60. data/db/migrate/20191225211712_create_ecom_core_crew_times.rb +17 -0
  61. data/lib/ecom/core.rb +4 -0
  62. data/lib/ecom/core/engine.rb +25 -0
  63. data/lib/ecom/core/version.rb +5 -0
  64. data/lib/ecom_core.rb +5 -0
  65. data/lib/tasks/ecom_core_tasks.rake +4 -0
  66. data/spec/factories/ecom/core/application_modules.rb +6 -0
  67. data/spec/factories/ecom/core/crew_times.rb +10 -0
  68. data/spec/factories/ecom/core/crew_types.rb +5 -0
  69. data/spec/factories/ecom/core/crews.rb +12 -0
  70. data/spec/factories/ecom/core/currencies.rb +6 -0
  71. data/spec/factories/ecom/core/equipment_types.rb +5 -0
  72. data/spec/factories/ecom/core/lookups.rb +6 -0
  73. data/spec/factories/ecom/core/material_types.rb +5 -0
  74. data/spec/factories/ecom/core/menus.rb +9 -0
  75. data/spec/factories/ecom/core/overtime_types.rb +5 -0
  76. data/spec/factories/ecom/core/product_types.rb +7 -0
  77. data/spec/factories/ecom/core/projects.rb +23 -0
  78. data/spec/factories/ecom/core/resource_types.rb +8 -0
  79. data/spec/factories/ecom/core/stakeholder_types.rb +5 -0
  80. data/spec/factories/ecom/core/stakeholders.rb +13 -0
  81. data/spec/factories/ecom/core/task_template_types.rb +6 -0
  82. data/spec/factories/ecom/core/task_templates.rb +15 -0
  83. data/spec/factories/ecom/core/tasks.rb +10 -0
  84. data/spec/factories/ecom/core/user_roles.rb +6 -0
  85. data/spec/factories/ecom/core/users.rb +9 -0
  86. data/spec/factories/ecom/core/work_component_templates.rb +11 -0
  87. data/spec/factories/ecom/core/work_components.rb +18 -0
  88. data/spec/factories/ecom/core/work_product_templates.rb +9 -0
  89. data/spec/factories/ecom/core/work_products.rb +22 -0
  90. metadata +300 -0
@@ -0,0 +1,12 @@
1
+ module Ecom
2
+ module Core
3
+ class UserRole < ApplicationRecord
4
+ belongs_to :application_module
5
+ has_and_belongs_to_many :users, join_table: 'ecom_core_users_user_roles'
6
+ has_and_belongs_to_many :menus, join_table: 'ecom_core_menus_user_roles'
7
+
8
+ validates :name, presence: true
9
+ validates :name, uniqueness: { scope: :application_module_id }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Ecom
2
+ module Core
3
+ class WorkComponent < ApplicationRecord
4
+ belongs_to :performer, class_name: 'Ecom::Core::User'
5
+ belongs_to :approver, class_name: 'Ecom::Core::User'
6
+ belongs_to :supervisor, class_name: 'Ecom::Core::User'
7
+ belongs_to :quality_controller, class_name: 'Ecom::Core::User'
8
+ belongs_to :work_component_template
9
+ belongs_to :work_product
10
+
11
+ validates :name, :assignment_status, :task_status, :percent_completed, presence: true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Ecom
2
+ module Core
3
+ class WorkComponentTemplate < ApplicationRecord
4
+ belongs_to :work_product_template
5
+ belongs_to :task_template
6
+
7
+ validates :code, :name, presence: true
8
+ validates :code, uniqueness: { scope: %i[work_product_template_id task_template_id] }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ # The WorkProduct core represents a task being implemented on a specific
2
+ # work product. To this regard, a work product is an assignable itself which
3
+ # contains the basic product attributes (e.g. dimension, name, design reference)
4
+ # on one hand, and task related attributes (e.g. start date and completion date)
5
+ # on the other hand. A task may have multiple work products under it. It is
6
+ # important to note that currently there is no direct way to link products and
7
+ # sub products, as we have done with tasks and sub tasks. If there is a desire
8
+ # to have such a link between products (e.g. we may later want to have reports
9
+ # per specific high level products, which in turn asks for finding all sub products
10
+ # under the selected high level product and do calculations), then a `code` field
11
+ # has been introduced to the WorkProduct core. This field can be used in a similar
12
+ # way as chart of accounts to identify parent and child relationships. Even then,
13
+ # there needs to be a well defined coding scheme developed before using the column
14
+ # field.
15
+ #
16
+ module Ecom
17
+ module Core
18
+ class WorkProduct < ApplicationRecord
19
+ include AASM
20
+
21
+ belongs_to :work_product_template
22
+ belongs_to :task
23
+ belongs_to :project
24
+ belongs_to :performer, class_name: 'Ecom::Core::User'
25
+ belongs_to :approver, class_name: 'Ecom::Core::User'
26
+ belongs_to :supervisor, class_name: 'Ecom::Core::User'
27
+ belongs_to :quality_controller, class_name: 'Ecom::Core::User'
28
+
29
+ validates :name, presence: true
30
+ validates :design_reference_no, uniqueness: true
31
+
32
+ aasm column: 'task_status' do
33
+ state :new, initial: true
34
+ state :in_progress
35
+ state :submitted
36
+ state :under_review
37
+ state :completed
38
+
39
+ event :start do
40
+ transitions from: :new, to: :in_progress
41
+ end
42
+
43
+ event :submit do
44
+ transitions from: :in_progress, to: :submitted
45
+ end
46
+
47
+ event :review do
48
+ transitions from: :submitted, to: :under_review
49
+ end
50
+
51
+ event :complete do
52
+ transitions from: %i[submitted under_review], to: :completed
53
+ end
54
+
55
+ event :rework do
56
+ transitions from: :under_review, to: :in_progress
57
+ end
58
+ end
59
+
60
+ aasm column: 'assignment_status' do
61
+ state :unassigned, initial: true
62
+ state :assigned
63
+
64
+ event :assign do
65
+ transitions from: :unassigned, to: :assigned
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ module Ecom
2
+ module Core
3
+ class WorkProductTemplate < ApplicationRecord
4
+ validates :code, :name, presence: true, uniqueness: true
5
+ belongs_to :task_template
6
+ has_many :product_types
7
+
8
+ scope :filtered_by_template_type, lambda { |id|
9
+ joins(:task_template).where('ecom_core_task_templates.task_template_type_id = ?', id)
10
+ .order(:code)
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module Ecom
2
+ module Core
3
+ class LookupSerializer
4
+ include FastJsonapi::ObjectSerializer
5
+ attributes :name, :type
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Ecom
2
+ module Core
3
+ class ResourceTypeSerializer
4
+ include FastJsonapi::ObjectSerializer
5
+ attributes :code, :name, :base_unit, :type
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ pool: 5
5
+ timeout: 5000
6
+ host: <%= ENV['DB_HOST'] %>
7
+ username: <%= ENV['POSTGRES_USER'] %>
8
+ password: <%= ENV['POSTGRES_PASSWORD'] %>
9
+ database: <%= ENV['POSTGRES_DB'] %>
10
+
11
+ test:
12
+ <<: *default
@@ -0,0 +1,5 @@
1
+ Ecom::Core::Engine.routes.draw do
2
+ resources :crew_types
3
+ resources :equipment_types
4
+ resources :material_types
5
+ end
@@ -0,0 +1,10 @@
1
+ class CreateEcomCoreLookups < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_lookups do |t|
4
+ t.string :name, null: false
5
+ t.string :type, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ class CreateEcomCoreTaskTemplateTypes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_task_template_types do |t|
4
+ t.string :code, null: false
5
+ t.string :name, null: false
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :ecom_core_task_template_types, :code, unique: true
11
+ add_index :ecom_core_task_template_types, :name, unique: true
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class CreateEcomCoreTaskTemplates < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_task_templates do |t|
4
+ t.string :code, null: false
5
+ t.string :name, null: false
6
+ t.string :description
7
+ t.references :task_template_type, index: { name: 'ttt_on_tt_indx' }
8
+ t.string :ancestry, index: true
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_foreign_key :ecom_core_task_templates, :ecom_core_task_template_types, column: :task_template_type_id
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class CreateEcomCoreWorkProductTemplates < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_work_product_templates do |t|
4
+ t.string :code, null: false, unique: true
5
+ t.string :name, null: false, unique: true
6
+ t.string :description
7
+ t.string :remark
8
+ t.references :task_template, index: { name: 'tt_on_wpt_indx' }
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_foreign_key :ecom_core_work_product_templates, :ecom_core_task_templates, column: :task_template_id
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ class CreateEcomCoreStakeholderTypes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_stakeholder_types do |t|
4
+ t.string :name, null: false, unique: true
5
+ t.string :description
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ class CreateEcomCoreStakeholders < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_stakeholders do |t|
4
+ t.string :name, null: false, unique: true
5
+ t.string :type_of_business
6
+ t.string :address
7
+ t.string :license_no
8
+ t.string :tin_no
9
+ t.string :contact_name, null: false
10
+ t.string :contact_phone, null: false
11
+ t.string :contact_email, null: false
12
+ t.references :stakeholder_type, index: { name: 'em_stakeholders_on_type_indx' }
13
+
14
+ t.timestamps
15
+ end
16
+
17
+ add_foreign_key :ecom_core_stakeholders, :ecom_core_stakeholder_types, column: :stakeholder_type_id
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ class CreateEcomCoreResourceTypes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_resource_types do |t|
4
+ t.string :code, null: false
5
+ t.string :name, null: false
6
+ t.string :base_unit, null: false
7
+ t.string :type, null: false
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :ecom_core_resource_types, %i[code type], unique: true
13
+ add_index :ecom_core_resource_types, %i[name type], unique: true
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEcomCoreProductTypes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_product_types do |t|
4
+ t.string :name, null: false
5
+ t.references :work_product_template, index: { name: 'pt_on_wpt_indx' }
6
+ t.json :dimension
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :ecom_core_product_types, %i[name work_product_template_id], unique: true, name: 'wpt_on_pt_name_indx'
12
+ add_foreign_key :ecom_core_product_types, :ecom_core_work_product_templates, column: :work_product_template_id
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ class CreateEcomCoreWorkComponentTemplates < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_work_component_templates do |t|
4
+ t.string :code, null: false
5
+ t.string :name, null: false
6
+ t.string :description
7
+ t.integer :relative_percentage
8
+ t.json :dimension
9
+ t.references :work_product_template, index: { name: 'wct_on_wpt_indx' }
10
+ t.references :task_template, index: { name: 'wct_on_tt_indx' }
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ add_index :ecom_core_work_component_templates, %i[code work_product_template_id task_template_id],
16
+ unique: true,
17
+ name: 'wct_on_code_wpt_id_tt_id_indx'
18
+ add_foreign_key :ecom_core_work_component_templates, :ecom_core_work_product_templates,
19
+ column: :work_product_template_id
20
+ add_foreign_key :ecom_core_work_component_templates, :ecom_core_task_templates,
21
+ column: :task_template_id
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ class CreateEcomCoreCurrencies < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_currencies do |t|
4
+ t.string :code, unique: true
5
+ t.string :name, unique: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ class CreateEcomCoreProjects < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_projects do |t|
4
+ t.string :name, null: false
5
+ t.string :description
6
+ t.string :location, null: false
7
+ t.string :objective
8
+ t.string :project_scope
9
+ t.references :employer, index: { name: 'employer_on_projects_indx' }
10
+ t.references :contractor, index: { name: 'employer_on_contractor_indx' }
11
+ t.references :consultant, index: { name: 'employer_on_consultant_indx' }
12
+ t.references :project_manager, index: { name: 'employer_on_pm_indx' }
13
+ t.references :task_template, index: { name: 'employer_on_tt_indx' }
14
+ t.string :contract_number, null: false
15
+ t.date :date_contract_signed, null: false
16
+ t.date :commencement_date, null: false
17
+ t.date :completion_date, null: false
18
+ t.float :contract_amount, null: false
19
+ t.float :advance_payment, null: false
20
+ t.float :retention, null: false
21
+ t.string :remark
22
+ t.references :currency, index: { name: 'employer_on_currency_indx' }
23
+
24
+ t.timestamps
25
+ end
26
+
27
+ add_foreign_key :ecom_core_projects, :ecom_core_stakeholders, column: :employer_id
28
+ add_foreign_key :ecom_core_projects, :ecom_core_stakeholders, column: :contractor_id
29
+ add_foreign_key :ecom_core_projects, :ecom_core_stakeholders, column: :consultant_id
30
+ add_foreign_key :ecom_core_projects, :ecom_core_stakeholders, column: :project_manager_id
31
+ add_foreign_key :ecom_core_projects, :ecom_core_task_templates, column: :task_template_id
32
+ add_foreign_key :ecom_core_projects, :ecom_core_currencies, column: :currency_id
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ class CreateEcomCoreTasks < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_tasks do |t|
4
+ t.string :code, null: false
5
+ t.string :name, null: false
6
+ t.string :description
7
+ t.string :ancestry
8
+ t.references :project, index: { name: 'tasks_on_project_indx' }
9
+ t.references :task_template, index: { name: 'tt_on_project_indx' }
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_foreign_key :ecom_core_tasks, :ecom_core_projects, column: :project_id
15
+ add_foreign_key :ecom_core_tasks, :ecom_core_task_templates, column: :task_template_id
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ class CreateTaskTemplatesResourceTypes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_task_templates_resource_types, id: false do |t|
4
+ t.references :task_template, index: false
5
+ t.references :resource_type, index: false
6
+ end
7
+
8
+ add_index :ecom_core_task_templates_resource_types, %i[task_template_id resource_type_id],
9
+ unique: true, name: 'ttr_on_tt_rt_indx'
10
+
11
+ add_foreign_key :ecom_core_task_templates_resource_types, :ecom_core_task_templates,
12
+ column: :task_template_id
13
+ add_foreign_key :ecom_core_task_templates_resource_types, :ecom_core_resource_types,
14
+ column: :resource_type_id
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class CreateEcomCoreApplicationModules < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_application_modules do |t|
4
+ t.string :code, unique: true
5
+ t.string :name, unique: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ class CreateEcomCoreUsers < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_users do |t|
4
+ t.string :first_name, null: false
5
+ t.string :last_name, null: false
6
+ t.string :email, null: false
7
+ t.boolean :active, null: false, default: true
8
+ t.string :password_digest
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :ecom_core_application_modules_users, id: false do |t|
14
+ t.references :user, index: false
15
+ t.references :application_module, index: false
16
+ end
17
+
18
+ add_index :ecom_core_application_modules_users, %i[user_id application_module_id], name: 'am_on_users_indx'
19
+
20
+ add_foreign_key :ecom_core_application_modules_users, :ecom_core_users, column: :user_id
21
+ add_foreign_key :ecom_core_application_modules_users, :ecom_core_application_modules,
22
+ column: :application_module_id
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ class CreateEcomCoreUserRoles < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_user_roles do |t|
4
+ t.string :name, index: false
5
+ t.references :application_module, index: { name: 'ur_on_am_indx' }
6
+
7
+ t.timestamps
8
+ end
9
+ add_index :ecom_core_user_roles, %i[name application_module_id], unique: true, name: 'am_name_indx'
10
+ add_foreign_key :ecom_core_user_roles, :ecom_core_application_modules,
11
+ column: :application_module_id
12
+
13
+ create_table :ecom_core_users_user_roles, id: false do |t|
14
+ t.references :user, index: false
15
+ t.references :user_role, index: false
16
+ end
17
+
18
+ add_index :ecom_core_users_user_roles, %i[user_id user_role_id], unique: true, name: 'users_user_roles_indx'
19
+ add_foreign_key :ecom_core_users_user_roles, :ecom_core_users, column: :user_id
20
+ add_foreign_key :ecom_core_users_user_roles, :ecom_core_user_roles, column: :user_role_id
21
+ end
22
+ end