diff --git a/app/models/ticket.rb b/app/models/ticket.rb index fdac09bf..d9723a2b 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -62,7 +62,11 @@ class Ticket < ApplicationRecord def tickets_turnover_total(id) tickets = TicketPurchase.where(ticket_id: id).paid - tickets.inject(Money.new(0,tickets.first.price_currency)){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) } + if tickets.nil? + tickets.inject(Money.new(0, tickets.first.price_currency)){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) } + else + Money.new(0, Ticket.find(id).price_currency) + end end def tickets_sold diff --git a/db/schema.rb b/db/schema.rb index ed33d5a3..48815a8a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -496,7 +496,7 @@ ActiveRecord::Schema.define(version: 20171201163628) do t.integer "user_id" t.integer "payment_id" t.integer "week" - t.float "amount_paid" + t.float "amount_paid", default: 0.0 end create_table "ticket_scannings", force: :cascade do |t|