made changes to Order model to reflect the fact that a site may use the new payment options component, resulting in orders of various dollar amounts, so revenue and goal percentage must be calculated differently

This commit is contained in:
Jesse Grant
2013-01-14 16:51:14 -05:00
parent 59b19d93b0
commit b6beadb72c
5 changed files with 18 additions and 12 deletions

View File

@@ -54,22 +54,25 @@ class Order < ActiveRecord::Base
end while Order.find_by_uuid(self.uuid).present?
end
# Implement these three methods to
# goal is a dollar amount, not a number of backers, beause you may be using the multiple payment options component
# by setting Settings.use_payment_options == true
def self.goal
Settings.project_goal
end
def self.percent
(Order.current.to_f / Order.goal.to_f) * 100.to_f
(Order.revenue.to_f / Order.goal.to_f) * 100.to_f
end
# See what it looks like when you have some backers! Drop in a number instead of Order.count
def self.current
def self.backers
Order.where("token != ? OR token != ?", "", nil).count
end
def self.revenue
Order.current.to_f * Settings.price
revenue = PaymentOption.joins(:orders).pluck('sum(amount)')[0]
return 0 if revenue.nil?
revenue
end
validates_presence_of :name, :price, :user_id

View File

@@ -1,3 +1,4 @@
class PaymentOption < ActiveRecord::Base
attr_accessible :amount, :amount_display, :delivery_desc, :description, :limit, :shipping_desc
has_many :orders
end

View File

@@ -20,12 +20,12 @@
<div id="backing">
<ul>
<li class="stats" id="backers">
<%= number_with_delimiter Order.current, :delimiter => "," %>
<%= number_with_delimiter Order.backers, :delimiter => "," %>
<span><%= Settings.primary_stat %></span>
</li>
<li class="stats">
<%= number_to_currency Order.revenue, :precision => 0 %>
<span>of <%= number_to_currency Settings.project_goal.to_f * Settings.price.to_f, :precision => 0 %></span>
<span>of <%= number_to_currency Settings.project_goal.to_f, :precision => 0 %></span>
</li>
<% if Settings.expiration_date.present? %>
@@ -41,7 +41,7 @@
<% end %>
</ul>
<% if Order.current < Order.goal %>
<% if Order.revenue < Order.goal %>
<div id='progress_bg' class='small'>
<div id='progress' class='' style='width: <%= Order.percent %>%;'>
</div>