mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Adding tweaks that have been missed from merges
This commit is contained in:
committed by
Rob Harrington
parent
0fd29dd32e
commit
7350dbb75e
@@ -77,14 +77,27 @@ Spree::Admin::ReportsController.class_eval do
|
||||
end
|
||||
|
||||
def order_cycle_management
|
||||
prepare_date_params params
|
||||
|
||||
# -- Prepare form options
|
||||
my_distributors = Enterprise.is_distributor.managed_by(spree_current_user)
|
||||
my_suppliers = Enterprise.is_primary_producer.managed_by(spree_current_user)
|
||||
|
||||
# My distributors and any distributors distributing products I supply
|
||||
@distributors = my_distributors | Enterprise.with_distributed_products_outer.merge(Spree::Product.in_any_supplier(my_suppliers))
|
||||
# My suppliers and any suppliers supplying products I distribute
|
||||
@suppliers = my_suppliers | my_distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq
|
||||
@order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC')
|
||||
|
||||
@report_types = REPORT_TYPES[:order_cycle_management]
|
||||
@report_type = params[:report_type]
|
||||
|
||||
# -- Build Report with Order Grouper
|
||||
@report = OpenFoodNetwork::OrderCycleManagementReport.new spree_current_user, params
|
||||
@table = @report.table_items
|
||||
csv_file_name = "#{params[:report_type]}_#{timestamp}.csv"
|
||||
|
||||
@search = Spree::Order.complete.not_state(:canceled).managed_by(spree_current_user).search(params[:q])
|
||||
@orders = @search.result
|
||||
|
||||
render_report(@report.header, @report.table, params[:csv], "order_cycle_management_#{timestamp}.csv")
|
||||
render_report(@report.header, @table, params[:csv], "order_cycle_management_#{timestamp}.csv")
|
||||
end
|
||||
|
||||
def packing
|
||||
@@ -294,9 +307,10 @@ Spree::Admin::ReportsController.class_eval do
|
||||
:sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" },
|
||||
:users_and_enterprises => { :name => "Users & Enterprises", :description => "Enterprise Ownership & Status" },
|
||||
:order_cycle_management => {:name => "Order Cycle Management", :description => ''},
|
||||
:packing => {:name => "Packing Reports", :description => ''},
|
||||
:sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" },
|
||||
:xero_invoices => { :name => "Xero Invoices", :description => 'Invoices for import into Xero' }
|
||||
:xero_invoices => { :name => "Xero Invoices", :description => 'Invoices for import into Xero' },
|
||||
:packing => { :name => "Packing Reports", :description => '' },
|
||||
:sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" }
|
||||
}
|
||||
# Return only reports the user is authorized to view.
|
||||
reports.select { |action| can? action, :report }
|
||||
|
||||
@@ -1,47 +1,46 @@
|
||||
= form_tag spree.order_cycle_management_admin_reports_url do |f|
|
||||
%br
|
||||
= label_tag nil, "Order Cycle: "
|
||||
= select_tag(:order_cycle_id,
|
||||
options_for_select(report_order_cycle_options(@order_cycles), params[:order_cycle_id]),
|
||||
include_blank: true)
|
||||
%br
|
||||
%br
|
||||
= label_tag nil, "Payment Methods (hold Ctrl to select multiple payment methods)"
|
||||
%br
|
||||
= form_for @report.search, :url => spree.order_cycle_management_admin_reports_path do |f|
|
||||
= render 'date_range_form', f: f
|
||||
|
||||
= select_tag(:payment_method_name,
|
||||
options_for_select(report_payment_method_options(@orders), params[:payment_method_name]),
|
||||
multiple: true, include_blank: true, size: 10)
|
||||
%br
|
||||
%br
|
||||
= label_tag nil, "Shipping Method: "
|
||||
= select_tag(:shipping_method_name,
|
||||
options_for_select(report_shipping_method_options(@orders), params[:shipping_method_name]),
|
||||
include_blank: true)
|
||||
%br
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select(@report_types, @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
%br
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, "Hubs: "
|
||||
.omega.fourteen.columns= f.collection_select(:distributor_id_in, @distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
|
||||
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, "Order Cycles: "
|
||||
.omega.fourteen.columns
|
||||
= f.select(:order_cycle_id_in, report_order_cycle_options(@order_cycles), {selected: params[:q][:order_cycle_id_in]}, {class: "select2 fullwidth", multiple: true})
|
||||
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, "Payment Methods: "
|
||||
.omega.fourteen.columns= select_tag(:payment_method_in, options_for_select(report_payment_method_options(@report.orders), params[:payment_method_in]), {class: "select2 fullwidth", multiple: true})
|
||||
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, "Shipping Methods: "
|
||||
.omega.fourteen.columns= select_tag(:shipping_method_in, options_for_select(report_shipping_method_options(@report.orders), params[:shipping_method_in]), {class: "select2 fullwidth", multiple: true})
|
||||
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, "Report Type: "
|
||||
.omega.fourteen.columns= select_tag(:report_type, options_for_select(@report_types, @report_type))
|
||||
|
||||
.row
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
|
||||
.row
|
||||
= button t(:search)
|
||||
|
||||
%br
|
||||
%br
|
||||
%table#listing_order_payment_methods.index
|
||||
%table#listing_ocm_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @report.header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @report.table.each do |row|
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @report.table.empty?
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
|
||||
@@ -16,24 +16,27 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
def table
|
||||
def search
|
||||
Spree::Order.complete.where("spree_orders.state != ?", :canceled).distributed_by_user(@user).managed_by(@user).search(params[:q])
|
||||
end
|
||||
|
||||
def orders
|
||||
filter search.result
|
||||
end
|
||||
|
||||
def table_items
|
||||
if is_payment_methods?
|
||||
orders.map { |o| payment_method_row o }
|
||||
else
|
||||
orders.map { |o| delivery_row o }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def orders
|
||||
filter Spree::Order.managed_by(@user).distributed_by_user(@user).complete.where("spree_orders.state != ?", :canceled)
|
||||
def filter(search_result)
|
||||
filter_to_payment_method filter_to_shipping_method filter_to_order_cycle search_result
|
||||
end
|
||||
|
||||
def filter(orders)
|
||||
filter_to_order_cycle filter_to_payment_method filter_to_shipping_method orders
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def payment_method_row(order)
|
||||
ba = order.billing_address
|
||||
|
||||
@@ -71,7 +71,9 @@ module OpenFoodNetwork
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.product.name } } ]
|
||||
sort_by: proc { |variant| variant.product.name } },
|
||||
{ group_by: proc { |line_item| line_item.order.bill_address.lastname },
|
||||
sort_by: proc { |lastname| lastname } } ]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ feature %q{
|
||||
|
||||
scenario "payment method report" do
|
||||
click_link "Payment Methods Report"
|
||||
rows = find("table#listing_order_payment_methods").all("thead tr")
|
||||
rows = find("table#listing_ocm_orders").all("thead tr")
|
||||
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
|
||||
table.sort.should == [
|
||||
["First Name", "Last Name", "Hub", "Hub Code", "Email", "Phone", "Shipping Method", "Payment Method", "Amount", "Balance"]
|
||||
@@ -76,7 +76,7 @@ feature %q{
|
||||
|
||||
scenario "delivery report" do
|
||||
click_link "Delivery Report"
|
||||
rows = find("table#listing_order_payment_methods").all("thead tr")
|
||||
rows = find("table#listing_ocm_orders").all("thead tr")
|
||||
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
|
||||
table.sort.should == [
|
||||
["First Name", "Last Name", "Hub", "Hub Code", "Delivery Address", "Delivery Postcode", "Phone", "Shipping Method", "Payment Method", "Amount", "Balance", "Temp Controlled Items?", "Special Instructions"]
|
||||
|
||||
Reference in New Issue
Block a user