Moved to external module for business time calculation.
This commit is contained in:
parent
be6a3fdcc4
commit
a702e39730
1 changed files with 7 additions and 28 deletions
|
@ -505,25 +505,11 @@ class Ticket < ApplicationModel
|
|||
|
||||
# get and set calendar settings
|
||||
if sla_selected
|
||||
BusinessTime::Config.beginning_of_workday = sla_selected.data['beginning_of_workday']
|
||||
BusinessTime::Config.end_of_workday = sla_selected.data['end_of_workday']
|
||||
days = []
|
||||
['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].each {|day|
|
||||
if sla_selected.data[day]
|
||||
days.push day.downcase.to_sym
|
||||
end
|
||||
}
|
||||
BusinessTime::Config.work_week = days
|
||||
TimeCalculation.config( sla_selected.data )
|
||||
end
|
||||
return sla_selected
|
||||
end
|
||||
|
||||
def _escalation_calculation_dest_time(start_time, diff_min)
|
||||
start_time = Time.parse( start_time.to_s )
|
||||
dest_time = (diff_min / 60).round.business_hour.after( start_time )
|
||||
return dest_time
|
||||
end
|
||||
|
||||
def _escalation_calculation_higher_time(escalation_time, check_time, done_time)
|
||||
return escalation_time if done_time
|
||||
return check_time if !escalation_time
|
||||
|
@ -532,13 +518,6 @@ class Ticket < ApplicationModel
|
|||
return escalation_time
|
||||
end
|
||||
|
||||
def _escalation_calculation_business_time_diff(start_time, end_time)
|
||||
start_time = Time.parse(start_time.to_s)
|
||||
end_time = Time.parse(end_time.to_s)
|
||||
diff = start_time.business_time_until(end_time) / 60
|
||||
diff.round
|
||||
end
|
||||
|
||||
def escalation_calculation
|
||||
|
||||
# set escalation off if ticket is already closed
|
||||
|
@ -574,13 +553,13 @@ class Ticket < ApplicationModel
|
|||
|
||||
# first response
|
||||
if sla_selected.first_response_time
|
||||
self.first_response_escal_date = self._escalation_calculation_dest_time( created_at, sla_selected.first_response_time )
|
||||
self.first_response_escal_date = TimeCalculation.dest_time( created_at, sla_selected.first_response_time )
|
||||
|
||||
# set ticket escalation
|
||||
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.first_response_escal_date, self.first_response )
|
||||
end
|
||||
if self.first_response# && !self.first_response_in_min
|
||||
self.first_response_in_min = self._escalation_calculation_business_time_diff( self.created_at, self.first_response )
|
||||
self.first_response_in_min = TimeCalculation.business_time_diff( self.created_at, self.first_response )
|
||||
|
||||
end
|
||||
# set sla time
|
||||
|
@ -595,13 +574,13 @@ class Ticket < ApplicationModel
|
|||
last_update = self.created_at
|
||||
end
|
||||
if sla_selected.update_time
|
||||
self.update_time_escal_date = self._escalation_calculation_dest_time( last_update, sla_selected.update_time )
|
||||
self.update_time_escal_date = TimeCalculation.dest_time( last_update, sla_selected.update_time )
|
||||
|
||||
# set ticket escalation
|
||||
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.update_time_escal_date, false )
|
||||
end
|
||||
if self.last_contact_agent
|
||||
self.update_time_in_min = self._escalation_calculation_business_time_diff( self.created_at, self.last_contact_agent )
|
||||
self.update_time_in_min = TimeCalculation.business_time_diff( self.created_at, self.last_contact_agent )
|
||||
end
|
||||
|
||||
# set sla time
|
||||
|
@ -612,13 +591,13 @@ class Ticket < ApplicationModel
|
|||
|
||||
# close time
|
||||
if sla_selected.close_time
|
||||
self.close_time_escal_date = self._escalation_calculation_dest_time( self.created_at, sla_selected.close_time )
|
||||
self.close_time_escal_date = TimeCalculation.dest_time( self.created_at, sla_selected.close_time )
|
||||
|
||||
# set ticket escalation
|
||||
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.close_time_escal_date, self.close_time )
|
||||
end
|
||||
if self.close_time# && !self.close_time_in_min
|
||||
self.close_time_in_min = self._escalation_calculation_business_time_diff( self.created_at, self.close_time )
|
||||
self.close_time_in_min = TimeCalculation.business_time_diff( self.created_at, self.close_time )
|
||||
end
|
||||
# set sla time
|
||||
if sla_selected.close_time && self.close_time_in_min
|
||||
|
|
Loading…
Reference in a new issue