Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard! #3788

Merged
merged 175 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 173 commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
e7f43d3
Create dashboard/card partial
Benabik Jul 28, 2023
64a5d6e
Also convert summary card to partial
Benabik Jul 28, 2023
e815d25
Github Workflows: Run rspec on all pull requests
Benabik Jul 28, 2023
30279cb
Merge pull request #3780 from rubyforgood/card-partial
awwaiid Jul 28, 2023
cd08a7b
Issue #3736 - move purchases to new area
rae-stanton Jul 29, 2023
a7e46c6
Revert "Issue #3736 - move purchases to new area"
rae-stanton Jul 29, 2023
3052d09
Add an "Outstanding Requests" card to org dashboard
Benabik Jul 29, 2023
c302248
Limit Outstanding Requests to 25
Benabik Jul 29, 2023
dd0265f
Restore remove button to dashboard cards
Benabik Jul 29, 2023
5c77138
Merge pull request #3785 from rubyforgood/3669-outstanding-requests
awwaiid Jul 29, 2023
7a4b9d0
Merge pull request #3787 from rubyforgood/card-remove-button
awwaiid Jul 29, 2023
73deb2f
Initial Itemized Donations report extract from dashboard [#3733]
awwaiid Jul 29, 2023
251f09c
Bring in date filter from other branch [#3733]
awwaiid Jul 29, 2023
59a5cfb
Align text better [#3733]
awwaiid Jul 29, 2023
914881a
Slight alignment cleanup [#3733]
awwaiid Jul 29, 2023
d4e67fa
refactor(dashboard): Move Distributions by County functionality [#372…
leesharma Jul 29, 2023
802505c
Add a basic spec for the itemized donations report [#3733]
awwaiid Jul 29, 2023
54e9f13
All the build on all the branches [#3733]
awwaiid Jul 29, 2023
be3f641
Add message when there are no items [#3733]
awwaiid Jul 29, 2023
8bba60e
Merge remote-tracking branch 'origin/dashboard' into dashboard-itemiz…
awwaiid Jul 29, 2023
d85cce4
Satiate Rubocop! [#3733]
awwaiid Jul 29, 2023
0a5b57d
Don't github action ci on both PR and Push [#3733]
awwaiid Jul 29, 2023
357df3a
Remove itemized donations partial [#3733]
awwaiid Jul 30, 2023
94f12c0
Issue #3736 - move purchases to new area
rae-stanton Jul 29, 2023
b8df3a5
Fix nesting of HTML rows [#3733]
awwaiid Jul 30, 2023
020b4bb
rm extra index card for purchases summary
rae-stanton Jul 30, 2023
1ca53e7
rm card partial under purchases summary
rae-stanton Jul 30, 2023
77fda90
Merge pull request #3792 from rubyforgood/3736-actual-move-purchase-f…
awwaiid Jul 30, 2023
fe27dbe
Merge remote-tracking branch 'origin/dashboard' into dashboard-itemiz…
awwaiid Jul 30, 2023
27b0309
Clean out some minor lint [#3733]
awwaiid Jul 30, 2023
72fa881
Merge pull request #3791 from rubyforgood/dashboard-itemized-donation…
awwaiid Jul 30, 2023
1a34dd7
Move itemized distribution into a standalone report [#3731]
awwaiid Jul 30, 2023
0dc6632
Merge pull request #3796 from rubyforgood/dashboard-itemized-distribu…
awwaiid Jul 30, 2023
48d0ebb
add a partners approval table to the dashboard
Jul 30, 2023
5268b42
Merge pull request #3799 from rubyforgood/3743-partner-approval-cards
awwaiid Jul 30, 2023
5ed4e7e
Distributions summary
rae-stanton Jul 30, 2023
c6b0625
Clean out some lint! [#3723]
awwaiid Jul 30, 2023
ab21419
Merge pull request #3802 from rubyforgood/3723-distributions-summary
awwaiid Jul 30, 2023
60a0515
Extract all helper methods related to donations into a DonationsHelper.
ChaelCodes Jul 30, 2023
d3098fe
Migrate Donations Summary (All Sources) from the Dashboard to Reporting
ChaelCodes Jul 30, 2023
39af23b
Fix active styling for Reporting & Auditing in the sidebar.
ChaelCodes Aug 3, 2023
1dd2d53
Working System Spec
ChaelCodes Aug 3, 2023
d4e6ec2
Merge pull request #3795 from ChaelCodes/3732-donations-all-sources
awwaiid Aug 5, 2023
79ddf74
Move activity graph to a standalone report [#3798]
awwaiid Aug 5, 2023
2f75591
Satiate Rubocop! [#3798]
awwaiid Aug 5, 2023
a6e84ce
Switch back to more tedious active-menu setup [#3798]
awwaiid Aug 5, 2023
ae90f1a
Make quotes consistent [#3798]
awwaiid Aug 5, 2023
4b0dc7a
Remove that that has been extracted into another report [#3798]
awwaiid Aug 5, 2023
1010cdc
Add very basic request spec for activity graph report [#3798]
awwaiid Aug 5, 2023
b2df7b1
boiler plate added
lokisk1155 Aug 7, 2023
0834a0d
try thisg
lokisk1155 Aug 7, 2023
955d9b9
add top manufactuers
lokisk1155 Aug 7, 2023
41aac22
dates + new donation button
lokisk1155 Aug 7, 2023
3b42cf0
Remove Feature specs for sections that are no longer on the dashboard.
ChaelCodes Aug 16, 2023
f726ba9
Add new Bank-wide low inventory report to Dashboard
ChaelCodes Aug 23, 2023
ef0b294
Only return if inventory levels are lower than minimum or recommended.
ChaelCodes Sep 28, 2023
9f2ac37
Setup system specs and setup sufficient inventory levels message
ChaelCodes Sep 28, 2023
f5bc55a
Highlight quantities below minumum in low inventory report
ChaelCodes Sep 28, 2023
5a73788
Move from using a QueryObject to a class method.
ChaelCodes Oct 8, 2023
7ec14dc
Add title tooltip to records below the minimum quantity.
ChaelCodes Oct 8, 2023
304e2a3
Merge branch 'main' into dashboard
awwaiid Nov 12, 2023
1bcc0ff
Merge branch 'dashboard' into dashboard-activity-card-3798
awwaiid Nov 12, 2023
1d38d58
Merge branch 'dashboard' into lokisk1155-#3735
awwaiid Nov 12, 2023
97369e3
Merge pull request #3840 from ChaelCodes/3788-delete-donations-specs
awwaiid Nov 12, 2023
4ada1e5
Merge branch 'dashboard' into dashboard-activity-card-3798
awwaiid Nov 12, 2023
19ebe3b
Merge branch 'dashboard' into 3742-low-inventory-report
awwaiid Nov 12, 2023
13d164a
Merge pull request #3857 from ChaelCodes/3742-low-inventory-report
awwaiid Nov 12, 2023
547d4ba
Merge branch 'dashboard' into dashboard-activity-card-3798
awwaiid Nov 12, 2023
9e92a98
Fix unrelated lint isue [#3798]
awwaiid Nov 12, 2023
17aa91c
Fix navigation items [#3798]
awwaiid Nov 12, 2023
b25e320
Re-organize reports list [#3798]
awwaiid Nov 12, 2023
6b890b7
Merge pull request #3819 from lokisk1155/lokisk1155-#3735
awwaiid Nov 12, 2023
7cc0763
Merge remote-tracking branch 'origin/dashboard' into dashboard-activi…
awwaiid Nov 12, 2023
88a53cb
Merge pull request #3812 from rubyforgood/dashboard-activity-card-3798
awwaiid Nov 12, 2023
756f294
Merge branch 'main' into dashboard
awwaiid Dec 17, 2023
8220e00
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Dec 22, 2023
75cd62e
Extract product drives card to separate report [#3734]
awwaiid Dec 23, 2023
a6b4849
Clean out some lint [#3734]
awwaiid Dec 23, 2023
517d0fb
Fix page helper for product drive report spec [#3734]
awwaiid Dec 23, 2023
afd8c64
Move helper method to the correct spec [#3734]
awwaiid Dec 24, 2023
c20401c
Copy page helper [#3734]
awwaiid Dec 24, 2023
6e0b771
Copy helper from dashboard page [#3734]
awwaiid Dec 24, 2023
872f4ea
Merge branch 'main' into dashboard
awwaiid Jan 13, 2024
96f245b
Merge branch 'dashboard' into 3734-move-product-drives-card-to-produc…
awwaiid Jan 13, 2024
0919c22
Click on correct header [#3734]
awwaiid Jan 13, 2024
90389b2
Remove clicking off of date range, it isn't needed [#3734]
awwaiid Jan 13, 2024
dbff0af
Rename to include summary [#3734]
awwaiid Jan 13, 2024
a216b66
Update tests to have Summary in the name [#3734]
awwaiid Jan 13, 2024
444aa49
Revert accidental path change [#3734]
awwaiid Jan 13, 2024
e3a5e71
Merge pull request #3984 from rubyforgood/3734-move-product-drives-ca…
awwaiid Jan 13, 2024
9c738a2
Add filter to mfg donation report and tune style [#3735]
awwaiid Jan 13, 2024
0868441
Merge pull request #4028 from rubyforgood/manufacture-donations-filte…
awwaiid Jan 13, 2024
831d4b0
Add basic request specs for some reports [#4029]
awwaiid Jan 14, 2024
e8e546c
Merge pull request #4030 from rubyforgood/dashboard-specs-4029
awwaiid Jan 14, 2024
36c0704
Remove date-filter, other unused queries, and obey Bullet [#3724]
awwaiid Jan 14, 2024
b272b91
Filter on counties report directly [#3724]
awwaiid Jan 14, 2024
e2d1c22
Merge pull request #4032 from rubyforgood/remove-dashboard-filter-3724
awwaiid Jan 14, 2024
f44e444
Merge branch 'main' into dashboard
awwaiid Jan 21, 2024
c8b5131
Merge branch 'main' into dashboard
awwaiid Jan 21, 2024
bab467f
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Feb 4, 2024
df0d759
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Feb 10, 2024
55d36e4
Clean out erb lint
awwaiid Feb 10, 2024
a6371f7
Fix expectations to work with cuprite
awwaiid Feb 10, 2024
b5dcff0
Wait for submenu to show before clicking through
awwaiid Feb 11, 2024
128ff44
Clean out some rubocop lint
awwaiid Feb 11, 2024
f40cbce
Move donations summary into main reports controller
awwaiid Feb 11, 2024
cacb59a
Consolidate manufacturer donations into main reports controller
awwaiid Feb 11, 2024
a6428bf
Consolidate product drives summary into main reports controller
awwaiid Feb 11, 2024
e5341eb
Consolidate itemized donations report
awwaiid Feb 11, 2024
2db7d1d
Consolidate itemized distributions report
awwaiid Feb 11, 2024
407f738
Consolidate activity graph report
awwaiid Feb 11, 2024
33ce9e4
Merge pull request #4095 from rubyforgood/dashboard-reports-controller
awwaiid Feb 11, 2024
81b1247
Remove generic count/buttons and extract getting-started
awwaiid Feb 11, 2024
8e89364
No longer displaying the totals
awwaiid Feb 11, 2024
80fc8ff
Fix flaky test by waiting for javascript result
awwaiid Feb 11, 2024
ecdd904
Re-organize reports menu entries
awwaiid Feb 11, 2024
8e4eb71
We no longer show the org logo on the dashboard
awwaiid Feb 11, 2024
49821c9
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Feb 24, 2024
e483637
Unify on request spec
awwaiid Feb 25, 2024
4c5bbeb
Remove unnecessary forced spaces
awwaiid Feb 25, 2024
db4d441
Move an assertion from system to request spec
awwaiid Feb 25, 2024
993778a
Clean out the lint trap
awwaiid Feb 25, 2024
f8ca6e0
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Feb 25, 2024
31bf22a
Move distributions summary into consolidated reports
awwaiid Feb 25, 2024
cefe205
Allow sub-controller paths for menu entries
awwaiid Feb 25, 2024
922ec32
Consolidate purchases summary report with the other reports
awwaiid Feb 25, 2024
bce1288
Fix sidebar highlighting for reports and organization admin
awwaiid Feb 25, 2024
2826843
Clean out some lint
awwaiid Feb 25, 2024
d7757c5
Consolidate summary reports specs
awwaiid Feb 25, 2024
ffef79b
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Mar 2, 2024
1f9c68b
Remove uneeded forced indent
awwaiid Mar 2, 2024
f3647c4
Validate the filters work
awwaiid Mar 2, 2024
971697a
Assume active-class is always an array
awwaiid Mar 2, 2024
0ebe7cf
Move donation spec from system to request style, fix lint
awwaiid Mar 2, 2024
258005d
Migrate itemized donation report from system to request spec
awwaiid Mar 2, 2024
123e8ca
Move system specs to request specs for product drive summary report
awwaiid Mar 3, 2024
c2638fe
Move purchase summary report spec from system to requests
awwaiid Mar 3, 2024
2de9bcb
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Mar 10, 2024
6fd2f10
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Mar 10, 2024
7287c11
Merge branch 'main' into dashboard
awwaiid Mar 26, 2024
df48642
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Mar 26, 2024
7c5f900
Remove test from incorrect merge
awwaiid Mar 27, 2024
5802818
Merge branch 'main' into dashboard
awwaiid Mar 29, 2024
982f322
Port forward the organization_name param
awwaiid Mar 29, 2024
fc3ea3a
Fix new reports to use organization_name param
awwaiid Mar 29, 2024
44b3978
Fix dashboard system spec to use application_name
awwaiid Mar 29, 2024
4919505
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Mar 30, 2024
d888831
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Apr 3, 2024
3049b6c
Merge branch 'main' into dashboard
awwaiid Apr 9, 2024
f4202a9
Only show outstanding requests for the current org
awwaiid Apr 10, 2024
b4c1cbd
Group low-inventory report by item, not storage location
awwaiid Apr 10, 2024
debb351
Show the expected email address for outstanding-request partners
awwaiid Apr 10, 2024
3b274a7
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Apr 10, 2024
ec47ef6
Update dashboard system spec with item-grouped low-inventory
awwaiid Apr 10, 2024
8354477
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Apr 14, 2024
0b3cbc0
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Apr 16, 2024
aba16d1
Run ci/cd checks on merges consistently
awwaiid Apr 16, 2024
b63d998
Pull :setup_date_range_picker call into before_action
awwaiid Apr 16, 2024
fadfd71
Match menu entries better
awwaiid Apr 16, 2024
6273aa3
Clean up outstanding requests partial extraction
awwaiid Apr 16, 2024
94c0ebd
Stringify action_name, esp when it is nil
awwaiid Apr 18, 2024
5bf83f8
Extract partials for other dashboard blocks
awwaiid Apr 18, 2024
9ab87d7
Update specs with new sidebar menu layout
awwaiid Apr 18, 2024
5026b95
Merge branch 'main' into dashboard
awwaiid Apr 26, 2024
72b1904
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid Apr 27, 2024
312d881
Alphabetize sub-menu-entries
awwaiid Apr 27, 2024
4ce6300
Add event-driven low inventory query
awwaiid Apr 28, 2024
f49a357
Update when github flows get executed
awwaiid Apr 28, 2024
b698b05
Update low inventory spec to work with events
awwaiid Apr 29, 2024
2392f4f
Switch from direct-creating inventoryItems to creating a purchase
awwaiid Apr 29, 2024
a52a7d0
Use controller/action name instead of path for active menus
awwaiid May 12, 2024
189dc89
Use Inventory::View to simplify low-inventory query
awwaiid May 12, 2024
a43b405
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid May 12, 2024
befd4fe
Fix up spec to match behavior
awwaiid May 12, 2024
d27aa81
Merge remote-tracking branch 'origin/main' into dashboard
awwaiid May 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/brakeman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: brakeman

on:
push:
branches:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the ones like it run brakeman and linting and such on all pushes/branches, not only main

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be reverted before merge, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep them -- they then will run the checks on any sub-branch PR which is what I expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All righty.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized - removing pull_request means that it'll run on the branch but not on the merge commit. If the main branch has been updated, these runs will miss those commits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK -- I tried to make it run on PR and consistently across all the jobs. Also updated the plantuml gen a bit. Here is the result -- aba16d1

- main
paths-ignore:
- 'doc/**'
- '*.md'
- 'bin/*'
pull_request:
branches:
- main
paths-ignore:
- 'doc/**'
- '*.md'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/factory-bot-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: factory bot lint

on:
push:
branches:
- main
paths-ignore:
- 'doc/**'
- '*.md'
- 'bin/*'
pull_request:
branches:
- main
paths-ignore:
- 'doc/**'
- '*.md'
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/plantuml.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: Generate PlantUML
on: push
paths:
- 'doc/**'
- '*.md'
pull_request:
- 'doc/**'
- '*.md'

jobs:
generate_plantuml:
runs-on: ubuntu-latest
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/rspec-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: rspec-events

on:
push:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
- "bin/*"
pull_request:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
Expand Down Expand Up @@ -87,4 +87,6 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: failed-browser-tests
path: tmp/screenshots
path: |
tmp/screenshots
tmp/capybara
8 changes: 4 additions & 4 deletions .github/workflows/rspec-system-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: rspec-system-events

on:
push:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
- "bin/*"
pull_request:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rspec-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: rspec-system

on:
push:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
- "bin/*"
pull_request:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: rspec

on:
push:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
- "bin/*"
pull_request:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/ruby_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ name: rubocop lint

on:
push:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
- "bin/*"
pull_request:
branches:
- main
paths-ignore:
- "doc/**"
- "*.md"
Expand Down
25 changes: 4 additions & 21 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,12 @@ class DashboardController < ApplicationController
respond_to :html, :js

def index
setup_date_range_picker

@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

@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

@org_stats = OrganizationStats.new(current_organization)
@total_inventory = current_organization.total_inventory
@partners_awaiting_review = current_organization.partners.awaiting_review
@outstanding_requests = current_organization.ordered_requests.where(status: %i[pending started]).order(:created_at)

# calling .recent on recent donations by manufacturers will only count the last 3 donations
# which may not make sense when calculating total count using a date range
@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)
@low_inventory_report = LowInventoryQuery.call(current_organization)

# passing nil here filters the announcements that didn't come from an organization
@broadcast_announcements = BroadcastAnnouncement.filter_announcements(nil)
Expand Down
66 changes: 66 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class ReportsController < ApplicationController
before_action :setup_date_range_picker

def donations_summary
@donations = current_organization.donations.during(helpers.selected_range)
@recent_donations = @donations.recent
end

def manufacturer_donations_summary
@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

def purchases_summary
@purchases = current_organization.purchases.during(helpers.selected_range)
@recent_purchases = @purchases.recent.includes(:vendor)
end

def product_drives_summary
@donations = current_organization.donations.during(helpers.selected_range)
@recent_donations = @donations.recent
end

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
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 distributions_summary
distributions = current_organization.distributions.includes(:partner).during(helpers.selected_range)
@recent_distributions = distributions.recent
end

def activity_graph
@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
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def default_title_content
end
end

def active_class(name)
name.include?(controller_path) ? "active" : controller_path
def active_class(controller_action_names)
(controller_action_names.include?(params[:controller]) || controller_action_names.include?("#{params[:controller]}/#{params[:action]}")) ? 'active' : ''
end

def menu_open?(name)
name.include?(controller_path) ? 'menu-open' : ''
def menu_open?(controller_action_names)
(controller_action_names.include?(params[:controller]) || controller_action_names.include?("#{params[:controller]}/#{params[:action]}")) ? 'menu-open' : ''
end

def can_administrate?
Expand Down
40 changes: 0 additions & 40 deletions app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
@@ -1,37 +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_received_money_donations(range = selected_range)
current_organization.donations.during(range).sum { |d| d.money_raised || 0 }
end

def total_received_money_donations_from_product_drives(range: selected_range)
current_organization.donations.by_source(:product_drive).during(range).sum { |d| d.money_raised || 0 }
end

def total_received_donations(range = selected_range)
number_with_delimiter total_received_donations_unformatted(range)
end

def total_received_from_product_drives(range = selected_range)
number_with_delimiter total_received_from_product_drives_unformatted(range)
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
Expand All @@ -46,18 +18,6 @@ def recently_added_user_display_text(user)

private

def total_received_donations_unformatted(range = selected_range)
LineItem.active.where(itemizable: current_organization.donations.during(range)).sum(:quantity)
end

def total_received_from_product_drives_unformatted(range = selected_range)
LineItem.active.where(itemizable: current_organization.donations.by_source(:product_drive).during(range)).sum(:quantity)
end

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
Expand Down
28 changes: 28 additions & 0 deletions app/helpers/donations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Encapsulates business logic related to displaying Donations
module DonationsHelper
def total_received_donations(range = selected_range)
number_with_delimiter total_received_donations_unformatted(range)
end

def total_received_money_donations(range = selected_range)
current_organization.donations.during(range).sum { |d| d.money_raised || 0 }
end

def total_received_money_donations_from_product_drives(range: selected_range)
current_organization.donations.by_source(:product_drive).during(range).sum { |d| d.money_raised || 0 }
end

def total_received_from_product_drives(range = selected_range)
number_with_delimiter total_received_from_product_drives_unformatted(range)
end

private

def total_received_donations_unformatted(range = selected_range)
LineItem.active.where(itemizable: current_organization.donations.during(range)).sum(:quantity)
end

def total_received_from_product_drives_unformatted(range = selected_range)
LineItem.active.where(itemizable: current_organization.donations.by_source(:product_drive).during(range)).sum(:quantity)
end
end
45 changes: 45 additions & 0 deletions app/queries/low_inventory_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class LowInventoryQuery
def self.call(organization)
if Event.read_events?(organization)
inventory = View::Inventory.new(organization.id)
items = inventory.all_items

low_inventory_items = []
items.each do |item|
quantity = inventory.quantity_for(item_id: item.id)
if quantity < item.on_hand_minimum_quantity.to_i || quantity < item.on_hand_recommended_quantity.to_i
low_inventory_items.push(OpenStruct.new(
id: item.id,
name: item.name,
on_hand_minimum_quantity: item.on_hand_minimum_quantity,
on_hand_recommended_quantity: item.on_hand_recommended_quantity,
total_quantity: quantity
))
end
end

low_inventory_items.sort_by { |item| item[:name] }

else
sql_query = <<-SQL
SELECT
items.id,
items.name,
items.on_hand_minimum_quantity,
items.on_hand_recommended_quantity,
sum(inventory_items.quantity) as total_quantity
FROM inventory_items
JOIN items ON items.id = inventory_items.item_id
JOIN storage_locations ON storage_locations.id = inventory_items.storage_location_id
WHERE storage_locations.organization_id = ?
GROUP BY items.id, items.name, items.on_hand_minimum_quantity, items.on_hand_recommended_quantity
HAVING sum(inventory_items.quantity) < items.on_hand_minimum_quantity
OR sum(inventory_items.quantity) < items.on_hand_recommended_quantity
ORDER BY items.name
SQL

sanitized_sql = ActiveRecord::Base.send(:sanitize_sql_array, [sql_query, organization.id])
ActiveRecord::Base.connection.execute(sanitized_sql).to_a
end
end
end
Loading
Loading