ecom_core 1.2.34 → 1.2.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ecom/core/{project_crews_controller.rb → site_crews_controller.rb} +5 -4
- data/app/models/ecom/core/attendance_sheet.rb +19 -19
- data/app/models/ecom/core/available_unit_of_measurement.rb +10 -0
- data/app/models/ecom/core/crew.rb +3 -2
- data/app/models/ecom/core/crew_contract.rb +41 -1
- data/app/models/ecom/core/crew_contract_transaction.rb +29 -0
- data/app/models/ecom/core/crew_id_card.rb +36 -0
- data/app/models/ecom/core/inspection_checklist.rb +6 -0
- data/app/models/ecom/core/material.rb +6 -0
- data/app/models/ecom/core/material_identity.rb +21 -0
- data/app/models/ecom/core/material_item.rb +18 -0
- data/app/models/ecom/core/material_sub_type.rb +20 -0
- data/app/models/ecom/core/overtime_sheet.rb +13 -15
- data/app/models/ecom/core/payroll.rb +3 -3
- data/app/models/ecom/core/project.rb +0 -3
- data/app/models/ecom/core/project_template.rb +11 -0
- data/app/models/ecom/core/project_work_item_template.rb +9 -0
- data/app/models/ecom/core/{project_crew.rb → site.rb} +8 -4
- data/app/models/ecom/core/site_crew.rb +27 -0
- data/app/models/ecom/core/task.rb +22 -5
- data/app/models/ecom/core/task_inspection_checklist.rb +18 -0
- data/app/models/ecom/core/task_template.rb +18 -90
- data/app/models/ecom/core/task_template_inspection_checklist.rb +8 -0
- data/app/models/ecom/core/work_package.rb +3 -0
- data/app/models/ecom/core/work_product.rb +2 -18
- data/app/models/ecom/core/work_product_template.rb +2 -2
- data/app/services/ecom/core/crew_contract_transaction_service.rb +89 -0
- data/app/services/ecom/core/site_crew_service.rb +44 -0
- data/config/routes.rb +2 -2
- data/db/migrate/20191119012030_create_ecom_core_task_templates.rb +6 -8
- data/db/migrate/20191119013236_create_ecom_core_work_product_templates.rb +0 -15
- data/db/migrate/20191119021405_create_ecom_core_project_templates.rb +15 -0
- data/db/migrate/20191119034319_create_ecom_core_project_work_item_templates.rb +20 -0
- data/db/migrate/20191201145849_create_ecom_core_sites.rb +16 -0
- data/db/migrate/20191202222210_create_ecom_core_work_packages.rb +12 -0
- data/db/migrate/20191202235434_create_ecom_core_work_products.rb +2 -17
- data/db/migrate/20191207103735_create_ecom_core_tasks.rb +14 -6
- data/db/migrate/20191225140433_create_ecom_core_attendance_sheets.rb +4 -4
- data/db/migrate/20200126081005_create_ecom_core_payrolls.rb +3 -3
- data/db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb +4 -4
- data/db/migrate/20200616044231_create_ecom_core_material_sub_types.rb +14 -0
- data/db/migrate/20200616051902_create_ecom_core_material_identities.rb +17 -0
- data/db/migrate/20200618105233_create_ecom_core_material_items.rb +16 -0
- data/db/migrate/20200813165555_create_ecom_core_available_unit_of_measurements.rb +16 -0
- data/db/migrate/20200901085227_create_ecom_core_crew_contracts.rb +7 -1
- data/db/migrate/20201013072924_create_ecom_core_crew_contract_transactions.rb +16 -0
- data/db/migrate/20201013090609_create_ecom_core_site_crews.rb.rb +22 -0
- data/db/migrate/20201013094100_create_ecom_core_crew_id_cards.rb +16 -0
- data/db/migrate/20201113050953_create_ecom_core_task_inspection_checklists.rb +22 -0
- data/db/migrate/20201113094302_create_ecom_core_task_template_inspection_checklists.rb +17 -0
- data/lib/ecom/core/version.rb +1 -1
- data/spec/factories/ecom/core/attendance_sheets.rb +1 -1
- data/spec/factories/ecom/core/available_unit_of_measurements.rb +6 -0
- data/spec/factories/ecom/core/crew_contract_transactions.rb +8 -0
- data/spec/factories/ecom/core/crew_contracts.rb +12 -0
- data/spec/factories/ecom/core/crew_id_cards.rb +8 -0
- data/spec/factories/{dimension_elements.rb → ecom/core/dimension_elements.rb} +0 -0
- data/spec/factories/ecom/core/inspection_checklists.rb +5 -0
- data/spec/factories/ecom/core/material_identities.rb +6 -0
- data/spec/factories/ecom/core/material_items.rb +6 -0
- data/spec/factories/ecom/core/material_sub_types.rb +6 -0
- data/spec/factories/ecom/core/materials.rb +5 -0
- data/spec/factories/{measurement_units.rb → ecom/core/measurement_units.rb} +6 -0
- data/spec/factories/ecom/core/overtime_sheets.rb +1 -1
- data/spec/factories/ecom/core/payrolls.rb +1 -1
- data/spec/factories/ecom/core/project_templates.rb +8 -0
- data/spec/factories/ecom/core/project_work_item_templates.rb +7 -0
- data/spec/factories/ecom/core/site_crews.rb +10 -0
- data/spec/factories/ecom/core/sites.rb +8 -0
- data/spec/factories/ecom/core/task_inspection_checklists.rb +11 -0
- data/spec/factories/ecom/core/task_template_inspection_checklists.rb +7 -0
- data/spec/factories/ecom/core/task_templates.rb +10 -6
- data/spec/factories/ecom/core/tasks.rb +8 -3
- data/spec/factories/ecom/core/work_packages.rb +6 -0
- data/spec/factories/ecom/core/work_product_templates.rb +0 -1
- data/spec/factories/ecom/core/work_products.rb +1 -7
- metadata +48 -20
- data/app/controllers/concerns/ecom/core/filterable.rb +0 -14
- data/app/models/ecom/core/takeoff_calculator.rb +0 -115
- data/app/models/ecom/core/task_step.rb +0 -85
- data/app/models/ecom/core/task_step_dependency.rb +0 -10
- data/app/services/ecom/core/project_crew_service.rb +0 -39
- data/db/migrate/20191119012027_create_ecom_core_takeoff_calculators.rb +0 -11
- data/db/migrate/20191225121850_create_ecom_core_project_crews.rb +0 -19
- data/db/migrate/20200820123719_create_ecom_core_task_steps.rb +0 -17
- data/db/migrate/20200821130934_create_ecom_core_task_step_dependencies.rb +0 -16
- data/spec/factories/ecom/core/project_crews.rb +0 -9
- data/spec/factories/ecom/core/takeoff_calculators.rb +0 -18
- data/spec/factories/ecom/core/task_step_dependencies.rb +0 -6
- data/spec/factories/ecom/core/task_steps.rb +0 -8
@@ -9,9 +9,6 @@ module Ecom
|
|
9
9
|
belongs_to :currency
|
10
10
|
belongs_to :company
|
11
11
|
|
12
|
-
has_many :project_crews
|
13
|
-
has_many :crews, through: :project_crews
|
14
|
-
|
15
12
|
validates :name, :location, :contract_number, :date_contract_signed, :commencement_date, :completion_date,
|
16
13
|
:contract_amount, :advance_payment, :retention, presence: true
|
17
14
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module Ecom
|
2
2
|
module Core
|
3
|
-
class
|
3
|
+
class Site < ApplicationRecord
|
4
4
|
ACTIVE = 'Active'.freeze
|
5
5
|
INACTIVE = 'Inactive'.freeze
|
6
|
+
|
6
7
|
STATUSES = [ACTIVE, INACTIVE].freeze
|
7
8
|
|
8
|
-
|
9
|
-
belongs_to :crew
|
9
|
+
validates :name, :project_id, :project, :address, :status, presence: true
|
10
10
|
|
11
|
-
validates :start_date, :status, presence: true
|
12
11
|
validates :status, inclusion: STATUSES
|
12
|
+
|
13
|
+
belongs_to :project
|
14
|
+
|
15
|
+
has_many :site_crews
|
16
|
+
has_many :crews, through: :site_crews
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class SiteCrew < ApplicationRecord
|
4
|
+
TEMPORARY_SITE_CREW = 'Temporary site crew'.freeze
|
5
|
+
PERMANENT_SITE_CREW = 'Permanent site crew'.freeze
|
6
|
+
|
7
|
+
SITE_CREW_TYPES = [TEMPORARY_SITE_CREW, PERMANENT_SITE_CREW].freeze
|
8
|
+
|
9
|
+
ACTIVE = 'Active'.freeze
|
10
|
+
INACTIVE = 'Inactive'.freeze
|
11
|
+
STATUSES = [ACTIVE, INACTIVE].freeze
|
12
|
+
|
13
|
+
validates :crew_id, :crew, :site_id, :site, :start_date, :site_crew_type, :status, presence: true
|
14
|
+
|
15
|
+
validates_uniqueness_of :site_id,
|
16
|
+
scope: :crew_id,
|
17
|
+
conditions: -> { where(status: 'Active') },
|
18
|
+
message: 'There can only be one record with status `Active` for a given site and crew'
|
19
|
+
|
20
|
+
validates :site_crew_type, inclusion: SITE_CREW_TYPES
|
21
|
+
validates :status, inclusion: STATUSES
|
22
|
+
|
23
|
+
belongs_to :crew
|
24
|
+
belongs_to :site
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -5,26 +5,43 @@ module Ecom
|
|
5
5
|
|
6
6
|
has_ancestry
|
7
7
|
|
8
|
+
NOT_INSPECTED = 'Not Inspected'.freeze
|
9
|
+
IN_PROGRESS = 'In Progress'.freeze
|
10
|
+
PASS = 'Pass'.freeze
|
11
|
+
FAIL = 'Fail'.freeze
|
12
|
+
|
13
|
+
INSPECTION_STATUSES = [NOT_INSPECTED, IN_PROGRESS, PASS, FAIL].freeze
|
14
|
+
|
8
15
|
belongs_to :work_product
|
9
16
|
belongs_to :task_template
|
10
17
|
belongs_to :work_package, optional: true
|
11
18
|
belongs_to :work_order, optional: true
|
12
19
|
belongs_to :plan, optional: true
|
13
20
|
belongs_to :performer, class_name: 'Ecom::Core::User', optional: true
|
14
|
-
belongs_to :
|
15
|
-
belongs_to :
|
16
|
-
belongs_to :
|
21
|
+
belongs_to :client_consultant, class_name: 'Ecom::Core::User', optional: true
|
22
|
+
belongs_to :foreman, class_name: 'Ecom::Core::User', optional: true
|
23
|
+
belongs_to :inspector, class_name: 'Ecom::Core::User', optional: true
|
24
|
+
belongs_to :change_order_for, class_name: 'Ecom::Core::User', optional: true
|
17
25
|
|
18
|
-
has_many :task_steps
|
19
26
|
has_many :task_resources
|
20
27
|
has_one :takeoff
|
28
|
+
has_one :change_order, foreign_key: :change_order_for_id, class_name: 'Ecom::Core::Task'
|
21
29
|
|
22
30
|
validates_with DateRangeValidator
|
23
|
-
validates :code, :name, :status, :percent_completed, presence: true
|
31
|
+
validates :code, :name, :status, :inspection_status, :percent_completed, presence: true
|
24
32
|
validates_numericality_of :percent_completed,
|
25
33
|
only_integer: true,
|
26
34
|
greater_than_or_equal_to: 0,
|
27
35
|
less_than_or_equal_to: 100
|
36
|
+
validates :percentage_contribution,
|
37
|
+
numericality: {
|
38
|
+
greater_than_or_equal_to: 0,
|
39
|
+
less_than_or_equal_to: 100,
|
40
|
+
only_integer: true
|
41
|
+
},
|
42
|
+
allow_nil: true
|
43
|
+
|
44
|
+
validates_inclusion_of :inspection_status, in: INSPECTION_STATUSES
|
28
45
|
|
29
46
|
scope :by_status, ->(status) { where(status: status) }
|
30
47
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class TaskInspectionChecklist < ApplicationRecord
|
4
|
+
NOT_INSPECTED = 'Not Inspected'.freeze
|
5
|
+
IN_PROGRESS = 'In Progress'.freeze
|
6
|
+
PASS = 'Pass'.freeze
|
7
|
+
FAIL = 'Fail'.freeze
|
8
|
+
|
9
|
+
INSPECTION_STATUSES = [NOT_INSPECTED, IN_PROGRESS, PASS, FAIL].freeze
|
10
|
+
|
11
|
+
belongs_to :inspected_by, class_name: 'Ecom::Core::User'
|
12
|
+
belongs_to :task
|
13
|
+
|
14
|
+
validates :name, :status, presence: true
|
15
|
+
validates :status, inclusion: INSPECTION_STATUSES
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,57 +1,28 @@
|
|
1
|
-
require 'json-schema'
|
2
1
|
module Ecom
|
3
2
|
module Core
|
4
3
|
class TaskTemplate < ApplicationRecord
|
5
|
-
TASK_STEP_SCHEMA = {
|
6
|
-
'type' => 'object',
|
7
|
-
'required' => %w[name total_contribution_percentage_to_task],
|
8
|
-
'additionalProperties' => false,
|
9
|
-
'properties' => {
|
10
|
-
'name' => { 'type' => 'string' },
|
11
|
-
'total_contribution_percentage_to_task' => {
|
12
|
-
'type' => 'integer',
|
13
|
-
'minimum' => 1,
|
14
|
-
'maximum' => 100
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
# here the json schema has a bug ( including all properties as required)
|
20
|
-
# and because task_step_name is required on a condition ( only if the
|
21
|
-
# milestone is after a task step ), we can solve this with a workaround
|
22
|
-
# by specifying task_step_name in patternProperties.
|
23
|
-
MILESTONE_SCHEMA = {
|
24
|
-
'type' => 'object',
|
25
|
-
'required' => %w[name is_after_task_step],
|
26
|
-
'additionalProperties' => false,
|
27
|
-
'properties' => {
|
28
|
-
'name' => { 'type' => 'string' },
|
29
|
-
'is_after_task_step' => {
|
30
|
-
'type' => 'boolean'
|
31
|
-
}
|
32
|
-
},
|
33
|
-
"patternProperties": {
|
34
|
-
"task_step_name": {
|
35
|
-
'type' => 'string'
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}.freeze
|
39
|
-
|
40
4
|
has_ancestry
|
41
5
|
|
42
6
|
belongs_to :task_template_type
|
43
|
-
|
7
|
+
has_many :task_template_inspection_checklists
|
8
|
+
has_many :inspection_checklists, through: :task_template_inspection_checklists
|
9
|
+
has_many :project_work_item_templates
|
10
|
+
has_many :work_product_templates, through: :project_work_item_templates
|
44
11
|
has_and_belongs_to_many :resource_types, join_table: 'ecom_core_task_templates_resource_types'
|
45
|
-
belongs_to :takeoff_calculator, optional: true
|
46
12
|
|
47
|
-
validates :name, :code, presence: true
|
13
|
+
validates :name, :code, :takeoff_fields, :task_completion_detail, presence: true
|
48
14
|
validates :code, uniqueness: true
|
15
|
+
validates :percentage_contribution,
|
16
|
+
numericality: {
|
17
|
+
greater_than_or_equal_to: 0,
|
18
|
+
less_than_or_equal_to: 100,
|
19
|
+
only_integer: true
|
20
|
+
},
|
21
|
+
allow_nil: true
|
22
|
+
|
49
23
|
delegate(:name, to: :task_template_type, prefix: true)
|
50
24
|
|
51
|
-
validate :
|
52
|
-
validate :milestones_schema_validator
|
53
|
-
validate :validate_sum_of_task_step_contribution
|
54
|
-
validate :validate_milestone_task_step_association
|
25
|
+
validate :percentage_contribution_sum_validator
|
55
26
|
|
56
27
|
def full_name
|
57
28
|
parent_name = parent&.name
|
@@ -72,54 +43,11 @@ module Ecom
|
|
72
43
|
resource_types.where(type: 'Ecom::Core::EquipmentType')
|
73
44
|
end
|
74
45
|
|
75
|
-
def
|
76
|
-
return if
|
77
|
-
|
78
|
-
validation_errors = JSON::Validator.fully_validate(TASK_STEP_SCHEMA,
|
79
|
-
task_steps, strict: true,
|
80
|
-
list: true, clear_cache: true)
|
81
|
-
|
82
|
-
errors.add(:task_steps, validation_errors) unless validation_errors.empty?
|
83
|
-
end
|
84
|
-
|
85
|
-
def milestones_schema_validator
|
86
|
-
return if milestones.nil?
|
87
|
-
|
88
|
-
validation_errors = JSON::Validator.fully_validate(MILESTONE_SCHEMA,
|
89
|
-
milestones, strict: true,
|
90
|
-
list: true, clear_cache: true)
|
91
|
-
|
92
|
-
errors.add(:milestones, validation_errors) unless validation_errors.empty?
|
93
|
-
end
|
94
|
-
|
95
|
-
def validate_sum_of_task_step_contribution
|
96
|
-
return if task_steps.nil?
|
97
|
-
|
98
|
-
filtered_task_steps = task_steps.select { |task_step| task_step['total_contribution_percentage_to_task'] }
|
99
|
-
|
100
|
-
sum_of_task_step_contribution =
|
101
|
-
filtered_task_steps.sum { |task_step| task_step['total_contribution_percentage_to_task'] }
|
102
|
-
|
103
|
-
errors.add(:task_steps, 'Sum of task step contributions has to be 100') if sum_of_task_step_contribution != 100
|
104
|
-
end
|
105
|
-
|
106
|
-
def validate_milestone_task_step_association
|
107
|
-
return if milestones.nil?
|
108
|
-
|
109
|
-
task_step_names = task_steps&.map { |task_step| task_step['name'] }
|
110
|
-
|
111
|
-
milestones_associated_with_task_step = milestones.select { |milestone| milestone['is_after_task_step'] }
|
112
|
-
|
113
|
-
milestones_associated_with_task_step.each do |milestone|
|
114
|
-
if milestone['task_step_name'].nil?
|
115
|
-
errors.add(:milestones, 'if the milestone is after a task step, please specify the task step name')
|
116
|
-
next
|
117
|
-
end
|
46
|
+
def percentage_contribution_sum_validator
|
47
|
+
return if percentage_contribution.nil?
|
118
48
|
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
49
|
+
sum = siblings.sum(:percentage_contribution)
|
50
|
+
errors.add(:task, 'Sum of percentage contributions has to be 100') if sum > 100
|
123
51
|
end
|
124
52
|
end
|
125
53
|
end
|
@@ -2,9 +2,12 @@ module Ecom
|
|
2
2
|
module Core
|
3
3
|
class WorkPackage < ApplicationRecord
|
4
4
|
belongs_to :project
|
5
|
+
belongs_to :site_engineer, class_name: 'Ecom::Core::User', optional: true
|
6
|
+
belongs_to :project_manager, class_name: 'Ecom::Core::User', optional: true
|
5
7
|
|
6
8
|
validates :code, :name, presence: true
|
7
9
|
validates :code, uniqueness: true
|
10
|
+
validates :budget, numericality: true, unless: proc { budget.nil? }
|
8
11
|
|
9
12
|
has_many :tasks
|
10
13
|
end
|
@@ -15,30 +15,14 @@
|
|
15
15
|
module Ecom
|
16
16
|
module Core
|
17
17
|
class WorkProduct < ApplicationRecord
|
18
|
-
include AASM
|
19
|
-
|
20
|
-
NEW = 'New'.freeze
|
21
|
-
UNDER_CONSTRUCTION = 'Under Construction'.freeze
|
22
|
-
COMPLETED = 'Completed'.freeze
|
23
|
-
|
24
|
-
STATUSES = [NEW, UNDER_CONSTRUCTION, COMPLETED].freeze
|
25
|
-
|
26
18
|
belongs_to :work_product_template
|
27
19
|
belongs_to :project
|
28
20
|
belongs_to :product_group, optional: true
|
29
|
-
belongs_to :approver, class_name: 'Ecom::Core::User', optional: true
|
30
|
-
belongs_to :supervisor, class_name: 'Ecom::Core::User', optional: true
|
31
|
-
belongs_to :quality_controller, class_name: 'Ecom::Core::User', optional: true
|
32
21
|
has_many :tasks
|
33
22
|
has_many :dimension_elements
|
34
23
|
|
35
|
-
validates :name, :
|
36
|
-
validates :
|
37
|
-
validates :status, inclusion: STATUSES
|
38
|
-
validates_numericality_of :percent_completed,
|
39
|
-
only_integer: true,
|
40
|
-
greater_than_or_equal_to: 0,
|
41
|
-
less_than_or_equal_to: 100
|
24
|
+
validates :name, :design_reference, presence: true
|
25
|
+
validates :design_reference, uniqueness: { scope: :project_id }
|
42
26
|
end
|
43
27
|
end
|
44
28
|
end
|
@@ -2,8 +2,8 @@ module Ecom
|
|
2
2
|
module Core
|
3
3
|
class WorkProductTemplate < ApplicationRecord
|
4
4
|
validates :code, :name, presence: true, uniqueness: true
|
5
|
-
|
6
|
-
|
5
|
+
has_many :project_work_item_templates
|
6
|
+
has_many :task_templates, through: :project_work_item_templates
|
7
7
|
has_many :product_types
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class CrewContractTransactionService
|
4
|
+
def execute(transaction_type, crew_contract)
|
5
|
+
Ecom::Core::CrewContractTransaction.transaction do
|
6
|
+
case transaction_type
|
7
|
+
when Ecom::Core::CrewContractTransaction::TXN_UPDATE_CREW_TYPE
|
8
|
+
|
9
|
+
create_new_id_card(crew_contract.crew, crew_contract.to)
|
10
|
+
# update crew type
|
11
|
+
crew = crew_contract.crew
|
12
|
+
crew.update(crew_type_id: crew_contract.crew_type_id)
|
13
|
+
|
14
|
+
when Ecom::Core::CrewContractTransaction::TXN_UPDATE_PLACE_OF_WORK
|
15
|
+
|
16
|
+
create_new_id_card(crew_contract.crew, crew_contract.to)
|
17
|
+
|
18
|
+
when Ecom::Core::CrewContractTransaction::TXN_UPDATE_WAGE
|
19
|
+
|
20
|
+
crew = crew_contract.crew
|
21
|
+
# update wage
|
22
|
+
crew.update(wage: crew_contract.wage, wage_in_words: crew_contract.wage_in_words)
|
23
|
+
|
24
|
+
when Ecom::Core::CrewContractTransaction::TXN_UPDATE_VALIDITY
|
25
|
+
|
26
|
+
# make crew active
|
27
|
+
create_new_id_card(crew_contract.crew, crew_contract.to)
|
28
|
+
make_crew_active(crew_contract.crew)
|
29
|
+
activate_contract(crew_contract)
|
30
|
+
|
31
|
+
when Ecom::Core::CrewContractTransaction::TXN_TERMINATE_CONTRACT
|
32
|
+
|
33
|
+
# make crew inactive
|
34
|
+
make_crew_inactive(crew_contract.crew)
|
35
|
+
|
36
|
+
# make ID card invalid
|
37
|
+
invalidate_id_card(crew_contract.crew)
|
38
|
+
|
39
|
+
# make the contract void
|
40
|
+
deactivate_contract(crew_contract)
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def activate_contract(crew_contract)
|
47
|
+
crew_contract.update(status: :in_effect)
|
48
|
+
end
|
49
|
+
|
50
|
+
def deactivate_contract(crew_contract)
|
51
|
+
crew_contract.update(status: :void)
|
52
|
+
end
|
53
|
+
|
54
|
+
def make_crew_active(crew)
|
55
|
+
return if crew.active
|
56
|
+
|
57
|
+
crew.update(active: true)
|
58
|
+
end
|
59
|
+
|
60
|
+
def make_crew_inactive(crew)
|
61
|
+
return unless crew.active
|
62
|
+
|
63
|
+
crew.update(active: false)
|
64
|
+
end
|
65
|
+
|
66
|
+
# invalidate other Id cards and creates a new ID card
|
67
|
+
def create_new_id_card(crew, valid_until)
|
68
|
+
issued_on = Time.now
|
69
|
+
|
70
|
+
previous_id_card = Ecom::Core::CrewIdCard.where(crew_id: crew.id).last
|
71
|
+
|
72
|
+
previous_id_card&.update(status: 'Invalid')
|
73
|
+
|
74
|
+
new_id_card = Ecom::Core::CrewIdCard.new(
|
75
|
+
crew_id: crew.id,
|
76
|
+
issued_on: issued_on,
|
77
|
+
valid_until: valid_until,
|
78
|
+
status: 'Valid'
|
79
|
+
)
|
80
|
+
raise StandardError, new_id_card.errors.messages unless new_id_card.save
|
81
|
+
end
|
82
|
+
|
83
|
+
def invalidate_id_card(crew)
|
84
|
+
current_id_card = Ecom::Core::CrewIdCard.where(crew_id: crew.id).last
|
85
|
+
current_id_card.update(status: 'Invalid')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class SiteCrewService
|
4
|
+
def update(params)
|
5
|
+
id = params[:site_id]
|
6
|
+
crew = params[:crew]
|
7
|
+
|
8
|
+
# Process new additions
|
9
|
+
new_crew = crew.select { |c| c[:status] == 'checked' }
|
10
|
+
removed = crew.select { |c| c[:status] == 'unchecked' }
|
11
|
+
|
12
|
+
crew_ids = new_crew.map { |c| c[:crew_id] }
|
13
|
+
|
14
|
+
site_crew = Ecom::Core::Crew.where(id: crew_ids)
|
15
|
+
|
16
|
+
new_entries = []
|
17
|
+
new_crew.each do |nc|
|
18
|
+
new_entries << Ecom::Core::SiteCrew.new(
|
19
|
+
site_id: id, crew_id: nc[:crew_id], start_date: Date.today,
|
20
|
+
site_crew_type: 'Temporary site crew',
|
21
|
+
status: 'Active'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
Ecom::Core::SiteCrew.transaction do
|
26
|
+
new_entries.each(&:save)
|
27
|
+
end
|
28
|
+
|
29
|
+
removed_ids = removed.map { |r| r[:crew_id] }
|
30
|
+
if removed_ids.count.positive?
|
31
|
+
removed_crews = Ecom::Core::SiteCrew.where(site_id: id, crew_id: removed_ids, status: 'Active')
|
32
|
+
Ecom::Core::SiteCrew.transaction do
|
33
|
+
# removed_crew.map(&:delete)
|
34
|
+
removed_crews.each do |removed_crew|
|
35
|
+
removed_crew.update(status: 'Inactive')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
{ success: true, data: site_crew }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|