diff --git a/Gemfile.lock b/Gemfile.lock index 37c1fe9..a6007c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -233,18 +233,18 @@ GEM net-smtp (0.5.1) net-protocol nio4r (2.7.4) - nokogiri (1.18.9) + nokogiri (1.19.1) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.9-aarch64-linux-gnu) + nokogiri (1.19.1-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.9-arm-linux-gnu) + nokogiri (1.19.1-arm-linux-gnu) racc (~> 1.4) - nokogiri (1.18.9-arm64-darwin) + nokogiri (1.19.1-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.9-x86_64-darwin) + nokogiri (1.19.1-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.9-x86_64-linux-gnu) + nokogiri (1.19.1-x86_64-linux-gnu) racc (~> 1.4) orm_adapter (0.5.0) pg (1.5.9) @@ -266,7 +266,7 @@ GEM puma (6.6.0) nio4r (~> 2.0) racc (1.8.1) - rack (3.1.18) + rack (3.1.20) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) diff --git a/app/admin/applications.rb b/app/admin/applications.rb index 3bc5eff..2f23f53 100644 --- a/app/admin/applications.rb +++ b/app/admin/applications.rb @@ -17,7 +17,15 @@ button_to "Send Offer", send_offer_path(application) if application.offer_status == "not_offered" end - filter :user_id, label: "User", as: :select, collection: -> { Application.all.map { |app| [app.display_name, app.user_id]}.uniq.sort} + filter :user_email, as: :select, + collection: -> { User.joins(:applications).distinct.order(:email).pluck(:email) }, + label: "User Email" + filter :last_name, as: :select, + collection: -> { Application.distinct.order(:last_name).pluck(:last_name) }, + label: "Last Name" + filter :first_name, as: :select, + collection: -> { Application.distinct.order(:first_name).pluck(:first_name) }, + label: "First Name" filter :offer_status, as: :select filter :result_email_sent, as: :select filter :workshop_selection1, label: "workshop_selection1", as: :select, collection: -> { Workshop.all.map { |mapp| [mapp.instructor, mapp.instructor]}.sort } @@ -81,14 +89,14 @@ def load_index_batch_data total_cost = cost_lodging + cost_partner balance_due = total_cost - ttl_paid panel "Payment Activity -- [Balance Due: #{number_to_currency(balance_due)} Total Cost: #{number_to_currency(total_cost)}]" do - table_for application.user.payments.where(conf_year: application.conf_year) do #application.user.payments.current_conference_payments + table_for application.user.payments.where(conf_year: application.conf_year) do column(:id) { |aid| link_to(aid.id, admin_payment_path(aid.id)) } column(:account_type) { |atype| atype.account_type.titleize } column(:transaction_type) column(:transaction_date) {|td| Date.parse(td.transaction_date) } column(:total_amount) { |ta| number_to_currency(ta.total_amount.to_f / 100) } end - text_node link_to("[Add Manual Payment]", new_admin_payment_path(:user_id => application)) + text_node link_to("[Add Manual Payment]", new_admin_payment_path(user_id: application.user_id)) end diff --git a/app/admin/payments.rb b/app/admin/payments.rb index b8478dd..d700870 100644 --- a/app/admin/payments.rb +++ b/app/admin/payments.rb @@ -3,36 +3,25 @@ action_item :delete_manual_payment, only: :show do link_to('Delete Manual Payment', delete_manual_payment_path(payment), method: :post, data: { confirm: 'Are you sure?' }) if payment.transaction_type == "ManuallyEntered" end - menu parent: "User Mangement", priority: 2 + menu parent: "User Management", priority: 2 - # See permitted parameters documentation: - # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters - # - # Uncomment all parameters which should be permitted for assignment - # permit_params :transaction_type, :transaction_status, :transaction_id, :total_amount, :transaction_date, :account_type, :result_code, :result_message, :user_account, :payer_identity, :timestamp, :transaction_hash, :user_id, :conf_year - # - # or - # - # permit_params do - # permitted = [:transaction_type, :transaction_status, :transaction_id, :total_amount, :transaction_date, :account_type, :result_code, :result_message, :user_account, :payer_identity, :timestamp, :transaction_hash, :user_id] - # permitted << :other if params[:action] == 'create' && current_user.admin? - # permitted - # end - - # filter :user, as: :select, collection: -> { User.all.order(:email) } - # filter user.current_application, label: "Last Name (Starts with)" - # filter :application_first_name_start, label: "First Name (Starts with)" scope :current_conference_payments scope :all - filter :user_id, as: :select, - # collection: -> { User.all.order(:email) }, - collection: -> { Application.all.order(:last_name).map { |app| [app.display_name, app.user_id] } }, - label: "Name" - filter :conf_year, as: :select - + filter :payer_identity, as: :select, + collection: -> { Payment.order(:payer_identity).distinct.pluck(:payer_identity) }, + label: "User Email" + filter :user_applications_last_name, as: :select, + collection: -> { Application.joins(user: :payments).distinct.order(:last_name).pluck(:last_name) }, + label: "Last Name" + filter :user_applications_first_name, as: :select, + collection: -> { Application.joins(user: :payments).distinct.order(:first_name).pluck(:first_name) }, + label: "First Name" + filter :payments_conf_year, as: :select, + collection: -> { Payment.order(:conf_year).distinct.pluck(:conf_year) }, + label: "Payment Conf Year" index do selectable_column @@ -47,23 +36,17 @@ number_to_currency(amount.total_amount.to_f / 100) end column :transaction_status - # column :transaction_id - column :transaction_date column :account_type column :result_code column :result_message - # column :user_account - # column :payer_identity - # column :timestamp - # column :transaction_hash column :created_at column :updated_at end show do attributes_table do - row :user do |user| + row :user do |user| if (app = payment.user.applications.find_by(conf_year: ApplicationSetting.get_current_app_year)) link_to(app.display_name, admin_application_path(app)) else @@ -100,7 +83,7 @@ li "User: #{User.find(params[:user_id]).display_name}".html_safe f.input :user_id, input_html: {value: params[:user_id]}, as: :hidden else - f.input :user, as: :select, :collection => User.all.map { |u| ["#{u.email}", u.id] }.sort # Application.active_conference_applications.map { |a| ["#{a.display_name}", a.user_id] }.sort + f.input :user, as: :select, :collection => User.all.map { |u| ["#{u.email}", u.id] }.sort end li "Conf Year #{f.object.conf_year}" unless f.object.new_record? f.input :conf_year, input_html: {value: ApplicationSetting.get_current_app_year} unless f.object.persisted? @@ -112,7 +95,7 @@ f.input :account_type, collection: ['scholarship', 'special', 'other'] f.input :result_code, as: :hidden, :input_html => { value: "Manually Entered" } # 'Manually Entered' f.input :result_message, as: :hidden, :input_html => { value: "This was manually entered by #{current_admin_user.email}" } - f.input :timestamp, as: :hidden, :input_html => { value: DateTime.now.strftime("%Q").to_i } # DateTime.now.strftime("%Q").to_i + f.input :timestamp, as: :hidden, :input_html => { value: DateTime.now.strftime("%Q").to_i } end f.actions end diff --git a/app/models/payment.rb b/app/models/payment.rb index 6d9177d..ba1fd8c 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -34,7 +34,13 @@ def self.ransackable_associations(auth_object = nil) end def self.ransackable_attributes(auth_object = nil) - ["account_type", "conf_year", "created_at", "id", "id_value", "payer_identity", "result_code", "result_message", "timestamp", "total_amount", "transaction_date", "transaction_hash", "transaction_id", "transaction_status", "transaction_type", "updated_at", "user_account", "user_id"] + ["account_type", "conf_year", "created_at", "id", "id_value", "payer_identity", "payments_conf_year", "result_code", "result_message", "timestamp", "total_amount", "transaction_date", "transaction_hash", "transaction_id", "transaction_status", "transaction_type", "updated_at", "user_account", "user_id"] + end + + # Disambiguate conf_year when joining associated tables in Ransack searches. + # This forces the filter to reference the payments table explicitly. + ransacker :payments_conf_year do |parent| + parent.table[:conf_year] end diff --git a/spec/models/payment_spec.rb b/spec/models/payment_spec.rb index 96eee72..f8d4495 100644 --- a/spec/models/payment_spec.rb +++ b/spec/models/payment_spec.rb @@ -79,7 +79,7 @@ it 'returns the correct attributes' do expected_attributes = [ "account_type", "conf_year", "created_at", "id", "id_value", - "payer_identity", "result_code", "result_message", "timestamp", + "payer_identity", "payments_conf_year", "result_code", "result_message", "timestamp", "total_amount", "transaction_date", "transaction_hash", "transaction_id", "transaction_status", "transaction_type", "updated_at", "user_account", "user_id" diff --git a/yarn.lock b/yarn.lock index e8f2440..4c10751 100644 --- a/yarn.lock +++ b/yarn.lock @@ -461,9 +461,9 @@ ignore@^5.2.4: integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw== immutable@^4.0.0: - version "4.3.5" - resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.5.tgz#f8b436e66d59f99760dc577f5c99a4fd2a5cc5a0" - integrity sha512-8eabxkth9gZatlwl5TBuJnCsoTADlL6ftEr7A4qgdaTsPyreilDSnUk57SO+jfKcNtxPa22U5KK6DSeAYhpBJw== + version "4.3.8" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.8.tgz#02d183c7727fb2bb1d5d0380da0d779dce9296a7" + integrity sha512-d/Ld9aLbKpNwyl0KiM2CT1WYvkitQ1TSvmRtkcV8FKStiDoA7Slzgjmb/1G2yhKM1p0XeNOieaTbFZmU1d3Xuw== is-binary-path@~2.1.0: version "2.1.0" @@ -529,9 +529,9 @@ micromatch@^4.0.4: picomatch "^2.3.1" minimatch@^3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" - integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== + version "3.1.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.4.tgz#89d910ea3970a77ac8edfd30340ccd038b758079" + integrity sha512-twmL+S8+7yIsE9wsqgzU3E8/LumN3M3QELrBZ20OdmQ9jB2JvW5oZtBEmft84k/Gs5CG9mqtWc6Y9vW+JEzGxw== dependencies: brace-expansion "^1.1.7"