From e7f43d303601b14f7eab5b724b31d5233404dfa0 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Fri, 28 Jul 2023 15:28:17 -0400 Subject: [PATCH 001/122] Create dashboard/card partial Removes the highly duplicated nested card divs and card-tools. Results in the same HTML (modulo whitespace) --- app/views/dashboard/_card.html.erb | 68 +++++ app/views/dashboard/index.html.erb | 420 +++++++++++++---------------- 2 files changed, 249 insertions(+), 239 deletions(-) create mode 100644 app/views/dashboard/_card.html.erb diff --git a/app/views/dashboard/_card.html.erb b/app/views/dashboard/_card.html.erb new file mode 100644 index 0000000000..7720acade1 --- /dev/null +++ b/app/views/dashboard/_card.html.erb @@ -0,0 +1,68 @@ +<% + # Allows locals to be optional + footer ||= nil + footer_div ||= nil + header_div ||= nil + id ||= nil + subtitle ||= nil + table ||= false + title ||= nil + + options ||= {} + options.symbolize_keys! + options[:class] ||= "" + options[:class] += " card" + options[:id] = id if id +%> +<%= content_tag(:div, **options) do %> + <%= + header_div || + begin + gradient ||= "primary" + + header_options ||= {} + header_options.symbolize_keys! + header_options[:class] ||= "" + header_options[:class] += " card-header border-0 bg-gradient-#{gradient}" + + header ||= + begin + title = h title + title += " ".html_safe + content_tag(:small, subtitle) if subtitle + content_tag :h3, title, class: "card-title" + end + + content_tag(:div, **header_options) do %> + <%= header %> +
+ +
+ <% end + end + %> + <% if table %> +
+ <%= yield %> +
+ <% else %> +
+
+
+ <%= yield %> +
+
+
+ <% end %> + <%= + footer_div || + if footer + footer_options ||= {} + footer_options.symbolize_keys! + footer_options[:class] ||= "" + footer_options[:class] += " card-footer" + content_tag(:div, footer, **footer_options) + end + %> +<% end %> diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 68ccd8d9ed..dd3bce0b4c 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -109,7 +109,7 @@ <%= if announcement.created_at.strftime("%Y") == DateTime.now.strftime("%Y") announcement.created_at.strftime("%B %d") else - announcement.created_at.strftime("%B %d %Y") + announcement.created_at.strftime("%B %d %Y") end %>
<%= announcement.message %> @@ -124,264 +124,206 @@ <% end %> -
-
-

Distributions - <%= @selected_date_range %>

-
- -
-
-
-
-
- <%= new_button_to new_distribution_path, {text: "New Distribution"} %> - <%= print_button_to distributions_by_county_report_path(filters: { date_range: date_range_params }), {text: "Distributions by County", size: "md"} %> + <%= render( + "card", + id: "distributions", + gradient: "info", + title: "Distributions", + subtitle: @selected_date_range, + footer: link_to("See more...", distributions_path), + footer_options: { class: "text-center" }, + ) do %> + <%= new_button_to new_distribution_path, {text: "New Distribution"} %> + <%= print_button_to distributions_by_county_report_path(filters: { date_range: date_range_params }), {text: "Distributions by County", size: "md"} %> -

- - <%= total_distributed %> - - items distributed <%= @selected_date_range_label %> -

-

(<%= future_distributed %> items scheduled for future distribution)

-
-

Recent distributions

- <%= render partial: "distribution", collection: @recent_distributions, as: :distribution %> -
-
-
-
- + <% end %> -
-
-

Itemized Distributions - <%= @selected_date_range %>

-
- -
+ <%= render( + "card", + gradient: "success", + title: "Itemized Distributions", + subtitle: @selected_date_range, + table: true, + ) do %> +
+ <%= download_button_to(itemized_breakdown_distributions_path(format: :csv, filters: { date_range: date_range_params }), {text: "Export To CSV"}) %>
-
-
- <%= download_button_to(itemized_breakdown_distributions_path(format: :csv, filters: { date_range: date_range_params }), {text: "Export To CSV"}) %> -
- - <%= render partial: "itemized_distributions_partial", locals: { itemized_breakdown: @itemized_distribution_data } %> -
-
-
-
-

Activity - <%= @selected_date_range %> -

-
- -
-
-
-
-
-
-
-
- <% - activity_chart_config = { - chart: { - type: "bar" - }, - title: "", - xAxis: { - categories: @distribution_data.keys, - title: { - text: nil - } - }, - yAxis: { - title: { - text: nil - } - }, - legend: { - enabled: false - }, - series: [ - { - data: @distribution_data.values - } - ] - }.to_json - %> -
-
-
+ <%= render partial: "itemized_distributions_partial", locals: { itemized_breakdown: @itemized_distribution_data } %> + <% end %> -
-
+ <%= render( + "card", + gradient: "warning", + title: "Activity", + subtitle: @selected_date_range, + ) do %> +
+
+
+ <% + activity_chart_config = { + chart: { + type: "bar" + }, + title: "", + xAxis: { + categories: @distribution_data.keys, + title: { + text: nil + } + }, + yAxis: { + title: { + text: nil + } + }, + legend: { + enabled: false + }, + series: [ + { + data: @distribution_data.values + } + ] + }.to_json + %> +
+
+
-
+ <% end %> +
-
-
-

Donations (All Sources) - <%= @selected_date_range %>

-
- -
+ <%= render( + "card", + id: "donations", + title: "Donations (All Sources)", + subtitle: @selected_date_range, + footer_options: { class: "text-center" }, + footer: link_to("See more...", donations_path), + ) do %> + <%= new_button_to new_donation_path, {text: "New Donation"} %> +

+ + <%= total_received_donations %> + + items + received <%= @selected_date_range_label %> +

+

+ <%= dollar_presentation(total_received_money_donations) %> + raised <%= @selected_date_range_label %> +

+
+

Recent Donations

+ <%= render partial: "donation", collection: @recent_donations, as: :donation %>
-
-
-
- <%= new_button_to new_donation_path, {text: "New Donation"} %> -

- - <%= total_received_donations %> - - items - received <%= @selected_date_range_label %>

-

<%= dollar_presentation(total_received_money_donations) %> - raised <%= @selected_date_range_label %>

-
-

Recent Donations

- <%= render partial: "donation", collection: @recent_donations, as: :donation %> -
-
-
-
- -
+ <% end %> -
-
-

Product Drives <%= @selected_date_range %>

-
- -
-
-
-
-
-

- - <%= total_received_from_product_drives %> - items - received <%= @selected_date_range_label %>

-

- - <%= dollar_presentation( total_received_money_donations_from_product_drives) %> - raised <%= @selected_date_range_label %>

-
-

Recent Donations from Product Drives

- <%= render partial: "product_drive", collection: @recent_donations.by_source(:product_drive), as: :donation %> -
-
-
-
- + <% end %> -
-
-

Manufacturer Donations <%= @selected_date_range %>

-
- -
-
-
-
-
-

- - <%= number_with_delimiter(@recent_donations_from_manufacturers.sum { |d| d.line_items.total }) %> - - items donated <%= @selected_date_range_label %> - by - - <%= pluralize(@recent_donations_from_manufacturers.group_by(&:manufacturer).count, 'Manufacturer') %> - -

-
-

Top Manufacturer Donations

- <%= render partial: "manufacturer", collection: @top_manufacturers, as: :manufacturer %> -
-
-
+ <%= render( + "card", + id: "manufacturers", + gradient: "success", + title: "Manufacturer Donations", + subtitle: @selected_date_range, + footer_options: { class: "text-center" }, + footer: link_to("See more...", donations_path( + filters: { + by_source: "Manufacturer" + } + )), + ) do %> +

+ + <%= number_with_delimiter(@recent_donations_from_manufacturers.sum { |d| d.line_items.total }) %> + + items donated <%= @selected_date_range_label %> + by + + <%= pluralize(@recent_donations_from_manufacturers.group_by(&:manufacturer).count, 'Manufacturer') %> + +

+
+

Top Manufacturer Donations

+ <%= render partial: "manufacturer", collection: @top_manufacturers, as: :manufacturer %>
- -
+ <% end %> -
-
-

Purchases <%= @selected_date_range %>

-
- -
+ <%= render( + "card", + id: "purchases", + gradient: "secondary", + title: "Purchases", + subtitle: @selected_date_range, + footer_options: { class: "text-center" }, + footer: link_to("See more...", purchases_path), + ) do %> + <%= new_button_to new_purchase_path, {text: "New Purchase"} %> +

<%= dollar_presentation(@purchases.sum(&:amount_spent_in_cents)) %> + spent + <%= @selected_date_range_label %> +

+
+

Recent purchases

+ <%= render partial: "purchase", collection: @recent_purchases, as: :purchase %>
-
-
-
- <%= new_button_to new_purchase_path, {text: "New Purchase"} %> -

<%= dollar_presentation(@purchases.sum(&:amount_spent_in_cents)) %> - spent - <%= @selected_date_range_label %>

-
-

Recent purchases

- <%= render partial: "purchase", collection: @recent_purchases, as: :purchase %> -
-
-
-
- -
- + <% end %> -
-
-

Itemized Donations - <%= @selected_date_range %>

-
-
-
-
- <%= render partial: "itemized_donations_partial", locals: { itemized_breakdown: @itemized_donation_data } %> -
-
+ <%= render( + "card", + gradient: "warning", + title: "Itemized Donations", + subtitle: @selected_date_range, + table: true, + ) do %> + <%= render partial: "itemized_donations_partial", locals: { itemized_breakdown: @itemized_donation_data } %> + <% end %>
From 64a5d6e59166faf37eb3900ff4bbb3872a2d5faf Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Fri, 28 Jul 2023 15:28:39 -0400 Subject: [PATCH 002/122] Also convert summary card to partial Has slightly different layout than the others, so required some changes to the partial. --- app/views/dashboard/_card.html.erb | 32 ++++++++++------- app/views/dashboard/index.html.erb | 55 +++++++++++++----------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/app/views/dashboard/_card.html.erb b/app/views/dashboard/_card.html.erb index 7720acade1..2772f635fd 100644 --- a/app/views/dashboard/_card.html.erb +++ b/app/views/dashboard/_card.html.erb @@ -5,8 +5,8 @@ header_div ||= nil id ||= nil subtitle ||= nil - table ||= false title ||= nil + type ||= :box # or :table or :plain options ||= {} options.symbolize_keys! @@ -42,19 +42,27 @@ <% end end %> - <% if table %> -
- <%= yield %> -
- <% else %> -
-
-
- <%= yield %> + <% case type.to_sym + when :box %> +
+
+
+ <%= yield %> +
-
- <% end %> + <% when :plain %> +
+ <%= yield %> +
+ <% when :table %> +
+ <%= yield %> +
+ <% else + raise "Unknown card type: #{type}" + end %> + <%= footer_div || if footer diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index dd3bce0b4c..185404290a 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -19,35 +19,11 @@
-
-
-
<%= current_organization.name %>
-
- - -
-
- -
-
- <%= render partial: "getting_started_prompt", locals: {org_stats: @org_stats} %> - -
- <%== display_logo_or_name %> -
- -
- -
- -
- -
- + + <% end %>
@@ -154,7 +145,7 @@ gradient: "success", title: "Itemized Distributions", subtitle: @selected_date_range, - table: true, + type: :table, ) do %>
<%= download_button_to(itemized_breakdown_distributions_path(format: :csv, filters: { date_range: date_range_params }), {text: "Export To CSV"}) %> @@ -320,7 +311,7 @@ gradient: "warning", title: "Itemized Donations", subtitle: @selected_date_range, - table: true, + type: :table, ) do %> <%= render partial: "itemized_donations_partial", locals: { itemized_breakdown: @itemized_donation_data } %> <% end %> From e815d2504803052f31b9fcff0b211d906812fdce Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Fri, 28 Jul 2023 15:59:56 -0400 Subject: [PATCH 003/122] Github Workflows: Run rspec on all pull requests --- .github/workflows/rspec-system.yml | 2 -- .github/workflows/rspec.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/rspec-system.yml b/.github/workflows/rspec-system.yml index 36ac0fdd27..815b478150 100644 --- a/.github/workflows/rspec-system.yml +++ b/.github/workflows/rspec-system.yml @@ -5,8 +5,6 @@ on: branches: - main pull_request: - branches: - - main paths-ignore: - 'doc/**' - '*.md' diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index ab95707a4e..8e0045163e 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -5,8 +5,6 @@ on: branches: - main pull_request: - branches: - - main paths-ignore: - 'doc/**' - '*.md' From cd08a7bd34c8329a6500bfbd4dd10c4af61e6b2a Mon Sep 17 00:00:00 2001 From: Rae Stanton Date: Sat, 29 Jul 2023 11:25:30 -0400 Subject: [PATCH 004/122] Issue #3736 - move purchases to new area Fixes #3736 These changes include: - Removing Purchase Summary card from user's dashboard - Adds new purchase summary page & item in navigation - Changes to updated card styling/formatting - Adds a shared date filter card partial in shared directory - Adds a shared card partial for use throughout in the shared directory --- app/controllers/dashboard_controller.rb | 2 - .../purchases_summary_controller.rb | 7 ++ app/views/dashboard/index.html.erb | 20 ----- app/views/layouts/_lte_sidebar.html.erb | 5 ++ app/views/purchases_summary/_card.html.erb | 76 +++++++++++++++++++ .../_purchase.html.erb | 3 +- app/views/purchases_summary/index.html.erb | 20 +++++ .../purchases_summary/index.html.orginal.erb | 19 +++++ app/views/shared/_card.html.erb | 76 +++++++++++++++++++ app/views/shared/_filtered_card.html.erb | 37 +++++++++ config/routes.rb | 1 + 11 files changed, 243 insertions(+), 23 deletions(-) create mode 100644 app/controllers/purchases_summary_controller.rb create mode 100644 app/views/purchases_summary/_card.html.erb rename app/views/{dashboard => purchases_summary}/_purchase.html.erb (98%) create mode 100644 app/views/purchases_summary/index.html.erb create mode 100644 app/views/purchases_summary/index.html.orginal.erb create mode 100644 app/views/shared/_card.html.erb create mode 100644 app/views/shared/_filtered_card.html.erb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 45454f4ba9..9004803f9f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -7,8 +7,6 @@ def index @donations = current_organization.donations.during(helpers.selected_range) @recent_donations = @donations.recent - @purchases = current_organization.purchases.during(helpers.selected_range) - @recent_purchases = @purchases.recent.includes(:vendor) distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) @recent_distributions = distributions.recent diff --git a/app/controllers/purchases_summary_controller.rb b/app/controllers/purchases_summary_controller.rb new file mode 100644 index 0000000000..3f81e0d5a3 --- /dev/null +++ b/app/controllers/purchases_summary_controller.rb @@ -0,0 +1,7 @@ +class PurchasesSummaryController < ApplicationController + def index + setup_date_range_picker + @purchases = current_organization.purchases.during(helpers.selected_range) + @recent_purchases = @purchases.recent.includes(:vendor) + end +end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 185404290a..d8ae90765c 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -286,26 +286,6 @@
<% end %> - <%= render( - "card", - id: "purchases", - gradient: "secondary", - title: "Purchases", - subtitle: @selected_date_range, - footer_options: { class: "text-center" }, - footer: link_to("See more...", purchases_path), - ) do %> - <%= new_button_to new_purchase_path, {text: "New Purchase"} %> -

<%= dollar_presentation(@purchases.sum(&:amount_spent_in_cents)) %> - spent - <%= @selected_date_range_label %> -

-
-

Recent purchases

- <%= render partial: "purchase", collection: @recent_purchases, as: :purchase %> -
- <% end %> - <%= render( "card", gradient: "warning", diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 0175496b56..60018a8449 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -62,6 +62,11 @@ New Purchase <% end %> + -
<% end %> + <%= + outstanding_type = @outstanding_requests.empty? ? :box : :table + render( + "card", + id: "outstanding", + gradient: "warning", + title: "Outstanding Requests", + type: outstanding_type, + footer: link_to("See more...", requests_path), + footer_options: { class: "text-center" }, + ) do + if @outstanding_requests.empty? + "No outstanding requests!" + else + render "outstanding_requests", outstanding_requests: @outstanding_requests + end + end + %> + <%= render( "card", id: "distributions", diff --git a/spec/support/pages/organization_dashboard_page.rb b/spec/support/pages/organization_dashboard_page.rb index 50fac9cc37..3e93161a4a 100644 --- a/spec/support/pages/organization_dashboard_page.rb +++ b/spec/support/pages/organization_dashboard_page.rb @@ -84,6 +84,10 @@ def has_organization_logo? has_selector? org_logo_selector end + def has_outstanding_section? + has_selector? outstanding_selector + end + def manufacturers_total_donations within manufacturers_section do parse_formatted_integer find(".total_received_donations").text @@ -164,6 +168,22 @@ def total_inventory end end + def outstanding_section + find outstanding_selector + end + + def outstanding_requests + within outstanding_section do + all('tbody > tr') + end + end + + def outstanding_requests_link + within outstanding_section do + find('.card-footer a') + end + end + private def product_drives_section @@ -201,4 +221,8 @@ def org_logo_selector def purchases_section find "#purchases" end + + def outstanding_selector + "#outstanding" + end end diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index ddd6bef210..f7ac62a91d 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -812,6 +812,80 @@ def create_next_product_drive_distribution(date_picker:) end end end + + describe "Outstanding Requests" do + it "has a card" do + org_dashboard_page.visit + expect(org_dashboard_page).to have_outstanding_section + end + + context "when empty" do + before { org_dashboard_page.visit } + + it "displays a message" do + expect(org_dashboard_page.outstanding_section).to have_content "No outstanding requests!" + end + + it "has a See More link" do + expect(org_dashboard_page.outstanding_requests_link).to have_content "See more" + end + end + + context "with a pending request" do + let!(:request) { create :request, :pending } + let!(:outstanding_request) do + org_dashboard_page.visit + requests = org_dashboard_page.outstanding_requests + expect(requests.length).to eq 1 + requests.first + end + + it "displays the date" do + date = outstanding_request.find "td.date" + expect(date.text).to eq request.created_at.strftime("%m/%d/%Y") + end + + it "displays the partner" do + expect(outstanding_request).to have_content request.partner.name + end + + it "displays the requestor" do + expect(outstanding_request).to have_content request.partner_user.name + end + + it "displays the comment" do + expect(outstanding_request).to have_content request.comments + end + + it "links to the request" do + expect { outstanding_request.find('a').click } + .to change { page.current_path } + .to "/#{org_short_name}/requests/#{request.id}" + end + + it "has a See More link" do + expect(org_dashboard_page.outstanding_requests_link).to have_content "See more" + end + end + + it "does display a started request" do + create :request, :started + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests.length).to eq 1 + end + + it "does not display a fulfilled request" do + create :request, :fulfilled + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests).to be_empty + end + + it "does not display a discarded request" do + create :request, :discarded + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests).to be_empty + end + end end def valid_bracketing_dates(date_range_info) From c302248ded1092b553897800a133dcadc6e1d508 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 29 Jul 2023 14:02:05 -0400 Subject: [PATCH 007/122] Limit Outstanding Requests to 25 A huge list of outstanding requests starts to overwhelm the page and make other things hard to find. Show 25 and a link that says how many other requests there are. --- app/views/dashboard/index.html.erb | 11 +++++++++-- spec/system/dashboard_system_spec.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index a666437f76..fed9dbeb5f 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -117,19 +117,26 @@ <%= outstanding_type = @outstanding_requests.empty? ? :box : :table + outstanding_footer = + if @outstanding_requests.count > 25 + "And #{@outstanding_requests.count - 25} more..." + else + "See more..." + end render( "card", id: "outstanding", gradient: "warning", title: "Outstanding Requests", type: outstanding_type, - footer: link_to("See more...", requests_path), + footer: link_to(outstanding_footer, requests_path), footer_options: { class: "text-center" }, ) do if @outstanding_requests.empty? "No outstanding requests!" else - render "outstanding_requests", outstanding_requests: @outstanding_requests + render "outstanding_requests", + outstanding_requests: @outstanding_requests.take(25) end end %> diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index f7ac62a91d..1adb9ce7a7 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -885,6 +885,23 @@ def create_next_product_drive_distribution(date_picker:) org_dashboard_page.visit expect(org_dashboard_page.outstanding_requests).to be_empty end + + context "with many pending requests" do + let(:num_requests) { 50 } + let(:limit) { 25 } + before do + create_list :request, num_requests, :pending + org_dashboard_page.visit + end + + it "displays a limited number of requests" do + expect(org_dashboard_page.outstanding_requests.length).to eq limit + end + + it "has a link with the number of other requests" do + expect(org_dashboard_page.outstanding_requests_link).to have_content num_requests - limit + end + end end end From dd0265f62dd0da8355106174a7ac52f38e70cc43 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 29 Jul 2023 14:12:51 -0400 Subject: [PATCH 008/122] Restore remove button to dashboard cards The +/- collapse doesn't work with the layout of the table cards. Instead, those cards had a remove button. --- app/views/dashboard/_card.html.erb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/views/dashboard/_card.html.erb b/app/views/dashboard/_card.html.erb index 2772f635fd..a590448a3b 100644 --- a/app/views/dashboard/_card.html.erb +++ b/app/views/dashboard/_card.html.erb @@ -35,9 +35,15 @@ content_tag(:div, **header_options) do %> <%= header %>
- + <% if type == :table %> + + <% else %> + + <% end %>
<% end end From 73deb2f0e787f718940e2be40739ff181dfa042c Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 29 Jul 2023 16:10:14 -0400 Subject: [PATCH 009/122] Initial Itemized Donations report extract from dashboard [#3733] --- .../reports/itemized_donations_controller.rb | 6 ++++ app/views/dashboard/index.html.erb | 31 ++++++------------- app/views/layouts/_lte_sidebar.html.erb | 5 +++ .../reports/itemized_donations/index.html.erb | 29 +++++++++++++++++ .../{dashboard => shared}/_card.html.erb | 0 config/routes.rb | 1 + 6 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 app/controllers/reports/itemized_donations_controller.rb create mode 100644 app/views/reports/itemized_donations/index.html.erb rename app/views/{dashboard => shared}/_card.html.erb (100%) diff --git a/app/controllers/reports/itemized_donations_controller.rb b/app/controllers/reports/itemized_donations_controller.rb new file mode 100644 index 0000000000..455d47701d --- /dev/null +++ b/app/controllers/reports/itemized_donations_controller.rb @@ -0,0 +1,6 @@ +class Reports::ItemizedDonationsController < ApplicationController + def index + @donations = current_organization.donations.during(helpers.selected_range) + @itemized_donation_data = DonationItemizedBreakdownService.new(organization: current_organization, donation_ids: @donations.pluck(:id)).fetch + end +end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index fed9dbeb5f..913b34771e 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -20,7 +20,7 @@
<%= render( - "card", + "shared/card", id: "summary", header: content_tag(:h5, current_organization.name, class: "card-title"), footer: capture { %> @@ -83,7 +83,7 @@
<% if @broadcast_announcements.any? %> -
+

Announcements from Human Essentials

@@ -124,7 +124,7 @@ "See more..." end render( - "card", + "shared/card", id: "outstanding", gradient: "warning", title: "Outstanding Requests", @@ -142,7 +142,7 @@ %> <%= render( - "card", + "shared/card", id: "distributions", gradient: "info", title: "Distributions", @@ -167,7 +167,7 @@ <% end %> <%= render( - "card", + "shared/card", gradient: "success", title: "Itemized Distributions", subtitle: @selected_date_range, @@ -181,7 +181,7 @@ <% end %> <%= render( - "card", + "shared/card", gradient: "warning", title: "Activity", subtitle: @selected_date_range, @@ -228,7 +228,7 @@
<%= render( - "card", + "shared/card", id: "donations", title: "Donations (All Sources)", subtitle: @selected_date_range, @@ -254,7 +254,7 @@ <% end %> <%= render( - "card", + "shared/card", id: "product_drives", gradient: "info", title: "Product Drives", @@ -284,7 +284,7 @@ <% end %> <%= render( - "card", + "shared/card", id: "manufacturers", gradient: "success", title: "Manufacturer Donations", @@ -313,7 +313,7 @@ <% end %> <%= render( - "card", + "shared/card", id: "purchases", gradient: "secondary", title: "Purchases", @@ -331,17 +331,6 @@ <%= render partial: "purchase", collection: @recent_purchases, as: :purchase %>
<% end %> - - <%= render( - "card", - gradient: "warning", - title: "Itemized Donations", - subtitle: @selected_date_range, - type: :table, - ) do %> - <%= render partial: "itemized_donations_partial", locals: { itemized_breakdown: @itemized_donation_data } %> - <% end %> -
diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 0175496b56..9203e9282d 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -189,6 +189,11 @@ Annual Survey <% end %> + <% end %> diff --git a/app/views/reports/itemized_donations/index.html.erb b/app/views/reports/itemized_donations/index.html.erb new file mode 100644 index 0000000000..574693dbda --- /dev/null +++ b/app/views/reports/itemized_donations/index.html.erb @@ -0,0 +1,29 @@ +<%= render( + "shared/card", + gradient: "warning", + title: "Itemized Donations", + subtitle: @selected_date_range, + type: :table, +) do %> + + + + + + + + + + <% # Ordering from highest distributed to lowest %> + <% @itemized_donation_data.each do |item| %> + + + + + + + <% end %> + +
   ItemTotal DonatedTotal On Hand
   <%= item[:name] %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %>
+ +<% end %> diff --git a/app/views/dashboard/_card.html.erb b/app/views/shared/_card.html.erb similarity index 100% rename from app/views/dashboard/_card.html.erb rename to app/views/shared/_card.html.erb diff --git a/config/routes.rb b/config/routes.rb index 05e5b017f4..d32f9f530a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,6 +104,7 @@ def set_up_flipper resources :annual_reports, only: [:index, :show], param: :year do post :recalculate, on: :member end + resources :itemized_donations, only: [:index] end resources :transfers, only: %i(index create new show destroy) From 251f09c6785a567206742ef49f47249eb17b71f4 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 29 Jul 2023 16:21:11 -0400 Subject: [PATCH 010/122] Bring in date filter from other branch [#3733] --- .../reports/itemized_donations_controller.rb | 1 + .../reports/itemized_donations/index.html.erb | 32 ++++++++-------- app/views/shared/_filtered_card.html.erb | 37 +++++++++++++++++++ 3 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 app/views/shared/_filtered_card.html.erb diff --git a/app/controllers/reports/itemized_donations_controller.rb b/app/controllers/reports/itemized_donations_controller.rb index 455d47701d..fa356fcb95 100644 --- a/app/controllers/reports/itemized_donations_controller.rb +++ b/app/controllers/reports/itemized_donations_controller.rb @@ -1,5 +1,6 @@ class Reports::ItemizedDonationsController < ApplicationController def index + setup_date_range_picker @donations = current_organization.donations.during(helpers.selected_range) @itemized_donation_data = DonationItemizedBreakdownService.new(organization: current_organization, donation_ids: @donations.pluck(:id)).fetch end diff --git a/app/views/reports/itemized_donations/index.html.erb b/app/views/reports/itemized_donations/index.html.erb index 574693dbda..071b93c6f2 100644 --- a/app/views/reports/itemized_donations/index.html.erb +++ b/app/views/reports/itemized_donations/index.html.erb @@ -1,29 +1,31 @@ <%= render( - "shared/card", - gradient: "warning", + "shared/filtered_card", + id: "purchases", + gradient: "secondary", title: "Itemized Donations", subtitle: @selected_date_range, type: :table, + filter_url: reports_itemized_donations_path ) do %> - - +
+ - - <% # Ordering from highest distributed to lowest %> - <% @itemized_donation_data.each do |item| %> - - - - - - - <% end %> + + <% # Ordering from highest distributed to lowest %> + <% @itemized_donation_data.each do |item| %> + + + + + + + <% end %> -
   Item Total Donated Total On Hand
   <%= item[:name] %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %>
   <%= item[:name] %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %>
+ <% end %> diff --git a/app/views/shared/_filtered_card.html.erb b/app/views/shared/_filtered_card.html.erb new file mode 100644 index 0000000000..2c3717f721 --- /dev/null +++ b/app/views/shared/_filtered_card.html.erb @@ -0,0 +1,37 @@ +<% + id ||= nil + title ||= nil + subtitle ||= nil + footer ||= nil +%> + +
+
+
+
+
+ <%= simple_form_for :filters, url: filter_url, method: :get do |f| %> + <%= render partial: "shared/date_range_picker", locals: {css_class: "form-control"} %>
+ <%= filter_button %> + <% end %> +
+
+
+
+
+ <%= render("shared/card", + id: id, + gradient: "secondary", + title: title, + subtitle: subtitle, + footer_options: { class: "text-center" }, + footer: footer + ) do + + yield + + end %> +
+
+
+
From 59a5cfb7c6b3a9b52b1e3a2a5dd2f24d74973372 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 29 Jul 2023 16:26:00 -0400 Subject: [PATCH 011/122] Align text better [#3733] --- app/views/reports/itemized_donations/index.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/reports/itemized_donations/index.html.erb b/app/views/reports/itemized_donations/index.html.erb index 071b93c6f2..fa35de1867 100644 --- a/app/views/reports/itemized_donations/index.html.erb +++ b/app/views/reports/itemized_donations/index.html.erb @@ -8,7 +8,7 @@ filter_url: reports_itemized_donations_path ) do %> - +
@@ -21,8 +21,8 @@ - - + + <% end %> From 914881afd0c1e46c4632f606b57655c5c2263cbf Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 29 Jul 2023 16:28:58 -0400 Subject: [PATCH 012/122] Slight alignment cleanup [#3733] --- app/views/reports/itemized_donations/index.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/reports/itemized_donations/index.html.erb b/app/views/reports/itemized_donations/index.html.erb index fa35de1867..bcbc1f5bbb 100644 --- a/app/views/reports/itemized_donations/index.html.erb +++ b/app/views/reports/itemized_donations/index.html.erb @@ -12,11 +12,11 @@ - - + + - <% # Ordering from highest distributed to lowest %> + <% @itemized_donation_data.each do |item| %> From d4e67fa2328ff9cc848a9533c732b65720c54ba8 Mon Sep 17 00:00:00 2001 From: Lee Sharma Date: Sat, 29 Jul 2023 21:14:36 +0000 Subject: [PATCH 013/122] refactor(dashboard): Move Distributions by County functionality [#3722] (#3793) * Remove old "Distributions by County" button * Add Distribution by County report to sidebar * Make reports menu visible to non-admin users --- app/views/dashboard/index.html.erb | 1 - app/views/layouts/_lte_sidebar.html.erb | 87 ++++++++++--------- .../distributions_by_county_system_spec.rb | 1 + spec/system/navigation_system_spec.rb | 14 ++- 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index fed9dbeb5f..129fa5807f 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -151,7 +151,6 @@ footer_options: { class: "text-center" }, ) do %> <%= new_button_to new_distribution_path, {text: "New Distribution"} %> - <%= print_button_to distributions_by_county_report_path(filters: { date_range: date_range_params }), {text: "Distributions by County", size: "md"} %>

diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 0175496b56..3a09e89e6b 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -170,52 +170,57 @@ - <% if current_user.has_role?(Role::ORG_ADMIN, current_organization) %> - + <% if current_user.has_role?(Role::ORG_ADMIN, current_organization) %>

   Item
   <%= item[:name] %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %>
   ItemTotal DonatedTotal On HandTotal DonatedTotal On Hand
- - - - - - - - - <% @itemized_donation_data.each do |item| %> - +<% if @itemized_donation_data.empty? %> + +<% else %> +
   ItemTotal DonatedTotal On Hand
+ - - - + + + - <% end %> - -
   <%= item[:name] %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %>   ItemTotal DonatedTotal On Hand
+ + + <% @itemized_donation_data.each do |item| %> + + +    <%= item[:name] %> + <%= item[:donated] %> + <%= item[:current_onhand] || "Unknown" %> + + <% end %> + + +<% end %> <% end %> From d85cce4139eea9d024f7761d4122ab3415601eea Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 29 Jul 2023 17:27:42 -0400 Subject: [PATCH 017/122] Satiate Rubocop! [#3733] Not sure how these got into this branch specifically, but ok. --- spec/support/pages/organization_dashboard_page.rb | 4 ++-- spec/system/navigation_system_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/support/pages/organization_dashboard_page.rb b/spec/support/pages/organization_dashboard_page.rb index 3e93161a4a..a70d5d4ce9 100644 --- a/spec/support/pages/organization_dashboard_page.rb +++ b/spec/support/pages/organization_dashboard_page.rb @@ -174,13 +174,13 @@ def outstanding_section def outstanding_requests within outstanding_section do - all('tbody > tr') + all("tbody > tr") end end def outstanding_requests_link within outstanding_section do - find('.card-footer a') + find(".card-footer a") end end diff --git a/spec/system/navigation_system_spec.rb b/spec/system/navigation_system_spec.rb index 842482ac71..7d9bad7d95 100644 --- a/spec/system/navigation_system_spec.rb +++ b/spec/system/navigation_system_spec.rb @@ -29,7 +29,7 @@ end end - describe "Reporting & Auditing submenu"do + describe "Reporting & Auditing submenu" do let(:reports) { ["Inventory Audit", "Annual Survey", "Distributions by County"] } before { click_link("Reporting & Auditing") } From 0a5b57d05420fd58884c12ee8605272156806a4d Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 29 Jul 2023 17:29:25 -0400 Subject: [PATCH 018/122] Don't github action ci on both PR and Push [#3733] --- .github/workflows/brakeman.yml | 1 - .github/workflows/factory-bot-lint.yml | 1 - .github/workflows/rspec-system.yml | 1 - .github/workflows/rspec.yml | 1 - .github/workflows/ruby_lint.yml | 5 ----- 5 files changed, 9 deletions(-) diff --git a/.github/workflows/brakeman.yml b/.github/workflows/brakeman.yml index 37b2596352..0f797c3d29 100644 --- a/.github/workflows/brakeman.yml +++ b/.github/workflows/brakeman.yml @@ -2,7 +2,6 @@ name: brakeman on: push: - pull_request: paths-ignore: - 'doc/**' - '*.md' diff --git a/.github/workflows/factory-bot-lint.yml b/.github/workflows/factory-bot-lint.yml index 0adec99afd..523d55b62a 100644 --- a/.github/workflows/factory-bot-lint.yml +++ b/.github/workflows/factory-bot-lint.yml @@ -2,7 +2,6 @@ name: factory bot lint on: push: - pull_request: paths-ignore: - 'doc/**' - '*.md' diff --git a/.github/workflows/rspec-system.yml b/.github/workflows/rspec-system.yml index ce97ea178b..cc2d8bac72 100644 --- a/.github/workflows/rspec-system.yml +++ b/.github/workflows/rspec-system.yml @@ -2,7 +2,6 @@ name: rspec-system on: push: - pull_request: paths-ignore: - 'doc/**' - '*.md' diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 94ebb9697c..15cb6c918b 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -2,7 +2,6 @@ name: rspec on: push: - pull_request: paths-ignore: - 'doc/**' - '*.md' diff --git a/.github/workflows/ruby_lint.yml b/.github/workflows/ruby_lint.yml index 5023ac905a..4aa094aa13 100644 --- a/.github/workflows/ruby_lint.yml +++ b/.github/workflows/ruby_lint.yml @@ -6,11 +6,6 @@ on: - 'doc/**' - '*.md' - 'bin/*' - pull_request: - paths-ignore: - - 'doc/**' - - '*.md' - - 'bin/*' jobs: ruby_lint: From 357df3a7223201fa72e7f2c1f09a68cedbfe4981 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sun, 30 Jul 2023 09:26:27 -0400 Subject: [PATCH 019/122] Remove itemized donations partial [#3733] --- .../_itemized_donations_partial.html.erb | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 app/views/dashboard/_itemized_donations_partial.html.erb diff --git a/app/views/dashboard/_itemized_donations_partial.html.erb b/app/views/dashboard/_itemized_donations_partial.html.erb deleted file mode 100644 index 0d33a68774..0000000000 --- a/app/views/dashboard/_itemized_donations_partial.html.erb +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - <% # Ordering from highest distributed to lowest %> - <% (local_assigns[:itemized_breakdown] || []).each do |item| %> - - - - - - - <% end %> - -
   ItemTotal DonatedTotal On Hand
   <%= item[:name] %><%= item[:donated] %><%= item[:current_onhand] || "Unknown" %>
From 94f12c0a4d7ccc1b63da3e2c7e41be65eb6f2ae0 Mon Sep 17 00:00:00 2001 From: Rae Stanton Date: Sat, 29 Jul 2023 11:25:30 -0400 Subject: [PATCH 020/122] Issue #3736 - move purchases to new area Fixes #3736 These changes include: Needed to change the dashboard to not contain any information about the purchases summary - this has now been moved to the new purchases summary page within the nav bar under `reporting and auditing`. Filtering has also been added to said page, and filter partials and the card have been added to a shared area for ease of access and consistency. Page tests added for new content. --- app/controllers/dashboard_controller.rb | 2 - .../purchases_summary_controller.rb | 7 + app/views/dashboard/index.html.erb | 20 --- app/views/layouts/_lte_sidebar.html.erb | 9 +- app/views/purchases_summary/_card.html.erb | 76 +++++++++ .../_purchase.html.erb | 3 +- app/views/purchases_summary/index.html.erb | 20 +++ .../purchases_summary/index.html.orginal.erb | 19 +++ app/views/shared/_card.html.erb | 76 +++++++++ app/views/shared/_filtered_card.html.erb | 37 +++++ config/routes.rb | 1 + .../purchases_summary_requests_spec.rb | 25 +++ .../pages/organization_dashboard_page.rb | 16 -- .../organization_purchases_summary_page.rb | 48 ++++++ spec/system/dashboard_system_spec.rb | 117 -------------- spec/system/purchases_summary_system_spec.rb | 147 ++++++++++++++++++ 16 files changed, 465 insertions(+), 158 deletions(-) create mode 100644 app/controllers/purchases_summary_controller.rb create mode 100644 app/views/purchases_summary/_card.html.erb rename app/views/{dashboard => purchases_summary}/_purchase.html.erb (98%) create mode 100644 app/views/purchases_summary/index.html.erb create mode 100644 app/views/purchases_summary/index.html.orginal.erb create mode 100644 app/views/shared/_card.html.erb create mode 100644 app/views/shared/_filtered_card.html.erb create mode 100644 spec/requests/purchases_summary_requests_spec.rb create mode 100644 spec/support/pages/organization_purchases_summary_page.rb create mode 100644 spec/system/purchases_summary_system_spec.rb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 990ff9ee2f..54706f9afc 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -7,8 +7,6 @@ def index @donations = current_organization.donations.during(helpers.selected_range) @recent_donations = @donations.recent - @purchases = current_organization.purchases.during(helpers.selected_range) - @recent_purchases = @purchases.recent.includes(:vendor) distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) @recent_distributions = distributions.recent diff --git a/app/controllers/purchases_summary_controller.rb b/app/controllers/purchases_summary_controller.rb new file mode 100644 index 0000000000..3f81e0d5a3 --- /dev/null +++ b/app/controllers/purchases_summary_controller.rb @@ -0,0 +1,7 @@ +class PurchasesSummaryController < ApplicationController + def index + setup_date_range_picker + @purchases = current_organization.purchases.during(helpers.selected_range) + @recent_purchases = @purchases.recent.includes(:vendor) + end +end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 129fa5807f..f4559ec9f8 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -311,26 +311,6 @@
<% end %> - <%= render( - "card", - id: "purchases", - gradient: "secondary", - title: "Purchases", - subtitle: @selected_date_range, - footer_options: { class: "text-center" }, - footer: link_to("See more...", purchases_path), - ) do %> - <%= new_button_to new_purchase_path, {text: "New Purchase"} %> -

<%= dollar_presentation(@purchases.sum(&:amount_spent_in_cents)) %> - spent - <%= @selected_date_range_label %> -

-
-

Recent purchases

- <%= render partial: "purchase", collection: @recent_purchases, as: :purchase %> -
- <% end %> - <%= render( "card", gradient: "warning", diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 3a09e89e6b..67a4124e2f 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -170,8 +170,8 @@ - + +
- + <%= render( + "shared/card", + id: "partner_approvals", + title: "Partner Approvals", + class: "wide-table", + type: @partners_awaiting_review.blank? ? :box : :table + ) do %> + <% if @partners_awaiting_review.present? %> + + + + + + + + + + + <% @partners_awaiting_review.each do |partner| %> + + + + + + + + <%end%> +
Partner NamePrimary Contact NamePrimary Contact EmailReview RequestedAction
<%= partner.name %><%= partner.profile.primary_contact_name %><%= partner.profile.primary_contact_email %><%= partner.updated_at.strftime("%B %d %Y") %> + <%= view_button_to partner_path(partner) + "#partner-information", { text: "Review Application", icon: "check", type: "warning", class: 'badge' } %> +
+ <% else %> + No partners waiting for approval + <% end %> + <% end %> <%= render( "shared/card", id: "donations", diff --git a/spec/factories/partners/profile.rb b/spec/factories/partners/profile.rb index 396787bc57..292100cb50 100644 --- a/spec/factories/partners/profile.rb +++ b/spec/factories/partners/profile.rb @@ -3,5 +3,7 @@ partner { Partner.first || create(:partner) } essentials_bank_id { Organization.try(:first).id || create(:organization).id } website { "http://some-site.org" } + primary_contact_email { Faker::Internet.email } + primary_contact_name { Faker::Name.name } end end diff --git a/spec/support/pages/organization_dashboard_page.rb b/spec/support/pages/organization_dashboard_page.rb index bc1c9003c9..186079fb9d 100644 --- a/spec/support/pages/organization_dashboard_page.rb +++ b/spec/support/pages/organization_dashboard_page.rb @@ -172,6 +172,14 @@ def outstanding_requests_link end end + def has_partner_approvals_section? + has_selector? "#partner_approvals.card" + end + + def partner_approvals_section + find "#partner_approvals.card" + end + private def product_drives_section diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index 5febe48201..022f9d250d 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -786,6 +786,57 @@ def create_next_product_drive_distribution(date_picker:) end end end + + describe "Partner Approvals" do + it "has a card" do + org_dashboard_page.visit + expect(org_dashboard_page).to have_partner_approvals_section + end + + context "when empty" do + it "displays a message" do + org_dashboard_page.visit + expect(org_dashboard_page.partner_approvals_section).to have_content "No partners waiting for approval" + end + end + + context "with no awaiting partners" do + let!(:partner) { create :partner, :approved } + + it "still displays the simple message" do + org_dashboard_page.visit + expect(org_dashboard_page.partner_approvals_section).to have_content "No partners waiting for approval" + end + end + + context "with awaiting partners" do + let!(:org) { create :organization } + let!(:user) { create :user, organization: org } + let!(:partner_to_see1) { create :partner, status: :awaiting_review, organization: org } + let!(:partner_to_see2) { create :partner, status: :awaiting_review, organization: org } + let!(:partner_hidden1) { create :partner, status: :approved, organization: org } + let!(:partner_hidden2) { create :partner, status: :invited, organization: org } + + it "only displays awaiting partners" do + sign_in user + org_dashboard_page.visit + within(org_dashboard_page.partner_approvals_section) do + [partner_to_see1, partner_to_see2].each do |partner| + expect(page).to have_content partner.name + expect(page).to have_content partner.profile.primary_contact_email + expect(page).to have_content partner.profile.primary_contact_name + expect(page).to have_link "Review Application", href: partner_path(organization_id: org, id: partner) + "#partner-information" + end + [partner_hidden1, partner_hidden2].each do |hidden_partner| + expect(page).to_not have_content hidden_partner.name + expect(page).to_not have_content hidden_partner.profile.primary_contact_email + expect(page).to_not have_content hidden_partner.profile.primary_contact_name + expect(page).to_not have_link "Review Application", href: partner_path(organization_id: org, id: hidden_partner) + "#partner-information" + end + end + end + end + end end def valid_bracketing_dates(date_range_info) From 5ed4e7e8d0e2da9a8c38c8d22db6659cec070607 Mon Sep 17 00:00:00 2001 From: Rae Stanton Date: Sun, 30 Jul 2023 11:18:24 -0400 Subject: [PATCH 027/122] Distributions summary Fixes issue #3723 Changes made: This creates a new area for distributions summary to live under audits, adds system, page, and request spec for testing. sidebar - we also fixed the weird issue with the sidebar for the annual reports, distributions by county, and itemized donations & distributions that were not staying selected. --- app/controllers/dashboard_controller.rb | 3 - .../distributions_summary_controller.rb | 8 + app/views/dashboard/index.html.erb | 24 --- .../_distribution.html.erb | 0 .../distributions_summary/index.html.erb | 24 +++ app/views/layouts/_lte_sidebar.html.erb | 25 +-- config/routes.rb | 1 + .../distributions_summary_requests_spec.rb | 25 +++ .../pages/organization_dashboard_page.rb | 30 ---- ...organization_distributions_summary_page.rb | 62 +++++++ spec/system/dashboard_system_spec.rb | 125 -------------- .../distributions_summary_system_spec.rb | 155 ++++++++++++++++++ 12 files changed, 290 insertions(+), 192 deletions(-) create mode 100644 app/controllers/distributions_summary_controller.rb rename app/views/{dashboard => distributions_summary}/_distribution.html.erb (100%) create mode 100644 app/views/distributions_summary/index.html.erb create mode 100644 spec/requests/distributions_summary_requests_spec.rb create mode 100644 spec/support/pages/organization_distributions_summary_page.rb create mode 100644 spec/system/distributions_summary_system_spec.rb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 28e34280cb..11bfb2eff4 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -9,9 +9,6 @@ def index @recent_donations = @donations.recent distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) - @recent_distributions = distributions.recent - - @itemized_donation_data = DonationItemizedBreakdownService.new(organization: current_organization, donation_ids: @donations.pluck(:id)).fetch @itemized_distribution_data = DistributionItemizedBreakdownService.new(organization: current_organization, distribution_ids: distributions.pluck(:id)).fetch @total_inventory = current_organization.total_inventory diff --git a/app/controllers/distributions_summary_controller.rb b/app/controllers/distributions_summary_controller.rb new file mode 100644 index 0000000000..c956f8e50c --- /dev/null +++ b/app/controllers/distributions_summary_controller.rb @@ -0,0 +1,8 @@ +class DistributionsSummaryController < ApplicationController + def index + setup_date_range_picker + + distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) + @recent_distributions = distributions.recent + end +end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index b71f87b35c..34d10dc04d 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -141,30 +141,6 @@ end %> - <%= render( - "shared/card", - id: "distributions", - gradient: "info", - title: "Distributions", - subtitle: @selected_date_range, - footer: link_to("See more...", distributions_path), - footer_options: { class: "text-center" }, - ) do %> - <%= new_button_to new_distribution_path, {text: "New Distribution"} %> - -

- - <%= total_distributed %> - - items distributed <%= @selected_date_range_label %> -

-

(<%= future_distributed %> items scheduled for future distribution)

-
-

Recent distributions

- <%= render partial: "distribution", collection: @recent_distributions, as: :distribution %> -
- <% end %> - <%= render( "shared/card", gradient: "warning", diff --git a/app/views/dashboard/_distribution.html.erb b/app/views/distributions_summary/_distribution.html.erb similarity index 100% rename from app/views/dashboard/_distribution.html.erb rename to app/views/distributions_summary/_distribution.html.erb diff --git a/app/views/distributions_summary/index.html.erb b/app/views/distributions_summary/index.html.erb new file mode 100644 index 0000000000..38daa0fb5d --- /dev/null +++ b/app/views/distributions_summary/index.html.erb @@ -0,0 +1,24 @@ +<%= render( + "shared/filtered_card", + id: "distributions", + gradient: "secondary", + title: "Distributions", + subtitle: @selected_date_range, + footer_options: { class: "text-center" }, + footer: link_to("See more...", distributions_path), + filter_url: distributions_summary_path +) do %> + <%= new_button_to new_distribution_path, {text: "New Distribution"} %> + +

+ + <%= total_distributed %> + + items distributed <%= @selected_date_range_label %> +

+

(<%= future_distributed %> items scheduled for future distribution)

+
+

Recent distributions

+ <%= render partial: "distribution", collection: @recent_distributions, as: :distribution %> +
+<% end %> diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 4aba0b674a..5f3a3a89bc 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -170,8 +170,8 @@ -
<% end %> - - - - @@ -210,6 +210,11 @@ Purchases Summary <% end %> + + - From 1dd2d537244ce8eefd336e43bf460764057a4966 Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Thu, 3 Aug 2023 20:36:24 +0000 Subject: [PATCH 032/122] Working System Spec --- .../reports/donations_summary/index.html.erb | 52 +++--- spec/system/donation_system_spec.rb | 118 ------------- spec/system/reports/donations_summary_spec.rb | 166 ++++++++++++++++++ 3 files changed, 192 insertions(+), 144 deletions(-) create mode 100644 spec/system/reports/donations_summary_spec.rb diff --git a/app/views/reports/donations_summary/index.html.erb b/app/views/reports/donations_summary/index.html.erb index ac3c2ca6c1..4343938bfd 100644 --- a/app/views/reports/donations_summary/index.html.erb +++ b/app/views/reports/donations_summary/index.html.erb @@ -1,27 +1,27 @@ - <%= render( - "shared/filtered_card", - id: "donations", - title: "Donations (All Sources)", - subtitle: @selected_date_range, - footer_options: { class: "text-center" }, - footer: link_to("See more...", donations_path), - filter_url: reports_donations_summary_index_path - ) do %> - <%= new_button_to new_donation_path, {text: "New Donation"} %> -

- - <%= total_received_donations %> - - items - received <%= @selected_date_range_label %> -

-

- <%= dollar_presentation(total_received_money_donations) %> - raised <%= @selected_date_range_label %> -

-
-

Recent Donations

- <%= render partial: "reports/donations_summary/donation", collection: @recent_donations, as: :donation %> -
- <% end %> +<%= render( + "shared/filtered_card", + id: "donations", + title: "Donations (All Sources)", + subtitle: @selected_date_range, + footer_options: { class: "text-center" }, + footer: link_to("See more...", donations_path), + filter_url: reports_donations_summary_index_path +) do %> + <%= new_button_to new_donation_path, {text: "New Donation"} %> +

+ + <%= total_received_donations %> + + items + received <%= @selected_date_range_label %> +

+

+ <%= dollar_presentation(total_received_money_donations) %> + raised <%= @selected_date_range_label %> +

+
+

Recent Donations

+ <%= render partial: "reports/donations_summary/donation", collection: @recent_donations, as: :donation %> +
+<% end %> diff --git a/spec/system/donation_system_spec.rb b/spec/system/donation_system_spec.rb index 002d3762d4..85baacb78d 100644 --- a/spec/system/donation_system_spec.rb +++ b/spec/system/donation_system_spec.rb @@ -638,124 +638,6 @@ end end end - - context "when visiting the summary page" do - it "has a link to create a new donation" do - org_new_donation_page = OrganizationNewDonationPage.new org_short_name: org_short_name - - org_dashboard_page.visit - - expect { org_dashboard_page.create_new_donation } - .to change { page.current_path } - .to org_new_donation_page.path - end - - # as of 28 Jan 2022, the "Recent Donations" list shows up to this many items matching the date filter - max_recent_donation_links_count = 3 - - # Make up to this many (inclusive) donations for each filtered period - # Keep it below (item_quantities.size - 1) so there's at least 2 values left for - # Donations outside of the filtered period - max_donations_in_filtered_period = max_recent_donation_links_count + 1 - - around do |example| - # Ensure "today" doesn't change for the server side during the example run - # Note, however, that this does *not* affect the client side - # So "today" for the server still might be "yesterday" - # —possibly even "last month" or "last year"- - # for the client - # Rely on rerun via rspec-retry for those edge cases - travel_to(test_time) - example.run - travel_back - end - - [ - # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators - [nil, test_time - 2.years, test_time - rand(180).days, :set_custom_dates], # arbitrary values - ["Today", test_time, test_time], - ["Yesterday", test_time.yesterday, test_time.yesterday], - ["Last 7 Days", test_time - 6.days, test_time], - ["Last 30 Days", test_time - 29.days, test_time], - ["This Month", test_time.beginning_of_month, test_time.end_of_month], - ["Last Month", test_time.last_month.beginning_of_month, test_time.last_month.end_of_month], - ["This Year", test_time.beginning_of_year, test_time.end_of_year] - # We now can't test the lower limit of All Time, because the earliest possible date is 2000-01-01 - # ["All Time", test_time - 100.years, test_time] - # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators - ].each do |date_range_info| - filtered_date_range_label, start_date, end_date, set_custom_dates = date_range_info - - filtered_date_range = start_date.to_date..end_date.to_date - before_filtered_date_range = start_date.yesterday.to_date - after_filtered_date_range = end_date.tomorrow.to_date - - start_date_formatted, end_date_formatted = [start_date, end_date].map { _1.to_formatted_s(:date_picker) } - - # Ideally different date ranges get different counts (incl. 0!) to test the various combinations - # w/out making a fixed pattern - num_donations_in_filtered_period = rand(0..max_donations_in_filtered_period) - - context "given 1 Donation on #{before_filtered_date_range} (only if a valid date), " \ - "#{num_donations_in_filtered_period} during #{filtered_date_range}, and " \ - "1 on #{after_filtered_date_range}" do - custom_dates = if set_custom_dates - "#{start_date_formatted} - #{end_date_formatted}" - end - - before do - filtered_dates = filtered_date_range.to_a - @quantities_donated_in_filtered_date_range = [] - - @item_quantity = item_quantities.to_enum - - def create_next_donation(donation_date:) - quantity_in_donation = @item_quantity.next - create :donation, :with_items, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: @organization - - quantity_in_donation - end - - # days_this_year.sample in num_donations_in_filtered_period.times loop - # rather than - # days_this_year.sample(num_donations_in_filtered_period).each - # because Array#sample(n) on an Array with m Date: Sat, 5 Aug 2023 10:46:38 -0400 Subject: [PATCH 033/122] Move activity graph to a standalone report [#3798] --- app/controllers/dashboard_controller.rb | 2 - .../reports/activity_graph_controller.rb | 29 +++++++++++ app/helpers/dashboard_helper.rb | 16 ------ app/views/dashboard/index.html.erb | 43 ---------------- app/views/layouts/_lte_sidebar.html.erb | 7 ++- .../reports/activity_graph/index.html.erb | 51 +++++++++++++++++++ config/routes.rb | 1 + 7 files changed, 87 insertions(+), 62 deletions(-) create mode 100644 app/controllers/reports/activity_graph_controller.rb create mode 100644 app/views/reports/activity_graph/index.html.erb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 11bfb2eff4..d8448efa47 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -20,8 +20,6 @@ def index @recent_donations_from_manufacturers = current_organization.donations.during(helpers.selected_range).by_source(:manufacturer) @top_manufacturers = current_organization.manufacturers.by_donation_count - @distribution_data = helpers.received_distributed_data(helpers.selected_range) - @partners_awaiting_review = current_organization.partners.awaiting_review # passing nil here filters the announcements that didn't come from an organization @broadcast_announcements = BroadcastAnnouncement.filter_announcements(nil) diff --git a/app/controllers/reports/activity_graph_controller.rb b/app/controllers/reports/activity_graph_controller.rb new file mode 100644 index 0000000000..e2ff7a6dcc --- /dev/null +++ b/app/controllers/reports/activity_graph_controller.rb @@ -0,0 +1,29 @@ +class Reports::ActivityGraphController < ApplicationController + def index + setup_date_range_picker + @distribution_data = received_distributed_data(helpers.selected_range) + end + + private + + def total_purchased_unformatted(range = selected_range) + LineItem.active.where(itemizable: current_organization.purchases.during(range)).sum(:quantity) + end + + def total_distributed_unformatted(range = selected_range) + LineItem.active.where(itemizable: current_organization.distributions.during(range)).sum(:quantity) + end + + def total_received_donations_unformatted(range = selected_range) + LineItem.active.where(itemizable: current_organization.donations.during(range)).sum(:quantity) + end + + def received_distributed_data(range = selected_range) + { + "Received donations" => total_received_donations_unformatted(range), + "Purchased" => total_purchased_unformatted(range), + "Distributed" => total_distributed_unformatted(range) + } + end + +end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb index a2909f7c1a..b434f79cdd 100644 --- a/app/helpers/dashboard_helper.rb +++ b/app/helpers/dashboard_helper.rb @@ -1,21 +1,9 @@ # Encapsulates methods used on the Dashboard that need some business logic module DashboardHelper - def received_distributed_data(range = selected_range) - { - "Received donations" => total_received_donations_unformatted(range), - "Purchased" => total_purchased_unformatted(range), - "Distributed" => total_distributed_unformatted(range) - } - end - def total_on_hand(total = nil) number_with_delimiter(total || "-1") end - def total_purchased(range = selected_range) - number_with_delimiter total_purchased_unformatted(range) - end - def total_distributed(range = selected_range) number_with_delimiter total_distributed_unformatted(range) end @@ -30,10 +18,6 @@ def recently_added_user_display_text(user) private - def total_purchased_unformatted(range = selected_range) - LineItem.active.where(itemizable: current_organization.purchases.during(range)).sum(:quantity) - end - def total_distributed_unformatted(range = selected_range) LineItem.active.where(itemizable: current_organization.distributions.during(range)).sum(:quantity) end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index c9ecd31a11..21224e00a3 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -141,49 +141,6 @@ end %> - <%= render( - "shared/card", - gradient: "warning", - title: "Activity", - subtitle: @selected_date_range, - ) do %> -
-
-
- <% - activity_chart_config = { - chart: { - type: "bar" - }, - title: "", - xAxis: { - categories: @distribution_data.keys, - title: { - text: nil - } - }, - yAxis: { - title: { - text: nil - } - }, - legend: { - enabled: false - }, - series: [ - { - data: @distribution_data.values - } - ] - }.to_json - %> -
-
-
- -
-
- <% end %>
diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 749653a8fa..721bbe2970 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -205,11 +205,16 @@ Itemized Distributions <% end %> - + - -
<% end %> - - <%= render( - "shared/card", - id: "manufacturers", - gradient: "success", - title: "Manufacturer Donations", - subtitle: @selected_date_range, - footer_options: { class: "text-center" }, - footer: link_to("See more...", donations_path( - filters: { - by_source: "Manufacturer" - } - )), - ) do %> -

- - <%= number_with_delimiter(@recent_donations_from_manufacturers.sum { |d| d.line_items.total }) %> - - items donated <%= @selected_date_range_label %> - by - - <%= pluralize(@recent_donations_from_manufacturers.group_by(&:manufacturer).count, 'Manufacturer') %> - -

-
-

Top Manufacturer Donations

- <%= render partial: "manufacturer", collection: @top_manufacturers, as: :manufacturer %> -
- <% end %> -
diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 749653a8fa..3eb150aac7 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -209,6 +209,11 @@ <%= link_to(reports_donations_summary_index_path(organization_id: current_user.organization), class: "nav-link #{active_class(['reports/donations_summary'])}") do %> Donations Summary <% end %> + +
<% end %> + <%= render partial: "low_inventory_report" %> + <%= outstanding_type = @outstanding_requests.empty? ? :box : :table outstanding_footer = diff --git a/spec/queries/low_inventory_query_spec.rb b/spec/queries/low_inventory_query_spec.rb new file mode 100644 index 0000000000..9517300959 --- /dev/null +++ b/spec/queries/low_inventory_query_spec.rb @@ -0,0 +1,67 @@ +RSpec.describe LowInventoryQuery do + subject { LowInventoryQuery.new(organization: organization).call } + + let(:organization) { create :organization } + + it { is_expected.to eq [] } + + context "with inventory items" do + let(:storage_location) { create :storage_location, organization: organization } + let(:minimum_quantity) { 0 } + let(:recommended_quantity) { 0 } + let!(:inventory_item) { create :inventory_item, item: item, storage_location: storage_location, quantity: 100 } + + let(:item) do + create :item, + organization: organization, + on_hand_minimum_quantity: minimum_quantity, + on_hand_recommended_quantity: recommended_quantity + end + + it { is_expected.to eq [] } + + context "when minimum_quantity and recommended_quantity is nil" do + let(:item) { create :item, organization: organization } + + it { is_expected.to eq [] } + end + + context "when inventory quantity is over minimum quantity" do + let(:minimum_quantity) { 50 } + + it { is_expected.to eq [] } + end + + context "when minimum_quantity is equal to quantity" do + let(:minimum_quantity) { 100 } + + it "returns the inventory item" do + is_expected.to include inventory_item + end + end + + context "when inventory quantity drops below minimum quantity" do + let(:minimum_quantity) { 200 } + + it "returns the inventory item" do + is_expected.to include inventory_item + end + end + + context "when inventory quantity equals recommended quantity" do + let(:recommended_quantity) { 100 } + + it "returns the inventory item" do + is_expected.to include inventory_item + end + end + + context "when inventory quantity drops below recommended quantity" do + let(:recommended_quantity) { 200 } + + it "returns the inventory item" do + is_expected.to include inventory_item + end + end + end +end \ No newline at end of file From ef0b29416432335176bf8c31e485c93cac537fe2 Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Thu, 28 Sep 2023 17:07:44 +0000 Subject: [PATCH 045/122] Only return if inventory levels are lower than minimum or recommended. If there is a minimum of 0 and amount of 0, the equality check used to return that inventory item, which we don't want. The cleanest way to handle this is to only return if the inventory levels are lower. --- app/queries/low_inventory_query.rb | 4 ++-- spec/queries/low_inventory_query_spec.rb | 27 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/queries/low_inventory_query.rb b/app/queries/low_inventory_query.rb index 02394b45e3..2ef4a25f06 100644 --- a/app/queries/low_inventory_query.rb +++ b/app/queries/low_inventory_query.rb @@ -7,8 +7,8 @@ def initialize(organization:) def call scope = organization.inventory_items - scope.where("inventory_items.quantity <= items.on_hand_minimum_quantity") - .or(scope.where("inventory_items.quantity <= items.on_hand_recommended_quantity")) + scope.where("inventory_items.quantity < items.on_hand_minimum_quantity") + .or(scope.where("inventory_items.quantity < items.on_hand_recommended_quantity")) .includes(:item, :storage_location) end end diff --git a/spec/queries/low_inventory_query_spec.rb b/spec/queries/low_inventory_query_spec.rb index 9517300959..630fbbc57a 100644 --- a/spec/queries/low_inventory_query_spec.rb +++ b/spec/queries/low_inventory_query_spec.rb @@ -9,7 +9,8 @@ let(:storage_location) { create :storage_location, organization: organization } let(:minimum_quantity) { 0 } let(:recommended_quantity) { 0 } - let!(:inventory_item) { create :inventory_item, item: item, storage_location: storage_location, quantity: 100 } + let!(:inventory_item) { create :inventory_item, item: item, storage_location: storage_location, quantity: inventory_item_quantity } + let(:inventory_item_quantity) { 100 } let(:item) do create :item, @@ -26,6 +27,14 @@ it { is_expected.to eq [] } end + context "when minimum_quantity is 0 and recommended_quantity is nil and item quantity is 0" do + let(:item) { create :item, organization: organization } + let(:minimum_quantity) { 0 } + let(:inventory_item_quantity) { 0 } + + it { is_expected.to eq [] } + end + context "when inventory quantity is over minimum quantity" do let(:minimum_quantity) { 50 } @@ -35,33 +44,25 @@ context "when minimum_quantity is equal to quantity" do let(:minimum_quantity) { 100 } - it "returns the inventory item" do - is_expected.to include inventory_item - end + it { is_expected.to eq [] } end context "when inventory quantity drops below minimum quantity" do let(:minimum_quantity) { 200 } - it "returns the inventory item" do - is_expected.to include inventory_item - end + it { is_expected.to include inventory_item } end context "when inventory quantity equals recommended quantity" do let(:recommended_quantity) { 100 } - it "returns the inventory item" do - is_expected.to include inventory_item - end + it { is_expected.to eq [] } end context "when inventory quantity drops below recommended quantity" do let(:recommended_quantity) { 200 } - it "returns the inventory item" do - is_expected.to include inventory_item - end + it { is_expected.to include inventory_item } end end end \ No newline at end of file From 9f2ac37b8d4d5155f4cfa9b11138b692c714b593 Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Thu, 28 Sep 2023 17:36:12 +0000 Subject: [PATCH 046/122] Setup system specs and setup sufficient inventory levels message --- .../dashboard/_low_inventory_report.html.erb | 48 ++++++++++--------- .../pages/organization_dashboard_page.rb | 18 +++++++ spec/system/dashboard_system_spec.rb | 27 +++++++++++ 3 files changed, 71 insertions(+), 22 deletions(-) diff --git a/app/views/dashboard/_low_inventory_report.html.erb b/app/views/dashboard/_low_inventory_report.html.erb index 0b4895cafa..229a1fed28 100644 --- a/app/views/dashboard/_low_inventory_report.html.erb +++ b/app/views/dashboard/_low_inventory_report.html.erb @@ -5,26 +5,30 @@ gradient: "info", title: "Bank-wide Low inventory" ) do %> - - - - - - - - - - - - <% @low_inventory_report.each do |inventory_item| %> - - - - - - - - <% end %> - -
Storage LocationItem NameQuantityMinimum QuantityRecommended Quantity
<%= inventory_item.storage_location.name %><%= inventory_item.item.name %><%= inventory_item.quantity %><%= inventory_item.item.on_hand_minimum_quantity %><%= inventory_item.item.on_hand_recommended_quantity %>
+ <% if @low_inventory_report.count == 0 %> +

Inventory is at recommended levels (minimum and recommended levels can be set on each item)

+ <% else %> + + + + + + + + + + + + <% @low_inventory_report.each do |inventory_item| %> + + + + + + + + <% end %> + +
Storage LocationItem NameQuantityMinimum QuantityRecommended Quantity
<%= inventory_item.storage_location.name %><%= inventory_item.item.name %><%= inventory_item.quantity %><%= inventory_item.item.on_hand_minimum_quantity %><%= inventory_item.item.on_hand_recommended_quantity %>
+ <% end %> <% end %> \ No newline at end of file diff --git a/spec/support/pages/organization_dashboard_page.rb b/spec/support/pages/organization_dashboard_page.rb index 1178c6792b..5b2f97a039 100644 --- a/spec/support/pages/organization_dashboard_page.rb +++ b/spec/support/pages/organization_dashboard_page.rb @@ -60,6 +60,10 @@ def has_getting_started_guide? has_selector? "#getting-started-guide" end + def has_low_inventory_section? + has_selector? low_inventory_selector + end + def has_manufacturers_section? has_selector? manufacturers_section_selector end @@ -134,6 +138,16 @@ def total_inventory end end + def low_inventory_section + find low_inventory_selector + end + + def low_inventories + within low_inventory_section do + all("tbody > tr").map(&:text) + end + end + def outstanding_section find outstanding_selector end @@ -160,6 +174,10 @@ def partner_approvals_section private + def low_inventory_selector + "#low_inventory" + end + def product_drives_section find product_drives_selector end diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index dedb455b9b..f1398c404c 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -446,6 +446,33 @@ def create_next_product_drive_donation(donation_date:) end end end + + describe "Bank-wide Low inventory" do + it "displays no low inventory message" do + org_dashboard_page.visit + expect(org_dashboard_page).to have_low_inventory_section + expect(org_dashboard_page.low_inventory_section).to have_text "Inventory is at recommended levels (minimum and recommended levels can be set on each item)" + end + + context "with low inventory" do + let(:below_recommended_item) { create :item, organization: @organization, on_hand_minimum_quantity: 0, on_hand_recommended_quantity: 200 } + let(:below_minimum_item) { create :item, organization: @organization, on_hand_minimum_quantity: 150, on_hand_recommended_quantity: 200 } + + let!(:below_recommended_inventory_item) { create :inventory_item, item: below_recommended_item, storage_location: storage_location, quantity: 100 } + let!(:below_minimum_inventory_item) { create :inventory_item, item: below_minimum_item, storage_location: storage_location, quantity: 100 } + + it "displays low inventory report" do + org_dashboard_page.visit + expect(org_dashboard_page).to have_low_inventory_section + inventories = org_dashboard_page.low_inventories + minimum_item = "#{storage_location.name} #{below_minimum_item.name} 100 150 200" + recommended_item = "#{storage_location.name} #{below_recommended_item.name} 100 0 200" + expect(inventories.count).to eq 2 + expect(inventories).to include minimum_item + expect(inventories).to include recommended_item + end + end + end end def valid_bracketing_dates(date_range_info) From f5bc55a50dd81408799055fd6d6220f64111dddf Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Thu, 28 Sep 2023 18:11:27 +0000 Subject: [PATCH 047/122] Highlight quantities below minumum in low inventory report --- app/views/dashboard/_low_inventory_report.html.erb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/dashboard/_low_inventory_report.html.erb b/app/views/dashboard/_low_inventory_report.html.erb index 229a1fed28..2234d91187 100644 --- a/app/views/dashboard/_low_inventory_report.html.erb +++ b/app/views/dashboard/_low_inventory_report.html.erb @@ -23,7 +23,13 @@ <%= inventory_item.storage_location.name %> <%= inventory_item.item.name %> - <%= inventory_item.quantity %> + + <% if inventory_item.quantity < inventory_item.item.on_hand_minimum_quantity %> + <%= inventory_item.quantity %> + <% else %> + <%= inventory_item.quantity %> + <% end %> + <%= inventory_item.item.on_hand_minimum_quantity %> <%= inventory_item.item.on_hand_recommended_quantity %> From 5a73788872c5ce0f6ffb80e44d98bdf3e9ef9961 Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Sun, 8 Oct 2023 14:56:11 +0000 Subject: [PATCH 048/122] Move from using a QueryObject to a class method. --- app/controllers/dashboard_controller.rb | 2 +- app/queries/low_inventory_query.rb | 8 +------- spec/queries/low_inventory_query_spec.rb | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 5cb07fd182..e2ed10d706 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -28,6 +28,6 @@ def index @outstanding_requests = Request.where(status: %i[pending started]).order(:created_at) - @low_inventory_report = LowInventoryQuery.new(organization: current_organization).call + @low_inventory_report = LowInventoryQuery.call(current_organization) end end diff --git a/app/queries/low_inventory_query.rb b/app/queries/low_inventory_query.rb index 2ef4a25f06..b86490c4b7 100644 --- a/app/queries/low_inventory_query.rb +++ b/app/queries/low_inventory_query.rb @@ -1,11 +1,5 @@ class LowInventoryQuery - attr_reader :organization - - def initialize(organization:) - @organization = organization - end - - def call + def self.call(organization) scope = organization.inventory_items scope.where("inventory_items.quantity < items.on_hand_minimum_quantity") .or(scope.where("inventory_items.quantity < items.on_hand_recommended_quantity")) diff --git a/spec/queries/low_inventory_query_spec.rb b/spec/queries/low_inventory_query_spec.rb index 630fbbc57a..3a06e7532c 100644 --- a/spec/queries/low_inventory_query_spec.rb +++ b/spec/queries/low_inventory_query_spec.rb @@ -1,5 +1,5 @@ RSpec.describe LowInventoryQuery do - subject { LowInventoryQuery.new(organization: organization).call } + subject { LowInventoryQuery.call(organization) } let(:organization) { create :organization } From 7ec14dc46898929da362fbf8192ee30500a8d36a Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Sun, 8 Oct 2023 14:56:46 +0000 Subject: [PATCH 049/122] Add title tooltip to records below the minimum quantity. --- app/views/dashboard/_low_inventory_report.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/dashboard/_low_inventory_report.html.erb b/app/views/dashboard/_low_inventory_report.html.erb index 2234d91187..f01eab8642 100644 --- a/app/views/dashboard/_low_inventory_report.html.erb +++ b/app/views/dashboard/_low_inventory_report.html.erb @@ -25,7 +25,7 @@ <%= inventory_item.item.name %> <% if inventory_item.quantity < inventory_item.item.on_hand_minimum_quantity %> - <%= inventory_item.quantity %> + <%= inventory_item.quantity %> <% else %> <%= inventory_item.quantity %> <% end %> From 9e92a985a537d8041af775d14413c0bfe022b19b Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 11 Nov 2023 22:42:24 -0500 Subject: [PATCH 050/122] Fix unrelated lint isue [#3798] --- spec/queries/low_inventory_query_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/queries/low_inventory_query_spec.rb b/spec/queries/low_inventory_query_spec.rb index 3a06e7532c..36cd771989 100644 --- a/spec/queries/low_inventory_query_spec.rb +++ b/spec/queries/low_inventory_query_spec.rb @@ -14,9 +14,9 @@ let(:item) do create :item, - organization: organization, - on_hand_minimum_quantity: minimum_quantity, - on_hand_recommended_quantity: recommended_quantity + organization: organization, + on_hand_minimum_quantity: minimum_quantity, + on_hand_recommended_quantity: recommended_quantity end it { is_expected.to eq [] } @@ -65,4 +65,4 @@ it { is_expected.to include inventory_item } end end -end \ No newline at end of file +end From 17aa91cfb8e965934d847d7d6f6b38725ed93529 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 11 Nov 2023 22:55:13 -0500 Subject: [PATCH 051/122] Fix navigation items [#3798] --- app/views/layouts/_lte_sidebar.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 55d41ac35d..0ea5c75c3b 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -170,8 +170,8 @@ -
- From b25e320c2995797e093539b30f441aed6a4097ed Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 11 Nov 2023 22:59:16 -0500 Subject: [PATCH 052/122] Re-organize reports list [#3798] --- app/views/layouts/_lte_sidebar.html.erb | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 0ea5c75c3b..a50de56485 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -178,6 +178,11 @@

<%= render( @@ -180,36 +178,6 @@ No partners waiting for approval <% end %> <% end %> - - <%= render( - "shared/card", - id: "product_drives", - gradient: "info", - title: "Product Drives", - subtitle: @selected_date_range, - footer_options: { class: "text-center" }, - footer: link_to("See more...", donations_path( - filters: { - by_source: "Product Drive" - } - )), - ) do %> -

- - <%= total_received_from_product_drives %> - items - received <%= @selected_date_range_label %> -

-

- - <%= dollar_presentation( total_received_money_donations_from_product_drives) %> - raised <%= @selected_date_range_label %> -

-
-

Recent Donations from Product Drives

- <%= render partial: "product_drive", collection: @recent_donations.by_source(:product_drive), as: :donation %> -
- <% end %>
diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index a50de56485..0bc4027948 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -170,8 +170,8 @@ - + - - diff --git a/app/views/reports/donations_summary/_donation.html.erb b/app/views/reports/_donation.html.erb similarity index 100% rename from app/views/reports/donations_summary/_donation.html.erb rename to app/views/reports/_donation.html.erb diff --git a/app/views/reports/donations_summary/index.html.erb b/app/views/reports/donations_summary.html.erb similarity index 81% rename from app/views/reports/donations_summary/index.html.erb rename to app/views/reports/donations_summary.html.erb index 4343938bfd..6c46da6515 100644 --- a/app/views/reports/donations_summary/index.html.erb +++ b/app/views/reports/donations_summary.html.erb @@ -5,7 +5,7 @@ subtitle: @selected_date_range, footer_options: { class: "text-center" }, footer: link_to("See more...", donations_path), - filter_url: reports_donations_summary_index_path + filter_url: reports_donations_summary_path ) do %> <%= new_button_to new_donation_path, {text: "New Donation"} %>

@@ -21,7 +21,7 @@

Recent Donations

- <%= render partial: "reports/donations_summary/donation", collection: @recent_donations, as: :donation %> + <%= render partial: "donation", collection: @recent_donations, as: :donation %>
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 7d93f68253..5ae0fa74cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,7 +104,7 @@ def set_up_flipper resources :annual_reports, only: [:index, :show], param: :year do post :recalculate, on: :member end - resources :donations_summary, only: [:index] + get :donations_summary resources :manufacturer_donations_summary, only: [:index] resources :product_drives_summary, only: [:index] resources :itemized_donations, only: [:index] diff --git a/spec/requests/reports/donations_summary_spec.rb b/spec/requests/reports/donations_summary_spec.rb index bd85a39c52..f6ce92b723 100644 --- a/spec/requests/reports/donations_summary_spec.rb +++ b/spec/requests/reports/donations_summary_spec.rb @@ -12,7 +12,7 @@ describe "GET #index" do subject do - get reports_donations_summary_index_path(default_params.merge(format: response_format)) + get reports_donations_summary_path(default_params.merge(format: response_format)) response end let(:response_format) { "html" } @@ -24,7 +24,7 @@ describe "while not signed in" do describe "GET /index" do subject do - get reports_donations_summary_index_path(default_params) + get reports_donations_summary_path(default_params) response end From cacb59af007c35c3572639185fb72c58550ddab7 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 10 Feb 2024 22:09:54 -0500 Subject: [PATCH 073/122] Consolidate manufacturer donations into main reports controller --- .../reports/donations_summary_controller.rb | 8 -------- .../manufacturer_donations_summary_controller.rb | 10 ---------- app/controllers/reports_controller.rb | 9 +++++++++ app/views/layouts/_lte_sidebar.html.erb | 2 +- .../_manufacturer.html.erb | 0 ...tml.erb => manufacturer_donations_summary.html.erb} | 2 +- config/routes.rb | 2 +- .../reports/manufacturer_donations_summary_spec.rb | 4 ++-- 8 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 app/controllers/reports/donations_summary_controller.rb delete mode 100644 app/controllers/reports/manufacturer_donations_summary_controller.rb rename app/views/reports/{manufacturer_donations_summary => }/_manufacturer.html.erb (100%) rename app/views/reports/{manufacturer_donations_summary/index.html.erb => manufacturer_donations_summary.html.erb} (93%) diff --git a/app/controllers/reports/donations_summary_controller.rb b/app/controllers/reports/donations_summary_controller.rb deleted file mode 100644 index 692916bc50..0000000000 --- a/app/controllers/reports/donations_summary_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Reports::DonationsSummaryController < ApplicationController - def index - setup_date_range_picker - - @donations = current_organization.donations.during(helpers.selected_range) - @recent_donations = @donations.recent - end -end diff --git a/app/controllers/reports/manufacturer_donations_summary_controller.rb b/app/controllers/reports/manufacturer_donations_summary_controller.rb deleted file mode 100644 index d7a6828cad..0000000000 --- a/app/controllers/reports/manufacturer_donations_summary_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Reports::ManufacturerDonationsSummaryController < ApplicationController - def index - setup_date_range_picker - - @recent_donations_from_manufacturers = current_organization.donations.during(helpers.selected_range).by_source(:manufacturer) - @top_manufacturers = current_organization.manufacturers.by_donation_count - @donations = current_organization.donations.during(helpers.selected_range) - @recent_donations = @donations.recent - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9032e9c8cc..9b4243e975 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -5,4 +5,13 @@ def donations_summary @donations = current_organization.donations.during(helpers.selected_range) @recent_donations = @donations.recent end + + def manufacturer_donations_summary + setup_date_range_picker + + @recent_donations_from_manufacturers = current_organization.donations.during(helpers.selected_range).by_source(:manufacturer) + @top_manufacturers = current_organization.manufacturers.by_donation_count + @donations = current_organization.donations.during(helpers.selected_range) + @recent_donations = @donations.recent + end end diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index f5ecfb1c17..6bf5350a45 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -201,7 +201,7 @@ <% end %> diff --git a/app/views/reports/manufacturer_donations_summary/_manufacturer.html.erb b/app/views/reports/_manufacturer.html.erb similarity index 100% rename from app/views/reports/manufacturer_donations_summary/_manufacturer.html.erb rename to app/views/reports/_manufacturer.html.erb diff --git a/app/views/reports/manufacturer_donations_summary/index.html.erb b/app/views/reports/manufacturer_donations_summary.html.erb similarity index 93% rename from app/views/reports/manufacturer_donations_summary/index.html.erb rename to app/views/reports/manufacturer_donations_summary.html.erb index 68343a7818..21ed6b9c93 100644 --- a/app/views/reports/manufacturer_donations_summary/index.html.erb +++ b/app/views/reports/manufacturer_donations_summary.html.erb @@ -5,7 +5,7 @@ gradient: "success", title: "Manufacturer Donations", subtitle: @selected_date_range, - filter_url: reports_manufacturer_donations_summary_index_path, + filter_url: reports_manufacturer_donations_summary_path, footer_options: { class: "text-center" }, footer: link_to("See more...", donations_path( filters: { diff --git a/config/routes.rb b/config/routes.rb index 5ae0fa74cf..cf1d8fae08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -105,7 +105,7 @@ def set_up_flipper post :recalculate, on: :member end get :donations_summary - resources :manufacturer_donations_summary, only: [:index] + get :manufacturer_donations_summary resources :product_drives_summary, only: [:index] resources :itemized_donations, only: [:index] resources :itemized_distributions, only: [:index] diff --git a/spec/requests/reports/manufacturer_donations_summary_spec.rb b/spec/requests/reports/manufacturer_donations_summary_spec.rb index c9a9b7c26a..4954f66906 100644 --- a/spec/requests/reports/manufacturer_donations_summary_spec.rb +++ b/spec/requests/reports/manufacturer_donations_summary_spec.rb @@ -12,7 +12,7 @@ describe "GET #index" do subject do - get reports_manufacturer_donations_summary_index_path(default_params.merge(format: response_format)) + get reports_manufacturer_donations_summary_path(default_params.merge(format: response_format)) response end let(:response_format) { "html" } @@ -24,7 +24,7 @@ describe "while not signed in" do describe "GET /index" do subject do - get reports_manufacturer_donations_summary_index_path(default_params) + get reports_manufacturer_donations_summary_path(default_params) response end From a6428bf16c782123d5f0dca0613d444851135df9 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 10 Feb 2024 22:14:19 -0500 Subject: [PATCH 074/122] Consolidate product drives summary into main reports controller --- .../reports/product_drives_summary_controller.rb | 7 ------- app/controllers/reports_controller.rb | 6 ++++++ app/views/layouts/_lte_sidebar.html.erb | 2 +- .../{product_drives_summary => }/_product_drive.html.erb | 0 .../index.html.erb => product_drives_summary.html.erb} | 2 +- config/routes.rb | 2 +- spec/requests/reports/product_drives_summary_spec.rb | 4 ++-- 7 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 app/controllers/reports/product_drives_summary_controller.rb rename app/views/reports/{product_drives_summary => }/_product_drive.html.erb (100%) rename app/views/reports/{product_drives_summary/index.html.erb => product_drives_summary.html.erb} (93%) diff --git a/app/controllers/reports/product_drives_summary_controller.rb b/app/controllers/reports/product_drives_summary_controller.rb deleted file mode 100644 index 82163411a4..0000000000 --- a/app/controllers/reports/product_drives_summary_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Reports::ProductDrivesSummaryController < ApplicationController - def index - setup_date_range_picker - @donations = current_organization.donations.during(helpers.selected_range) - @recent_donations = @donations.recent - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9b4243e975..cb1cdf3b61 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -14,4 +14,10 @@ def manufacturer_donations_summary @donations = current_organization.donations.during(helpers.selected_range) @recent_donations = @donations.recent end + + def product_drives_summary + setup_date_range_picker + @donations = current_organization.donations.during(helpers.selected_range) + @recent_donations = @donations.recent + end end diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 6bf5350a45..6befa36d44 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -206,7 +206,7 @@ <% end %> diff --git a/app/views/reports/product_drives_summary/_product_drive.html.erb b/app/views/reports/_product_drive.html.erb similarity index 100% rename from app/views/reports/product_drives_summary/_product_drive.html.erb rename to app/views/reports/_product_drive.html.erb diff --git a/app/views/reports/product_drives_summary/index.html.erb b/app/views/reports/product_drives_summary.html.erb similarity index 93% rename from app/views/reports/product_drives_summary/index.html.erb rename to app/views/reports/product_drives_summary.html.erb index 5d3198384e..c1fdf786da 100644 --- a/app/views/reports/product_drives_summary/index.html.erb +++ b/app/views/reports/product_drives_summary.html.erb @@ -5,7 +5,7 @@ title: "Product Drives", subtitle: @selected_date_range, type: :table, - filter_url: reports_product_drives_summary_index_path, + filter_url: reports_product_drives_summary_path, footer_options: { class: "text-center" }, footer: link_to("See more...", product_drives_path), ) do %> diff --git a/config/routes.rb b/config/routes.rb index cf1d8fae08..287aa4ed98 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -106,7 +106,7 @@ def set_up_flipper end get :donations_summary get :manufacturer_donations_summary - resources :product_drives_summary, only: [:index] + get :product_drives_summary, only: [:index] resources :itemized_donations, only: [:index] resources :itemized_distributions, only: [:index] resources :activity_graph, only: [:index] diff --git a/spec/requests/reports/product_drives_summary_spec.rb b/spec/requests/reports/product_drives_summary_spec.rb index 80bd26da9b..a9ced4943a 100644 --- a/spec/requests/reports/product_drives_summary_spec.rb +++ b/spec/requests/reports/product_drives_summary_spec.rb @@ -12,7 +12,7 @@ describe "GET #index" do subject do - get reports_product_drives_summary_index_path(default_params.merge(format: response_format)) + get reports_product_drives_summary_path(default_params.merge(format: response_format)) response end let(:response_format) { "html" } @@ -24,7 +24,7 @@ describe "while not signed in" do describe "GET /index" do subject do - get reports_product_drives_summary_index_path(default_params) + get reports_product_drives_summary_path(default_params) response end From e5341ebf775d77df53c9bae8a3fe14884773953f Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 10 Feb 2024 22:20:14 -0500 Subject: [PATCH 075/122] Consolidate itemized donations report --- app/controllers/reports/itemized_donations_controller.rb | 7 ------- app/controllers/reports_controller.rb | 6 ++++++ .../index.html.erb => itemized_donations.html.erb} | 0 config/routes.rb | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 app/controllers/reports/itemized_donations_controller.rb rename app/views/reports/{itemized_donations/index.html.erb => itemized_donations.html.erb} (100%) diff --git a/app/controllers/reports/itemized_donations_controller.rb b/app/controllers/reports/itemized_donations_controller.rb deleted file mode 100644 index fa356fcb95..0000000000 --- a/app/controllers/reports/itemized_donations_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Reports::ItemizedDonationsController < ApplicationController - def index - setup_date_range_picker - @donations = current_organization.donations.during(helpers.selected_range) - @itemized_donation_data = DonationItemizedBreakdownService.new(organization: current_organization, donation_ids: @donations.pluck(:id)).fetch - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index cb1cdf3b61..03ad7d374b 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -20,4 +20,10 @@ def product_drives_summary @donations = current_organization.donations.during(helpers.selected_range) @recent_donations = @donations.recent end + + def itemized_donations + setup_date_range_picker + @donations = current_organization.donations.during(helpers.selected_range) + @itemized_donation_data = DonationItemizedBreakdownService.new(organization: current_organization, donation_ids: @donations.pluck(:id)).fetch + end end diff --git a/app/views/reports/itemized_donations/index.html.erb b/app/views/reports/itemized_donations.html.erb similarity index 100% rename from app/views/reports/itemized_donations/index.html.erb rename to app/views/reports/itemized_donations.html.erb diff --git a/config/routes.rb b/config/routes.rb index 287aa4ed98..08f5c82d93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -106,8 +106,8 @@ def set_up_flipper end get :donations_summary get :manufacturer_donations_summary - get :product_drives_summary, only: [:index] - resources :itemized_donations, only: [:index] + get :product_drives_summary + get :itemized_donations resources :itemized_distributions, only: [:index] resources :activity_graph, only: [:index] end From 2db7d1d692afdc5ec92e7991a491e565950efc0e Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 10 Feb 2024 22:23:09 -0500 Subject: [PATCH 076/122] Consolidate itemized distributions report --- .../reports/itemized_distributions_controller.rb | 7 ------- app/controllers/reports_controller.rb | 6 ++++++ .../index.html.erb => itemized_distributions.html.erb} | 0 config/routes.rb | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 app/controllers/reports/itemized_distributions_controller.rb rename app/views/reports/{itemized_distributions/index.html.erb => itemized_distributions.html.erb} (100%) diff --git a/app/controllers/reports/itemized_distributions_controller.rb b/app/controllers/reports/itemized_distributions_controller.rb deleted file mode 100644 index a1f1e68be1..0000000000 --- a/app/controllers/reports/itemized_distributions_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Reports::ItemizedDistributionsController < ApplicationController - def index - setup_date_range_picker - distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) - @itemized_distribution_data = DistributionItemizedBreakdownService.new(organization: current_organization, distribution_ids: distributions.pluck(:id)).fetch - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 03ad7d374b..9426245711 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -26,4 +26,10 @@ def itemized_donations @donations = current_organization.donations.during(helpers.selected_range) @itemized_donation_data = DonationItemizedBreakdownService.new(organization: current_organization, donation_ids: @donations.pluck(:id)).fetch end + + def itemized_distributions + setup_date_range_picker + distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) + @itemized_distribution_data = DistributionItemizedBreakdownService.new(organization: current_organization, distribution_ids: distributions.pluck(:id)).fetch + end end diff --git a/app/views/reports/itemized_distributions/index.html.erb b/app/views/reports/itemized_distributions.html.erb similarity index 100% rename from app/views/reports/itemized_distributions/index.html.erb rename to app/views/reports/itemized_distributions.html.erb diff --git a/config/routes.rb b/config/routes.rb index 08f5c82d93..3462aaa331 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -108,7 +108,7 @@ def set_up_flipper get :manufacturer_donations_summary get :product_drives_summary get :itemized_donations - resources :itemized_distributions, only: [:index] + get :itemized_distributions resources :activity_graph, only: [:index] end From 407f7382d723412ed380b02ca3a8f2527cd292d6 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sat, 10 Feb 2024 22:26:14 -0500 Subject: [PATCH 077/122] Consolidate activity graph report --- .../reports/activity_graph_controller.rb | 28 ------------------- app/controllers/reports_controller.rb | 27 ++++++++++++++++++ app/views/layouts/_lte_sidebar.html.erb | 2 +- ...index.html.erb => activity_graph.html.erb} | 2 +- config/routes.rb | 2 +- spec/requests/reports/activity_graph_spec.rb | 4 +-- 6 files changed, 32 insertions(+), 33 deletions(-) delete mode 100644 app/controllers/reports/activity_graph_controller.rb rename app/views/reports/{activity_graph/index.html.erb => activity_graph.html.erb} (96%) diff --git a/app/controllers/reports/activity_graph_controller.rb b/app/controllers/reports/activity_graph_controller.rb deleted file mode 100644 index 356290853e..0000000000 --- a/app/controllers/reports/activity_graph_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -class Reports::ActivityGraphController < ApplicationController - def index - setup_date_range_picker - @distribution_data = received_distributed_data(helpers.selected_range) - end - - private - - def total_purchased_unformatted(range = selected_range) - LineItem.active.where(itemizable: current_organization.purchases.during(range)).sum(:quantity) - end - - def total_distributed_unformatted(range = selected_range) - LineItem.active.where(itemizable: current_organization.distributions.during(range)).sum(:quantity) - end - - def total_received_donations_unformatted(range = selected_range) - LineItem.active.where(itemizable: current_organization.donations.during(range)).sum(:quantity) - end - - def received_distributed_data(range = selected_range) - { - "Received donations" => total_received_donations_unformatted(range), - "Purchased" => total_purchased_unformatted(range), - "Distributed" => total_distributed_unformatted(range) - } - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9426245711..2f707ea1ab 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -32,4 +32,31 @@ def itemized_distributions distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range) @itemized_distribution_data = DistributionItemizedBreakdownService.new(organization: current_organization, distribution_ids: distributions.pluck(:id)).fetch end + + def activity_graph + setup_date_range_picker + @distribution_data = received_distributed_data(helpers.selected_range) + end + + private + + def total_purchased_unformatted(range = selected_range) + LineItem.active.where(itemizable: current_organization.purchases.during(range)).sum(:quantity) + end + + def total_distributed_unformatted(range = selected_range) + LineItem.active.where(itemizable: current_organization.distributions.during(range)).sum(:quantity) + end + + def total_received_donations_unformatted(range = selected_range) + LineItem.active.where(itemizable: current_organization.donations.during(range)).sum(:quantity) + end + + def received_distributed_data(range = selected_range) + { + "Received donations" => total_received_donations_unformatted(range), + "Purchased" => total_purchased_unformatted(range), + "Distributed" => total_distributed_unformatted(range) + } + end end diff --git a/app/views/layouts/_lte_sidebar.html.erb b/app/views/layouts/_lte_sidebar.html.erb index 6befa36d44..831c082fe1 100644 --- a/app/views/layouts/_lte_sidebar.html.erb +++ b/app/views/layouts/_lte_sidebar.html.erb @@ -179,7 +179,7 @@