Last active
October 6, 2016 15:16
-
-
Save helpse/a1fd06f8b6fa9c15aca7d75dfa11bebb to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
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