Skip to content

Instantly share code, notes, and snippets.

@adamrunner
Last active July 8, 2019 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamrunner/760d8aa323c6198ad11e2680397a5ba6 to your computer and use it in GitHub Desktop.
Save adamrunner/760d8aa323c6198ad11e2680397a5ba6 to your computer and use it in GitHub Desktop.
Exports some order and promotion data to a CSV
def export_orders_promo_info_csv(start_date, end_date)
# start_date and end_date params should be Date objects
rows = []
rows << ["order_number", "status", "sub_total", "total", "discount", "promotion_code"]
Order::History.where(order_number: /^WO/, finalized_at: start_date..end_date).each do |order|
row = []
row << order.order_number
row << order.status
row << order.final_sub_total
row << order.final_total
row << order.promotion_code_discount
row << order.promotion_code
rows << row
end
File.write("discount_orders_#{start_date}_#{end_date}.csv", rows.map(&:to_csv).join)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment