ecom_core 1.1.14 → 1.1.19

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: 8b8bc2e6d8400e996f20f351ee949cff29dbbbba72dbb396c2039b51714ac6f7
4
- data.tar.gz: f4c58d21264802a0dc6b18a2adf895205a66c33cbbb160e7b677e9e65eae5465
3
+ metadata.gz: dcebadd1810f6eea78c0ac3507080297092400114d9bc9eefdeda30361e9eb92
4
+ data.tar.gz: efde6b5cea91a56d8a7cf87e5fb58650fb5bffa5b3a5e8a849915e0a89713665
5
5
  SHA512:
6
- metadata.gz: e3a700353f3e4fc0bf5e7402026c0ae492a51dae4e30c42a21125e0cef713923910add513c1dc37dfd5aefff06de0451e15c8ca6493e6e226903ec389c736b78
7
- data.tar.gz: 39c78b1cd0607c49a7c954b96ce87af031067c198ee78ac628f43715604a38b5b665a11d3019d5abfd5a72db8efb386878a91112143140a4b81bc782126b30a6
6
+ metadata.gz: 50c886b4ea192ff7addd00bbb21d88dcc022b91e428c8a8776d3a298ac6f8443c4ce8790ebd3968af2ad1e7a5e1037429090455d81f98dac4f2b7fece6b3cee1
7
+ data.tar.gz: '058f44af017d5cb20b7bd5da50f859d6cb8e494b9ed1e11c494b1f49e6681ee2d9f3d2c04b1895d1553f53448bb6ac9139e3f72b0c351f678732998210345a4e'
@@ -2,22 +2,32 @@ module Ecom
2
2
  module Core
3
3
  class AttendanceSheet < ApplicationRecord
4
4
  OPEN = 'Open'.freeze
5
- CLOSED = 'Closed'.freeze
5
+ SUBMITTED = 'Submitted'.freeze
6
+ APPROVED = 'Approved'.freeze
6
7
 
7
8
  validates :date, :opened_at, presence: true, uniqueness: true
8
- validates :status, inclusion: [OPEN, CLOSED]
9
+ validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
9
10
 
10
11
  has_many :attendance_sheet_entries
11
12
 
12
- scope :open, -> { find_by(status: OPEN) }
13
- 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
20
+
21
+ def self.open_exists?
22
+ AttendanceSheet.open.exists?
23
+ end
14
24
 
15
25
  def self.exists_for_today?
16
- AttendanceSheet.where(date: Date.today).exists?
26
+ AttendanceSheet.current.exists?
17
27
  end
18
28
 
19
29
  def self.open_exists_for_today?
20
- where(status: OPEN, date: Date.today).exists?
30
+ AttendanceSheet.current_open.exists?
21
31
  end
22
32
 
23
33
  # Attendance sheet should be created using the
@@ -28,29 +38,32 @@ module Ecom
28
38
  def self.create_current
29
39
  raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?
30
40
 
41
+ raise 'There is an open attendance sheet which needs to be submitted before creating a new one.' if AttendanceSheet.open_exists?
42
+
31
43
  AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN)
32
44
  end
33
45
 
34
- def self.close_current
46
+ def self.submit_current
35
47
  sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN)
36
48
 
37
- raise 'There is no attendance sheet to close.' if sheet.nil?
49
+ raise 'There is no open attendance sheet to submit.' if sheet.nil?
38
50
 
39
51
  sheet.closed_at = Time.now
40
- sheet.status = CLOSED
52
+ sheet.status = SUBMITTED
41
53
  sheet.save
42
54
  sheet
43
55
  end
44
56
 
45
57
  # This method should be used by privileged users
46
- # to close the attendance sheet after the date has
58
+ # to submit the attendance sheet after the date has
47
59
  # passed. Normally, timekeepers need to open and close
48
60
  # an attendance sheet of a date on the specific date.
49
- def self.close
50
- raise 'There is no attendance sheet to close.' unless AttendanceSheet.open_exists_for_today?
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
51
64
 
52
- sheet = AttendanceSheet.open
53
65
  sheet.closed_at = Time.now
66
+ sheet.status = SUBMITTED
54
67
  sheet.save
55
68
  sheet
56
69
  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, :converted_hours, presence: true
12
+
13
+ before_save :calculate_converted_hours
14
+
15
+ def calculate_converted_hours
16
+ rate = OvertimeType.find(overtime_type_id).rate
17
+ self.converted_hours = hours * rate
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,25 +2,11 @@ module Ecom
2
2
  module Core
3
3
  class CrewTime < ApplicationRecord
4
4
  belongs_to :attendance_sheet_entry
5
- belongs_to :overtime_type, optional: true
5
+ belongs_to :revision_to, class_name: 'Ecom::Core::CrewTime', optional: true
6
+ belongs_to :created_by, class_name: 'Ecom::Core::User'
7
+ has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
6
8
 
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
13
-
14
- before_save :calculate_converted_hours
15
-
16
- def calculate_converted_hours
17
- if overtime
18
- rate = OvertimeType.find(overtime_type_id).rate
19
- self.converted_hours = hours * rate
20
- else
21
- self.converted_hours = hours
22
- end
23
- end
9
+ validates :hours, presence: true
24
10
  end
25
11
  end
26
12
  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
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.14'.freeze
3
+ VERSION = '1.1.19'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ FactoryBot.define do
2
+ factory :crew_overtime, class: 'Ecom::Core::CrewOvertime' do
3
+ hours { 2 }
4
+ converted_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.14
4
+ version: 1.1.19
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-04 00:00:00.000000000 Z
11
+ date: 2020-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -219,6 +219,7 @@ files:
219
219
  - app/models/ecom/core/attendance_sheet.rb
220
220
  - app/models/ecom/core/attendance_sheet_entry.rb
221
221
  - app/models/ecom/core/crew.rb
222
+ - app/models/ecom/core/crew_overtime.rb
222
223
  - app/models/ecom/core/crew_time.rb
223
224
  - app/models/ecom/core/crew_type.rb
224
225
  - app/models/ecom/core/currency.rb
@@ -234,6 +235,8 @@ files:
234
235
  - app/models/ecom/core/lookup.rb
235
236
  - app/models/ecom/core/material_type.rb
236
237
  - app/models/ecom/core/menu.rb
238
+ - app/models/ecom/core/overtime_sheet.rb
239
+ - app/models/ecom/core/overtime_sheet_entry.rb
237
240
  - app/models/ecom/core/overtime_type.rb
238
241
  - app/models/ecom/core/payment.rb
239
242
  - app/models/ecom/core/payment_detail.rb
@@ -303,6 +306,10 @@ files:
303
306
  - db/migrate/20200401122539_create_ecom_core_attendance_sheet_entries.rb
304
307
  - db/migrate/20200401142959_relate_crew_time_with_attendance_sheet_entry.rb
305
308
  - db/migrate/20200401144137_remove_crew_time_id_from_crew.rb
309
+ - db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb
310
+ - db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb
311
+ - db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb
312
+ - db/migrate/20200413144023_fix_crew_time_columns.rb
306
313
  - lib/ecom/core.rb
307
314
  - lib/ecom/core/engine.rb
308
315
  - lib/ecom/core/version.rb
@@ -311,6 +318,7 @@ files:
311
318
  - spec/factories/ecom/core/application_modules.rb
312
319
  - spec/factories/ecom/core/attendance_sheet_entries.rb
313
320
  - spec/factories/ecom/core/attendance_sheets.rb
321
+ - spec/factories/ecom/core/crew_overtimes.rb
314
322
  - spec/factories/ecom/core/crew_times.rb
315
323
  - spec/factories/ecom/core/crew_types.rb
316
324
  - spec/factories/ecom/core/crews.rb
@@ -327,6 +335,8 @@ files:
327
335
  - spec/factories/ecom/core/lookups.rb
328
336
  - spec/factories/ecom/core/material_types.rb
329
337
  - spec/factories/ecom/core/menus.rb
338
+ - spec/factories/ecom/core/overtime_sheet_entries.rb
339
+ - spec/factories/ecom/core/overtime_sheets.rb
330
340
  - spec/factories/ecom/core/overtime_types.rb
331
341
  - spec/factories/ecom/core/payment_details.rb
332
342
  - spec/factories/ecom/core/payments.rb