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
|
|
|
|
2019-09-16 20:36:03 +00:00
|
|
|
class ExcelSheet::Ticket < ExcelSheet
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
excel = ExcelSheet::Ticket.new(
|
|
|
|
title: "#{year}-#{month}",
|
|
|
|
ticket_ids: ticket_ids,
|
|
|
|
additional_attributes: additional_attributes,
|
|
|
|
additional_attributes_header: additional_attributes_header,
|
|
|
|
timezone: params[:timezone],
|
|
|
|
locale: current_user.locale,
|
|
|
|
)
|
|
|
|
|
|
|
|
excel.content
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@ticket_ids = params[:ticket_ids] || []
|
|
|
|
@additional_attributes = params[:additional_attributes] || []
|
|
|
|
@additional_attributes_header = params[:additional_attributes_header] || []
|
|
|
|
|
|
|
|
super(
|
|
|
|
title: params[:title],
|
|
|
|
header: ticket_header,
|
|
|
|
records: [],
|
|
|
|
timezone: params[:timezone],
|
|
|
|
locale: params[:locale]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ticket_header
|
|
|
|
header = [
|
|
|
|
{ display: '#', name: 'number', width: 18, data_type: 'string' },
|
2021-11-15 15:58:19 +00:00
|
|
|
{ display: __('Title'), name: 'title', width: 34, data_type: 'string' },
|
|
|
|
{ display: __('State'), name: 'state_id', width: 14, data_type: 'string' },
|
|
|
|
{ display: __('Priority'), name: 'priority_id', width: 14, data_type: 'string' },
|
|
|
|
{ display: __('Group'), name: 'group_id', width: 20, data_type: 'string' },
|
|
|
|
{ display: __('Owner'), name: 'owner_id', width: 20, data_type: 'string' },
|
|
|
|
{ display: __('Customer'), name: 'customer_id', width: 20, data_type: 'string' },
|
|
|
|
{ display: __('Organization'), name: 'organization_id', width: 20, data_type: 'string' },
|
|
|
|
{ display: __('Create Channel'), name: 'create_article_type_id', width: 10, data_type: 'string' },
|
|
|
|
{ display: __('Sender'), name: 'create_article_sender_id', width: 14, data_type: 'string' },
|
|
|
|
{ display: __('Tags'), name: 'tag_list', width: 20, data_type: 'string' },
|
|
|
|
{ display: __('Time Units Total'), name: 'time_unit', width: 10, data_type: 'float' },
|
2019-09-16 20:36:03 +00:00
|
|
|
]
|
|
|
|
|
2020-09-30 09:07:01 +00:00
|
|
|
header.concat(@additional_attributes_header) if @additional_attributes_header
|
2019-09-16 20:36:03 +00:00
|
|
|
|
|
|
|
# ObjectManager attributes
|
2020-12-08 14:06:41 +00:00
|
|
|
ObjectManager::Attribute
|
|
|
|
.where(
|
|
|
|
active: true,
|
|
|
|
to_create: false,
|
|
|
|
object_lookup: ObjectLookup.lookup(name: 'Ticket')
|
|
|
|
)
|
|
|
|
.where.not(
|
2021-06-23 11:35:27 +00:00
|
|
|
name: header.pluck(:name)
|
|
|
|
)
|
|
|
|
.where.not(
|
2020-12-08 14:06:41 +00:00
|
|
|
display: header.pluck(:display)
|
|
|
|
)
|
|
|
|
.pluck_as_hash(:name, :display, :data_type, :data_option)
|
|
|
|
.each { |elem| elem[:width] = 20 }
|
|
|
|
.then { |objects| header.concat(objects) }
|
2019-09-16 20:36:03 +00:00
|
|
|
|
2020-07-07 06:30:20 +00:00
|
|
|
header.concat([
|
2021-11-15 15:58:19 +00:00
|
|
|
{ display: __('Created At'), name: 'created_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Updated At'), name: 'updated_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Closed At'), name: 'close_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Close Escalation At'), name: 'close_escalation_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Close In Min'), name: 'close_in_min', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('Close Diff In Min'), name: 'close_diff_in_min', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('First Response At'), name: 'first_response_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('First Response Escalation At'), name: 'first_response_escalation_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('First Response In Min'), name: 'first_response_in_min', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('First Response Diff In Min'), name: 'first_response_diff_in_min', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('Update Escalation At'), name: 'update_escalation_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Update In Min'), name: 'update_in_min', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('Update Diff In Min'), name: 'update_diff_in_min', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('Last Contact At'), name: 'last_contact_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Last Contact Agent At'), name: 'last_contact_agent_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Last Contact Customer At'), name: 'last_contact_customer_at', width: 18, data_type: 'datetime' },
|
|
|
|
{ display: __('Article Count'), name: 'article_count', width: 10, data_type: 'integer' },
|
|
|
|
{ display: __('Escalation At'), name: 'escalation_at', width: 18, data_type: 'datetime' },
|
2020-07-07 06:30:20 +00:00
|
|
|
])
|
|
|
|
|
2019-09-16 20:36:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def gen_rows
|
|
|
|
@ticket_ids.each_with_index do |ticket_id, index|
|
|
|
|
ticket = ::Ticket.lookup(id: ticket_id)
|
|
|
|
raise "Can't find Ticket with ID #{ticket_id} for '#{@title}' #{self.class.name} generation" if !ticket
|
|
|
|
|
|
|
|
gen_row_by_header(ticket, @additional_attributes[index])
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.error e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|