ecom_core 1.1.17 → 1.1.22

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bdf3745639577dacd60d41eb82831de69cd41040b71411628f17be1a8397b42
4
- data.tar.gz: 21fd30d003500d6648d42eb6be7e5d073eff6b7810148cd00aed1fd2496363ec
3
+ metadata.gz: 1b94415c80a265d838bd9ea7ce3ea2f7ca1993ffeb10dfe30d29462f5cf10c7d
4
+ data.tar.gz: 8d69cd67d8101909bd6c0a62dd10d296746b0e90a03837bce669e6a82098531b
5
5
  SHA512:
6
- metadata.gz: 769ccb1b054f0b6faf9421e323e562053d3fe7770fb3abed2af5e0535be3f61f39803deff27b4816d4b58efcb07419b46519c73906ff44c7480ee4b03e9ac099
7
- data.tar.gz: 6d852af57207ad9cfbc6f30d7eaadf239c338b6c4796198e5ec8f833b69b16fba2d790d555b64b37279583e87edb8a517a7dfe0811e74b66fc21f1e0659c3b9c
6
+ metadata.gz: 33126ede6c788eb2eff9665b16df30b53d4ce172bb6e2517546237ac81daf52904414732b2a313760686976d48ffe60111394a9fb2b996cbbc32fe1a9fc76377
7
+ data.tar.gz: 0c3fa5d8541eeaa4c46234c2a2e4854d1606b0c843e6babcbdcc226f6a7bfa77fc609abba6465a856075abf950917fdd31f7aa2896aed823cb94dbfa289cb6b5
@@ -10,19 +10,24 @@ module Ecom
10
10
 
11
11
  has_many :attendance_sheet_entries
12
12
 
13
- scope :open, -> { find_by(status: OPEN) }
14
- scope :current_open, -> { where(status: OPEN, date: Date.today) }
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :current, -> { where(date: Date.today) }
15
+ scope :current_open, -> { open.current }
16
+
17
+ def self.open_for_date(date)
18
+ AttendanceSheet.find_by(status: OPEN, date: date)
19
+ end
15
20
 
16
21
  def self.open_exists?
17
- AttendanceSheet.where(status: OPEN).exists?
22
+ AttendanceSheet.open.exists?
18
23
  end
19
24
 
20
25
  def self.exists_for_today?
21
- AttendanceSheet.where(date: Date.today).exists?
26
+ AttendanceSheet.current.exists?
22
27
  end
23
28
 
24
29
  def self.open_exists_for_today?
25
- where(status: OPEN, date: Date.today).exists?
30
+ AttendanceSheet.current_open.exists?
26
31
  end
27
32
 
28
33
  # Attendance sheet should be created using the
@@ -53,13 +58,14 @@ module Ecom
53
58
  # to submit the attendance sheet after the date has
54
59
  # passed. Normally, timekeepers need to open and close
55
60
  # an attendance sheet of a date on the specific date.
56
- def submit
57
- raise 'This attendance sheet is not open. Therefore it cannot be submitted' unless status == OPEN
61
+ def self.submit(date)
62
+ sheet = AttendanceSheet.open_for_date(date)
63
+ raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
58
64
 
59
- self.closed_at = Time.now
60
- self.status = SUBMITTED
61
- save
62
- self
65
+ sheet.closed_at = Time.now
66
+ sheet.status = SUBMITTED
67
+ sheet.save
68
+ sheet
63
69
  end
64
70
  end
65
71
  end
@@ -6,15 +6,15 @@ module Ecom
6
6
  belongs_to :revision_to, class_name: 'Ecom::Core::CrewOvertime', optional: true
7
7
  belongs_to :created_by, class_name: 'Ecom::Core::User'
8
8
 
9
- has_one :revision, class_name: 'Ecom::Core::CrewOvertime'
9
+ has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
10
10
 
11
- validates :hours, :converted_hours, presence: true
11
+ validates :hours, :raw_hours, presence: true
12
12
 
13
- before_save :calculate_converted_hours
13
+ before_save :calculate_hours
14
14
 
15
- def calculate_converted_hours
15
+ def calculate_hours
16
16
  rate = OvertimeType.find(overtime_type_id).rate
17
- self.converted_hours = hours * rate
17
+ self.hours = raw_hours * rate
18
18
  end
19
19
  end
20
20
  end
@@ -1,26 +1,52 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class CrewTime < ApplicationRecord
4
+ # Time Ranges
5
+ MORNING = 'Morning'.freeze
6
+ AFTERNOON = 'Afternoon'.freeze
7
+ BOTH = 'Both'.freeze
8
+
9
+ TIME_RANGE = {
10
+ MORNING => {start: Time.parse('8:00 AM'), end: Time.parse('12:00 PM')},
11
+ AFTERNOON => {start: Time.parse('1:00 PM'), end: Time.parse('5:00 PM')},
12
+ BOTH => {start: Time.parse('8:00 AM'), end: Time.parse('5:00 PM')}
13
+ }.freeze
14
+
4
15
  belongs_to :attendance_sheet_entry
5
- belongs_to :overtime_type, optional: true
16
+ belongs_to :revision_to, class_name: 'Ecom::Core::CrewTime', optional: true
17
+ belongs_to :created_by, class_name: 'Ecom::Core::User'
18
+ has_one :revision, class_name: 'Ecom::Core::CrewTime', foreign_key: :revision_to_id
19
+
20
+ validates :hours, presence: true
6
21
 
7
- validates :hours, :converted_hours, presence: true
8
- # validates_each :date do |record, attr, value|
9
- # if record.crew && value && (value < record.crew.employment_date)
10
- # record.errors.add(attr, 'should be after employment date')
11
- # end
12
- # end
22
+ before_save :calculate_hours
13
23
 
14
- before_save :calculate_converted_hours
24
+ def calculate_hours
25
+ self.hours = checkout_time.nil? ? 0 : compute_hours
26
+ end
15
27
 
16
- def calculate_converted_hours
17
- if overtime
18
- rate = OvertimeType.find(overtime_type_id).rate
19
- self.converted_hours = hours * rate
28
+ # A method to check if checkin and checkout range falls in the morning,
29
+ # afternoon, or both.
30
+ def find_range
31
+ if checkin_time.before?(TIME_RANGE[MORNING][:end]) && checkout_time.before?(TIME_RANGE[AFTERNOON][:start])
32
+ MORNING
33
+ elsif checkin_time.after?(TIME_RANGE[MORNING][:end]) && checkout_time.after?(TIME_RANGE[AFTERNOON][:start])
34
+ AFTERNOON
20
35
  else
21
- self.converted_hours = hours
36
+ BOTH
22
37
  end
23
38
  end
39
+
40
+ # A method to adjust time ranges by trimming any time value outside
41
+ # of the defined morning and afternoon ranges
42
+ def compute_hours
43
+ range = find_range
44
+ left = checkin_time.before?(TIME_RANGE[range][:start]) ? TIME_RANGE[range][:start] : checkin_time
45
+ right = checkout_time.after?(TIME_RANGE[range][:end]) ? TIME_RANGE[range][:end] : checkout_time
46
+ time = (right - left) / 1.hour
47
+ time -= 1 if range == BOTH
48
+ time
49
+ end
24
50
  end
25
51
  end
26
52
  end
@@ -10,10 +10,15 @@ module Ecom
10
10
 
11
11
  has_many :overtime_sheet_entries
12
12
 
13
- scope :open, -> { find_by(status: OPEN) }
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :for_date, ->(date) { where(date: date) }
14
15
 
15
16
  def self.open_exists?
16
- OvertimeSheet.where(status: OPEN).exists?
17
+ OvertimeSheet.open.exists?
18
+ end
19
+
20
+ def self.open_for_date_exists?(date)
21
+ OvertimeSheet.open.for_date(date).exists?
17
22
  end
18
23
 
19
24
  # Overtime sheet should be created using the
@@ -22,6 +27,10 @@ module Ecom
22
27
  # and also that we have only one open overtime
23
28
  # sheet at a time.
24
29
  def self.create_new(date)
30
+ if OvertimeSheet.open_for_date_exists?(date)
31
+ raise 'There is already an open overtime sheet for the selected date.'
32
+ end
33
+
25
34
  if OvertimeSheet.open_exists?
26
35
  raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
27
36
  end
@@ -3,6 +3,7 @@ module Ecom
3
3
  class OvertimeSheetEntry < ApplicationRecord
4
4
  belongs_to :overtime_sheet
5
5
  belongs_to :crew
6
+ has_many :crew_overtimes
6
7
  end
7
8
  end
8
9
  end
@@ -6,7 +6,7 @@ module Ecom
6
6
  has_and_belongs_to_many :user_roles, join_table: 'ecom_core_users_user_roles'
7
7
 
8
8
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze
9
- validates :first_name, :last_name, :active, presence: true
9
+ validates :first_name, :last_name, presence: true
10
10
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
11
11
  validates :password, presence: true, length: { minimum: 6 }, confirmation: true, if: :password
12
12
 
@@ -0,0 +1,17 @@
1
+ class FixCrewTimeColumns < ActiveRecord::Migration[6.0]
2
+ def change
3
+ remove_column :ecom_core_crew_times, :overtime, :boolean
4
+ remove_column :ecom_core_crew_times, :overtime_type_id, :integer
5
+ remove_column :ecom_core_crew_times, :converted_hours, :float
6
+
7
+ add_column :ecom_core_crew_times, :revised, :boolean, default: false, null: false
8
+ add_column :ecom_core_crew_times, :revision_to_id, :integer
9
+ add_column :ecom_core_crew_times, :created_by_id, :integer
10
+
11
+ add_index :ecom_core_crew_times, :revision_to_id, name: 'ct_on_rt_indx'
12
+ add_index :ecom_core_crew_times, :created_by_id, name: 'cb_on_ct_indx'
13
+
14
+ add_foreign_key :ecom_core_crew_times, :ecom_core_crew_times, column: :revision_to_id
15
+ add_foreign_key :ecom_core_crew_times, :ecom_core_users, column: :created_by_id
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ class AdjustCrewOvertimeColumnNames < ActiveRecord::Migration[6.0]
2
+ def change
3
+ rename_column :ecom_core_crew_overtimes, :hours, :raw_hours
4
+ rename_column :ecom_core_crew_overtimes, :converted_hours, :hours
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class ChangeTimeColumnsToDatetime < ActiveRecord::Migration[6.0]
2
+ def change
3
+ remove_column :ecom_core_crew_times, :checkin_time, :time
4
+ add_column :ecom_core_crew_times, :checkin_time, :datetime
5
+ remove_column :ecom_core_crew_times, :checkout_time, :time
6
+ add_column :ecom_core_crew_times, :checkout_time, :datetime
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.17'.freeze
3
+ VERSION = '1.1.22'.freeze
4
4
  end
5
5
  end
@@ -3,4 +3,3 @@ require 'ecom/core/engine'
3
3
  require 'ancestry'
4
4
  require 'aasm'
5
5
  require 'active_model_serializers'
6
- require 'data_migrate'
@@ -1,7 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :crew_overtime, class: 'Ecom::Core::CrewOvertime' do
3
+ raw_hours { 2 }
3
4
  hours { 2 }
4
- converted_hours { 2 }
5
5
  remark { FFaker::Name.name }
6
6
  association :overtime_type
7
7
  association :overtime_sheet_entry
@@ -3,10 +3,10 @@ FactoryBot.define do
3
3
  checkin_time { Time.now }
4
4
  checkout_time { Time.now + 2 * 60 * 60 }
5
5
  hours { 2 }
6
- converted_hours { 2 }
7
6
  remark { FFaker::Name.name }
8
- overtime { false }
9
- overtime_type { nil }
10
7
  association :attendance_sheet_entry
8
+ revised { false }
9
+ revision_to { nil }
10
+ association :created_by, factory: :user
11
11
  end
12
12
  end
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.1.17
4
+ version: 1.1.22
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-04-10 00:00:00.000000000 Z
11
+ date: 2020-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -25,21 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ancestry
28
+ name: active_model_serializers
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.10.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.10.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: bcrypt
42
+ name: ancestry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: active_model_serializers
56
+ name: bcrypt
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.0
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.0
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jwt
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 6.0.2
97
- - !ruby/object:Gem::Dependency
98
- name: data_migrate
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: factory_bot_rails
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -264,7 +250,6 @@ files:
264
250
  - app/services/ecom/core/token_auth_service.rb
265
251
  - config/database.ci.yml
266
252
  - config/routes.rb
267
- - db/data/20200401064242_move_date_to_attendance_sheet.rb
268
253
  - db/migrate/20190101112620_create_ecom_core_lookups.rb
269
254
  - db/migrate/20190101112625_create_ecom_core_overtime_types.rb
270
255
  - db/migrate/20191119010518_create_ecom_core_task_template_types.rb
@@ -309,6 +294,9 @@ files:
309
294
  - db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb
310
295
  - db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb
311
296
  - db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb
297
+ - db/migrate/20200413144023_fix_crew_time_columns.rb
298
+ - db/migrate/20200414044144_adjust_crew_overtime_column_names.rb
299
+ - db/migrate/20200414185248_change_time_columns_to_datetime.rb
312
300
  - lib/ecom/core.rb
313
301
  - lib/ecom/core/engine.rb
314
302
  - lib/ecom/core/version.rb
@@ -1,20 +0,0 @@
1
- class MoveDateToAttendanceSheet < ActiveRecord::Migration[6.0]
2
- def up
3
- dates = Ecom::Core::CrewTime.pluck('DISTINCT date(date)')
4
-
5
- return if dates.count.zero?
6
-
7
- attendances = []
8
- dates.each do |date|
9
- attendances << Ecom::Core::AttendanceSheet.new(date: date)
10
- end
11
-
12
- Ecom::Core::AttendanceSheet.transaction do
13
- attendances.each(&:save)
14
- end
15
- end
16
-
17
- def down
18
- raise ActiveRecord::IrreversibleMigration
19
- end
20
- end