first cut at orders report.

This commit is contained in:
Andrew Spinks
2012-07-15 20:48:10 +10:00
parent 8f5b5e7ae4
commit 54559c4a5f
4 changed files with 101 additions and 29 deletions

29
.gitignore vendored
View File

@@ -10,48 +10,19 @@ log/*.log.lck
log/*.log.*
tmp/
.idea/*
solr/data/
solr/pids/
\#*
.#*
*~
*.~lock.*
.emacs.desktop
.DS_Store
.emacs.desktop.lock*
coverage
merged_coverage
upstream_coverage
true/
reports
*.tmproj
*tags
dump.rdb
bin/
spec/javascripts/generated/*
db/development_structure.sql
db/test_structure.sql
db/staging_structure.sql
db/production_structure.sql
db/bootstrap/*.sql
db/bootstrap/*.dump
db/bootstrap/*.bak
db/bootstrap/*.pgz
db/bootstrap/image_fixtures/*
db/bootstrap/image_fixtures/properties/*
public/system
public/stylesheets
public/images
vendor/bundle
config/database.Tom-Meiers-MacBook-Pro.local.yml
config/abr.yml
vendor/ruby
ey-cloud-recipes/db/bootstrap/*.dump
ey-cloud-recipes/db/bootstrap/*.pgz
ey-cloud-recipes/db/bootstrap/image_fixtures/*
ey-cloud-recipes/.idea/*
chromedriver.log
financial_reports/*.csv
NERD_tree*
spec/reference_images/*
public/search

View File

@@ -0,0 +1,42 @@
require 'csv'
Spree::Admin::ReportsController.class_eval do
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:orders => {:name => "Orders", :description => "Orders with distributor details"}})
def orders
params[:q] = {} unless params[:q]
if params[:q][:created_at_gt].blank?
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
else
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
end
if params[:q] && !params[:q][:created_at_lt].blank?
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
end
params[:q][:meta_sort] ||= "created_at.desc"
@search = Spree::Order.complete.search(params[:q])
@orders = @search.result
if(!params[:csv])
render :html => @orders
else
csv_string = CSV.generate do |csv|
csv << ["Order date", "Order Id", "Name","Email", "SKU", "Item cost", "Quantity", "Cost", "Shipping cost", "Distributor", "Distributor address", "Distributor city", "Distributor postcode"]
puts @orders
@orders.each do |order|
order.line_items.each do |line_item|
csv << [order.created_at, order.id, order.bill_address.full_name, order.user.email,
line_item.product.sku, line_item.product.name, line_item.quantity, line_item.price * line_item.quantity, line_item.itemwise_shipping_cost,
order.distributor.pickup_address.full_name, order.distributor.pickup_address.address1, order.distributor.pickup_address.city, order.distributor.pickup_address.zipcode ]
end
end
end
send_data csv_string
end
end
end

View File

@@ -0,0 +1,57 @@
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
%th Order Date
%th Order Id
%th Name
%th Email
%th SKU
%th Item name
%th Item cost
%th Quantity
%th Shipping cost
%th Distributor
%th Distributor address
%th Distributor city
%th Distributor postcode
%tbody
- @orders.each do |order|
- order.line_items.each do |line_item|
%tr
%td= order.created_at
%td= order.id
%td= order.bill_address.full_name
%td= order.user.email
%td= line_item.product.sku
%td= line_item.product.name
%td= line_item.quantity
%td= line_item.price * line_item.quantity
%td= line_item.itemwise_shipping_cost
%td= order.distributor.pickup_address.full_name
%td= order.distributor.pickup_address.address1
%td= order.distributor.pickup_address.city
%td= order.distributor.pickup_address.zipcode
- if @orders.empty?
%tr
%td{:colspan => "2"}= t(:none)
- content_for :sidebar do
= form_for @search, :url => spree.orders_admin_reports_path do |s|
= label_tag nil, t(:date_range)
%br
.date-range-filter
%div{"class" => "left sub-field"}
= s.text_field :created_at_gt, :class => 'datepicker'
%br
= label_tag nil, t(:start), :class => 'sub'
%div{"class" => "right sub-field"}
= s.text_field :created_at_lt, :class => 'datepicker'
%br
= label_tag nil, t(:stop)
= check_box_tag :csv
= label_tag :csv, "Download as csv"
%br
= button t(:search)

View File

@@ -17,4 +17,6 @@ Spree::Core::Engine.routes.prepend do
end
resources :suppliers
end
match '/admin/reports/orders' => 'admin/reports#orders', :as => "orders_admin_reports", :via => [:get, :post]
end