ecom_core 1.1.16 → 1.1.21

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: fe250f7096d4de2dbcce2ab0e9ad159f107812cf69768fa6cd92962c8c80c937
4
- data.tar.gz: 29bba333d43472d8339ad18a0ecd9e238a72b705c13fd86ae283ac095d9adf0b
3
+ metadata.gz: 20baeb3e84b28e3138d9d2b64cc0f91afe5e3e79361baa4564b280eca1d7db92
4
+ data.tar.gz: 714499d1b00181a32b8ac85dd2a469d3474ec590ac4c0bb958d655285420647a
5
5
  SHA512:
6
- metadata.gz: 981a42e43a0beeef91423b2f282c2908dd516d1c4ee56d5ad55cf6275221f3962e2ba1eacb7861d63bdb5ae4805041f1e786f321473696f540c927b8c8472b8f
7
- data.tar.gz: 2a84218270b5001b34d02c16e4a5c6cfc6fc0e9d47651389e2851524bf4e6910dc8e99b6578e2d52dd7996802c06953f266034df6652a42c97c8e6608e48f162
6
+ metadata.gz: 99fa344c2db5b7a704eed5cf9191c9f620f95b0f74cb1e38da9c121e91b6d3b477b1b8bea16387647f0bda528054f8b6ae55276a74944bf08998c070d660a4a7
7
+ data.tar.gz: 1959a1648e993edd98fa846391b38bc967c8844fde3b85ab9c99dde4bbbed683bcb9c57ce215fc2657348a36eb3b539a7dfdb878dd73df022a21d4bcdc4bee6b
@@ -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
@@ -0,0 +1,21 @@
1
+ module Ecom
2
+ module Core
3
+ class CrewOvertime < ApplicationRecord
4
+ belongs_to :overtime_type
5
+ belongs_to :overtime_sheet_entry
6
+ belongs_to :revision_to, class_name: 'Ecom::Core::CrewOvertime', optional: true
7
+ belongs_to :created_by, class_name: 'Ecom::Core::User'
8
+
9
+ has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
10
+
11
+ validates :hours, :raw_hours, presence: true
12
+
13
+ before_save :calculate_hours
14
+
15
+ def calculate_hours
16
+ rate = OvertimeType.find(overtime_type_id).rate
17
+ self.hours = raw_hours * rate
18
+ end
19
+ end
20
+ end
21
+ 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
@@ -0,0 +1,42 @@
1
+ module Ecom
2
+ module Core
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]
10
+
11
+ has_many :overtime_sheet_entries
12
+
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :for_date, ->(date) { where(date: date) }
15
+
16
+ def self.open_exists?
17
+ OvertimeSheet.open.exists?
18
+ end
19
+
20
+ def self.open_for_date_exists?(date)
21
+ OvertimeSheet.open.for_date(date).exists?
22
+ end
23
+
24
+ # Overtime sheet should be created using the
25
+ # method below only. This is because we need to
26
+ # check if there is an open overtime already,
27
+ # and also that we have only one open overtime
28
+ # sheet at a time.
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
+
34
+ if OvertimeSheet.open_exists?
35
+ raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
36
+ end
37
+
38
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module Ecom
2
+ module Core
3
+ class OvertimeSheetEntry < ApplicationRecord
4
+ belongs_to :overtime_sheet
5
+ belongs_to :crew
6
+ has_many :crew_overtimes
7
+ end
8
+ end
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,12 @@
1
+ class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_overtime_sheets do |t|
4
+ t.date :date, null: false, unique: true
5
+ t.time :opened_at, null: false
6
+ t.time :submitted_at
7
+ t.string :status, null: false, default: 'Open'
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEcomCoreOvertimeSheetEntries < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_overtime_sheet_entries do |t|
4
+ t.references :overtime_sheet, null: false, index: { name: 'ose_on_os_indx' }
5
+ t.references :crew, null: false, index: { name: 'ose_on_crew_indx' }
6
+ t.float :total_overtime
7
+
8
+ t.timestamps
9
+ end
10
+ add_foreign_key :ecom_core_overtime_sheet_entries, :ecom_core_overtime_sheets,
11
+ column: :overtime_sheet_id
12
+ add_foreign_key :ecom_core_overtime_sheet_entries, :ecom_core_crews, column: :crew_id
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ class CreateEcomCoreCrewOvertimes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_crew_overtimes do |t|
4
+ t.float :hours, null: false
5
+ t.float :converted_hours, null: false, default: 0
6
+ t.string :remark
7
+ t.references :overtime_type, null: false, index: { name: 'ot_on_co_indx' }
8
+ t.references :overtime_sheet_entry, null: false, index: { name: 'ose_on_co_indx' }
9
+ t.boolean :revised, null: false, default: false
10
+ t.references :revision_to, null: true
11
+ t.references :created_by, null: false, index: { name: 'cb_on_co_indx' }
12
+
13
+ t.timestamps
14
+ end
15
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_overtime_types, column: :overtime_type_id
16
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_overtime_sheet_entries,
17
+ column: :overtime_sheet_entry_id
18
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_crew_overtimes, column: :revision_to_id
19
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_users, column: :created_by_id
20
+ end
21
+ end
@@ -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,6 @@
1
+ class ChangeTimeColumnsToDatetime < ActiveRecord::Migration[6.0]
2
+ def change
3
+ change_column :ecom_core_crew_times, :checkin_time, :datetime
4
+ change_column :ecom_core_crew_times, :checkout_time, :datetime
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.16'.freeze
3
+ VERSION = '1.1.21'.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'
@@ -0,0 +1,12 @@
1
+ FactoryBot.define do
2
+ factory :crew_overtime, class: 'Ecom::Core::CrewOvertime' do
3
+ raw_hours { 2 }
4
+ hours { 2 }
5
+ remark { FFaker::Name.name }
6
+ association :overtime_type
7
+ association :overtime_sheet_entry
8
+ revised { false }
9
+ revision_to { nil }
10
+ association :created_by, factory: :user
11
+ end
12
+ end
@@ -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
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :overtime_sheet_entry, class: 'Ecom::Core::OvertimeSheetEntry' do
3
+ association :overtime_sheet
4
+ association :crew
5
+ total_overtime { FFaker::Random.rand(0..8) }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :overtime_sheet, class: 'Ecom::Core::OvertimeSheet' do
3
+ date { Date.today }
4
+ opened_at { Time.now }
5
+ submitted_at { Time.now + 1.day }
6
+ status { Ecom::Core::OvertimeSheet::OPEN }
7
+ end
8
+ 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.16
4
+ version: 1.1.21
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-14 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
@@ -219,6 +205,7 @@ files:
219
205
  - app/models/ecom/core/attendance_sheet.rb
220
206
  - app/models/ecom/core/attendance_sheet_entry.rb
221
207
  - app/models/ecom/core/crew.rb
208
+ - app/models/ecom/core/crew_overtime.rb
222
209
  - app/models/ecom/core/crew_time.rb
223
210
  - app/models/ecom/core/crew_type.rb
224
211
  - app/models/ecom/core/currency.rb
@@ -234,6 +221,8 @@ files:
234
221
  - app/models/ecom/core/lookup.rb
235
222
  - app/models/ecom/core/material_type.rb
236
223
  - app/models/ecom/core/menu.rb
224
+ - app/models/ecom/core/overtime_sheet.rb
225
+ - app/models/ecom/core/overtime_sheet_entry.rb
237
226
  - app/models/ecom/core/overtime_type.rb
238
227
  - app/models/ecom/core/payment.rb
239
228
  - app/models/ecom/core/payment_detail.rb
@@ -261,7 +250,6 @@ files:
261
250
  - app/services/ecom/core/token_auth_service.rb
262
251
  - config/database.ci.yml
263
252
  - config/routes.rb
264
- - db/data/20200401064242_move_date_to_attendance_sheet.rb
265
253
  - db/migrate/20190101112620_create_ecom_core_lookups.rb
266
254
  - db/migrate/20190101112625_create_ecom_core_overtime_types.rb
267
255
  - db/migrate/20191119010518_create_ecom_core_task_template_types.rb
@@ -303,6 +291,12 @@ files:
303
291
  - db/migrate/20200401122539_create_ecom_core_attendance_sheet_entries.rb
304
292
  - db/migrate/20200401142959_relate_crew_time_with_attendance_sheet_entry.rb
305
293
  - db/migrate/20200401144137_remove_crew_time_id_from_crew.rb
294
+ - db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb
295
+ - db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb
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
306
300
  - lib/ecom/core.rb
307
301
  - lib/ecom/core/engine.rb
308
302
  - lib/ecom/core/version.rb
@@ -311,6 +305,7 @@ files:
311
305
  - spec/factories/ecom/core/application_modules.rb
312
306
  - spec/factories/ecom/core/attendance_sheet_entries.rb
313
307
  - spec/factories/ecom/core/attendance_sheets.rb
308
+ - spec/factories/ecom/core/crew_overtimes.rb
314
309
  - spec/factories/ecom/core/crew_times.rb
315
310
  - spec/factories/ecom/core/crew_types.rb
316
311
  - spec/factories/ecom/core/crews.rb
@@ -327,6 +322,8 @@ files:
327
322
  - spec/factories/ecom/core/lookups.rb
328
323
  - spec/factories/ecom/core/material_types.rb
329
324
  - spec/factories/ecom/core/menus.rb
325
+ - spec/factories/ecom/core/overtime_sheet_entries.rb
326
+ - spec/factories/ecom/core/overtime_sheets.rb
330
327
  - spec/factories/ecom/core/overtime_types.rb
331
328
  - spec/factories/ecom/core/payment_details.rb
332
329
  - spec/factories/ecom/core/payments.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