From bd2b4c0134d5acaf7aa4d65493add5ac79ecde35 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 10 Oct 2018 18:52:34 +0800 Subject: [PATCH] Add enterprise fee summary form without options The objects will be filled in another commit. This simply sets up the filters UI for now. --- ...nterprise_fee_summary_report_controller.rb | 10 ++-- .../_filters.html.haml | 50 +++++++++++++++++++ config/locales/en.yml | 15 ++++++ .../enterprise_fee_summary/parameters.rb | 4 ++ 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/app/controllers/spree/admin/reports/enterprise_fee_summary_report_controller.rb b/app/controllers/spree/admin/reports/enterprise_fee_summary_report_controller.rb index 3f6f9e957e..c990a5199d 100644 --- a/app/controllers/spree/admin/reports/enterprise_fee_summary_report_controller.rb +++ b/app/controllers/spree/admin/reports/enterprise_fee_summary_report_controller.rb @@ -7,11 +7,13 @@ module Spree module Admin module Reports class EnterpriseFeeSummaryReportController < BaseController + before_filter :load_report_parameters, only: [:index] + def index return render_report_form if params[:report].blank? - return respond_to_invalid_parameters unless report_parameters.valid? + return respond_to_invalid_parameters unless @report_parameters.valid? - service = report_klass::ReportService.new(report_parameters, report_renderer_klass) + service = report_klass::ReportService.new(@report_parameters, report_renderer_klass) send_data service.render, filename: service.filename end @@ -34,8 +36,8 @@ module Spree OrderManagement::Reports::EnterpriseFeeSummary end - def report_parameters - @report_parameters ||= report_klass::Parameters.new(params[:report]) + def load_report_parameters + @report_parameters = report_klass::Parameters.new(params[:report] || {}) end def report_renderer_klass diff --git a/app/views/spree/admin/reports/enterprise_fee_summary_report/_filters.html.haml b/app/views/spree/admin/reports/enterprise_fee_summary_report/_filters.html.haml index e69de29bb2..f4c5db1f56 100644 --- a/app/views/spree/admin/reports/enterprise_fee_summary_report/_filters.html.haml +++ b/app/views/spree/admin/reports/enterprise_fee_summary_report/_filters.html.haml @@ -0,0 +1,50 @@ += form_for @report_parameters, as: :report, url: spree.enterprise_fee_summary_admin_reports_path, method: :get do |f| + .row.date-range-filter + .sixteen.columns.alpha + = label_tag nil, t(".date_range") + %br + + = f.label :start_at, class: "inline" + = f.text_field :start_at, class: "datetimepicker datepicker-from" + + %span.range-divider + %i.icon-arrow-right + + = f.text_field :end_at, class: "datetimepicker datepicker-to" + = f.label :end_at, class: "inline" + + .row + .sixteen.columns.alpha + = f.label :distributor_ids + = f.collection_select(:distributor_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + + .row + .sixteen.columns.alpha + = f.label :producer_ids + = f.collection_select(:producer_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + + .row + .sixteen.columns.alpha + = f.label :order_cycle_ids + = f.collection_select(:order_cycle_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + + .row + .eight.columns.alpha + = f.label :enterprise_fee_ids + = f.collection_select(:enterprise_fee_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + .eight.columns.omega + = f.label :shipping_method_ids + = f.collection_select(:shipping_method_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + + .row + .eight.columns.alpha   + .eight.columns.omega + = f.label :payment_method_ids + = f.collection_select(:payment_method_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + + .row + .sixteen.columns.alpha + = check_box_tag :report_format, "csv", false, id: "report_format_csv" + = label_tag :report_format_csv, t(".report_format_csv") + + = button t(".generate_report") diff --git a/config/locales/en.yml b/config/locales/en.yml index 19e5295b8d..19eede5447 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -54,6 +54,16 @@ en: on_demand_but_count_on_hand_set: "must be blank if on demand" limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock" activemodel: + attributes: + order_management/reports/enterprise_fee_summary/parameters: + start_at: "Start" + end_at: "End" + distributor_ids: "Hubs" + producer_ids: "Producers" + order_cycle_ids: "Order Cycles" + enterprise_fee_ids: "Fees Names" + shipping_method_ids: "Shipping Methods" + payment_method_ids: "Payment Methods" errors: models: subscription_validator: @@ -2820,6 +2830,11 @@ See the %{link} to find out more about %{sitename}'s features and to start using bulk_coop_allocation: 'Bulk Co-op - Allocation' bulk_coop_packing_sheets: 'Bulk Co-op - Packing Sheets' bulk_coop_customer_payments: 'Bulk Co-op - Customer Payments' + enterprise_fee_summary_report: + filters: + date_range: "Date Range" + report_format_csv: "Download as CSV" + generate_report: "Generate Report" users: index: listing_users: "Listing Users" diff --git a/lib/order_management/reports/enterprise_fee_summary/parameters.rb b/lib/order_management/reports/enterprise_fee_summary/parameters.rb index 62b10f308e..70f8d89c78 100644 --- a/lib/order_management/reports/enterprise_fee_summary/parameters.rb +++ b/lib/order_management/reports/enterprise_fee_summary/parameters.rb @@ -7,6 +7,7 @@ module OrderManagement DATE_END_BEFORE_START_ERROR = I18n.t("date_end_before_start_error", scope: @i18n_scope) extend ActiveModel::Naming + extend ActiveModel::Translation include ActiveModel::Validations attr_accessor :start_at, :end_at, :distributor_ids, :producer_ids, :order_cycle_ids, @@ -33,6 +34,9 @@ module OrderManagement end end + # The parameters are never persisted. + def to_key; end + protected def require_valid_datetime_range