ecom_core 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/ecom/core/attendance_sheet.rb +24 -19
  3. data/app/models/ecom/core/attendance_sheet_entry.rb +1 -1
  4. data/app/models/ecom/core/company.rb +10 -0
  5. data/app/models/ecom/core/crew.rb +0 -2
  6. data/app/models/ecom/core/crew_overtime.rb +1 -1
  7. data/app/models/ecom/core/crew_time.rb +0 -3
  8. data/app/models/ecom/core/overtime_sheet.rb +13 -10
  9. data/app/models/ecom/core/payment_detail.rb +1 -1
  10. data/app/models/ecom/core/payroll.rb +1 -0
  11. data/app/models/ecom/core/project.rb +4 -0
  12. data/app/models/ecom/core/project_crew.rb +15 -0
  13. data/db/migrate/20190101085530_create_ecom_core_companies.rb +14 -0
  14. data/db/migrate/20191119012030_create_ecom_core_task_templates.rb +4 -3
  15. data/db/migrate/20191119013236_create_ecom_core_work_product_templates.rb +4 -3
  16. data/db/migrate/20191119144618_create_ecom_core_stakeholders.rb +4 -3
  17. data/db/migrate/20191201131341_create_ecom_core_product_types.rb +4 -2
  18. data/db/migrate/20191201134420_create_ecom_core_work_component_templates.rb +8 -6
  19. data/db/migrate/20191201145848_create_ecom_core_projects.rb +28 -13
  20. data/db/migrate/20191202103735_create_ecom_core_tasks.rb +8 -5
  21. data/db/migrate/20191202105355_create_task_templates_resource_types.rb +8 -7
  22. data/db/migrate/20191202220832_create_ecom_core_users.rb +9 -6
  23. data/db/migrate/20191202220953_create_ecom_core_user_roles.rb +13 -8
  24. data/db/migrate/20191202221423_create_ecom_core_menus.rb +16 -9
  25. data/db/migrate/20191202235434_create_ecom_core_work_products.rb +29 -15
  26. data/db/migrate/20191206104247_create_ecom_core_work_components.rb +24 -14
  27. data/db/migrate/20191225100054_create_ecom_core_crews.rb +5 -3
  28. data/db/migrate/20191225121850_create_ecom_core_project_crews.rb +19 -0
  29. data/db/migrate/{20200401040433_create_ecom_core_attendance_sheets.rb → 20191225140433_create_ecom_core_attendance_sheets.rb} +4 -0
  30. data/db/migrate/20191225162539_create_ecom_core_attendance_sheet_entries.rb +17 -0
  31. data/db/migrate/20191225211712_create_ecom_core_crew_times.rb +15 -9
  32. data/db/migrate/20200126081005_create_ecom_core_payrolls.rb +4 -0
  33. data/db/migrate/20200126082103_create_ecom_core_payments.rb +6 -3
  34. data/db/migrate/20200126183218_create_ecom_core_payment_details.rb +10 -5
  35. data/db/migrate/20200307112519_create_ecom_core_custom_payment_details.rb +4 -3
  36. data/db/migrate/20200315145215_create_ecom_core_equipment_locations.rb +4 -3
  37. data/db/migrate/20200315150500_create_ecom_core_equipment_categories.rb +4 -2
  38. data/db/migrate/20200315152143_create_ecom_core_equipment.rb +4 -2
  39. data/db/migrate/20200315153640_create_ecom_core_equipment_items.rb +8 -5
  40. data/db/migrate/20200315160810_create_ecom_core_equipment_valuations.rb +4 -3
  41. data/db/migrate/20200316125323_create_ecom_core_equipment_components.rb +4 -3
  42. data/db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb +4 -0
  43. data/db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb +8 -5
  44. data/db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb +17 -11
  45. data/lib/ecom/core/version.rb +1 -1
  46. data/spec/factories/ecom/core/application_modules.rb +1 -1
  47. data/spec/factories/ecom/core/attendance_sheet_entries.rb +1 -1
  48. data/spec/factories/ecom/core/attendance_sheets.rb +2 -1
  49. data/spec/factories/ecom/core/companies.rb +9 -0
  50. data/spec/factories/ecom/core/crew_overtimes.rb +1 -1
  51. data/spec/factories/ecom/core/crew_times.rb +1 -1
  52. data/spec/factories/ecom/core/crew_types.rb +1 -1
  53. data/spec/factories/ecom/core/crews.rb +1 -1
  54. data/spec/factories/ecom/core/currencies.rb +1 -1
  55. data/spec/factories/ecom/core/custom_payment_details.rb +1 -1
  56. data/spec/factories/ecom/core/equipment.rb +1 -1
  57. data/spec/factories/ecom/core/equipment_categories.rb +1 -1
  58. data/spec/factories/ecom/core/equipment_components.rb +1 -1
  59. data/spec/factories/ecom/core/equipment_items.rb +1 -1
  60. data/spec/factories/ecom/core/equipment_locations.rb +1 -1
  61. data/spec/factories/ecom/core/equipment_types.rb +1 -1
  62. data/spec/factories/ecom/core/equipment_valuations.rb +1 -1
  63. data/spec/factories/ecom/core/location_types.rb +1 -1
  64. data/spec/factories/ecom/core/lookups.rb +1 -1
  65. data/spec/factories/ecom/core/material_types.rb +1 -1
  66. data/spec/factories/ecom/core/menus.rb +1 -1
  67. data/spec/factories/ecom/core/overtime_sheet_entries.rb +1 -1
  68. data/spec/factories/ecom/core/overtime_sheets.rb +2 -1
  69. data/spec/factories/ecom/core/overtime_types.rb +1 -1
  70. data/spec/factories/ecom/core/payment_details.rb +1 -1
  71. data/spec/factories/ecom/core/payments.rb +1 -1
  72. data/spec/factories/ecom/core/payrolls.rb +2 -1
  73. data/spec/factories/ecom/core/product_types.rb +1 -1
  74. data/spec/factories/ecom/core/project_crews.rb +9 -0
  75. data/spec/factories/ecom/core/projects.rb +2 -1
  76. data/spec/factories/ecom/core/resource_types.rb +1 -1
  77. data/spec/factories/ecom/core/stakeholder_types.rb +1 -1
  78. data/spec/factories/ecom/core/stakeholders.rb +1 -1
  79. data/spec/factories/ecom/core/task_template_types.rb +1 -1
  80. data/spec/factories/ecom/core/task_templates.rb +1 -1
  81. data/spec/factories/ecom/core/tasks.rb +1 -1
  82. data/spec/factories/ecom/core/user_roles.rb +1 -1
  83. data/spec/factories/ecom/core/users.rb +1 -1
  84. data/spec/factories/ecom/core/work_component_templates.rb +1 -1
  85. data/spec/factories/ecom/core/work_components.rb +1 -1
  86. data/spec/factories/ecom/core/work_product_templates.rb +1 -1
  87. data/spec/factories/ecom/core/work_products.rb +2 -2
  88. metadata +25 -15
  89. data/db/migrate/20200207035823_add_additional_columns_to_payment.rb +0 -6
  90. data/db/migrate/20200207040844_add_net_pay_column_to_payment_details.rb +0 -5
  91. data/db/migrate/20200210095535_add_advance_column_to_payment_details.rb +0 -5
  92. data/db/migrate/20200221123207_add_employee_id_to_crew.rb +0 -5
  93. data/db/migrate/20200401071343_remove_date_column_from_crew_times.rb +0 -5
  94. data/db/migrate/20200401122539_create_ecom_core_attendance_sheet_entries.rb +0 -14
  95. data/db/migrate/20200401142959_relate_crew_time_with_attendance_sheet_entry.rb +0 -8
  96. data/db/migrate/20200401144137_remove_crew_time_id_from_crew.rb +0 -7
  97. data/db/migrate/20200413144023_fix_crew_time_columns.rb +0 -17
  98. data/db/migrate/20200414044144_adjust_crew_overtime_column_names.rb +0 -6
  99. data/db/migrate/20200414185248_change_time_columns_to_datetime.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af5b4a780b7955f760cb545de69cd06f6c9680201530a42d6afad3635dbcda85
4
- data.tar.gz: a0de01812e60a48302575d8330640df98f47af37a94e95ac8bb020c0cb3ddf85
3
+ metadata.gz: fa793b02a7d9a24882708250c891541910d0f2d4d97c8e713f0226a03da2c7b9
4
+ data.tar.gz: 102319f9e9313bac6294441dbb4218dc3ed61fd527b4e5fdc81fbf6e3f70032e
5
5
  SHA512:
6
- metadata.gz: c1ad0ef3200e95e456da5c497683dfe7a64ee0fd4a268ca6cc6fa8fae7e037bc35fa61d4a852875866804a48fc713ddc2fe3fa2c4ed1fbf34511d98eae1e81e3
7
- data.tar.gz: 9db37f16f20f784a9dfd66727c96bbce998a731cd3cf9d1e02e023a5bc319ad1520ff0dcf2c343aa9f7fd0c37be3f2cd28456c1b35f4facd59c1f5cc80932b13
6
+ metadata.gz: a80e478986df2a080fc9573565fcbe99bb75313c95a54946d74b731633c2f67877dc9371ddd014c9cbd6b358edeef1319b2e8c00b632a2c404b03479eb4e7c97
7
+ data.tar.gz: 3bcfcd09666b8847e6d61ae03908a799eb7ce02322fa97f42a78a2d4dbdac81a40aa22d4cf44967a0bd52ecea8587b8120f71248aaf7feb55e0ad6c0b5a5f809
@@ -8,27 +8,30 @@ module Ecom
8
8
  validates :date, presence: true, uniqueness: true
9
9
  validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
10
10
 
11
+ belongs_to :project
12
+
11
13
  has_many :attendance_sheet_entries
12
14
  has_many :crew_times, through: :attendance_sheet_entries
13
15
 
14
- scope :open, -> { where(status: OPEN) }
15
- scope :current, -> { where(date: Date.today) }
16
- scope :current_open, -> { open.current }
16
+ scope :open, ->(id) { where(status: OPEN, project_id: id) }
17
+ scope :submitted, ->(id) { where(status: SUBMITTED, project_id: id) }
18
+ scope :current, ->(id) { where(date: Date.today, project_id: id) }
19
+ scope :current_open, ->(id) { where(date: Date.today, project_id: id, status: OPEN) }
17
20
 
18
- def self.open_for_date(date)
19
- AttendanceSheet.find_by(status: OPEN, date: date)
21
+ def self.open_for_date(date, project_id)
22
+ AttendanceSheet.find_by(status: OPEN, date: date, project_id: project_id)
20
23
  end
21
24
 
22
- def self.open_exists?
23
- AttendanceSheet.open.exists?
25
+ def self.open_exists?(project_id)
26
+ AttendanceSheet.open(project_id).exists?
24
27
  end
25
28
 
26
- def self.exists_for_today?
27
- AttendanceSheet.current.exists?
29
+ def self.exists_for_today?(project_id)
30
+ AttendanceSheet.current(project_id).exists?
28
31
  end
29
32
 
30
- def self.open_exists_for_today?
31
- AttendanceSheet.current_open.exists?
33
+ def self.open_exists_for_today?(project_id)
34
+ AttendanceSheet.current_open(project_id).exists?
32
35
  end
33
36
 
34
37
  # Attendance sheet should be created using the
@@ -36,16 +39,18 @@ module Ecom
36
39
  # check if there is an open attendance already,
37
40
  # and also that we have only one attendace sheet
38
41
  # per day.
39
- def self.create_current
40
- raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?
42
+ def self.create_current(project_id)
43
+ raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?(project_id)
41
44
 
42
- raise 'There is an open attendance sheet which needs to be submitted before creating a new one.' if AttendanceSheet.open_exists?
45
+ if AttendanceSheet.open_exists?(project_id)
46
+ raise 'There is an open attendance sheet which needs to be submitted before creating a new one.'
47
+ end
43
48
 
44
- AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN)
49
+ AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN, project_id: project_id)
45
50
  end
46
51
 
47
- def self.submit_current
48
- sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN)
52
+ def self.submit_current(project_id)
53
+ sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN, project_id: project_id)
49
54
 
50
55
  raise 'There is no open attendance sheet to submit.' if sheet.nil?
51
56
 
@@ -59,8 +64,8 @@ module Ecom
59
64
  # to submit the attendance sheet after the date has
60
65
  # passed. Normally, timekeepers need to open and close
61
66
  # an attendance sheet of a date on the specific date.
62
- def self.submit(date)
63
- sheet = AttendanceSheet.open_for_date(date)
67
+ def self.submit(date, project_id)
68
+ sheet = AttendanceSheet.open_for_date(date, project_id)
64
69
  raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
65
70
 
66
71
  sheet.closed_at = Time.now
@@ -6,4 +6,4 @@ module Ecom
6
6
  has_many :crew_times
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Ecom
2
+ module Core
3
+ class Company < ApplicationRecord
4
+ has_many :projects
5
+
6
+ validates :code, :name, :address, :telephone, presence: true
7
+ validates :code, :name, uniqueness: true
8
+ end
9
+ end
10
+ end
@@ -11,8 +11,6 @@ module Ecom
11
11
 
12
12
  validates :name, :qualification, presence: true
13
13
  validates :employment, inclusion: [PERMANENT, TEMPORARY]
14
- #validates :wage, presence: true, if: ->(o) { o.employment == PERMANENT }
15
- #validates :wage, absence: true, if: ->(o) { o.employment == TEMPORARY }
16
14
 
17
15
  def set_employment_date
18
16
  self.employment_date = Date.today
@@ -18,4 +18,4 @@ module Ecom
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -61,13 +61,10 @@ module Ecom
61
61
  start = Time.zone.parse(checkin_time.strftime('%I:%M%p'))
62
62
  finish = Time.zone.parse(checkout_time.strftime('%I:%M%p'))
63
63
  range = find_range(start, finish)
64
- puts "Found the range #{range} for [#{start} - #{finish}]"
65
64
  left = start.before?(TIME_RANGE[range][:start]) ? TIME_RANGE[range][:start] : start
66
65
  right = finish.after?(TIME_RANGE[range][:end]) ? TIME_RANGE[range][:end] : finish
67
- puts "Applicable time range is [#{left} - #{right}]"
68
66
  time = (right - left) / 1.hour
69
67
  time -= 1 if range == BOTH
70
- puts "Calculated time is #{time}"
71
68
  time
72
69
  end
73
70
  end
@@ -8,17 +8,20 @@ module Ecom
8
8
  validates :date, :opened_at, presence: true, uniqueness: true
9
9
  validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
10
10
 
11
+ belongs_to :project
12
+
11
13
  has_many :overtime_sheet_entries
14
+ has_many :crew_overtimes, through: :overtime_sheet_entries
12
15
 
13
- scope :open, -> { where(status: OPEN) }
14
- scope :for_date, ->(date) { where(date: date) }
16
+ scope :open, ->(id) { where(status: OPEN, project_id: id) }
17
+ scope :submitted, ->(id) { where(status: SUBMITTED, project_id: id) }
15
18
 
16
- def self.open_exists?
17
- OvertimeSheet.open.exists?
19
+ def self.open_exists?(project_id)
20
+ OvertimeSheet.open(project_id).exists?
18
21
  end
19
22
 
20
- def self.open_for_date_exists?(date)
21
- OvertimeSheet.open.for_date(date).exists?
23
+ def self.open_for_date_exists?(date, project_id)
24
+ OvertimeSheet.open(project_id).where(date: date).exists?
22
25
  end
23
26
 
24
27
  # Overtime sheet should be created using the
@@ -26,16 +29,16 @@ module Ecom
26
29
  # check if there is an open overtime already,
27
30
  # and also that we have only one open overtime
28
31
  # sheet at a time.
29
- def self.create_new(date)
30
- if OvertimeSheet.open_for_date_exists?(date)
32
+ def self.create_new(date, project_id)
33
+ if OvertimeSheet.open_for_date_exists?(date, project_id)
31
34
  raise 'There is already an open overtime sheet for the selected date.'
32
35
  end
33
36
 
34
- if OvertimeSheet.open_exists?
37
+ if OvertimeSheet.open_exists?(project_id)
35
38
  raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
36
39
  end
37
40
 
38
- OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN)
41
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN, project_id: project_id)
39
42
  end
40
43
  end
41
44
  end
@@ -8,4 +8,4 @@ module Ecom
8
8
  :advance, presence: true
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -4,6 +4,7 @@ module Ecom
4
4
  validates :month, :year, presence: true
5
5
 
6
6
  has_many :payments, class_name: 'Ecom::Core::Payment'
7
+ belongs_to :project
7
8
  end
8
9
  end
9
10
  end
@@ -7,6 +7,10 @@ module Ecom
7
7
  belongs_to :project_manager, class_name: 'Ecom::Core::Stakeholder'
8
8
  belongs_to :task_template
9
9
  belongs_to :currency
10
+ belongs_to :company
11
+
12
+ has_many :project_crews
13
+ has_many :crews, through: :project_crews
10
14
 
11
15
  validates :name, :location, :contract_number, :date_contract_signed, :commencement_date, :completion_date,
12
16
  :contract_amount, :advance_payment, :retention, presence: true
@@ -0,0 +1,15 @@
1
+ module Ecom
2
+ module Core
3
+ class ProjectCrew < ApplicationRecord
4
+ ACTIVE = 'Active'.freeze
5
+ INACTIVE = 'Inactive'.freeze
6
+ STATUSES = [ACTIVE, INACTIVE].freeze
7
+
8
+ belongs_to :project
9
+ belongs_to :crew
10
+
11
+ validates :start_date, :status, presence: true
12
+ validates :status, inclusion: STATUSES
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEcomCoreCompanies < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_companies do |t|
4
+ t.string :code, null: false, unique: true
5
+ t.string :name, null: false, unique: true
6
+ t.string :address, null: false
7
+ t.string :telephone, null: false
8
+ t.string :email
9
+ t.json :settings
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -4,12 +4,13 @@ class CreateEcomCoreTaskTemplates < ActiveRecord::Migration[6.0]
4
4
  t.string :code, null: false
5
5
  t.string :name, null: false
6
6
  t.string :description
7
- t.references :task_template_type, index: { name: 'ttt_on_tt_indx' }
7
+ t.references :task_template_type,
8
+ null: false,
9
+ index: { name: 'tt_on_ttt_indx' },
10
+ foreign_key: { to_table: :ecom_core_task_template_types }
8
11
  t.string :ancestry, index: true
9
12
 
10
13
  t.timestamps
11
14
  end
12
-
13
- add_foreign_key :ecom_core_task_templates, :ecom_core_task_template_types, column: :task_template_type_id
14
15
  end
15
16
  end
@@ -5,11 +5,12 @@ class CreateEcomCoreWorkProductTemplates < ActiveRecord::Migration[6.0]
5
5
  t.string :name, null: false, unique: true
6
6
  t.string :description
7
7
  t.string :remark
8
- t.references :task_template, index: { name: 'tt_on_wpt_indx' }
8
+ t.references :task_template,
9
+ null: false,
10
+ index: { name: 'tt_on_wpt_indx' },
11
+ foreign_key: { to_table: :ecom_core_task_templates }
9
12
 
10
13
  t.timestamps
11
14
  end
12
-
13
- add_foreign_key :ecom_core_work_product_templates, :ecom_core_task_templates, column: :task_template_id
14
15
  end
15
16
  end
@@ -9,11 +9,12 @@ class CreateEcomCoreStakeholders < ActiveRecord::Migration[6.0]
9
9
  t.string :contact_name, null: false
10
10
  t.string :contact_phone, null: false
11
11
  t.string :contact_email, null: false
12
- t.references :stakeholder_type, index: { name: 'em_stakeholders_on_type_indx' }
12
+ t.references :stakeholder_type,
13
+ null: false,
14
+ index: { name: 'stakeholders_on_st_indx' },
15
+ foreign_key: { to_table: :ecom_core_stakeholder_types }
13
16
 
14
17
  t.timestamps
15
18
  end
16
-
17
- add_foreign_key :ecom_core_stakeholders, :ecom_core_stakeholder_types, column: :stakeholder_type_id
18
19
  end
19
20
  end
@@ -2,13 +2,15 @@ class CreateEcomCoreProductTypes < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_product_types do |t|
4
4
  t.string :name, null: false
5
- t.references :work_product_template, index: { name: 'pt_on_wpt_indx' }
5
+ t.references :work_product_template,
6
+ null: false,
7
+ index: { name: 'pt_on_wpt_indx' },
8
+ foreign_key: { to_table: :ecom_core_work_product_templates }
6
9
  t.json :dimension
7
10
 
8
11
  t.timestamps
9
12
  end
10
13
 
11
14
  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
15
  end
14
16
  end
@@ -6,8 +6,14 @@ class CreateEcomCoreWorkComponentTemplates < ActiveRecord::Migration[6.0]
6
6
  t.string :description
7
7
  t.integer :relative_percentage
8
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' }
9
+ t.references :work_product_template,
10
+ null: false,
11
+ index: { name: 'wct_on_wpt_indx' },
12
+ foreign_key: { to_table: :ecom_core_work_product_templates }
13
+ t.references :task_template,
14
+ null: false,
15
+ index: { name: 'wct_on_tt_indx' },
16
+ foreign_key: { to_table: :ecom_core_task_templates }
11
17
 
12
18
  t.timestamps
13
19
  end
@@ -15,9 +21,5 @@ class CreateEcomCoreWorkComponentTemplates < ActiveRecord::Migration[6.0]
15
21
  add_index :ecom_core_work_component_templates, %i[code work_product_template_id task_template_id],
16
22
  unique: true,
17
23
  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
24
  end
23
25
  end
@@ -6,11 +6,26 @@ class CreateEcomCoreProjects < ActiveRecord::Migration[6.0]
6
6
  t.string :location, null: false
7
7
  t.string :objective
8
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' }
9
+ t.references :employer,
10
+ null: false,
11
+ index: { name: 'employer_on_projects_indx' },
12
+ foreign_key: { to_table: :ecom_core_stakeholders }
13
+ t.references :contractor,
14
+ null: false,
15
+ index: { name: 'employer_on_contractor_indx' },
16
+ foreign_key: { to_table: :ecom_core_stakeholders }
17
+ t.references :consultant,
18
+ null: false,
19
+ index: { name: 'employer_on_consultant_indx' },
20
+ foreign_key: { to_table: :ecom_core_stakeholders }
21
+ t.references :project_manager,
22
+ null: false,
23
+ index: { name: 'employer_on_pm_indx' },
24
+ foreign_key: { to_table: :ecom_core_stakeholders }
25
+ t.references :task_template,
26
+ null: false,
27
+ index: { name: 'employer_on_tt_indx' },
28
+ foreign_key: { to_table: :ecom_core_task_templates }
14
29
  t.string :contract_number, null: false
15
30
  t.date :date_contract_signed, null: false
16
31
  t.date :commencement_date, null: false
@@ -19,16 +34,16 @@ class CreateEcomCoreProjects < ActiveRecord::Migration[6.0]
19
34
  t.float :advance_payment, null: false
20
35
  t.float :retention, null: false
21
36
  t.string :remark
22
- t.references :currency, index: { name: 'employer_on_currency_indx' }
37
+ t.references :currency,
38
+ null: false,
39
+ index: { name: 'employer_on_currency_indx' },
40
+ foreign_key: { to_table: :ecom_core_currencies }
41
+ t.references :company,
42
+ null: false,
43
+ index: { name: 'project_on_company_indx' },
44
+ foreign_key: { to_table: :ecom_core_companies }
23
45
 
24
46
  t.timestamps
25
47
  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
48
  end
34
49
  end
@@ -5,13 +5,16 @@ class CreateEcomCoreTasks < ActiveRecord::Migration[6.0]
5
5
  t.string :name, null: false
6
6
  t.string :description
7
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' }
8
+ t.references :project,
9
+ null: false,
10
+ index: { name: 'tasks_on_project_indx' },
11
+ foreign_key: { to_table: :ecom_core_projects }
12
+ t.references :task_template,
13
+ null: false,
14
+ index: { name: 'tt_on_project_indx' },
15
+ foreign_key: { to_table: :ecom_core_task_templates }
10
16
 
11
17
  t.timestamps
12
18
  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
19
  end
17
20
  end
@@ -1,16 +1,17 @@
1
1
  class CreateTaskTemplatesResourceTypes < ActiveRecord::Migration[6.0]
2
2
  def change
3
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
4
+ t.references :task_template,
5
+ null: false,
6
+ index: false,
7
+ foreign_key: { to_table: :ecom_core_task_templates }
8
+ t.references :resource_type,
9
+ null: false,
10
+ index: false,
11
+ foreign_key: { to_table: :ecom_core_resource_types }
6
12
  end
7
13
 
8
14
  add_index :ecom_core_task_templates_resource_types, %i[task_template_id resource_type_id],
9
15
  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
16
  end
16
17
  end
@@ -6,19 +6,22 @@ class CreateEcomCoreUsers < ActiveRecord::Migration[6.0]
6
6
  t.string :email, null: false
7
7
  t.boolean :active, null: false, default: true
8
8
  t.string :password_digest
9
+ t.jsonb :projects
9
10
 
10
11
  t.timestamps
11
12
  end
12
13
 
13
14
  create_table :ecom_core_application_modules_users, id: false do |t|
14
- t.references :user, index: false
15
- t.references :application_module, index: false
15
+ t.references :user,
16
+ null: false,
17
+ index: false,
18
+ foreign_key: { to_table: :ecom_core_users }
19
+ t.references :application_module,
20
+ null: false,
21
+ index: false,
22
+ foreign_key: { to_table: :ecom_core_application_modules }
16
23
  end
17
24
 
18
25
  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
26
  end
24
27
  end
@@ -2,21 +2,26 @@ class CreateEcomCoreUserRoles < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_user_roles do |t|
4
4
  t.string :name, index: false
5
- t.references :application_module, index: { name: 'ur_on_am_indx' }
5
+ t.references :application_module,
6
+ null: false,
7
+ index: { name: 'ur_on_am_indx' },
8
+ foreign_key: { to_table: :ecom_core_application_modules }
6
9
 
7
10
  t.timestamps
8
11
  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
12
 
13
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
14
+ t.references :user,
15
+ null: false,
16
+ index: false,
17
+ foreign_key: { to_table: :ecom_core_users }
18
+ t.references :user_role,
19
+ null: false,
20
+ index: false,
21
+ foreign_key: { to_table: :ecom_core_user_roles }
16
22
  end
17
23
 
24
+ add_index :ecom_core_user_roles, %i[name application_module_id], unique: true, name: 'am_name_indx'
18
25
  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
26
  end
22
27
  end
@@ -4,22 +4,29 @@ class CreateEcomCoreMenus < ActiveRecord::Migration[6.0]
4
4
  t.string :label, null: false
5
5
  t.string :icon
6
6
  t.string :route, null: false
7
- t.references :parent, index: { name: 'menus_on_menus_indx' }
8
- t.references :application_module, index: { name: 'menus_on_am_indx' }
7
+ t.references :parent,
8
+ null: true,
9
+ index: false,
10
+ foreign_key: { to_table: :ecom_core_menus }
11
+ t.references :application_module,
12
+ null: false,
13
+ index: { name: 'menus_on_am_indx' },
14
+ foreign_key: { to_table: :ecom_core_application_modules }
9
15
 
10
16
  t.timestamps
11
17
  end
12
18
 
13
- add_foreign_key :ecom_core_menus, :ecom_core_menus, column: :parent_id
14
- add_foreign_key :ecom_core_menus, :ecom_core_application_modules, column: :application_module_id
15
-
16
19
  create_table :ecom_core_menus_user_roles, id: false do |t|
17
- t.references :menu, index: false
18
- t.references :user_role, index: false
20
+ t.references :menu,
21
+ null: false,
22
+ index: false,
23
+ foreign_key: { to_table: :ecom_core_menus }
24
+ t.references :user_role,
25
+ null: false,
26
+ index: false,
27
+ foreign_key: { to_table: :ecom_core_user_roles }
19
28
  end
20
29
 
21
30
  add_index :ecom_core_menus_user_roles, %i[menu_id user_role_id], unique: true, name: 'menus_user_roles_indx'
22
- add_foreign_key :ecom_core_menus_user_roles, :ecom_core_menus, column: :menu_id
23
- add_foreign_key :ecom_core_menus_user_roles, :ecom_core_user_roles, column: :user_role_id
24
31
  end
25
32
  end
@@ -6,30 +6,44 @@ class CreateEcomCoreWorkProducts < ActiveRecord::Migration[6.0]
6
6
  t.string :description
7
7
  t.string :design_reference_no, unique: true
8
8
  t.json :dimension
9
- t.references :task, index: { name: 'task_on_wp_indx' }
10
- t.references :work_product_template, index: { name: 'wpt_on_wp_indx' }
11
- t.references :project, index: { name: 'projects_on_wp_indx' }
9
+ t.references :task,
10
+ null: false,
11
+ index: { name: 'task_on_wp_indx' },
12
+ foreign_key: { to_table: :ecom_core_tasks }
13
+ t.references :work_product_template,
14
+ null: false,
15
+ index: { name: 'wpt_on_wp_indx' },
16
+ foreign_key: { to_table: :ecom_core_work_product_templates }
17
+ t.references :project,
18
+ null: false,
19
+ index: { name: 'projects_on_wp_indx' },
20
+ foreign_key: { to_table: :ecom_core_projects }
12
21
  t.string :assignment_status, default: 'UNASSIGNED'
13
22
  t.string :task_status, default: 'NEW'
14
23
  t.integer :percent_completed
15
24
  t.string :remark
16
- t.references :performer, index: { name: 'pr_on_work_product_indx' }
17
- t.references :approver, index: { name: 'app_on_work_product_indx' }
18
- t.references :supervisor, index: { name: 'sup_on_work_product_indx' }
19
- t.references :quality_controller, index: { name: 'qut_ctr_on_work_product_indx' }
25
+ t.references :performer,
26
+ null: true,
27
+ index: false,
28
+ foreign_key: { to_table: :ecom_core_users }
29
+ t.references :approver,
30
+ null: true,
31
+ index: false,
32
+ foreign_key: { to_table: :ecom_core_users }
33
+ t.references :supervisor,
34
+ null: true,
35
+ index: false,
36
+ foreign_key: { to_table: :ecom_core_users }
37
+ t.references :quality_controller,
38
+ null: true,
39
+ index: false,
40
+ foreign_key: { to_table: :ecom_core_users }
20
41
  t.datetime :start_date
21
42
  t.datetime :completion_date
22
43
 
23
44
  t.timestamps
24
45
  end
46
+
25
47
  add_index :ecom_core_work_products, %i[code project_id], unique: true
26
- add_foreign_key :ecom_core_work_products, :ecom_core_tasks, column: :task_id
27
- add_foreign_key :ecom_core_work_products, :ecom_core_work_product_templates,
28
- column: :work_product_template_id
29
- add_foreign_key :ecom_core_work_products, :ecom_core_projects, column: :project_id
30
- add_foreign_key :ecom_core_work_products, :ecom_core_users, column: :performer_id
31
- add_foreign_key :ecom_core_work_products, :ecom_core_users, column: :approver_id
32
- add_foreign_key :ecom_core_work_products, :ecom_core_users, column: :supervisor_id
33
- add_foreign_key :ecom_core_work_products, :ecom_core_users, column: :quality_controller_id
34
48
  end
35
49
  end