Merge branch 'master' into openshift_compatibility

This commit is contained in:
James Mason 2017-11-02 08:23:24 -07:00 committed by GitHub
commit 2b7066cd8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 37 deletions

View file

@ -11,7 +11,7 @@ function update_price($this){
$('.total_row').each(function( index ) { $('.total_row').each(function( index ) {
total += parseFloat($(this).text()); total += parseFloat($(this).text());
}); });
$('#total_price').text(total); $('#total_price').text(total.toFixed(2));
} }
$( document ).ready(function() { $( document ).ready(function() {

View file

@ -27,8 +27,9 @@ class ConferenceRegistrationsController < ApplicationController
end end
def show 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 @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) @ticket_payments = @tickets.group_by(&:ticket_id)
@total_quantity = @tickets.group(:ticket_id).sum(:quantity) @total_quantity = @tickets.group(:ticket_id).sum(:quantity)
end end

View file

@ -496,7 +496,7 @@ class Conference < ActiveRecord::Base
if tickets && ticket_purchases if tickets && ticket_purchases
tickets.each do |ticket| tickets.each do |ticket|
result[ticket.title] = { 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]}" 'color' => "\##{Digest::MD5.hexdigest(ticket.title)[0..5]}"
} }
end end

View file

@ -55,12 +55,18 @@ class Ticket < ActiveRecord::Base
result ? result : Money.new(0, 'USD') result ? result : Money.new(0, 'USD')
end end
def tickets_sold def self.total_price_user(conference, user, paid: false)
ticket_purchases.paid.sum(:quantity) tickets = TicketPurchase.where(conference: conference, user: user, paid: paid)
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
end end
def tickets_turnover def tickets_turnover_total(id)
tickets_sold * price 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 end
private private

View file

@ -52,7 +52,8 @@ class TicketPurchase < ActiveRecord::Base
purchase = new(ticket_id: ticket.id, purchase = new(ticket_id: ticket.id,
conference_id: conference.id, conference_id: conference.id,
user_id: user.id, user_id: user.id,
quantity: quantity) quantity: quantity,
amount_paid: ticket.price)
purchase.pay(nil) if ticket.price_cents.zero? purchase.pay(nil) if ticket.price_cents.zero?
end end
purchase purchase

View 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'

View file

@ -21,23 +21,11 @@
%th ID %th ID
%th Type %th Type
%th User %th User
%th Paid
%th Actions %th Actions
%tbody %tbody
- @physical_tickets.each do |physical_ticket| - @physical_tickets.each do |physical_ticket|
%tr = render "physical_ticket", physical_ticket: physical_ticket,
%td= physical_ticket.id conference: @conference
%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'
- else - else
%h5 No Tickets sold! %h5 No Tickets sold!

View file

@ -27,7 +27,7 @@
%td %td
= ticket.tickets_sold = ticket.tickets_sold
%td %td
= humanized_money_with_symbol ticket.tickets_turnover = humanized_money_with_symbol ticket.tickets_turnover_total(ticket.id)
%td %td
= ticket.registration_ticket? ? 'Yes' : 'No' = ticket.registration_ticket? ? 'Yes' : 'No'
%td %td

View file

@ -12,10 +12,13 @@
- role = Role.find_by(id: users_role.role_id) if users_role - role = Role.find_by(id: users_role.role_id) if users_role
role role
- if role.name == 'organization_admin' - if role.name == 'organization_admin'
-# organization_admin belongs to organization and not conferences - if Organization.find_by(id: version.conference_id)
- organization = Organization.find(version.conference_id) -# organization_admin belongs to organization and not conferences
= link_if_alive version, role.name, - organization = Organization.find_by(id: version.conference_id)
= link_if_alive version, role.name,
admins_admin_organization_path(organization), organization admins_admin_organization_path(organization), organization
- else
(Deleted Organization)
- else - else
- conference = Conference.find_by(id: version.conference_id) - conference = Conference.find_by(id: version.conference_id)
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' ' - conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
@ -140,10 +143,13 @@
- role = current_or_last_object_state(version.item_type, version.item_id) - role = current_or_last_object_state(version.item_type, version.item_id)
- role_name = role.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: version.item_id).last.changeset[:name].second - role_name = role.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: version.item_id).last.changeset[:name].second
- if role_name == 'organization_admin' - if role_name == 'organization_admin'
-# organization_admin belongs to organization and not conferences - if Organization.find_by(id: version.conference_id)
- organization = Organization.find(version.conference_id) -# organization_admin belongs to organization and not conferences
= link_if_alive version, role_name, - organization = Organization.find_by(id: version.conference_id)
= link_if_alive version, role.name,
admins_admin_organization_path(organization), organization admins_admin_organization_path(organization), organization
- else
(Role Deleted)
- else - else
- conference = Conference.find_by(id: version.conference_id) - conference = Conference.find_by(id: version.conference_id)
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' ' - conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
@ -224,7 +230,12 @@
- unless %w(Conference Subscription Registration User Organization).include?(version.item_type) - unless %w(Conference Subscription Registration User Organization).include?(version.item_type)
- if (version.item_type == 'Role' && role_name == 'organization_admin') || (version.item_type == 'UsersRole' && role.name == 'organization_admin') - if (version.item_type == 'Role' && role_name == 'organization_admin') || (version.item_type == 'UsersRole' && role.name == 'organization_admin')
in organization in organization
= link_to_organization(version.conference_id) - if Organization.find_by(id: version.conference_id)
-# organization_admin belongs to organization and not conferences
- organization = Organization.find_by(id: version.conference_id)
= link_to_organization(version.conference_id)
- else
(Organization Deleted)
- else - else
in conference in conference
= link_to_conference(version.conference_id) = link_to_conference(version.conference_id)

View file

@ -101,7 +101,7 @@
= word_pluralize(@total_quantity[ticket_id], 'Ticket') = word_pluralize(@total_quantity[ticket_id], 'Ticket')
for for
= tickets.first.price.symbol = tickets.first.price.symbol
= humanized_money tickets.first.price = humanized_money @total_price_per_ticket[ticket_id]
%br %br
- if @tickets.any? - if @tickets.any?
= link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default" = link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"

View file

@ -3,7 +3,7 @@ require 'mina/rails'
require 'mina/git' require 'mina/git'
set :domain, 'proxy-opensuse.suse.de' set :domain, 'proxy-opensuse.suse.de'
set :port, 2214 set :port, 2252
set :user, 'osem' set :user, 'osem'
set :deploy_to, '/srv/www/vhosts/opensuse.org/events' set :deploy_to, '/srv/www/vhosts/opensuse.org/events'
set :repository, 'https://github.com/openSUSE/osem.git' set :repository, 'https://github.com/openSUSE/osem.git'
@ -42,7 +42,7 @@ task deploy: :environment do
#invoke :notify_errbit #invoke :notify_errbit
to :launch do to :launch do
queue "sudo /etc/init.d/apache2 restart" queue "sudo /usr/bin/systemctl restart apache2"
queue "cd #{deploy_to}/current && RAILS_ENV=production bin/delayed_job start" queue "cd #{deploy_to}/current && RAILS_ENV=production bin/delayed_job start"
end end

View file

@ -0,0 +1,5 @@
class AddAmountPaidToTicketPurchases < ActiveRecord::Migration
def change
add_column :ticket_purchases, :amount_paid, :float, default: 0
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "ahoy_events", force: :cascade do |t|
t.uuid "visit_id", limit: 16 t.uuid "visit_id", limit: 16
@ -504,6 +504,7 @@ ActiveRecord::Schema.define(version: 20170816203325) do
t.integer "user_id" t.integer "user_id"
t.integer "payment_id" t.integer "payment_id"
t.integer "week" t.integer "week"
t.float "amount_paid"
end end
create_table "ticket_scannings", force: :cascade do |t| create_table "ticket_scannings", force: :cascade do |t|

View file

@ -252,7 +252,7 @@ describe ConferenceRegistrationsController, type: :controller do
end end
it 'does not assign price of purchased tickets to total_price and purchased tickets to tickets without payment' do 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
end end
@ -262,7 +262,7 @@ describe ConferenceRegistrationsController, type: :controller do
end end
it 'assigns 0 dollars to total_price and empty array to tickets variables' do 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 [] expect(assigns(:tickets)).to match_array []
end end
end end