Class: Forgeos::Commerce::Statistics
- Inherits:
-
Object
- Object
- Forgeos::Commerce::Statistics
- Defined in:
- lib/forgeos/commerce/statistics.rb
Class Method Summary collapse
- .best_customers(date, limit = nil) ⇒ Object
- .new_customers(date, limit = nil) ⇒ Object
- .products_most_sold(date, limit = nil) ⇒ Object
- .products_most_viewed(date, limit = nil) ⇒ Object
- .total_of_sales(date = nil) ⇒ Object
- .total_of_sold_products(date) ⇒ Object
Class Method Details
.best_customers(date, limit = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/forgeos/commerce/statistics.rb', line 38 def self.best_customers(date, limit = nil) new_hash = {} OrderDetail.sum(:price, :conditions => { :orders => { :status => %w(paid shipped closed), :updated_at => date } }, :include => :order, :group => 'orders.user_id', :order => 'sum_price DESC' ).each_with_index do |item,index| break if index < limit new_hash[item.first] = item.last end return new_hash end |
.new_customers(date, limit = nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/forgeos/commerce/statistics.rb', line 52 def self.new_customers(date, limit = nil) User.all( :conditions => { :created_at => date }, :order => 'created_at DESC', :limit => limit ) end |
.products_most_sold(date, limit = nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/forgeos/commerce/statistics.rb', line 25 def self.products_most_sold(date,limit = nil) ProductSoldCounter.sum(:counter, :conditions => { :date => date }, :order => 'sum_counter DESC', :limit => limit, :group => 'element_id' ) end |
.products_most_viewed(date, limit = nil) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/forgeos/commerce/statistics.rb', line 16 def self.products_most_viewed(date,limit = nil) ProductViewedCounter.sum(:counter, :conditions => { :date => date }, :order => 'sum_counter DESC', :limit => limit, :group => 'element_id' ) end |
.total_of_sales(date = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/forgeos/commerce/statistics.rb', line 4 def self.total_of_sales(date = nil) conditions = { :status => %w(paid accepted shipped closed) } if date if date.kind_of?(Date) conditions[:created_at] = date.beginning_of_day..date.end_of_day else conditions[:created_at] = date end end Order.all(:conditions => conditions).collect(&:total).sum end |
.total_of_sold_products(date) ⇒ Object
34 35 36 |
# File 'lib/forgeos/commerce/statistics.rb', line 34 def self.total_of_sold_products(date) ProductSoldCounter.sum(:counter, :conditions => { :date => date }) end |