Skip to content

Instantly share code, notes, and snippets.

@airspeed
Last active January 4, 2016 00:19
Show Gist options
  • Save airspeed/8541184 to your computer and use it in GitHub Desktop.
Save airspeed/8541184 to your computer and use it in GitHub Desktop.
stats = []
(Date.parse('2012-09-01') .. Date.today).select{|d| d.day === 1}.map{|erster| erster - 1.month .. erster}.each do |range|
Invoice.state_machine.states.map(&:name).each do |state|
rechnungen = Invoice.where(:created_at => range, :state => state.to_s)
bestellungen = rechnungen.map(&:order_cart)
stats << [range.first.strftime("%m.%Y"), state.to_s, rechnungen.count, ActionController::Base.helpers.number_with_precision(bestellungen.sum(&:final_amount).to_f, :precision => 2)]
end
end
stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment