Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revenue xls report #85

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
:major: 0
:minor: 3
:patch: 5
:patch: 6
:special: ''
:metadata: ''
1 change: 0 additions & 1 deletion app/models/withdraw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Withdraw < PeatioRecord
scope :last_24_hours, -> { where('created_at > ?', 24.hour.ago) }
scope :last_1_month, -> { where('created_at > ?', 1.month.ago) }
scope :locked, -> { where(is_locked: true) }
scope :accountable, -> { where(aasm_state: %i[confirming succeed]) }

delegate :uid, to: :member, prefix: true

Expand Down
5 changes: 3 additions & 2 deletions app/views/dashboard/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ table.table.table-condensed.table-striped.table-cross-row
- currencies = [currency] + currency.merged_tokens
- ids = [currency_id] + currency.merged_tokens.ids
- total_deposit = Deposit.accountable.where(currency_id: ids).sum(:amount)
- total_withdraw = Withdraw.accountable.where(currency_id: ids).sum(:amount)
- confirming_withdrawals_amount = Withdraw.confirming.where(currency_id: ids).sum(:amount)
- success_withdrawals_amount = Withdraw.success.where(currency_id: ids).sum(:amount)
- total_withdraw = confirming_withdrawals_amount + success_withdrawals_amount
- total_operations_amount = Operations::Revenue.where(currency_id: ids).sum('credit - debit')
- total_operations_assets_credit = Operations::Asset.where(currency_id: ids).sum('credit - debit')
- investment_amount = ids.sum { |id| adjustments[[id, 'investment']].to_d }
Expand Down Expand Up @@ -148,7 +149,7 @@ table.table.table-condensed.table-striped.table-cross-row
= format_money row[2], currency_id, show_currency: false
// 7
td.text-right
= format_divergence (total_deposit - total_withdraw + total_member_transfers) - (row[1] + row[2]) - total_operations_amount + investment_amount - total_skipped_deposits + asset_registration_amount + compensation_amount, currency, show_currency: false
= format_divergence (total_deposit - success_withdrawals_amount + total_member_transfers) - (row[1] + row[2]) - total_operations_amount + investment_amount - total_skipped_deposits + asset_registration_amount + compensation_amount, currency, show_currency: false
.text-small.text-muted.mt-2
// 8
td.text-right
Expand Down
2 changes: 1 addition & 1 deletion app/views/operations/accounts/_table.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ tbody
= middot
- else
- par = d == :balance ? {} : { d.to_s+"_gt" => 0}
= link_to url_for([:operations, account.records_name, q: par.merge( account_id_eq: account.id, currency_id_eq: currency.id )]) do
= link_to url_for([:operations, account.records_name.to_sym, q: par.merge( account_id_eq: account.id, currency_id_eq: currency.id )]) do
= format_money data[d], currency
= check_operations_amount(account)
30 changes: 30 additions & 0 deletions app/views/reports/revenues_report.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

wb = xlsx_package.workbook
header = wb.styles.add_style b: true, alignment: { horizontal: :center }

wb.add_worksheet(name: report.name) do |sheet|
render 'present_form', sheet: sheet, form: report.form_object if report.form_object.present?

sheet.add_row ['Fees By Market'], style: header
sheet.add_row ['Currency', 'Base Turnover', 'Quote Turnover', 'Makers Fee','Takers Fee'], style: header
report.results[:markets].each_pair do |market, data|
market = Market.find_by(symbol: market)

sheet.add_row([
market.to_s,
number_to_currency(data[:base_turnover], unit: market.base_unit.upcase, precision: 8),
number_to_currency(data[:quote_turnover], unit: market.quote_unit.upcase, precision: 8),
number_to_currency(data[market.base_unit], unit: market.base_unit.upcase, precision: 8),
number_to_currency(data[market.quote_unit], unit: market.quote_unit.upcase, precision: 8)
])
end

sheet.add_row []
sheet.add_row ['Fees By Currency'], style: header
sheet.add_row ['Currency', 'Fee'], style: header

report.results[:currency_fees].each_pair do |currency, amount|
sheet.add_row [currency, amount]
end
end
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
set :keep_releases, 10

set :linked_files, %w[.env config/master.key config/settings.yml]
set :linked_dirs, %w[log node_modules tmp/pids tmp/cache tmp/sockets public/assets public/uploads public/uploads public/packs]
set :linked_dirs, %w[log node_modules tmp/pids tmp/cache tmp/sockets tmp/divergence_exists tmp/wallet_low_balances public/assets public/uploads public/uploads public/packs]

set :config_files, fetch(:linked_files)

Expand Down