Skip to content

Instantly share code, notes, and snippets.

@helpse
Last active October 6, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helpse/a1fd06f8b6fa9c15aca7d75dfa11bebb to your computer and use it in GitHub Desktop.
Save helpse/a1fd06f8b6fa9c15aca7d75dfa11bebb to your computer and use it in GitHub Desktop.
ActiveAdmin.register Order, as: 'FinanceOrders' do
idx = 0
index do |x|
column :id do
idx += 1
end
column :contractor do |order|
amount = order.contractor_payment_amount
Finances.add amount
amount.to_money
end
summary = Finances.get_summary collection
tfoot do
tr do
column :contractor do |order|
Finances.total.to_money
end
column :profit do |order|
(order.sum_cost / 100).to_money * (1 - FEE) - Finances.total.to_money
end
end
end
td
end
end
end
end
class Finances
@@sum = 0
def self.get_orders
Order.where(state: [1, 2, 3, 4])
end
def self.get_bids
BidRequest.where(state: [1, 2, 3, 5])
end
def self.get_summary(collection)
collection.select('*, sum(contractor_tip_cents) sum_tips, sum(total_cost_cents) sum_cost')
end
def self.add(amount)
@@sum += amount
end
def self.total
@@sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment