Skip to content

Commit

Permalink
Add turnover for admin
Browse files Browse the repository at this point in the history
Admin can see the turnover amount for each ticket type.
  • Loading branch information
rahul2240 committed Oct 14, 2017
1 parent 0d70832 commit 03c9f7d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def tickets_turnover_distribution
if tickets && ticket_purchases
tickets.each do |ticket|
result[ticket.title] = {
'value' => ApplicationController.helpers.humanized_money(ticket.tickets_turnover).delete(',').to_i,
'value' => ApplicationController.helpers.humanized_money(ticket.tickets_turnover_total(ticket.id)).delete(',').to_i,
'color' => "\##{Digest::MD5.hexdigest(ticket.title)[0..5]}"
}
end
Expand Down
9 changes: 5 additions & 4 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def self.total_price_user(conference, user, paid: false)
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
end

def tickets_sold
ticket_purchases.paid.sum(:quantity)
def tickets_turnover_total(id)
tickets = TicketPurchase.where(ticket_id: id)
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
end

def tickets_turnover
tickets_sold * price
def tickets_sold
ticket_purchases.paid.sum(:quantity)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/tickets/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%td
= ticket.tickets_sold
%td
= humanized_money_with_symbol ticket.tickets_turnover
= humanized_money_with_symbol ticket.tickets_turnover_total(ticket.id)
%td
= ticket.registration_ticket? ? 'Yes' : 'No'
%td
Expand Down

0 comments on commit 03c9f7d

Please sign in to comment.