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
|
# get and set calendar settings
|
||||||
if sla_selected
|
if sla_selected
|
||||||
BusinessTime::Config.beginning_of_workday = sla_selected.data['beginning_of_workday']
|
TimeCalculation.config( sla_selected.data )
|
||||||
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
|
|
||||||
end
|
end
|
||||||
return sla_selected
|
return sla_selected
|
||||||
end
|
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)
|
def _escalation_calculation_higher_time(escalation_time, check_time, done_time)
|
||||||
return escalation_time if done_time
|
return escalation_time if done_time
|
||||||
return check_time if !escalation_time
|
return check_time if !escalation_time
|
||||||
|
@ -532,13 +518,6 @@ class Ticket < ApplicationModel
|
||||||
return escalation_time
|
return escalation_time
|
||||||
end
|
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
|
def escalation_calculation
|
||||||
|
|
||||||
# set escalation off if ticket is already closed
|
# set escalation off if ticket is already closed
|
||||||
|
@ -574,13 +553,13 @@ class Ticket < ApplicationModel
|
||||||
|
|
||||||
# first response
|
# first response
|
||||||
if sla_selected.first_response_time
|
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
|
# set ticket escalation
|
||||||
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.first_response_escal_date, self.first_response )
|
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.first_response_escal_date, self.first_response )
|
||||||
end
|
end
|
||||||
if self.first_response# && !self.first_response_in_min
|
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
|
end
|
||||||
# set sla time
|
# set sla time
|
||||||
|
@ -595,13 +574,13 @@ class Ticket < ApplicationModel
|
||||||
last_update = self.created_at
|
last_update = self.created_at
|
||||||
end
|
end
|
||||||
if sla_selected.update_time
|
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
|
# set ticket escalation
|
||||||
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.update_time_escal_date, false )
|
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.update_time_escal_date, false )
|
||||||
end
|
end
|
||||||
if self.last_contact_agent
|
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
|
end
|
||||||
|
|
||||||
# set sla time
|
# set sla time
|
||||||
|
@ -612,13 +591,13 @@ class Ticket < ApplicationModel
|
||||||
|
|
||||||
# close time
|
# close time
|
||||||
if sla_selected.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
|
# set ticket escalation
|
||||||
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.close_time_escal_date, self.close_time )
|
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.close_time_escal_date, self.close_time )
|
||||||
end
|
end
|
||||||
if self.close_time# && !self.close_time_in_min
|
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
|
end
|
||||||
# set sla time
|
# set sla time
|
||||||
if sla_selected.close_time && self.close_time_in_min
|
if sla_selected.close_time && self.close_time_in_min
|
||||||
|
|
Loading…
Reference in a new issue