ecom_core 1.2.26 → 1.2.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc33c4120563276cee995e753b7c6e9bdcff0740e9b2e306549abfca286fa8b0
4
- data.tar.gz: 3cf51d8bf2777ff6a56b4659b404513d85c1aa9289069284ae17f8339c3f0df8
3
+ metadata.gz: 42f95a3904d7cdfebcafa09111ccfa6739bfda3496f67126e7d2fc43b586000f
4
+ data.tar.gz: e9cbda9dfca1b89b7660a50a1550ec0a0218dc2faaef488e179d5c0a5a21eedf
5
5
  SHA512:
6
- metadata.gz: 6380cdb381fe5dd76533f94351ee2fddb3be0ef6559c39d883f2e41999c50dd7fd045a9f9b58854e58433c3f5a67924c3f9fed4c24977f5fc1d880be7bf1bb43
7
- data.tar.gz: ce5cb1bac51e23a63dbc85b77129b1281d847323fae967f5fa9178544f91efeb679047748da472d1139e4396dc2e7d77a1699acc6fd88912dadd97066c98e125
6
+ metadata.gz: 704d938a16a2f48723e94663ba0161ada47c46d4c3cea081e1856d476aaaabb0820d1c0de57422f0787946bcf35a9eaac87973568c2736e3f63b7f03e4f9c77f
7
+ data.tar.gz: ceb93623c85ace2292f56142d3982e8be76fff618cdcad2cea79bdfe7c70d35a008e213114a885f16eacbd2de83df995287b94d66face645abb6513feeda0bbc
@@ -0,0 +1,17 @@
1
+ module Ecom
2
+ module Core
3
+ class CrewContract < ApplicationRecord
4
+ belongs_to :crew
5
+
6
+ validates :contract_no, :from, :to, :place_of_work, :probation_period, :contract_type, presence: true
7
+ validates :contract_no, uniqueness: true
8
+ validate :validate_date_range
9
+
10
+ def validate_date_range
11
+ return unless from && to
12
+
13
+ errors.add(:to, 'cannot be before from date.') if from >= to
14
+ end
15
+ end
16
+ end
17
+ end
@@ -9,6 +9,7 @@ module Ecom
9
9
  has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
10
10
 
11
11
  validates :hours, :raw_hours, presence: true
12
+ validate :validate_overtime_by_type
12
13
 
13
14
  scope :by_overtime, lambda { |id|
14
15
  joins(:overtime_sheet_entry).where(ecom_core_overtime_sheet_entries: { overtime_sheet_id: id })
@@ -17,6 +18,18 @@ module Ecom
17
18
 
18
19
  before_save :calculate_hours
19
20
 
21
+ def validate_overtime_by_type
22
+ return unless overtime_type
23
+
24
+ start = Time.zone.parse(overtime_type.from)
25
+ finish = Time.zone.parse(overtime_type.to)
26
+ diff = ((finish - start) / 3600).round
27
+
28
+ return unless raw_hours > diff
29
+
30
+ errors.add(:crew_overtime, 'The selected overtime type does not allow the specified amount of hours.')
31
+ end
32
+
20
33
  def calculate_hours
21
34
  rate = OvertimeType.find(overtime_type_id).rate
22
35
  self.hours = raw_hours * rate
@@ -6,18 +6,13 @@ module Ecom
6
6
  AFTERNOON = :afternoon
7
7
  FULL_DAY = :full_day
8
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
-
15
9
  belongs_to :attendance_sheet_entry
16
10
  belongs_to :revision_to, class_name: 'Ecom::Core::CrewTime', optional: true
17
11
  belongs_to :created_by, class_name: 'Ecom::Core::User'
18
12
  has_one :revision, class_name: 'Ecom::Core::CrewTime', foreign_key: :revision_to_id
19
13
 
20
14
  validates :checkin_time, presence: true, if: :checkout_time
15
+ validate :checkout_is_greater_than_checkin
21
16
 
22
17
  scope :by_attendance, lambda { |id|
23
18
  joins(:attendance_sheet_entry).where(ecom_core_attendance_sheet_entries: { attendance_sheet_id: id })
@@ -27,6 +22,12 @@ module Ecom
27
22
  before_save :calculate_hours
28
23
  after_save :calculate_total
29
24
 
25
+ def checkout_is_greater_than_checkin
26
+ return unless checkin_time && checkout_time && checkout_time <= checkin_time
27
+
28
+ errors.add(:checkout_time, "can't be less than checkin time.")
29
+ end
30
+
30
31
  def calculate_hours
31
32
  self.hours = if checkout_time.nil? || checkin_time.nil?
32
33
  0
@@ -0,0 +1,20 @@
1
+ class CreateEcomCoreCrewContracts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_crew_contracts do |t|
4
+ t.string :contract_no, null: false, unique: true
5
+ t.date :from, null: false
6
+ t.date :to, null: false
7
+ t.string :place_of_work, null: false
8
+ t.integer :probation_period, null: false
9
+ t.string :contract_type, null: false
10
+ t.boolean :contract_signed, null: false, default: false
11
+ t.date :date_contract_signed
12
+ t.references :crew,
13
+ null: false,
14
+ index: { name: 'cc_on_crew_indx' },
15
+ foreign_key: { to_table: :ecom_core_crews }
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.2.26'.freeze
3
+ VERSION = '1.2.27'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :crew_contract, class: 'Ecom::Core::CrewContract' do
3
+ from { Date.yesterday }
4
+ to { Date.tomorrow }
5
+ place_of_work { FFaker::Name.name }
6
+ probation_period { 45 }
7
+ contract_no { FFaker::Name.name }
8
+ contract_type { FFaker::Name.name }
9
+ contract_signed { false }
10
+ date_contract_signed { Date.today }
11
+ association :crew
12
+ end
13
+ end
@@ -4,7 +4,7 @@ FactoryBot.define do
4
4
  "OTName#{n}"
5
5
  end
6
6
  from { '07:00 AM' }
7
- to { '08:00 AM' }
7
+ to { '09:00 AM' }
8
8
  rate { 1.5 }
9
9
  end
10
10
  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.2.26
4
+ version: 1.2.27
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-08-11 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -259,6 +259,7 @@ files:
259
259
  - app/models/ecom/core/component_type.rb
260
260
  - app/models/ecom/core/country.rb
261
261
  - app/models/ecom/core/crew.rb
262
+ - app/models/ecom/core/crew_contract.rb
262
263
  - app/models/ecom/core/crew_overtime.rb
263
264
  - app/models/ecom/core/crew_time.rb
264
265
  - app/models/ecom/core/crew_type.rb
@@ -354,6 +355,7 @@ files:
354
355
  - db/migrate/20200602130247_create_ecom_core_requested_items.rb
355
356
  - db/migrate/20200602830603_create_ecom_core_bookings.rb
356
357
  - db/migrate/20200603115317_create_ecom_core_booked_items.rb
358
+ - db/migrate/20200901085227_create_ecom_core_crew_contracts.rb
357
359
  - lib/ecom/core.rb
358
360
  - lib/ecom/core/engine.rb
359
361
  - lib/ecom/core/version.rb
@@ -367,6 +369,7 @@ files:
367
369
  - spec/factories/ecom/core/companies.rb
368
370
  - spec/factories/ecom/core/component_types.rb
369
371
  - spec/factories/ecom/core/countries.rb
372
+ - spec/factories/ecom/core/crew_contracts.rb
370
373
  - spec/factories/ecom/core/crew_overtimes.rb
371
374
  - spec/factories/ecom/core/crew_times.rb
372
375
  - spec/factories/ecom/core/crew_types.rb