From c87c8ed0df53176403567968759cd4107253e1e8 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 5 Jan 2023 10:21:16 +0100 Subject: [PATCH] subreport filtering partial --- app/helpers/reports_helper.rb | 6 ++++++ app/models/spree/order.rb | 2 +- .../filters/_sales_tax_totals_by_producer.html.haml | 13 +++++++++++++ app/views/admin/reports/show.html.haml | 2 ++ lib/reporting/frontend_data.rb | 8 ++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/reports/filters/_sales_tax_totals_by_producer.html.haml diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 953a4bbffa..1fbaa8889a 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -26,6 +26,12 @@ module ReportsHelper end.uniq end + def customer_email_options(order_customers) + order_customers.map do |customer| + [customer&.email, customer&.id] + end + end + def currency_symbol Spree::Money.currency_symbol end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 7333301c94..802992a73c 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -13,7 +13,7 @@ module Spree include SetUnusedAddressFields searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id, - :order_cycle_id, :email, :total + :order_cycle_id, :email, :total, :customer_id searchable_associations :shipping_method, :bill_address searchable_scopes :complete, :incomplete diff --git a/app/views/admin/reports/filters/_sales_tax_totals_by_producer.html.haml b/app/views/admin/reports/filters/_sales_tax_totals_by_producer.html.haml new file mode 100644 index 0000000000..2de1715da7 --- /dev/null +++ b/app/views/admin/reports/filters/_sales_tax_totals_by_producer.html.haml @@ -0,0 +1,13 @@ +.row + .alpha.two.columns= label_tag nil, t(:report_producers) + .omega.fourteen.columns= select_tag(:supplier_id_in, options_from_collection_for_select(@data.orders_suppliers, :id, :name, params[:supplier_id_in]), {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_customers_cycle) + .omega.fourteen.columns + = f.select(:order_cycle_id_in, report_order_cycle_options(@data.order_cycles), {selected: params.dig(:q, :order_cycle_id_in)}, {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_customers) + .omega.fourteen.columns + = f.select(:customer_id_in, customer_email_options(@data.order_customers), {selected: params.dig(:q, :customer_id_in)}, {class: "select2 fullwidth", multiple: true}) diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 92de53506a..6c87081aec 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -5,6 +5,8 @@ %fieldset.no-border-bottom.print-hidden %legend{ align: 'center'}= t(:report_filters) = render partial: "admin/reports/filters/#{@report_type}", locals: { f: f } + - if @report_subtype && lookup_context.exists?(@report_subtype, "admin/reports/filters/", true) + = render partial: "admin/reports/filters/#{@report_subtype}", locals: { f: f } %fieldset.print-hidden %legend{ align: 'center'}= t(:report_render_options) diff --git a/lib/reporting/frontend_data.rb b/lib/reporting/frontend_data.rb index a702a91de0..09eda3782f 100644 --- a/lib/reporting/frontend_data.rb +++ b/lib/reporting/frontend_data.rb @@ -44,6 +44,10 @@ module Reporting order('order_cycles.orders_close_at DESC') end + def order_customers + Customer.where(id: visible_order_customer_ids).select("customers.id, customers.email") + end + private attr_reader :current_user @@ -51,5 +55,9 @@ module Reporting def permissions @permissions ||= OpenFoodNetwork::Permissions.new(current_user) end + + def visible_order_customer_ids + Permissions::Order.new(current_user).visible_orders.pluck(:customer_id) + end end end