Skip to content

Commit

Permalink
REFACTOR remove unused code childrenservedreportservice
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyli97 committed Aug 15, 2024
1 parent 2c5ed05 commit 1969e05
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions app/services/reports/children_served_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,8 @@ def average_children_monthly
total_children_served / 12.0
end

def disposable_diapers_from_kits_total
organization_id = @organization.id
year = @year

sql_query = <<-SQL
SELECT SUM(line_items.quantity * kit_line_items.quantity)
FROM distributions
INNER JOIN line_items ON line_items.itemizable_type = 'Distribution' AND line_items.itemizable_id = distributions.id
INNER JOIN items ON items.id = line_items.item_id
INNER JOIN kits ON kits.id = items.kit_id
INNER JOIN line_items AS kit_line_items ON kits.id = kit_line_items.itemizable_id
INNER JOIN items AS kit_items ON kit_items.id = kit_line_items.item_id
INNER JOIN base_items ON base_items.partner_key = kit_items.partner_key
WHERE distributions.organization_id = ?
AND EXTRACT(year FROM issued_at) = ?
AND LOWER(base_items.category) LIKE '%diaper%'
AND NOT (LOWER(base_items.category) LIKE '%cloth%' OR LOWER(base_items.name) LIKE '%cloth%')
AND NOT (LOWER(base_items.category) LIKE '%adult%')
SQL

sanitized_sql = ActiveRecord::Base.send(:sanitize_sql_array, [sql_query, organization_id, year])

result = ActiveRecord::Base.connection.execute(sanitized_sql)
result.first['sum'].to_i
end

private

def total_disposable_diapers_distributed
loose_disposable_distribution_total + disposable_diapers_from_kits_total
end

def loose_disposable_distribution_total
organization
.distributions
.for_year(year)
.joins(line_items: :item)
.merge(Item.disposable)
.sum("line_items.quantity")
end

def total_children_served_with_loose_disposables
organization
.distributions
Expand Down

0 comments on commit 1969e05

Please sign in to comment.