Merge pull request #1701 from rahul2240/amount
Add paid option in physical ticket#index
This commit is contained in:
commit
1d07125e7d
12 changed files with 46 additions and 28 deletions
|
|
@ -11,7 +11,7 @@ function update_price($this){
|
|||
$('.total_row').each(function( index ) {
|
||||
total += parseFloat($(this).text());
|
||||
});
|
||||
$('#total_price').text(total);
|
||||
$('#total_price').text(total.toFixed(2));
|
||||
}
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@total_price = Ticket.total_price(@conference, current_user, paid: true)
|
||||
@total_price = Ticket.total_price_user(@conference, current_user, paid: true)
|
||||
@tickets = current_user.ticket_purchases.by_conference(@conference).paid
|
||||
@total_price_per_ticket = @tickets.group(:ticket_id).sum('amount_paid * quantity')
|
||||
@ticket_payments = @tickets.group_by(&:ticket_id)
|
||||
@total_quantity = @tickets.group(:ticket_id).sum(:quantity)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -496,7 +496,7 @@ class Conference < ActiveRecord::Base
|
|||
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
|
||||
|
|
|
|||
|
|
@ -55,12 +55,18 @@ class Ticket < ActiveRecord::Base
|
|||
result ? result : Money.new(0, 'USD')
|
||||
end
|
||||
|
||||
def tickets_sold
|
||||
ticket_purchases.paid.sum(:quantity)
|
||||
def self.total_price_user(conference, user, paid: false)
|
||||
tickets = TicketPurchase.where(conference: conference, user: user, paid: paid)
|
||||
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
|
||||
end
|
||||
|
||||
def tickets_turnover
|
||||
tickets_sold * price
|
||||
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_sold
|
||||
ticket_purchases.paid.sum(:quantity)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase = new(ticket_id: ticket.id,
|
||||
conference_id: conference.id,
|
||||
user_id: user.id,
|
||||
quantity: quantity)
|
||||
quantity: quantity,
|
||||
amount_paid: ticket.price)
|
||||
purchase.pay(nil) if ticket.price_cents.zero?
|
||||
end
|
||||
purchase
|
||||
|
|
|
|||
16
app/views/admin/physical_tickets/_physical_ticket.html.haml
Normal file
16
app/views/admin/physical_tickets/_physical_ticket.html.haml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
%tr
|
||||
%td= physical_ticket.id
|
||||
%td= physical_ticket.ticket.title
|
||||
%td= physical_ticket.user.email
|
||||
%td= humanized_money_with_symbol physical_ticket.ticket_purchase.amount_paid
|
||||
%td
|
||||
.btn-group
|
||||
= link_to 'Show',
|
||||
conference_physical_ticket_path(conference.short_title,
|
||||
physical_ticket.token),
|
||||
class: 'btn btn-primary'
|
||||
= link_to 'Generate PDF',
|
||||
conference_physical_ticket_path(conference.short_title,
|
||||
physical_ticket.token,
|
||||
format: :pdf),
|
||||
class: 'button btn btn-default btn-info'
|
||||
|
|
@ -21,23 +21,11 @@
|
|||
%th ID
|
||||
%th Type
|
||||
%th User
|
||||
%th Paid
|
||||
%th Actions
|
||||
%tbody
|
||||
- @physical_tickets.each do |physical_ticket|
|
||||
%tr
|
||||
%td= physical_ticket.id
|
||||
%td= physical_ticket.ticket.title
|
||||
%td= physical_ticket.user.email
|
||||
%td
|
||||
.btn-group
|
||||
= link_to 'Show',
|
||||
conference_physical_ticket_path(@conference.short_title,
|
||||
physical_ticket.token),
|
||||
class: 'btn btn-primary'
|
||||
= link_to 'Generate PDF',
|
||||
conference_physical_ticket_path(@conference.short_title,
|
||||
physical_ticket.token,
|
||||
format: :pdf),
|
||||
class: 'button btn btn-default btn-info'
|
||||
= render "physical_ticket", physical_ticket: physical_ticket,
|
||||
conference: @conference
|
||||
- else
|
||||
%h5 No Tickets sold!
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@
|
|||
= word_pluralize(@total_quantity[ticket_id], 'Ticket')
|
||||
for
|
||||
= tickets.first.price.symbol
|
||||
= humanized_money tickets.first.price
|
||||
= humanized_money @total_price_per_ticket[ticket_id]
|
||||
%br
|
||||
- if @tickets.any?
|
||||
= link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AddAmountPaidToTicketPurchases < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :ticket_purchases, :amount_paid, :float, default: 0
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170816203325) do
|
||||
ActiveRecord::Schema.define(version: 20170924190528) do
|
||||
|
||||
create_table "ahoy_events", force: :cascade do |t|
|
||||
t.uuid "visit_id", limit: 16
|
||||
|
|
@ -504,6 +504,7 @@ ActiveRecord::Schema.define(version: 20170816203325) do
|
|||
t.integer "user_id"
|
||||
t.integer "payment_id"
|
||||
t.integer "week"
|
||||
t.float "amount_paid"
|
||||
end
|
||||
|
||||
create_table "ticket_scannings", force: :cascade do |t|
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ describe ConferenceRegistrationsController, type: :controller do
|
|||
end
|
||||
|
||||
it 'does not assign price of purchased tickets to total_price and purchased tickets to tickets without payment' do
|
||||
expect(assigns(:total_price)).to eq Money.new(0, 'USD')
|
||||
expect(assigns(:total_price)).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ describe ConferenceRegistrationsController, type: :controller do
|
|||
end
|
||||
|
||||
it 'assigns 0 dollars to total_price and empty array to tickets variables' do
|
||||
expect(assigns(:total_price)).to eq Money.new(0, 'USD')
|
||||
expect(assigns(:total_price)).to eq 0
|
||||
expect(assigns(:tickets)).to match_array []
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue