mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Merge branch 'fixes-for-reports'
This commit is contained in:
@@ -95,15 +95,17 @@ Spree::Admin::ReportsController.class_eval do
|
||||
case params[:report_type]
|
||||
when "bulk_coop_supplier_report"
|
||||
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total"]
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Units Required", "Remainder"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } } ]
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
@@ -111,32 +113,45 @@ Spree::Admin::ReportsController.class_eval do
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * li.variant.weight || 0 } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * li.variant.weight || 0 } } ] },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * li.variant.weight || 0 } },
|
||||
proc { |lis| ( lis.first.variant.product.group_buy_unit_size.zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } / lis.first.variant.product.group_buy_unit_size ) ).floor },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } - ( ( lis.first.variant.product.group_buy_unit_size.zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } / lis.first.variant.product.group_buy_unit_size ) ).floor * lis.first.variant.product.group_buy_unit_size ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "bulk_coop_allocation"
|
||||
|
||||
header = ["Customer", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total"]
|
||||
header = ["Customer", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Total Allocated", "Remainder"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } } ]
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * li.variant.weight || 0 } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * li.variant.weight || 0 } },
|
||||
proc { |lis| ( lis.first.variant.product.group_buy_unit_size.zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } / lis.first.variant.product.group_buy_unit_size ) ).floor * lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } - ( ( lis.first.variant.product.group_buy_unit_size.zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } / lis.first.variant.product.group_buy_unit_size ) ).floor * lis.first.variant.product.group_buy_unit_size ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } },
|
||||
{ group_by: proc { |li| li.order.user },
|
||||
sort_by: proc { |user| user.to_s } } ]
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.to_s } } ]
|
||||
|
||||
when "bulk_coop_packing_sheets"
|
||||
|
||||
@@ -151,42 +166,52 @@ Spree::Admin::ReportsController.class_eval do
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } },
|
||||
{ group_by: proc { |li| li.order.user },
|
||||
sort_by: proc { |user| user.to_s } } ]
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.to_s } } ]
|
||||
|
||||
when "bulk_coop_customer_payments"
|
||||
|
||||
header = ["Customer", "Date of Order", "Total Cost", "Amount Owing", "Amount Paid"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.order.created_at.to_s },
|
||||
proc { |lis| lis.first.order.completed_at.to_s },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.total } },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.outstanding_balance } },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.payment_total } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.order.user },
|
||||
sort_by: proc { |user| user.to_s } },
|
||||
{ group_by: proc { |li| li.order },
|
||||
rules = [ { group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.created_at } } ]
|
||||
|
||||
else # List all line items
|
||||
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total"]
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Units Required", "Remainder"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } } ]
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * li.variant.weight || 0 } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * li.variant.weight || 0 } },
|
||||
proc { |lis| ( lis.first.variant.product.group_buy_unit_size.zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } / lis.first.variant.product.group_buy_unit_size ) ).floor },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } - ( ( lis.first.variant.product.group_buy_unit_size.zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity, li.quantity].max || 0 ) * li.variant.weight || 0 } / lis.first.variant.product.group_buy_unit_size ) ).floor * lis.first.variant.product.group_buy_unit_size ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
@@ -337,7 +362,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "status" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
@@ -404,7 +429,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "total shipping cost" },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
@@ -415,11 +440,12 @@ Spree::Admin::ReportsController.class_eval do
|
||||
|
||||
when "order_cycle_customer_totals"
|
||||
table_items = line_items
|
||||
@include_blank = false
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Customer", "Email", "Phone", "Product", "Variant", "Amount", "Total Cost", "Paid?", "Packed?", "Shipped?"]
|
||||
header = ["Distributor", "Customer", "Email", "Phone", "Product", "Variant", "Amount", "Item ($)", "Ship ($)", "Total ($)", "Paid?", "Packed?", "Shipped?"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
columns = [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
proc { |line_items| line_items.first.order.email },
|
||||
proc { |line_items| line_items.first.order.bill_address.phone },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
@@ -428,18 +454,25 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.order.user },
|
||||
sort_by: proc { |user| user.to_s },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
rules = [ { group_by: proc { |line_item| line_item.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } },
|
||||
{ group_by: proc { |line_item| line_item.order },
|
||||
sort_by: proc { |order| order.bill_address.lastname + " " + order.bill_address.firstname },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
proc { |line_items| line_items.first.order.email },
|
||||
proc { |line_items| line_items.first.order.bill_address.phone },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "work out whether paid or not" },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.total } },
|
||||
proc { |line_items| line_items.map { |li| li.order.paid? }.all? { |paid| paid == true } ? "Yes" : "No" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
@@ -449,6 +482,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
|
||||
else
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Status", "Incoming Transport"]
|
||||
|
||||
@@ -458,7 +492,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "status" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
|
||||
Reference in New Issue
Block a user