mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Fix tickets turnover calculation
This commit is contained in:
parent
69de418ccd
commit
58cb62dd6d
3 changed files with 20 additions and 6 deletions
|
|
@ -61,12 +61,10 @@ class Ticket < ApplicationRecord
|
|||
end
|
||||
|
||||
def tickets_turnover_total(id)
|
||||
tickets = TicketPurchase.where(ticket_id: id).paid
|
||||
if tickets.blank?
|
||||
Money.new(0, Ticket.find(id).price_currency)
|
||||
else
|
||||
tickets.inject(Money.new(0, tickets.first.price_currency)){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
|
||||
end
|
||||
ticket = Ticket.find(id)
|
||||
return Money.new(0, 'USD') unless ticket
|
||||
sum = ticket.ticket_purchases.paid.total
|
||||
Money.new(sum, ticket.price_currency)
|
||||
end
|
||||
|
||||
def tickets_sold
|
||||
|
|
|
|||
|
|
@ -69,6 +69,11 @@ class TicketPurchase < ApplicationRecord
|
|||
purchase
|
||||
end
|
||||
|
||||
# Total amount
|
||||
def self.total
|
||||
sum('amount_paid * quantity')
|
||||
end
|
||||
|
||||
def pay(payment)
|
||||
update_attributes(paid: true, payment: payment)
|
||||
PhysicalTicket.transaction do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue