2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-04-10 08:06:11 +00:00
|
|
|
module TicketStats
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ticket_ids_and_assets(condition, current_user, limit, assets)
|
|
|
|
tickets = Ticket.search(
|
2018-12-19 17:31:51 +00:00
|
|
|
limit: limit,
|
|
|
|
condition: condition,
|
2017-04-10 08:06:11 +00:00
|
|
|
current_user: current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
sort_by: 'created_at',
|
|
|
|
order_by: 'desc',
|
2017-04-10 08:06:11 +00:00
|
|
|
)
|
|
|
|
assets_of_tickets(tickets, assets)
|
|
|
|
end
|
|
|
|
|
2021-07-20 17:35:02 +00:00
|
|
|
def ticket_stats_last_year(condition)
|
2017-04-10 08:06:11 +00:00
|
|
|
volume_by_year = []
|
|
|
|
now = Time.zone.now
|
|
|
|
|
2017-10-01 12:25:52 +00:00
|
|
|
(0..11).each do |month_back|
|
2017-04-10 08:06:11 +00:00
|
|
|
date_to_check = now - month_back.month
|
|
|
|
date_start = "#{date_to_check.year}-#{date_to_check.month}-01 00:00:00"
|
|
|
|
date_end = "#{date_to_check.year}-#{date_to_check.month}-#{date_to_check.end_of_month.day} 00:00:00"
|
|
|
|
|
|
|
|
# created
|
2021-07-20 17:35:02 +00:00
|
|
|
created = TicketPolicy::ReadScope.new(current_user).resolve
|
2021-07-21 14:04:17 +00:00
|
|
|
.where(created_at: (date_start..date_end))
|
2021-07-20 17:35:02 +00:00
|
|
|
.where(condition)
|
|
|
|
.count
|
2017-04-10 08:06:11 +00:00
|
|
|
|
|
|
|
# closed
|
2021-07-20 17:35:02 +00:00
|
|
|
closed = TicketPolicy::ReadScope.new(current_user).resolve
|
2021-07-21 14:04:17 +00:00
|
|
|
.where(close_at: (date_start..date_end))
|
2021-07-20 17:35:02 +00:00
|
|
|
.where(condition)
|
|
|
|
.count
|
2017-04-10 08:06:11 +00:00
|
|
|
|
|
|
|
data = {
|
2018-12-19 17:31:51 +00:00
|
|
|
month: date_to_check.month,
|
|
|
|
year: date_to_check.year,
|
|
|
|
text: Date::MONTHNAMES[date_to_check.month],
|
2017-04-10 08:06:11 +00:00
|
|
|
created: created,
|
2018-12-19 17:31:51 +00:00
|
|
|
closed: closed,
|
2017-04-10 08:06:11 +00:00
|
|
|
}
|
|
|
|
volume_by_year.push data
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-04-10 08:06:11 +00:00
|
|
|
volume_by_year
|
|
|
|
end
|
|
|
|
|
|
|
|
def assets_of_tickets(tickets, assets)
|
|
|
|
ticket_ids = []
|
|
|
|
tickets.each do |ticket|
|
|
|
|
ticket_ids.push ticket.id
|
|
|
|
assets = ticket.assets(assets)
|
|
|
|
end
|
|
|
|
ticket_ids
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|