Skip to content

Commit

Permalink
Graph should display values for all days of target period.
Browse files Browse the repository at this point in the history
[spree#1269 state:resolved]
  • Loading branch information
romul committed Mar 24, 2010
1 parent d43f6d9 commit b64d845
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -57,16 +57,26 @@ def conditions(params)
["completed_at >= ?", params[:from]]
end
end

def fill_empty_entries(orders, params)
from_date = params[:from].to_date
to_date = (params[:to] || Time.now).to_date
(from_date..to_date).each do |date|
orders[date] ||= []
end
end

def orders_by_day(params)

if params[:value] == "Count"
orders = Order.find(:all, :select => 'created_at', :conditions => conditions(params))
orders = orders.group_by { |o| o.created_at.beginning_of_day }
orders = orders.group_by { |o| o.created_at.to_date }
fill_empty_entries(orders, params)
orders.keys.sort.map {|key| [key.strftime('%Y-%m-%d'), orders[key].size ]}
else
orders = Order.find(:all, :select => 'total, created_at', :conditions => conditions(params))
orders = orders.group_by { |o| o.created_at.beginning_of_day }
orders = orders.group_by { |o| o.created_at.to_date }
fill_empty_entries(orders, params)
orders.keys.sort.map {|key| [key.strftime('%Y-%m-%d'), orders[key].inject(0){|s,o| s += o.total} ]}
end
end
Expand Down
Expand Up @@ -64,7 +64,7 @@ jQuery(document).ready(function(){
fontSize: '10pt',
textColor: '#476D9B'
},
min: 1
min: 0
},
xaxis:{
renderer:$.jqplot.DateAxisRenderer,
Expand Down Expand Up @@ -140,4 +140,4 @@ jQuery(document).ready(function(){
});


});
});

0 comments on commit b64d845

Please sign in to comment.