Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/models/metric/user/wise_transfer_amount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: metrics
#
# id :bigint not null, primary key
# metric :jsonb
# subject_type :string
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# subject_id :bigint
#
# Indexes
#
# index_metrics_on_subject (subject_type,subject_id)
# index_metrics_on_subject_type_and_subject_id_and_type (subject_type,subject_id,type) UNIQUE
#
class Metric
module User
class WiseTransferAmount < Metric
include Subject

def calculate
user.wise_transfers.where("EXTRACT(YEAR FROM created_at) = ?", Metric.year).sum(:usd_amount_cents) +
Reimbursement::PayoutHolding.where(report: user.reimbursement_reports.reimbursed.where("EXTRACT(YEAR FROM created_at) = ?", Metric.year).where.not(currency: "USD")).sum(:amount_cents)
end

end
end

end
33 changes: 33 additions & 0 deletions app/models/metric/user/wise_transfer_count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: metrics
#
# id :bigint not null, primary key
# metric :jsonb
# subject_type :string
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# subject_id :bigint
#
# Indexes
#
# index_metrics_on_subject (subject_type,subject_id)
# index_metrics_on_subject_type_and_subject_id_and_type (subject_type,subject_id,type) UNIQUE
#
class Metric
module User
class WiseTransferCount < Metric
include Subject

def calculate
user.wise_transfers.where("EXTRACT(YEAR FROM created_at) = ?", Metric.year).count +
user.reimbursement_reports.reimbursed.where("EXTRACT(YEAR FROM created_at) = ?", Metric.year).where.not(currency: "USD").count
end

end
end

end
Loading