2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-10-29 02:33:36 +00:00
|
|
|
class Report::TicketMoved < Report::Base
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
result = Report::TicketMoved.aggs(
|
2019-03-26 00:17:17 +00:00
|
|
|
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
|
|
|
|
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
|
2015-10-29 02:33:36 +00:00
|
|
|
interval: 'month', # quarter, month, week, day, hour, minute, second
|
|
|
|
selector: selector, # ticket selector to get only a collection of tickets
|
|
|
|
params: { type: 'in' }, # in|out
|
2019-03-26 00:17:17 +00:00
|
|
|
timezone: 'Europe/Berlin',
|
2015-10-29 02:33:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
[4,5,1,5,0,51,5,56,7,4]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
def self.aggs(params_origin)
|
|
|
|
params = params_origin.dup
|
2015-10-29 02:33:36 +00:00
|
|
|
|
|
|
|
selector = params[:selector]['ticket.group_id']
|
|
|
|
|
|
|
|
if !selector
|
|
|
|
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
|
|
end
|
|
|
|
|
|
|
|
result = []
|
2020-07-13 12:46:08 +00:00
|
|
|
case params[:interval]
|
|
|
|
when 'month'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 12
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'week'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 7
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'day'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 31
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'hour'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 24
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'minute'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 60
|
|
|
|
end
|
2017-10-01 12:25:52 +00:00
|
|
|
(1..stop_interval).each do |_counter|
|
2020-07-13 12:46:08 +00:00
|
|
|
case params[:interval]
|
|
|
|
when 'month'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start].next_month
|
2020-11-12 11:42:44 +00:00
|
|
|
when 'week', 'day'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start].next_day
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'hour'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start] + 1.hour
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'minute'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start] + 1.minute
|
2015-10-29 02:33:36 +00:00
|
|
|
end
|
|
|
|
local_params = group_attributes(selector, params)
|
|
|
|
local_selector = params[:selector].clone
|
2018-02-07 09:15:00 +00:00
|
|
|
without_merged_tickets = {
|
|
|
|
'ticket_state.name' => {
|
|
|
|
'operator' => 'is not',
|
|
|
|
'value' => 'merged'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local_selector.merge!(without_merged_tickets) # do not show merged tickets in reports
|
2015-10-29 02:33:36 +00:00
|
|
|
if params[:params][:type] == 'out'
|
|
|
|
local_selector.delete('ticket.group_id')
|
|
|
|
end
|
|
|
|
defaults = {
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
type: 'updated',
|
2015-10-29 02:33:36 +00:00
|
|
|
attribute: 'group',
|
2019-03-26 00:17:17 +00:00
|
|
|
start: params[:range_start],
|
|
|
|
end: params[:range_end],
|
2018-12-19 17:31:51 +00:00
|
|
|
selector: local_selector
|
2015-10-29 02:33:36 +00:00
|
|
|
}
|
|
|
|
local_params = defaults.merge(local_params)
|
|
|
|
count = history_count(local_params)
|
|
|
|
result.push count
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_start] = params[:range_end]
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-10-29 02:33:36 +00:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
result = Report::TicketMoved.items(
|
2019-03-26 00:17:17 +00:00
|
|
|
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
|
|
|
|
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
|
2015-10-29 02:33:36 +00:00
|
|
|
selector: selector, # ticket selector to get only a collection of tickets
|
|
|
|
params: { type: 'in' }, # in|out
|
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
count: 123,
|
|
|
|
ticket_ids: [4,5,1,5,0,51,5,56,7,4],
|
|
|
|
assets: assets,
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.items(params)
|
|
|
|
|
|
|
|
selector = params[:selector]['ticket.group_id']
|
|
|
|
|
|
|
|
if !selector
|
|
|
|
return {
|
2018-12-19 17:31:51 +00:00
|
|
|
count: 0,
|
2015-10-29 02:33:36 +00:00
|
|
|
ticket_ids: [],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local_params = group_attributes(selector, params)
|
2018-02-07 09:15:00 +00:00
|
|
|
without_merged_tickets = {
|
|
|
|
'ticket_state.name' => {
|
|
|
|
'operator' => 'is not',
|
|
|
|
'value' => 'merged'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local_selector = params[:selector].merge!(without_merged_tickets) # do not show merged tickets in reports
|
2015-10-29 02:33:36 +00:00
|
|
|
if params[:params][:type] == 'out'
|
|
|
|
local_selector.delete('ticket.group_id')
|
|
|
|
end
|
|
|
|
defaults = {
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
type: 'updated',
|
2015-10-29 02:33:36 +00:00
|
|
|
attribute: 'group',
|
2018-12-19 17:31:51 +00:00
|
|
|
start: params[:range_start],
|
|
|
|
end: params[:range_end],
|
|
|
|
selector: local_selector
|
2015-10-29 02:33:36 +00:00
|
|
|
}
|
|
|
|
local_params = defaults.merge(local_params)
|
|
|
|
result = history(local_params)
|
2017-12-12 02:54:50 +00:00
|
|
|
return result if params[:sheet].present?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-10-29 02:33:36 +00:00
|
|
|
assets = {}
|
2017-10-01 12:25:52 +00:00
|
|
|
result[:ticket_ids].each do |ticket_id|
|
2015-10-29 02:33:36 +00:00
|
|
|
ticket_full = Ticket.find(ticket_id)
|
|
|
|
assets = ticket_full.assets(assets)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-10-29 02:33:36 +00:00
|
|
|
result[:assets] = assets
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.group_attributes(selector, params)
|
2017-11-23 08:09:44 +00:00
|
|
|
group_id = selector['value']
|
2020-07-13 12:46:08 +00:00
|
|
|
case selector['operator']
|
|
|
|
when 'is'
|
2015-10-29 02:33:36 +00:00
|
|
|
if params[:params][:type] == 'in'
|
|
|
|
return {
|
|
|
|
id_not_from: group_id,
|
2018-12-19 17:31:51 +00:00
|
|
|
id_to: group_id,
|
2015-10-29 02:33:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return {
|
2018-12-19 17:31:51 +00:00
|
|
|
id_from: group_id,
|
2015-10-29 02:33:36 +00:00
|
|
|
id_not_to: group_id,
|
|
|
|
}
|
|
|
|
end
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'is not'
|
2015-10-29 02:33:36 +00:00
|
|
|
if params[:params][:type] == 'in'
|
|
|
|
return {
|
2018-12-19 17:31:51 +00:00
|
|
|
id_from: group_id,
|
2015-10-29 02:33:36 +00:00
|
|
|
id_not_to: group_id,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return {
|
|
|
|
id_not_from: group_id,
|
2018-12-19 17:31:51 +00:00
|
|
|
id_to: group_id,
|
2015-10-29 02:33:36 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-03-01 14:26:46 +00:00
|
|
|
raise "Unknown selector params '#{selector.inspect}'"
|
2015-10-29 02:33:36 +00:00
|
|
|
end
|
|
|
|
end
|