mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Merge branch '266reportsbranch' of https://github.com/lin-d-hop/openfoodnetwork into lin-d-hop-266reportsbranch
Conflicts: app/controllers/spree/admin/reports_controller_decorator.rb spec/models/spree/order_spec.rb
This commit is contained in:
65
lib/open_food_network/order_cycle_management_report.rb
Normal file
65
lib/open_food_network/order_cycle_management_report.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
module OpenFoodNetwork
|
||||
class OrderCycleManagementReport
|
||||
attr_reader :params
|
||||
def initialize(user, params = {})
|
||||
@params = params
|
||||
@user = user
|
||||
end
|
||||
|
||||
def header
|
||||
["First Name", "Last Name", "Email", "Phone", "Hub", "Shipping Method", "Payment Method", "Amount ", "Amount Paid"]
|
||||
|
||||
end
|
||||
|
||||
def table
|
||||
orders.map do |order|
|
||||
ba = order.billing_address
|
||||
da = order.distributor.andand.address
|
||||
[ba.firstname,
|
||||
ba.lastname,
|
||||
order.email,
|
||||
ba.phone,
|
||||
order.distributor.andand.name,
|
||||
order.shipping_method.andand.name,
|
||||
order.payments.first.andand.payment_method.andand.name,
|
||||
order.payments.first.amount
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def orders
|
||||
filter Spree::Order.managed_by(@user).distributed_by_user(@user).complete.where("spree_orders.state != ?", :canceled)
|
||||
end
|
||||
|
||||
def filter(orders)
|
||||
filter_to_order_cycle filter_to_payment_method filter_to_shipping_method orders
|
||||
end
|
||||
|
||||
def filter_to_payment_method (orders)
|
||||
if params[:payment_method_name].present?
|
||||
orders.with_payment_method_name(params[:payment_method_name])
|
||||
else
|
||||
orders
|
||||
end
|
||||
end
|
||||
|
||||
def filter_to_shipping_method (orders)
|
||||
if params[:shipping_method_name].present?
|
||||
orders.joins(:shipping_method).where("spree_shipping_methods.name = ?", params[:shipping_method_name])
|
||||
else
|
||||
orders
|
||||
end
|
||||
end
|
||||
|
||||
def filter_to_order_cycle(orders)
|
||||
if params[:order_cycle_id].present?
|
||||
orders.where(order_cycle_id: params[:order_cycle_id])
|
||||
else
|
||||
orders
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user