ecom_core 1.2.7 → 1.2.13

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/app/constants/ecom/core/status_constants.rb +11 -0
  3. data/app/controllers/concerns/ecom/core/lookupable.rb +1 -2
  4. data/app/controllers/concerns/ecom/core/resource_typeable.rb +1 -1
  5. data/app/controllers/ecom/core/access_controller.rb +2 -3
  6. data/app/controllers/ecom/core/application_controller.rb +0 -1
  7. data/app/controllers/ecom/core/application_modules_controller.rb +1 -1
  8. data/app/controllers/ecom/core/menus_controller.rb +1 -1
  9. data/app/controllers/ecom/core/user_roles_controller.rb +1 -2
  10. data/app/controllers/ecom/core/users_controller.rb +1 -2
  11. data/app/models/ecom/core/attendance_sheet.rb +25 -18
  12. data/app/models/ecom/core/booked_equipment_item.rb +12 -0
  13. data/app/models/ecom/core/booking.rb +16 -0
  14. data/app/models/ecom/core/component_type.rb +6 -0
  15. data/app/models/ecom/core/country.rb +6 -0
  16. data/app/models/ecom/core/crew.rb +4 -0
  17. data/app/models/ecom/core/crew_overtime.rb +5 -0
  18. data/app/models/ecom/core/crew_time.rb +8 -3
  19. data/app/models/ecom/core/equipment_component.rb +1 -0
  20. data/app/models/ecom/core/equipment_item.rb +15 -2
  21. data/app/models/ecom/core/equipment_location.rb +2 -1
  22. data/app/models/ecom/core/equipment_request.rb +19 -0
  23. data/app/models/ecom/core/overtime_sheet.rb +9 -9
  24. data/app/models/ecom/core/payment.rb +1 -1
  25. data/app/models/ecom/core/payroll.rb +4 -0
  26. data/app/models/ecom/core/requested_item.rb +13 -0
  27. data/app/models/ecom/core/work_product.rb +0 -1
  28. data/app/serializers/ecom/core/lookup_serializer.rb +1 -1
  29. data/app/serializers/ecom/core/resource_type_serializer.rb +1 -1
  30. data/app/serializers/ecom/core/user_role_serializer.rb +1 -1
  31. data/app/services/ecom/core/menu_service.rb +1 -3
  32. data/app/services/ecom/core/token_auth_service.rb +2 -1
  33. data/app/validators/ecom/core/date_range_validator.rb +11 -0
  34. data/db/migrate/20191225140433_create_ecom_core_attendance_sheets.rb +2 -1
  35. data/db/migrate/20200315152143_create_ecom_core_equipment.rb +1 -0
  36. data/db/migrate/20200315153640_create_ecom_core_equipment_items.rb +6 -1
  37. data/db/migrate/20200316125323_create_ecom_core_equipment_components.rb +5 -0
  38. data/db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb +3 -1
  39. data/db/migrate/20200601104719_create_ecom_core_equipment_requests.rb +18 -0
  40. data/db/migrate/20200602130247_create_ecom_core_requested_items.rb +26 -0
  41. data/db/migrate/20200602830603_create_ecom_core_bookings.rb +22 -0
  42. data/db/migrate/20200603115317_create_ecom_core_booked_equipment_items.rb +23 -0
  43. data/lib/ecom/core/engine.rb +0 -1
  44. data/lib/ecom/core/version.rb +1 -1
  45. data/spec/factories/ecom/core/attendance_sheets.rb +1 -1
  46. data/spec/factories/ecom/core/booked_equipment_items.rb +10 -0
  47. data/spec/factories/ecom/core/bookings.rb +9 -0
  48. data/spec/factories/ecom/core/component_types.rb +5 -0
  49. data/spec/factories/ecom/core/countries.rb +5 -0
  50. data/spec/factories/ecom/core/equipment.rb +1 -0
  51. data/spec/factories/ecom/core/equipment_components.rb +2 -0
  52. data/spec/factories/ecom/core/equipment_items.rb +3 -1
  53. data/spec/factories/ecom/core/equipment_requests.rb +8 -0
  54. data/spec/factories/ecom/core/overtime_sheets.rb +1 -1
  55. data/spec/factories/ecom/core/requested_items.rb +13 -0
  56. data/spec/factories/ecom/core/task_templates.rb +0 -1
  57. data/spec/factories/ecom/core/users.rb +1 -0
  58. data/spec/factories/ecom/core/work_products.rb +1 -1
  59. metadata +20 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8604bb41df95be804fb66c2ac48f3e1b55b8f776de07f2dee665c4704350858
4
- data.tar.gz: 30decab7dc7997c9c4a22bc2a90548c0b72a67b6648e894b6f1234c785739166
3
+ metadata.gz: 785564a6c5e451baa829ed1114ec89b5fb0247a3894a09fd2683b2967e1ae49b
4
+ data.tar.gz: d0dbc33358d5759b276f0d92575efc6e2333f2bac15674deb81a40c6b5cb850a
5
5
  SHA512:
6
- metadata.gz: ac72d68e86a4ff54ee5bf33d3068cf57eb44ab5038873481be623cf1eb1c461c8c65749385536e973a9909c8269e5e06a1125562ff7c14a8c9dba322257fe500
7
- data.tar.gz: 44c1ff6ddcbb054bd262ef9a0a75ab2fb6f42d4558a74afe7866c0ee451b45c577003f8c988a60e4a3e8341212451864cb4f633ffa4a6bf5d95bce1615ac7065
6
+ metadata.gz: be05151af2bb4f6117929e9a220ee1a466629464704ba24054f1be4da8ac1b67f03b8fb8affcea5958d8d6e6f18681f0783dce2744d2f01ef00be6af2479fa0d
7
+ data.tar.gz: 87f31a859e9e3c2aaa26af4ae2627a425883e4ab3a8c555bbf3a0ed80b30b754fd9ca0ecce920bee1a78fc69f8ab9f266c5878bea6f3fb6814595e8a0e28290c
@@ -0,0 +1,11 @@
1
+ module Ecom
2
+ module Core
3
+ class StatusConstants
4
+ OPEN = 'Open'.freeze
5
+ SUBMITTED = 'Submitted'.freeze
6
+ APPROVED = 'Approved'.freeze
7
+
8
+ STATUSES = [OPEN, SUBMITTED, APPROVED].freeze
9
+ end
10
+ end
11
+ end
@@ -29,7 +29,6 @@ module Ecom
29
29
  end
30
30
  end
31
31
 
32
-
33
32
  private
34
33
 
35
34
  def set_clazz
@@ -41,4 +40,4 @@ module Ecom
41
40
  end
42
41
  end
43
42
  end
44
- end
43
+ end
@@ -40,4 +40,4 @@ module Ecom
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -18,7 +18,7 @@ module Ecom
18
18
  return
19
19
  end
20
20
 
21
- payload = { id: user.id, email: user.email, name: user.full_name, roles: roles }
21
+ payload = { id: user.id, email: user.email, name: user.full_name, roles: roles, projects: user.projects }
22
22
  jwt = TokenAuthService.issue(payload)
23
23
  render json: { token: jwt, user: payload, error: nil }
24
24
  else
@@ -34,7 +34,6 @@ module Ecom
34
34
  def auth_params
35
35
  params.require(:auth).permit(:email, :password)
36
36
  end
37
-
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -14,7 +14,6 @@ module Ecom
14
14
  @current_user ||= user if user
15
15
  end
16
16
 
17
-
18
17
  private
19
18
 
20
19
  def authenticate
@@ -30,4 +30,4 @@ module Ecom
30
30
  end
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -7,4 +7,4 @@ module Ecom
7
7
  end
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -25,7 +25,6 @@ module Ecom
25
25
  end
26
26
  end
27
27
 
28
-
29
28
  private
30
29
 
31
30
  def set_user_role
@@ -37,4 +36,4 @@ module Ecom
37
36
  end
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -28,7 +28,6 @@ module Ecom
28
28
  end
29
29
  end
30
30
 
31
-
32
31
  private
33
32
 
34
33
  def set_user
@@ -40,4 +39,4 @@ module Ecom
40
39
  end
41
40
  end
42
41
  end
43
- end
42
+ end
@@ -1,37 +1,43 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class AttendanceSheet < ApplicationRecord
4
- OPEN = 'Open'.freeze
5
- SUBMITTED = 'Submitted'.freeze
6
- APPROVED = 'Approved'.freeze
7
-
8
- validates :date, presence: true, uniqueness: true
9
- validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
4
+ validates :date, presence: true, uniqueness: { scope: :project_id }
5
+ validates :status, inclusion: StatusConstants::STATUSES
10
6
 
11
7
  belongs_to :project
12
8
 
13
9
  has_many :attendance_sheet_entries
14
10
  has_many :crew_times, through: :attendance_sheet_entries
15
11
 
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) }
12
+ scope :by_project, ->(id) { where(project_id: id) }
13
+ scope :by_date, ->(date) { where(date: date) }
14
+ scope :by_status, ->(status) { where(status: status) }
15
+ scope :by_date_between, ->(from, to) { where('date BETWEEN ? AND ?', from, to) }
20
16
 
21
17
  def self.open_for_date(date, project_id)
22
- AttendanceSheet.find_by(status: OPEN, date: date, project_id: project_id)
18
+ AttendanceSheet.find_by(status: StatusConstants::OPEN, date: date, project_id: project_id)
23
19
  end
24
20
 
25
21
  def self.open_exists?(project_id)
26
- AttendanceSheet.open(project_id).exists?
22
+ AttendanceSheet
23
+ .by_project(project_id)
24
+ .by_status(StatusConstants::OPEN)
25
+ .exists?
27
26
  end
28
27
 
29
28
  def self.exists_for_today?(project_id)
30
- AttendanceSheet.current(project_id).exists?
29
+ AttendanceSheet
30
+ .by_project(project_id)
31
+ .by_date(Date.today)
32
+ .exists?
31
33
  end
32
34
 
33
35
  def self.open_exists_for_today?(project_id)
34
- AttendanceSheet.current_open(project_id).exists?
36
+ AttendanceSheet
37
+ .by_project(project_id)
38
+ .by_date(Date.today)
39
+ .by_status(StatusConstants::OPEN)
40
+ .exists?
35
41
  end
36
42
 
37
43
  # Attendance sheet should be created using the
@@ -46,16 +52,17 @@ module Ecom
46
52
  raise 'There is an open attendance sheet which needs to be submitted before creating a new one.'
47
53
  end
48
54
 
49
- AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN, project_id: project_id)
55
+ AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: StatusConstants::OPEN,
56
+ project_id: project_id)
50
57
  end
51
58
 
52
59
  def self.submit_current(project_id)
53
- sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN, project_id: project_id)
60
+ sheet = AttendanceSheet.find_by(date: Date.today, status: StatusConstants::OPEN, project_id: project_id)
54
61
 
55
62
  raise 'There is no open attendance sheet to submit.' if sheet.nil?
56
63
 
57
64
  sheet.closed_at = Time.now
58
- sheet.status = SUBMITTED
65
+ sheet.status = StatusConstants::SUBMITTED
59
66
  sheet.save
60
67
  sheet
61
68
  end
@@ -69,7 +76,7 @@ module Ecom
69
76
  raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
70
77
 
71
78
  sheet.closed_at = Time.now
72
- sheet.status = SUBMITTED
79
+ sheet.status = StatusConstants::SUBMITTED
73
80
  sheet.save
74
81
  sheet
75
82
  end
@@ -0,0 +1,12 @@
1
+ module Ecom
2
+ module Core
3
+ class BookedEquipmentItem < ApplicationRecord
4
+ belongs_to :booking
5
+ belongs_to :requested_item
6
+ belongs_to :equipment_item
7
+
8
+ validates :start_date, :end_date, presence: true
9
+ validates_with DateRangeValidator
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Ecom
2
+ module Core
3
+ class Booking < ApplicationRecord
4
+ APPROVED = 'Approved'.freeze
5
+ UNAPPROVED = 'Unapproved'.freeze
6
+
7
+ STATUSES = [APPROVED, UNAPPROVED].freeze
8
+
9
+ belongs_to :equipment_request
10
+ belongs_to :booked_by, class_name: 'Ecom::Core::User'
11
+ belongs_to :booked_for, class_name: 'Ecom::Core::User'
12
+
13
+ validates :status, presence: true, inclusion: STATUSES
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ module Ecom
2
+ module Core
3
+ class ComponentType < Lookup
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Ecom
2
+ module Core
3
+ class Country < Lookup
4
+ end
5
+ end
6
+ end
@@ -14,6 +14,10 @@ module Ecom
14
14
  validates :name, :address, :qualification, :employment, :wage, :wage_in_words, presence: true
15
15
  validates :employment, inclusion: EMPLOYMENT_TYPES
16
16
 
17
+ scope :by_active, ->(active) { where(active: active) }
18
+ scope :by_qualification, ->(qualification) { where(qualification: qualification) }
19
+ scope :by_sub_contracted, ->(sub_contracted) { where(sub_contracted: sub_contracted) }
20
+
17
21
  def set_employment_date
18
22
  self.employment_date = Date.today
19
23
  end
@@ -10,6 +10,11 @@ module Ecom
10
10
 
11
11
  validates :hours, :raw_hours, presence: true
12
12
 
13
+ scope :by_overtime, lambda { |id|
14
+ joins(:overtime_sheet_entry).where(ecom_core_overtime_sheet_entries: { overtime_sheet_id: id })
15
+ }
16
+ scope :revised, ->(revised) { where(revised: revised) }
17
+
13
18
  before_save :calculate_hours
14
19
 
15
20
  def calculate_hours
@@ -7,9 +7,9 @@ module Ecom
7
7
  BOTH = 'Both'.freeze
8
8
 
9
9
  TIME_RANGE = {
10
- MORNING => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM')},
11
- AFTERNOON => {start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM')},
12
- BOTH => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('2:00 PM')}
10
+ MORNING => { start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM') },
11
+ AFTERNOON => { start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM') },
12
+ BOTH => { start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('2:00 PM') }
13
13
  }.freeze
14
14
 
15
15
  belongs_to :attendance_sheet_entry
@@ -19,6 +19,11 @@ module Ecom
19
19
 
20
20
  validates :checkin_time, presence: true, if: :checkout_time
21
21
 
22
+ scope :by_attendance, lambda { |id|
23
+ joins(:attendance_sheet_entry).where(ecom_core_attendance_sheet_entries: { attendance_sheet_id: id })
24
+ }
25
+ scope :revised, ->(revised) { where(revised: revised) }
26
+
22
27
  before_save :calculate_hours
23
28
  after_save :calculate_total
24
29
 
@@ -2,6 +2,7 @@ module Ecom
2
2
  module Core
3
3
  class EquipmentComponent < ApplicationRecord
4
4
  belongs_to :equipment_item
5
+ belongs_to :component_type
5
6
 
6
7
  validates :name, presence: true
7
8
  end
@@ -1,13 +1,26 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class EquipmentItem < ApplicationRecord
4
- READY = 'Ready'
5
- UNDER_MAINTENANCE = 'Under Maintenance'
4
+ # Equipment Statuses
5
+ READY = 'Ready'.freeze
6
+ UNDER_MAINTENANCE = 'Under Maintenance'.freeze
7
+ EQUIPMENT_STATUSES = [READY, UNDER_MAINTENANCE].freeze
8
+
9
+ # Duty Statuses
10
+ AVAILABLE = 'Available'.freeze
11
+ BOOKED = 'Booked'.freeze
12
+ ON_DUTY = 'On Duty'.freeze
13
+ DUTY_STATUSES = [AVAILABLE, BOOKED, ON_DUTY].freeze
6
14
 
7
15
  belongs_to :equipment
16
+ belongs_to :country
8
17
  belongs_to :current_location, class_name: 'Ecom::Core::EquipmentLocation'
18
+ has_many :equipment_components
9
19
 
10
20
  validates :name, :status, :serial_number, :purchase_date, :purchase_price, presence: true
21
+ validates :status, inclusion: EQUIPMENT_STATUSES
22
+ validates :duty_status, inclusion: DUTY_STATUSES
23
+
11
24
  validates :serial_number, uniqueness: true
12
25
 
13
26
  def self.search(param)
@@ -18,7 +18,8 @@ module Ecom
18
18
  joins(:location_type).where(
19
19
  'ecom_core_lookups.name = ? AND ecom_core_lookups.type = ?',
20
20
  LocationType::STORE,
21
- Ecom::Core::LocationType)
21
+ Ecom::Core::LocationType
22
+ )
22
23
  }
23
24
  end
24
25
  end
@@ -0,0 +1,19 @@
1
+ module Ecom
2
+ module Core
3
+ class EquipmentRequest < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ UNDER_REVIEW = 'Under Review'.freeze
6
+ APPROVED = 'Approved'.freeze
7
+ REJECTED = 'Rejected'.freeze
8
+
9
+ STATUSES = [DRAFT, UNDER_REVIEW, APPROVED, REJECTED].freeze
10
+ belongs_to :project
11
+ belongs_to :requested_by, class_name: 'Ecom::Core::User'
12
+ has_one :booking
13
+
14
+ validates :status, presence: true, inclusion: STATUSES
15
+
16
+ scope :by_status, ->(status) { where(status: status) }
17
+ end
18
+ end
19
+ end
@@ -1,20 +1,20 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class OvertimeSheet < ApplicationRecord
4
- OPEN = 'Open'.freeze
5
- SUBMITTED = 'Submitted'.freeze
6
- APPROVED = 'Approved'.freeze
7
-
8
- validates :date, :opened_at, presence: true, uniqueness: true
9
- validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
4
+ validates :date, :opened_at, presence: true, uniqueness: { scope: :project_id }
5
+ validates :status, inclusion: StatusConstants::STATUSES
10
6
 
11
7
  belongs_to :project
12
8
 
13
9
  has_many :overtime_sheet_entries
14
10
  has_many :crew_overtimes, through: :overtime_sheet_entries
15
11
 
16
- scope :open, ->(id) { where(status: OPEN, project_id: id) }
17
- scope :submitted, ->(id) { where(status: SUBMITTED, project_id: id) }
12
+ scope :by_project, ->(id) { where(project_id: id) }
13
+ scope :by_date, ->(date) { where(date: date) }
14
+ scope :by_status, ->(status) { where(status: status) }
15
+ scope :by_date_between, ->(from, to) { where('date BETWEEN ? AND ?', from, to) }
16
+ scope :open, ->(id) { where(status: StatusConstants::OPEN, project_id: id) }
17
+ scope :submitted, ->(id) { where(status: StatusConstants::SUBMITTED, project_id: id) }
18
18
 
19
19
  def self.open_exists?(project_id)
20
20
  OvertimeSheet.open(project_id).exists?
@@ -38,7 +38,7 @@ module Ecom
38
38
  raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
39
39
  end
40
40
 
41
- OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN, project_id: project_id)
41
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
42
42
  end
43
43
  end
44
44
  end
@@ -17,4 +17,4 @@ module Ecom
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -5,6 +5,10 @@ module Ecom
5
5
 
6
6
  has_many :payments, class_name: 'Ecom::Core::Payment'
7
7
  belongs_to :project
8
+
9
+ scope :by_project, ->(id) { where(project_id: id) }
10
+ scope :by_month, ->(month) { where(month: month) }
11
+ scope :by_year, ->(year) { where(year: year) }
8
12
  end
9
13
  end
10
14
  end
@@ -0,0 +1,13 @@
1
+ module Ecom
2
+ module Core
3
+ class RequestedItem < ApplicationRecord
4
+ belongs_to :equipment_request
5
+ belongs_to :equipment
6
+ belongs_to :country, optional: true
7
+
8
+ validates :start_date, :end_date, :quantity, presence: true
9
+ validates :quantity, numericality: { only_integer: true, greater_than: 0 }
10
+ validates_with DateRangeValidator
11
+ end
12
+ end
13
+ end
@@ -12,7 +12,6 @@
12
12
  # way as chart of accounts to identify parent and child relationships. Even then,
13
13
  # there needs to be a well defined coding scheme developed before using the column
14
14
  # field.
15
- #
16
15
  module Ecom
17
16
  module Core
18
17
  class WorkProduct < ApplicationRecord
@@ -4,4 +4,4 @@ module Ecom
4
4
  attributes :id, :name, :type
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -4,4 +4,4 @@ module Ecom
4
4
  attributes :id, :code, :name, :base_unit, :type
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -4,4 +4,4 @@ module Ecom
4
4
  attributes :id, :name
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -14,9 +14,7 @@ module Ecom
14
14
 
15
15
  menu_list.each do |ml|
16
16
  ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
17
- if item.parent_id == ml[:id]
18
- list << { id: item.id, text: item.label, iconCss: item.icon, url: item.route }
19
- end
17
+ list << { id: item.id, text: item.label, iconCss: item.icon, url: item.route } if item.parent_id == ml[:id]
20
18
  end
21
19
  end
22
20
  { success: true, data: menu_list }
@@ -3,7 +3,8 @@ require 'jwt'
3
3
  module Ecom
4
4
  module Core
5
5
  class TokenAuthService
6
- AUTH_SECRET = '31a70abfaa57e5e77a3fc9f27aeaaf59b9a9f5355b5e16c842ee172035a8ed40bf82c1c971ecc176e4f0b4c9e6141db07fd4a5af3f7db9265e719fbe340b105a'
6
+ AUTH_SECRET = '31a70abfaa57e5e77a3fc9f27aeaaf59b9a9f5355b5e16c842ee172035a8ed40bf82c1c971ecc176e4f0b4c9e6141db07'\
7
+ 'fd4a5af3f7db9265e719fbe340b105a'.freeze
7
8
 
8
9
  def self.issue(payload)
9
10
  JWT.encode(payload, auth_secret, 'HS256')
@@ -0,0 +1,11 @@
1
+ module Ecom
2
+ module Core
3
+ class DateRangeValidator < ActiveModel::Validator
4
+ def validate(record)
5
+ return unless record.start_date && record.end_date && record.start_date > record.end_date
6
+
7
+ record.errors.add(:base, 'End date cannot be before start date')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  class CreateEcomCoreAttendanceSheets < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_attendance_sheets do |t|
4
- t.date :date, null: false, unique: true
4
+ t.date :date, null: false
5
5
  t.time :opened_at, null: false
6
6
  t.time :closed_at
7
7
  t.string :remark
@@ -13,5 +13,6 @@ class CreateEcomCoreAttendanceSheets < ActiveRecord::Migration[6.0]
13
13
 
14
14
  t.timestamps
15
15
  end
16
+ add_index :ecom_core_attendance_sheets, %i[date project_id], unique: true
16
17
  end
17
18
  end
@@ -4,6 +4,7 @@ class CreateEcomCoreEquipment < ActiveRecord::Migration[6.0]
4
4
  t.string :name, null: false
5
5
  t.string :description
6
6
  t.float :minimum_acquisition_time, null: false, default: 0
7
+ t.string :brands, array: true, default: []
7
8
  t.references :equipment_category,
8
9
  null: false,
9
10
  index: { name: 'ec_on_ece_indx' },
@@ -3,7 +3,8 @@ class CreateEcomCoreEquipmentItems < ActiveRecord::Migration[6.0]
3
3
  create_table :ecom_core_equipment_items do |t|
4
4
  t.string :name, null: false
5
5
  t.string :description
6
- t.string :status, null: false
6
+ t.string :status, null: false, default: 'Ready'
7
+ t.string :duty_status, null: false, default: 'Available'
7
8
  t.string :serial_number, unique: true
8
9
  t.string :brand
9
10
  t.string :item_model
@@ -11,6 +12,10 @@ class CreateEcomCoreEquipmentItems < ActiveRecord::Migration[6.0]
11
12
  t.date :purchase_date, null: false
12
13
  t.float :license_fee
13
14
  t.float :tax
15
+ t.references :country,
16
+ null: false,
17
+ index: { name: 'equipment_on_country_indx' },
18
+ foreign_key: { to_table: :ecom_core_lookups }
14
19
  t.references :equipment,
15
20
  null: false,
16
21
  index: { name: 'equipment_on_ei_indx' },
@@ -3,10 +3,15 @@ class CreateEcomCoreEquipmentComponents < ActiveRecord::Migration[6.0]
3
3
  create_table :ecom_core_equipment_components do |t|
4
4
  t.string :serial_number
5
5
  t.string :name, null: false
6
+ t.references :component_type,
7
+ null: false,
8
+ index: { name: 'ei_on_ct_indx' },
9
+ foreign_key: { to_table: :ecom_core_lookups }
6
10
  t.references :equipment_item,
7
11
  null: false,
8
12
  index: { name: 'ei_on_ec_indx' },
9
13
  foreign_key: { to_table: :ecom_core_equipment_items }
14
+ t.string :remark
10
15
 
11
16
  t.timestamps
12
17
  end
@@ -1,9 +1,10 @@
1
1
  class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_overtime_sheets do |t|
4
- t.date :date, null: false, unique: true
4
+ t.date :date, null: false
5
5
  t.time :opened_at, null: false
6
6
  t.time :submitted_at
7
+ t.string :remark
7
8
  t.string :status, null: false, default: 'Open'
8
9
  t.references :project,
9
10
  null: false,
@@ -12,5 +13,6 @@ class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
12
13
 
13
14
  t.timestamps
14
15
  end
16
+ add_index :ecom_core_overtime_sheets, %i[date project_id], unique: true
15
17
  end
16
18
  end
@@ -0,0 +1,18 @@
1
+ class CreateEcomCoreEquipmentRequests < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_equipment_requests do |t|
4
+ t.references :requested_by,
5
+ null: false,
6
+ index: { name: 'er_on_rb_indx' },
7
+ foreign_key: { to_table: :ecom_core_users }
8
+ t.string :remark
9
+ t.string :status, null: false
10
+ t.references :project,
11
+ null: false,
12
+ index: { name: 'er_on_project_indx' },
13
+ foreign_key: { to_table: :ecom_core_projects }
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ class CreateEcomCoreRequestedItems < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_requested_items do |t|
4
+ t.references :equipment_request,
5
+ null: false,
6
+ index: { name: 'ri_on_er_indx' },
7
+ foreign_key: { to_table: :ecom_core_equipment_requests }
8
+ t.date :start_date, null: false
9
+ t.date :end_date, null: false
10
+ t.references :equipment,
11
+ null: false,
12
+ index: { name: 'br_on_equipment_indx' },
13
+ foreign_key: { to_table: :ecom_core_equipment }
14
+ t.integer :quantity, null: false
15
+ t.string :brand
16
+ t.references :country,
17
+ null: true,
18
+ index: { name: 'br_on_country_indx' },
19
+ foreign_key: { to_table: :ecom_core_lookups }
20
+ t.integer :components, array: true, default: []
21
+ t.string :remark
22
+
23
+ t.timestamps
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ class CreateEcomCoreBookings < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_bookings do |t|
4
+ t.references :equipment_request,
5
+ null: false,
6
+ index: { name: 'booking_on_er_indx' },
7
+ foreign_key: { to_table: :ecom_core_equipment_requests }
8
+ t.references :booked_by,
9
+ null: false,
10
+ index: { name: 'er_on_bb_indx' },
11
+ foreign_key: { to_table: :ecom_core_users }
12
+ t.references :booked_for,
13
+ null: false,
14
+ index: { name: 'booking_on_bf_indx' },
15
+ foreign_key: { to_table: :ecom_core_users }
16
+ t.string :remark
17
+ t.string :status, null: false
18
+
19
+ t.timestamps
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ class CreateEcomCoreBookedEquipmentItems < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_booked_equipment_items do |t|
4
+ t.references :booking,
5
+ null: false,
6
+ index: { name: 'bei_on_booking_indx' },
7
+ foreign_key: { to_table: :ecom_core_bookings }
8
+ t.references :requested_item,
9
+ null: false,
10
+ index: { name: 'bei_on_ri_indx' },
11
+ foreign_key: { to_table: :ecom_core_bookings }
12
+ t.references :equipment_item,
13
+ null: false,
14
+ index: { name: 'be_on_ei_indx' },
15
+ foreign_key: { to_table: :ecom_core_equipment_items }
16
+ t.date :start_date, null: false
17
+ t.date :end_date, null: false
18
+ t.string :remark
19
+
20
+ t.timestamps
21
+ end
22
+ end
23
+ end
@@ -19,7 +19,6 @@ module Ecom
19
19
  app.config.paths['db/migrate'].concat(config.paths['db/migrate'].expanded)
20
20
  end
21
21
  end
22
-
23
22
  end
24
23
  end
25
24
  end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.2.7'.freeze
3
+ VERSION = '1.2.13'.freeze
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ FactoryBot.define do
4
4
  opened_at { Time.now }
5
5
  closed_at { nil }
6
6
  remark { FFaker::Name.name }
7
- status { Ecom::Core::AttendanceSheet::OPEN }
7
+ status { Ecom::Core::StatusConstants::OPEN }
8
8
  association :project
9
9
  end
10
10
  end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :booked_equipment_item, class: Ecom::Core::BookedEquipmentItem do
3
+ association :booking
4
+ association :requested_item
5
+ association :equipment_item
6
+ start_date { Date.yesterday }
7
+ end_date { Date.today }
8
+ remark { FFaker::Name.name }
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :booking, class: Ecom::Core::Booking do
3
+ association :equipment_request
4
+ association :booked_by, factory: :user
5
+ association :booked_for, factory: :user
6
+ remark { FFaker::Name.name }
7
+ status { Ecom::Core::Booking::UNAPPROVED }
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :component_type, class: Ecom::Core::ComponentType, parent: :lookup do
3
+ type { 'Ecom::Core::ComponentType' }
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :country, class: Ecom::Core::Country, parent: :lookup do
3
+ type { 'Ecom::Core::Country' }
4
+ end
5
+ end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  name { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
5
  minimum_acquisition_time { 10 }
6
+ brands { ['Brand I', 'Brand II', 'Brand III'] }
6
7
  association :equipment_category
7
8
  end
8
9
  end
@@ -2,6 +2,8 @@ FactoryBot.define do
2
2
  factory :equipment_component, class: Ecom::Core::EquipmentComponent do
3
3
  serial_number { FFaker::Name.name }
4
4
  name { FFaker::Name.name }
5
+ remark { FFaker::Name.name }
5
6
  association :equipment_item
7
+ association :component_type
6
8
  end
7
9
  end
@@ -2,7 +2,8 @@ FactoryBot.define do
2
2
  factory :equipment_item, class: Ecom::Core::EquipmentItem do
3
3
  name { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
- status { FFaker::Name.name }
5
+ status { Ecom::Core::EquipmentItem::READY }
6
+ duty_status { Ecom::Core::EquipmentItem::AVAILABLE }
6
7
  serial_number { FFaker::Name.name }
7
8
  brand { FFaker::Name.name }
8
9
  item_model { FFaker::Name.name }
@@ -11,6 +12,7 @@ FactoryBot.define do
11
12
  license_fee { 200 }
12
13
  tax { 500 }
13
14
  association :equipment
15
+ association :country
14
16
  association :current_location, factory: :equipment_location
15
17
  end
16
18
  end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :equipment_request, class: Ecom::Core::EquipmentRequest do
3
+ association :requested_by, factory: :user
4
+ remark { FFaker::Name.name }
5
+ status { Ecom::Core::EquipmentRequest::DRAFT }
6
+ association :project
7
+ end
8
+ end
@@ -3,7 +3,7 @@ FactoryBot.define do
3
3
  date { Date.today }
4
4
  opened_at { Time.now }
5
5
  submitted_at { Time.now + 1.day }
6
- status { Ecom::Core::OvertimeSheet::OPEN }
6
+ status { Ecom::Core::StatusConstants::OPEN }
7
7
  association :project
8
8
  end
9
9
  end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :requested_item, class: Ecom::Core::RequestedItem do
3
+ association :equipment_request
4
+ start_date { Date.yesterday }
5
+ end_date { Date.today }
6
+ association :equipment
7
+ quantity { 1 }
8
+ brand { FFaker::Name.name }
9
+ association :country
10
+ components { [] }
11
+ remark { FFaker::Name.name }
12
+ end
13
+ end
@@ -10,6 +10,5 @@ FactoryBot.define do
10
10
  create(:work_product_template, task_template: task_template)
11
11
  end
12
12
  end
13
-
14
13
  end
15
14
  end
@@ -5,5 +5,6 @@ FactoryBot.define do
5
5
  email { FFaker::Internet.email }
6
6
  active { true }
7
7
  password { FFaker::Internet.password }
8
+ projects { [{ id: 1, name: 'Sample Project' }] }
8
9
  end
9
10
  end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :work_product, class: Ecom::Core::WorkProduct do
3
- code { FFaker::Name.unique.name }
3
+ code { FFaker::Name.name }
4
4
  name { FFaker::Name.unique.name }
5
5
  description { FFaker::Name.name }
6
6
  design_reference_no { FFaker::Name.name }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecom_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -178,20 +178,6 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: solargraph
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
181
  description: An engine which contains the core of a construction management app as
196
182
  a layer.
197
183
  email:
@@ -203,6 +189,7 @@ files:
203
189
  - MIT-LICENSE
204
190
  - README.md
205
191
  - Rakefile
192
+ - app/constants/ecom/core/status_constants.rb
206
193
  - app/controllers/concerns/ecom/core/lookupable.rb
207
194
  - app/controllers/concerns/ecom/core/resource_typeable.rb
208
195
  - app/controllers/ecom/core/access_controller.rb
@@ -218,7 +205,11 @@ files:
218
205
  - app/models/ecom/core/application_record.rb
219
206
  - app/models/ecom/core/attendance_sheet.rb
220
207
  - app/models/ecom/core/attendance_sheet_entry.rb
208
+ - app/models/ecom/core/booked_equipment_item.rb
209
+ - app/models/ecom/core/booking.rb
221
210
  - app/models/ecom/core/company.rb
211
+ - app/models/ecom/core/component_type.rb
212
+ - app/models/ecom/core/country.rb
222
213
  - app/models/ecom/core/crew.rb
223
214
  - app/models/ecom/core/crew_overtime.rb
224
215
  - app/models/ecom/core/crew_time.rb
@@ -230,6 +221,7 @@ files:
230
221
  - app/models/ecom/core/equipment_component.rb
231
222
  - app/models/ecom/core/equipment_item.rb
232
223
  - app/models/ecom/core/equipment_location.rb
224
+ - app/models/ecom/core/equipment_request.rb
233
225
  - app/models/ecom/core/equipment_type.rb
234
226
  - app/models/ecom/core/equipment_valuation.rb
235
227
  - app/models/ecom/core/location_type.rb
@@ -245,6 +237,7 @@ files:
245
237
  - app/models/ecom/core/product_type.rb
246
238
  - app/models/ecom/core/project.rb
247
239
  - app/models/ecom/core/project_crew.rb
240
+ - app/models/ecom/core/requested_item.rb
248
241
  - app/models/ecom/core/resource_type.rb
249
242
  - app/models/ecom/core/stakeholder.rb
250
243
  - app/models/ecom/core/stakeholder_type.rb
@@ -264,6 +257,7 @@ files:
264
257
  - app/serializers/ecom/core/user_serializer.rb
265
258
  - app/services/ecom/core/menu_service.rb
266
259
  - app/services/ecom/core/token_auth_service.rb
260
+ - app/validators/ecom/core/date_range_validator.rb
267
261
  - config/database.ci.yml
268
262
  - config/routes.rb
269
263
  - db/migrate/20190101085530_create_ecom_core_companies.rb
@@ -305,6 +299,10 @@ files:
305
299
  - db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb
306
300
  - db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb
307
301
  - db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb
302
+ - db/migrate/20200601104719_create_ecom_core_equipment_requests.rb
303
+ - db/migrate/20200602130247_create_ecom_core_requested_items.rb
304
+ - db/migrate/20200602830603_create_ecom_core_bookings.rb
305
+ - db/migrate/20200603115317_create_ecom_core_booked_equipment_items.rb
308
306
  - lib/ecom/core.rb
309
307
  - lib/ecom/core/engine.rb
310
308
  - lib/ecom/core/version.rb
@@ -313,7 +311,11 @@ files:
313
311
  - spec/factories/ecom/core/application_modules.rb
314
312
  - spec/factories/ecom/core/attendance_sheet_entries.rb
315
313
  - spec/factories/ecom/core/attendance_sheets.rb
314
+ - spec/factories/ecom/core/booked_equipment_items.rb
315
+ - spec/factories/ecom/core/bookings.rb
316
316
  - spec/factories/ecom/core/companies.rb
317
+ - spec/factories/ecom/core/component_types.rb
318
+ - spec/factories/ecom/core/countries.rb
317
319
  - spec/factories/ecom/core/crew_overtimes.rb
318
320
  - spec/factories/ecom/core/crew_times.rb
319
321
  - spec/factories/ecom/core/crew_types.rb
@@ -325,6 +327,7 @@ files:
325
327
  - spec/factories/ecom/core/equipment_components.rb
326
328
  - spec/factories/ecom/core/equipment_items.rb
327
329
  - spec/factories/ecom/core/equipment_locations.rb
330
+ - spec/factories/ecom/core/equipment_requests.rb
328
331
  - spec/factories/ecom/core/equipment_types.rb
329
332
  - spec/factories/ecom/core/equipment_valuations.rb
330
333
  - spec/factories/ecom/core/location_types.rb
@@ -340,6 +343,7 @@ files:
340
343
  - spec/factories/ecom/core/product_types.rb
341
344
  - spec/factories/ecom/core/project_crews.rb
342
345
  - spec/factories/ecom/core/projects.rb
346
+ - spec/factories/ecom/core/requested_items.rb
343
347
  - spec/factories/ecom/core/resource_types.rb
344
348
  - spec/factories/ecom/core/stakeholder_types.rb
345
349
  - spec/factories/ecom/core/stakeholders.rb