Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created March 14, 2010 07:14
Show Gist options
  • Select an option

  • Save tonyarnold/331818 to your computer and use it in GitHub Desktop.

Select an option

Save tonyarnold/331818 to your computer and use it in GitHub Desktop.
def revenue_history_months
limit = 12
@orders = Order.find(:all, :conditions => ["status = 'C' and lower(payment_type) != 'free' and order_time >= ?", limit.months.ago])
@orders_months = @orders.group_by { |m| m.order_time.beginning_of_month }
values = []
@orders_months.each {| month, order |
monthly_total = 0;
order.each { |o|
monthly_total += o.total
}
values << "[#{month.to_date.to_time.to_i*1000}, #{monthly_total}]"
}
values_str = values.join(", ").strip
render :js => "$(function () { drawGraph([#{values_str}], 'month'); });"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment