ecom_core 1.1.20 → 1.1.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/ecom/core/crew_overtime.rb +4 -4
- data/app/models/ecom/core/crew_time.rb +41 -1
- data/app/services/ecom/core/menu_service.rb +3 -3
- data/db/migrate/20200414044144_adjust_crew_overtime_column_names.rb +6 -0
- data/db/migrate/20200414185248_change_time_columns_to_datetime.rb +8 -0
- data/lib/ecom/core/version.rb +1 -1
- data/spec/factories/ecom/core/crew_overtimes.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86640c77f0e0fe2e4189f07074e563db7c94b288896e2f107c828568d0ee7b35
|
4
|
+
data.tar.gz: bfe06daba688e464f4d8f88e29d75a3fe8a606a787ff6c1b0ac2a01efbdb987c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1479a2f0ae7f32989810bb43c549709f4c1e2d9f649009f39b402662dcc34c1165339746c63c7d9981749804dee3d94d885b7f5e440d2efd27ea01c631e5fbc6
|
7
|
+
data.tar.gz: 2c0d7d2d4ffa6beaa7cf854dc817bf023b415a785e98b527c65b6e862f58e645e04b1a461296df21dee6dd47be06f5e892b6b2bcaf154a527b87a14f1649f5ae
|
@@ -8,13 +8,13 @@ module Ecom
|
|
8
8
|
|
9
9
|
has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
|
10
10
|
|
11
|
-
validates :hours, :
|
11
|
+
validates :hours, :raw_hours, presence: true
|
12
12
|
|
13
|
-
before_save :
|
13
|
+
before_save :calculate_hours
|
14
14
|
|
15
|
-
def
|
15
|
+
def calculate_hours
|
16
16
|
rate = OvertimeType.find(overtime_type_id).rate
|
17
|
-
self.
|
17
|
+
self.hours = raw_hours * rate
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,12 +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.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
|
+
}.freeze
|
14
|
+
|
4
15
|
belongs_to :attendance_sheet_entry
|
5
16
|
belongs_to :revision_to, class_name: 'Ecom::Core::CrewTime', optional: true
|
6
17
|
belongs_to :created_by, class_name: 'Ecom::Core::User'
|
7
|
-
has_one :revision, class_name: 'Ecom::Core::
|
18
|
+
has_one :revision, class_name: 'Ecom::Core::CrewTime', foreign_key: :revision_to_id
|
8
19
|
|
9
20
|
validates :hours, presence: true
|
21
|
+
|
22
|
+
before_save :calculate_hours
|
23
|
+
|
24
|
+
def calculate_hours
|
25
|
+
self.hours = checkout_time.nil? ? 0 : compute_hours
|
26
|
+
end
|
27
|
+
|
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
|
35
|
+
else
|
36
|
+
BOTH
|
37
|
+
end
|
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
|
10
50
|
end
|
11
51
|
end
|
12
52
|
end
|
@@ -9,13 +9,13 @@ module Ecom
|
|
9
9
|
SQL
|
10
10
|
menu = Menu.joins(join_sql).where('UR.id IN (?)', role_ids).distinct
|
11
11
|
menu_list = menu.select { |m| m.parent.nil? }.each_with_object([]) do |item, list|
|
12
|
-
list << { id: item.id,
|
12
|
+
list << { id: item.id, text: item.label, iconCss: item.icon, items: [] }
|
13
13
|
end
|
14
14
|
|
15
15
|
menu_list.each do |ml|
|
16
|
-
ml[:
|
16
|
+
ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
|
17
17
|
if item.parent_id == ml[:id]
|
18
|
-
list << { id: item.id,
|
18
|
+
list << { id: item.id, text: item.label, iconCss: item.icon, url: item.route }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
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
|
data/lib/ecom/core/version.rb
CHANGED
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.
|
4
|
+
version: 1.1.25
|
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-
|
11
|
+
date: 2020-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aasm
|
@@ -295,6 +295,8 @@ files:
|
|
295
295
|
- db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb
|
296
296
|
- db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb
|
297
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
|
298
300
|
- lib/ecom/core.rb
|
299
301
|
- lib/ecom/core/engine.rb
|
300
302
|
- lib/ecom/core/version.rb
|