Skip to content

Commit 1aa0549

Browse files
authored
Merge branch 'main' into 5231-cancel-requests-deactivated-partners
2 parents b92f2dc + cbe828e commit 1aa0549

17 files changed

+277
-43
lines changed

app/controllers/reports_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def activity_graph
3939
@distribution_data = received_distributed_data(helpers.selected_range)
4040
end
4141

42+
def itemized_requests
43+
requests = current_organization.requests.during(helpers.selected_range)
44+
@itemized_request_data = RequestItemizedBreakdownService.call(organization: current_organization, request_ids: requests.pluck(:id))
45+
end
46+
4247
private
4348

4449
def total_purchased_unformatted(range = selected_range)

app/helpers/ui_helper.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ def _link_to(link, options = {}, properties = {})
162162
text = options[:text]
163163
size = options[:size]
164164
type = options[:type]
165+
166+
properties[:data] ||= {}
167+
properties[:data][:disable_with] ||= "Please wait..."
168+
165169
if options[:data].present?
166-
properties[:data] ||= {}
167170
properties[:data].merge!(options[:data])
168171
end
169172
properties[:title] = options[:title] if options[:title].present?
@@ -180,7 +183,7 @@ def _link_to(link, options = {}, properties = {})
180183
end
181184
end
182185

183-
def _button_to(options = {}, other_properties = {})
186+
def _button_to(options = {}, properties = {})
184187
submit_type = options[:submit_type] || "submit"
185188
id = options[:id]
186189
type = options[:type]
@@ -189,7 +192,10 @@ def _button_to(options = {}, other_properties = {})
189192
text = options[:text]
190193
align = options[:align]
191194

192-
button_tag({ type: submit_type, id: id, class: "btn btn-#{type} btn-#{size} #{align}" }.merge(other_properties)) do
195+
properties[:data] ||= {}
196+
properties[:data][:disable_with] ||= "Please wait..."
197+
198+
button_tag({ type: submit_type, id: id, class: "btn btn-#{type} btn-#{size} #{align}" }.merge(properties)) do
193199
fa_icon icon, text: text
194200
end
195201
end
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
class RequestItemizedBreakdownService
2+
class << self
3+
def call(organization:, request_ids:, format: :hash)
4+
data = fetch(organization: organization, request_ids: request_ids)
5+
(format == :csv) ? convert_to_csv(data) : data
6+
end
7+
8+
def fetch(organization:, request_ids:)
9+
inventory = View::Inventory.new(organization.id)
10+
current_onhand = current_onhand_quantities(inventory)
11+
current_min_onhand = current_onhand_minimums(inventory)
12+
items_requested = fetch_items_requested(organization: organization, request_ids: request_ids)
13+
14+
items_requested.each do |item|
15+
id = item[:item_id]
16+
17+
on_hand = current_onhand[id]
18+
minimum = current_min_onhand[id]
19+
below_onhand_minimum = on_hand && minimum && on_hand < minimum
20+
21+
item.merge!(
22+
on_hand: on_hand,
23+
onhand_minimum: minimum,
24+
below_onhand_minimum: below_onhand_minimum
25+
)
26+
end
27+
28+
items_requested.sort_by { |item| [item[:name], item[:unit].to_s] }
29+
end
30+
31+
def csv(organization:, request_ids:)
32+
convert_to_csv(fetch(organization: organization, request_ids: request_ids))
33+
end
34+
35+
private
36+
37+
def current_onhand_quantities(inventory)
38+
inventory.all_items.group_by(&:item_id).to_h { |item_id, rows| [item_id, rows.sum { |r| r.quantity.to_i }] }
39+
end
40+
41+
def current_onhand_minimums(inventory)
42+
inventory.all_items.group_by(&:item_id).to_h { |item_id, rows| [item_id, rows.map(&:on_hand_minimum_quantity).compact.max] }
43+
end
44+
45+
def fetch_items_requested(organization:, request_ids:)
46+
Partners::ItemRequest
47+
.includes(:item)
48+
.where(partner_request_id: request_ids)
49+
.group_by { |ir| [ir.item_id, ir.request_unit] }
50+
.map do |(item_id, unit), grouped|
51+
item = grouped.first.item
52+
{
53+
item_id: item.id,
54+
name: item.name,
55+
unit: unit,
56+
quantity: grouped.sum { |ri| ri.quantity.to_i }
57+
}
58+
end
59+
end
60+
61+
def convert_to_csv(items_requested_data)
62+
CSV.generate do |csv|
63+
csv << ["Item", "Total Requested", "Total On Hand"]
64+
items_requested_data.each do |item|
65+
csv << [item[:name], item[:quantity], item[:on_hand]]
66+
end
67+
end
68+
end
69+
end
70+
end

app/views/audits/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<div class="col-md-12">
2929
<div class="callout callout-info">
3030
<h5><i class="fas fa-info"></i> Note:</h5>
31-
<p class="help">Edit the <strong>Audit</strong> recording all the inventory present in a particular storage location.</p>
31+
<p class="help">Edit the <strong>Audit</strong> recording the inventory present in a particular storage location.</p>
3232
<p class="help">Enter <em>all</em> the items with their corresponding <em>quantity</em> that are present in the storage location</p>
3333
<p class="help">Click on <em>Save Progress</em> button to save the current progress of audit.</p>
3434
<p class="help">You can <em>resume</em> the saved audit at a later time again.</p>

app/views/audits/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<div class="col-md-12">
2929
<div class="callout callout-info">
3030
<h5><i class="fas fa-info"></i> Note:</h5>
31-
<p class="box-title">Create an <strong>Audit</strong> recording all the inventory present in a
31+
<p class="box-title">Create an <strong>Audit</strong> recording the inventory present in a
3232
particular storage location.</p>
3333
<p class="help">Enter the <em>items</em> with their corresponding <em>quantity</em> that are present in the storage location. You can do a partial audit - if you do not enter a new value, the level in the records will not be changed.</p>
3434
<p class="help">Click on <em>Save Progress</em> button to save the current progress of audit.</p>

app/views/layouts/_lte_sidebar.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@
239239
<i class="nav-icon fa fa-circle-o"></i> Purchases - Trends
240240
<% end %>
241241
</li>
242+
<li class="nav-item <%= active_class(['reports/itemized_requests']) %>">
243+
<%= link_to(reports_itemized_requests_path, class: "nav-link #{active_class(['reports/itemized_requests'])}") do %>
244+
<i class="nav-icon fa fa-circle-o"></i> Requests - Itemized
245+
<% end %>
246+
</li>
242247
</ul>
243248
</li>
244249
<% if current_user.has_cached_role?(Role::ORG_ADMIN, current_organization) %>

app/views/partner_users/_user.html.erb

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/views/partner_users/_users.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
</td>
5050
<td class='d-flex flex-column'>
5151
<% unless user.invitation_accepted_at %>
52-
<%= button_to resend_invitation_partner_user_path(partner, user), method: :post, class: "btn btn-warning btn-xs mb-2" do %>
52+
<%= button_to resend_invitation_partner_user_path(partner, user), method: :post, data: { disable_with: "Please wait..." }, class: "btn btn-warning btn-xs mb-2" do %>
5353
<i class="fa fa-envelope"></i> Resend Invitation
5454
<% end %>
5555
<% end %>
56-
<%= button_to reset_password_partner_user_path(partner, user), method: :post, data: { confirm: "Are you sure?" }, class: "btn btn-info btn-xs mb-2" do %>
56+
<%= button_to reset_password_partner_user_path(partner, user), method: :post, data: { confirm: "Are you sure?", disable_with: "Please wait..." }, class: "btn btn-info btn-xs mb-2" do %>
5757
<i class="fa fa-key"></i> Reset Password
5858
<% end %>
59-
<%= button_to partner_user_path(partner, user), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-xs" do %>
59+
<%= button_to partner_user_path(partner, user), method: :delete, data: { confirm: "Are you sure?", disable_with: "Please wait..." }, class: "btn btn-danger btn-xs" do %>
6060
<i class="fa fa-ban"></i> Remove Access
6161
<% end %>
6262

app/views/partners/_partner_row.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<% when "awaiting_review" %>
4040
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Applicant's Profile", icon: "check", type: "warning" } %>
4141
<% when "approved" %>
42-
<%= button_to recertify_partner_partner_path(partner_row), data: { confirm: "Recertify partner #{partner_row.name}?"}, class: "btn btn-xs bg-red" do %>
42+
<%= button_to recertify_partner_partner_path(partner_row), data: { confirm: "Recertify partner #{partner_row.name}?", disable_with: "Please wait..."}, class: "btn btn-xs bg-red" do %>
4343
<i class="fa fa-refresh"></i> Request Recertification
4444
<% end %>
4545
<% when "deactivated" %>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<%= render(
2+
"shared/filtered_card",
3+
id: "purchases",
4+
gradient: "secondary",
5+
title: "Itemized Requests",
6+
subtitle: @selected_date_range,
7+
type: :table,
8+
filter_url: reports_itemized_requests_path
9+
) do %>
10+
11+
<% if @itemized_request_data.empty? %>
12+
<div class="alert alert-warning" role="alert">
13+
No itemized requests found for the selected date range.
14+
</div>
15+
<% else %>
16+
<table class="table table-hover striped text-left">
17+
<thead>
18+
<tr>
19+
<th>Item</th>
20+
<th class="text-right">Total Requested</th>
21+
<th class="text-right">Total On Hand</th>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
<% @itemized_request_data.each do |item| %>
26+
<tr>
27+
<td>
28+
<%= item[:name] %>
29+
<% if item[:unit].present? %>
30+
(<%= h(item[:unit]) %>)
31+
<% end %>
32+
</td>
33+
<td class="text-right"><%= item[:quantity] %></td>
34+
<td class="text-right <%= 'table-danger' if item[:below_onhand_minimum] %>">
35+
<%= item[:on_hand] || 0 %>
36+
</td>
37+
</tr>
38+
<% end %>
39+
</tbody>
40+
</table>
41+
<% end %>
42+
<% end %>

0 commit comments

Comments
 (0)