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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ecom/core/{project_crews_controller.rb → site_crews_controller.rb} +5 -4
  3. data/app/models/ecom/core/attendance_sheet.rb +19 -19
  4. data/app/models/ecom/core/available_unit_of_measurement.rb +10 -0
  5. data/app/models/ecom/core/crew.rb +3 -2
  6. data/app/models/ecom/core/crew_contract.rb +41 -1
  7. data/app/models/ecom/core/crew_contract_transaction.rb +29 -0
  8. data/app/models/ecom/core/crew_id_card.rb +36 -0
  9. data/app/models/ecom/core/inspection_checklist.rb +6 -0
  10. data/app/models/ecom/core/material.rb +6 -0
  11. data/app/models/ecom/core/material_identity.rb +21 -0
  12. data/app/models/ecom/core/material_item.rb +18 -0
  13. data/app/models/ecom/core/material_sub_type.rb +20 -0
  14. data/app/models/ecom/core/overtime_sheet.rb +13 -15
  15. data/app/models/ecom/core/payroll.rb +3 -3
  16. data/app/models/ecom/core/project.rb +0 -3
  17. data/app/models/ecom/core/project_template.rb +11 -0
  18. data/app/models/ecom/core/project_work_item_template.rb +9 -0
  19. data/app/models/ecom/core/{project_crew.rb → site.rb} +8 -4
  20. data/app/models/ecom/core/site_crew.rb +27 -0
  21. data/app/models/ecom/core/task.rb +22 -5
  22. data/app/models/ecom/core/task_inspection_checklist.rb +18 -0
  23. data/app/models/ecom/core/task_template.rb +18 -90
  24. data/app/models/ecom/core/task_template_inspection_checklist.rb +8 -0
  25. data/app/models/ecom/core/work_package.rb +3 -0
  26. data/app/models/ecom/core/work_product.rb +2 -18
  27. data/app/models/ecom/core/work_product_template.rb +2 -2
  28. data/app/services/ecom/core/crew_contract_transaction_service.rb +89 -0
  29. data/app/services/ecom/core/site_crew_service.rb +44 -0
  30. data/config/routes.rb +2 -2
  31. data/db/migrate/20191119012030_create_ecom_core_task_templates.rb +6 -8
  32. data/db/migrate/20191119013236_create_ecom_core_work_product_templates.rb +0 -15
  33. data/db/migrate/20191119021405_create_ecom_core_project_templates.rb +15 -0
  34. data/db/migrate/20191119034319_create_ecom_core_project_work_item_templates.rb +20 -0
  35. data/db/migrate/20191201145849_create_ecom_core_sites.rb +16 -0
  36. data/db/migrate/20191202222210_create_ecom_core_work_packages.rb +12 -0
  37. data/db/migrate/20191202235434_create_ecom_core_work_products.rb +2 -17
  38. data/db/migrate/20191207103735_create_ecom_core_tasks.rb +14 -6
  39. data/db/migrate/20191225140433_create_ecom_core_attendance_sheets.rb +4 -4
  40. data/db/migrate/20200126081005_create_ecom_core_payrolls.rb +3 -3
  41. data/db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb +4 -4
  42. data/db/migrate/20200616044231_create_ecom_core_material_sub_types.rb +14 -0
  43. data/db/migrate/20200616051902_create_ecom_core_material_identities.rb +17 -0
  44. data/db/migrate/20200618105233_create_ecom_core_material_items.rb +16 -0
  45. data/db/migrate/20200813165555_create_ecom_core_available_unit_of_measurements.rb +16 -0
  46. data/db/migrate/20200901085227_create_ecom_core_crew_contracts.rb +7 -1
  47. data/db/migrate/20201013072924_create_ecom_core_crew_contract_transactions.rb +16 -0
  48. data/db/migrate/20201013090609_create_ecom_core_site_crews.rb.rb +22 -0
  49. data/db/migrate/20201013094100_create_ecom_core_crew_id_cards.rb +16 -0
  50. data/db/migrate/20201113050953_create_ecom_core_task_inspection_checklists.rb +22 -0
  51. data/db/migrate/20201113094302_create_ecom_core_task_template_inspection_checklists.rb +17 -0
  52. data/lib/ecom/core/version.rb +1 -1
  53. data/spec/factories/ecom/core/attendance_sheets.rb +1 -1
  54. data/spec/factories/ecom/core/available_unit_of_measurements.rb +6 -0
  55. data/spec/factories/ecom/core/crew_contract_transactions.rb +8 -0
  56. data/spec/factories/ecom/core/crew_contracts.rb +12 -0
  57. data/spec/factories/ecom/core/crew_id_cards.rb +8 -0
  58. data/spec/factories/{dimension_elements.rb → ecom/core/dimension_elements.rb} +0 -0
  59. data/spec/factories/ecom/core/inspection_checklists.rb +5 -0
  60. data/spec/factories/ecom/core/material_identities.rb +6 -0
  61. data/spec/factories/ecom/core/material_items.rb +6 -0
  62. data/spec/factories/ecom/core/material_sub_types.rb +6 -0
  63. data/spec/factories/ecom/core/materials.rb +5 -0
  64. data/spec/factories/{measurement_units.rb → ecom/core/measurement_units.rb} +6 -0
  65. data/spec/factories/ecom/core/overtime_sheets.rb +1 -1
  66. data/spec/factories/ecom/core/payrolls.rb +1 -1
  67. data/spec/factories/ecom/core/project_templates.rb +8 -0
  68. data/spec/factories/ecom/core/project_work_item_templates.rb +7 -0
  69. data/spec/factories/ecom/core/site_crews.rb +10 -0
  70. data/spec/factories/ecom/core/sites.rb +8 -0
  71. data/spec/factories/ecom/core/task_inspection_checklists.rb +11 -0
  72. data/spec/factories/ecom/core/task_template_inspection_checklists.rb +7 -0
  73. data/spec/factories/ecom/core/task_templates.rb +10 -6
  74. data/spec/factories/ecom/core/tasks.rb +8 -3
  75. data/spec/factories/ecom/core/work_packages.rb +6 -0
  76. data/spec/factories/ecom/core/work_product_templates.rb +0 -1
  77. data/spec/factories/ecom/core/work_products.rb +1 -7
  78. metadata +48 -20
  79. data/app/controllers/concerns/ecom/core/filterable.rb +0 -14
  80. data/app/models/ecom/core/takeoff_calculator.rb +0 -115
  81. data/app/models/ecom/core/task_step.rb +0 -85
  82. data/app/models/ecom/core/task_step_dependency.rb +0 -10
  83. data/app/services/ecom/core/project_crew_service.rb +0 -39
  84. data/db/migrate/20191119012027_create_ecom_core_takeoff_calculators.rb +0 -11
  85. data/db/migrate/20191225121850_create_ecom_core_project_crews.rb +0 -19
  86. data/db/migrate/20200820123719_create_ecom_core_task_steps.rb +0 -17
  87. data/db/migrate/20200821130934_create_ecom_core_task_step_dependencies.rb +0 -16
  88. data/spec/factories/ecom/core/project_crews.rb +0 -9
  89. data/spec/factories/ecom/core/takeoff_calculators.rb +0 -18
  90. data/spec/factories/ecom/core/task_step_dependencies.rb +0 -6
  91. data/spec/factories/ecom/core/task_steps.rb +0 -8
@@ -1,14 +0,0 @@
1
- module Ecom
2
- module Core
3
- module Filterable
4
- extend ActiveSupport::Concern
5
-
6
- module ClassMethods
7
- def filter(filtering_params)
8
- results = where(nil)
9
- results.public_send('filter_by_condition', filtering_params) if filtering_params.present?
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,115 +0,0 @@
1
- module Ecom
2
- module Core
3
- class TakeoffCalculator < ApplicationRecord
4
- INPUT_PARAMETERS_SCHEMA = {
5
- 'type' => 'object',
6
- 'required' => %w[name label input_type],
7
- 'additionalProperties' => false,
8
- 'properties' => {
9
- 'name' => { 'type' => 'string' },
10
- 'label' => { 'type' => 'string' },
11
- 'input_type' => {
12
- 'type' => 'string',
13
- 'enum' => %w[string number measurement enum]
14
- }
15
- },
16
- "patternProperties": {
17
- "enum_values": {
18
- 'type' => 'array'
19
- },
20
- "default_value": {
21
- 'type' => 'object',
22
- 'required' => %w[value],
23
- 'properties' => {
24
- 'value' => { 'type' => 'string' }
25
- },
26
- "patternProperties": {
27
- "measurement_unit_id": { 'type' => 'integer' }
28
- }
29
- },
30
- "validation": {
31
- 'type' => 'object',
32
- 'required' => %w[required],
33
- 'properties' => {
34
- 'required' => { 'type' => 'boolean' }
35
- },
36
- "patternProperties": {
37
- "minimum": { 'type' => 'number' },
38
- "maximum": { 'type' => 'number' }
39
- }
40
- }
41
- }
42
- }.freeze
43
-
44
- REBAR_TAKEOFF_CALCULATOR = 'Rebar Takeoff Calculator'.freeze
45
- FORMWORK_TAKEOFF_CALCULATOR = 'Formwork Takeoff Calculator'.freeze
46
- CONCRETE_POURING_TAKEOFF_CALCULATOR =
47
- 'Concrete Pouring Takeoff Calculator'.freeze
48
-
49
- TAKEOFF_CALCULATOR_NAMES =
50
- [
51
- REBAR_TAKEOFF_CALCULATOR,
52
- FORMWORK_TAKEOFF_CALCULATOR,
53
- CONCRETE_POURING_TAKEOFF_CALCULATOR
54
- ].freeze
55
-
56
- validates :name, :input_parameters, presence: true
57
- validates :name, inclusion: TAKEOFF_CALCULATOR_NAMES
58
-
59
- validates :name, uniqueness: true
60
-
61
- validate :input_parameters_schema
62
- validate :measurement_unit_id_in_input_parameters
63
- validate :enum_in_input_parameters
64
-
65
- def input_parameters_schema
66
- return if input_parameters.nil?
67
-
68
- errors.add(:input_parameters, 'There has to be one or more input parameters') if input_parameters.count.zero?
69
-
70
- validation_errors = JSON::Validator.fully_validate(INPUT_PARAMETERS_SCHEMA,
71
- input_parameters, strict: true,
72
- list: true, clear_cache: true)
73
-
74
- errors.add(:input_parameters, validation_errors) unless validation_errors.empty?
75
- end
76
-
77
- def measurement_unit_id_in_input_parameters
78
- return if input_parameters.nil?
79
-
80
- input_parameters.each do |input_parameter|
81
- next unless input_parameter['input_type'] == 'measurement' && !input_parameter['default_value'].nil?
82
-
83
- if input_parameter['default_value']['measurement_unit_id'].nil?
84
- errors.add(:base, 'measurement_unit_id is required')
85
- next
86
- end
87
-
88
- measurement_unit_id = input_parameter['default_value']['measurement_unit_id']
89
- measurement_unit = Ecom::Core::MeasurementUnit.find_by(id: measurement_unit_id)
90
-
91
- errors.add(:base, "measurement unit with id #{measurement_unit_id} does not exist") if measurement_unit.nil?
92
- end
93
- end
94
-
95
- def enum_in_input_parameters
96
- return if input_parameters.nil?
97
-
98
- input_parameters.each do |input_parameter|
99
- next if input_parameter['input_type'] != 'enum'
100
-
101
- if input_parameter['enum_values'].nil?
102
- errors.add(:base, 'enum_values are requiered if the input_type is enum')
103
- next
104
- end
105
-
106
- next unless !input_parameter['enum_values'].nil? &&
107
- input_parameter['enum_values'].class == Array &&
108
- input_parameter['enum_values'].count.zero?
109
-
110
- errors.add(:base, 'Provide at least one enum value')
111
- end
112
- end
113
- end
114
- end
115
- end
@@ -1,85 +0,0 @@
1
- module Ecom
2
- module Core
3
- class TaskStep < ApplicationRecord
4
- include Filterable
5
-
6
- before_save :update_task_progress
7
-
8
- scope :filter_by_condition, ->(condition) { where(condition) }
9
-
10
- validates :name, :total_contribution_percentage_to_task, presence: true
11
- validates_with DateRangeValidator
12
- validate :date_range_validator
13
- validates_numericality_of :total_contribution_percentage_to_task,
14
- greater_than: 0,
15
- less_than_or_equal_to: 100
16
-
17
- validate :task_step_percentage_validator, on: :create
18
-
19
- validate :task_step_in_task_template_inclusion_validator
20
-
21
- belongs_to :task
22
- has_many :dependent_task_steps,
23
- class_name: 'Ecom::Core::TaskStepDependency', foreign_key: 'dependent_task_step_id'
24
- has_many :dependee_task_steps,
25
- class_name: 'Ecom::Core::TaskStepDependency', foreign_key: 'dependee_task_step_id'
26
-
27
- def date_range_validator
28
- task_ = Ecom::Core::Task.find_by(id: task_id)
29
-
30
- return if task_.nil?
31
-
32
- if !start_date.nil? && start_date < task_.start_date
33
- errors.add(:start_date, "The task steps start date can not be before the task's start date")
34
- end
35
-
36
- return unless !end_date.nil? && end_date > task_.end_date
37
-
38
- errors.add(:end_date, "The task steps end date can not be after the task's end date")
39
- end
40
-
41
- def task_step_percentage_validator
42
- return if task_id.nil?
43
-
44
- task = Ecom::Core::Task.find_by(id: task_id)
45
-
46
- return if task.nil?
47
-
48
- total_contribution_of_all_task_steps = task.task_steps.sum(:total_contribution_percentage_to_task)
49
-
50
- max_total_contribution = 100 - total_contribution_of_all_task_steps
51
- return unless total_contribution_percentage_to_task > max_total_contribution
52
-
53
- errors
54
- .add(:total_contribution_of_all_task_steps,
55
- "The maximum that this task step can contribute to the total task is #{max_total_contribution}")
56
- end
57
-
58
- def update_task_progress
59
- return unless completed_changed? && completed == true
60
-
61
- # update the task progress
62
- task = self.task
63
- percent_completed = task.percent_completed
64
- task.percent_completed = (percent_completed + total_contribution_percentage_to_task).to_i
65
- task.save
66
- end
67
-
68
- def task_step_in_task_template_inclusion_validator
69
- return if task_id.nil?
70
-
71
- task = Ecom::Core::Task.find_by(id: task_id)
72
-
73
- return if task.nil?
74
-
75
- task_template = task.task_template
76
-
77
- return unless task_template.task_steps.nil?
78
-
79
- errors.add(:base,
80
- 'Task steps are not defined for the given task in the
81
- task template, please first define the task steps in the task template.')
82
- end
83
- end
84
- end
85
- end
@@ -1,10 +0,0 @@
1
- module Ecom
2
- module Core
3
- class TaskStepDependency < ApplicationRecord
4
- validates :dependent_task_step_id, :dependee_task_step_id, presence: true
5
-
6
- belongs_to :dependent_task_step, class_name: 'Ecom::Core::TaskStep'
7
- belongs_to :dependee_task_step, class_name: 'Ecom::Core::TaskStep'
8
- end
9
- end
10
- end
@@ -1,39 +0,0 @@
1
- module Ecom
2
- module Core
3
- class ProjectCrewService
4
- def update(params)
5
- id = params[:project_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
- project_crew = Ecom::Core::Crew.where(id: crew_ids)
15
-
16
- new_entries = []
17
- new_crew.each do |nc|
18
- new_entries << Ecom::Core::ProjectCrew.new(
19
- project_id: id, crew_id: nc[:crew_id], start_date: Date.today, status: 'Active'
20
- )
21
- end
22
-
23
- Ecom::Core::ProjectCrew.transaction do
24
- new_entries.each(&:save)
25
- end
26
-
27
- removed_ids = removed.map { |r| r[:crew_id] }
28
- if removed_ids.count.positive?
29
- removed_crew = Ecom::Core::ProjectCrew.where(project_id: id, crew_id: removed_ids)
30
- Ecom::Core::ProjectCrew.transaction do
31
- removed_crew.map(&:delete)
32
- end
33
- end
34
-
35
- { success: true, data: project_crew }
36
- end
37
- end
38
- end
39
- end
@@ -1,11 +0,0 @@
1
- class CreateEcomCoreTakeoffCalculators < ActiveRecord::Migration[6.0]
2
- def change
3
- create_table :ecom_core_takeoff_calculators do |t|
4
- t.string :name, unique: true
5
- t.boolean :is_custom_calculator, null: false, default: false
6
- t.jsonb :input_parameters
7
-
8
- t.timestamps
9
- end
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- class CreateEcomCoreProjectCrews < ActiveRecord::Migration[6.0]
2
- def change
3
- create_table :ecom_core_project_crews do |t|
4
- t.references :project,
5
- null: false,
6
- index: { name: 'pc_on_project_indx' },
7
- foreign_key: { to_table: :ecom_core_projects }
8
- t.references :crew,
9
- null: false,
10
- index: { name: 'pc_on_crew_indx' },
11
- foreign_key: { to_table: :ecom_core_crews }
12
- t.date :start_date, null: false
13
- t.date :end_date
14
- t.string :status, null: false, default: 'Inactive'
15
-
16
- t.timestamps
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- class CreateEcomCoreTaskSteps < ActiveRecord::Migration[6.0]
2
- def change
3
- create_table :ecom_core_task_steps do |t|
4
- t.references :task,
5
- null: false,
6
- index: { name: 'ts_on_task_indx' },
7
- foreign_key: { to_table: :ecom_core_tasks }
8
- t.string :name, null: false
9
- t.date :start_date
10
- t.date :end_date
11
- t.float :total_contribution_percentage_to_task, null: false
12
- t.boolean :completed, null: false, default: false
13
-
14
- t.timestamps
15
- end
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- class CreateEcomCoreTaskStepDependencies < ActiveRecord::Migration[6.0]
2
- def change
3
- create_table :ecom_core_task_step_dependencies do |t|
4
- t.references :dependent_task_step,
5
- null: false,
6
- index: { name: 'tsd_on_dts_indx' },
7
- foreign_key: { to_table: :ecom_core_task_steps }
8
-
9
- t.references :dependee_task_step,
10
- null: false,
11
- index: { name: 'tsd_on_dependee_ts_indx' },
12
- foreign_key: { to_table: :ecom_core_task_steps }
13
- t.timestamps
14
- end
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- FactoryBot.define do
2
- factory :project_crew, class: Ecom::Core::ProjectCrew do
3
- association :project
4
- association :crew
5
- start_date { 1.month.ago }
6
- end_date { Date.tomorrow }
7
- status { Ecom::Core::ProjectCrew::ACTIVE }
8
- end
9
- end
@@ -1,18 +0,0 @@
1
- FactoryBot.define do
2
- factory :takeoff_calculator, class: Ecom::Core::TakeoffCalculator do
3
- name { Ecom::Core::TakeoffCalculator::TAKEOFF_CALCULATOR_NAMES.sample }
4
- is_custom_calculator { false }
5
- input_parameters do
6
- [
7
- {
8
- name: 'number_of_bar',
9
- label: 'Number Of Bar',
10
- input_type: 'number',
11
- default_value: {
12
- value: '1'
13
- }
14
- }
15
- ]
16
- end
17
- end
18
- end
@@ -1,6 +0,0 @@
1
- FactoryBot.define do
2
- factory :task_step_dependency, class: Ecom::Core::TaskStepDependency do
3
- association :dependent_task_step, factory: :task_step
4
- association :dependee_task_step, factory: :task_step
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :task_step, class: Ecom::Core::TaskStep do
3
- association :task
4
- name { 'Cutting' }
5
- total_contribution_percentage_to_task { 30 }
6
- completed { false }
7
- end
8
- end