Last active
October 6, 2015 01:54
-
-
Save raulsouzalima/7b05d15f7a4bc911b016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Reports | |
class ActiveUsersCreditsByPublicationAndInstitution < ActiveUsersByInstitution | |
def records | |
# retorna os usuários ativos em um período do redshift | |
User.with_deleted.select("login, active, bonus_quota").where(system_id: reporter.system.id).includes(:deactivation_periods) | |
.where("users.created_at <= :end_of_month", end_of_month: end_of_month) | |
.where("deleted_at is null or deleted_at >= :beginning_of_month", beginning_of_month: beginning_of_month) | |
.where("(deactivation_periods.id is null and active is true) or (deactivation_periods.id is not null and ((#{changed_state_in_period}) or (#{changed_state_before_or_after_period})) and not (#{where_inactive_around_period}))", beginning_of_month: beginning_of_month, end_of_month: end_of_month) | |
end | |
def add_sheets(doc) | |
add_worksheet "Créditos por publicação e instituição".truncate(31), doc do |sheet| | |
sheet.add_row ["Login", "Instituição", "Nome publicação", "ISBN", "Créditos disponíveis"], style: [bold_style, bold_style, bold_style, bold_style, bold_style] | |
Octopus.using(:warehouse) do | |
records.each do |user| | |
PrintQuota.where(user_id: user.id).each do |print_quota| | |
if publication = ::Publication.find(print_quota.publication_id) | |
credit = print_quota.credit | |
sheet.add_row([user.login, clean(user.institution.try(:name)), clean(publication.try(:title)), publication.uid, credit], style: [default_style, default_style, default_style, plain_number_style, default_style]) if credit > 0 | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment