ecom_core 1.1.12 → 1.1.17

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: c687788f0d44a5f5c2901060c47c1bf682861d5ea49c031ea8b194445e809353
4
- data.tar.gz: 41618d80915b2ce3ac830288ff71bc7c24221069d6265ea6cd18068259cecf1f
3
+ metadata.gz: 7bdf3745639577dacd60d41eb82831de69cd41040b71411628f17be1a8397b42
4
+ data.tar.gz: 21fd30d003500d6648d42eb6be7e5d073eff6b7810148cd00aed1fd2496363ec
5
5
  SHA512:
6
- metadata.gz: 8fe8051081c7dd7c06a1ed23a51fe5b606b3c019d1ce6b5a1b0990cd1c994de28b171a16e92749e25a25f2f587f4fb9cf908d8042269a2de0428984f39796ce7
7
- data.tar.gz: fdb7d80fce6ef7ffe4bbdf31d9c96d3cb8479cc07146e4f80906cf3839ec07f0c0d4f089c72c4bbefbccc81b130cf982aceb27847f53100e495a9c9f94f03088
6
+ metadata.gz: 769ccb1b054f0b6faf9421e323e562053d3fe7770fb3abed2af5e0535be3f61f39803deff27b4816d4b58efcb07419b46519c73906ff44c7480ee4b03e9ac099
7
+ data.tar.gz: 6d852af57207ad9cfbc6f30d7eaadf239c338b6c4796198e5ec8f833b69b16fba2d790d555b64b37279583e87edb8a517a7dfe0811e74b66fc21f1e0659c3b9c
@@ -2,14 +2,20 @@ 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
13
  scope :open, -> { find_by(status: OPEN) }
14
+ scope :current_open, -> { where(status: OPEN, date: Date.today) }
15
+
16
+ def self.open_exists?
17
+ AttendanceSheet.where(status: OPEN).exists?
18
+ end
13
19
 
14
20
  def self.exists_for_today?
15
21
  AttendanceSheet.where(date: Date.today).exists?
@@ -27,31 +33,33 @@ module Ecom
27
33
  def self.create_current
28
34
  raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?
29
35
 
36
+ raise 'There is an open attendance sheet which needs to be submitted before creating a new one.' if AttendanceSheet.open_exists?
37
+
30
38
  AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN)
31
39
  end
32
40
 
33
- def self.close_current
41
+ def self.submit_current
34
42
  sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN)
35
43
 
36
- raise 'There is no attendance sheet to close.' if sheet.nil?
44
+ raise 'There is no open attendance sheet to submit.' if sheet.nil?
37
45
 
38
46
  sheet.closed_at = Time.now
39
- sheet.status = CLOSED
47
+ sheet.status = SUBMITTED
40
48
  sheet.save
41
49
  sheet
42
50
  end
43
51
 
44
52
  # This method should be used by privileged users
45
- # to close the attendance sheet after the date has
53
+ # to submit the attendance sheet after the date has
46
54
  # passed. Normally, timekeepers need to open and close
47
55
  # an attendance sheet of a date on the specific date.
48
- def self.close
49
- raise 'There is no attendance sheet to close.' unless AttendanceSheet.open_exists_for_today?
56
+ def submit
57
+ raise 'This attendance sheet is not open. Therefore it cannot be submitted' unless status == OPEN
50
58
 
51
- sheet = AttendanceSheet.open
52
- sheet.closed_at = Time.now
53
- sheet.save
54
- sheet
59
+ self.closed_at = Time.now
60
+ self.status = SUBMITTED
61
+ save
62
+ self
55
63
  end
56
64
  end
57
65
  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'
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
@@ -0,0 +1,33 @@
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, -> { find_by(status: OPEN) }
14
+
15
+ def self.open_exists?
16
+ OvertimeSheet.where(status: OPEN).exists?
17
+ end
18
+
19
+ # Overtime sheet should be created using the
20
+ # method below only. This is because we need to
21
+ # check if there is an open overtime already,
22
+ # and also that we have only one open overtime
23
+ # sheet at a time.
24
+ def self.create_new(date)
25
+ if OvertimeSheet.open_exists?
26
+ raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
27
+ end
28
+
29
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Ecom
2
+ module Core
3
+ class OvertimeSheetEntry < ApplicationRecord
4
+ belongs_to :overtime_sheet
5
+ belongs_to :crew
6
+ end
7
+ end
8
+ end
@@ -9,19 +9,16 @@ 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, label: item.label, icon: item.icon, items: [] }
12
+ list << { id: item.id, label: item.label, icon: item.icon, children: [] }
13
13
  end
14
14
 
15
15
  menu_list.each do |ml|
16
- ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
16
+ ml[:children] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
17
17
  if item.parent_id == ml[:id]
18
18
  list << { id: item.id, label: item.label, icon: item.icon, route: item.route }
19
19
  end
20
20
  end
21
21
  end
22
-
23
- # Remove id key
24
- menu_list.map { |ml| ml.delete(:id) }
25
22
  menu_list
26
23
  end
27
24
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.12'.freeze
3
+ VERSION = '1.1.17'.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
@@ -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.12
4
+ version: 1.1.17
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-10 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,9 @@ 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
306
312
  - lib/ecom/core.rb
307
313
  - lib/ecom/core/engine.rb
308
314
  - lib/ecom/core/version.rb
@@ -311,6 +317,7 @@ files:
311
317
  - spec/factories/ecom/core/application_modules.rb
312
318
  - spec/factories/ecom/core/attendance_sheet_entries.rb
313
319
  - spec/factories/ecom/core/attendance_sheets.rb
320
+ - spec/factories/ecom/core/crew_overtimes.rb
314
321
  - spec/factories/ecom/core/crew_times.rb
315
322
  - spec/factories/ecom/core/crew_types.rb
316
323
  - spec/factories/ecom/core/crews.rb
@@ -327,6 +334,8 @@ files:
327
334
  - spec/factories/ecom/core/lookups.rb
328
335
  - spec/factories/ecom/core/material_types.rb
329
336
  - spec/factories/ecom/core/menus.rb
337
+ - spec/factories/ecom/core/overtime_sheet_entries.rb
338
+ - spec/factories/ecom/core/overtime_sheets.rb
330
339
  - spec/factories/ecom/core/overtime_types.rb
331
340
  - spec/factories/ecom/core/payment_details.rb
332
341
  - spec/factories/ecom/core/payments.rb