Skip to content

Commit c09977a

Browse files
authored
Merge branch 'main' into 4977_add_ability_to_delete_unused_item_categories
2 parents 5b81927 + 36b9034 commit c09977a

30 files changed

Lines changed: 466 additions & 287 deletions

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,4 +831,4 @@ DEPENDENCIES
831831
webmock (~> 3.24)
832832

833833
BUNDLED WITH
834-
2.6.6
834+
2.6.7

app/controllers/donations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def index
4949
respond_to do |format|
5050
format.html
5151
format.csv do
52-
send_data Exports::ExportDonationsCSVService.new(donation_ids: @donations.map(&:id)).generate_csv, filename: "Donations-#{Time.zone.today}.csv"
52+
send_data Exports::ExportDonationsCSVService.new(donation_ids: @donations.map(&:id), organization: current_organization).generate_csv, filename: "Donations-#{Time.zone.today}.csv"
5353
end
5454
end
5555
end

app/controllers/organizations_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def organization_params
102102
:ytd_on_distribution_printout, :one_step_partner_invite,
103103
:hide_value_columns_on_receipt, :hide_package_column_on_receipt,
104104
:signature_for_distribution_pdf, :receive_email_on_requests,
105+
:include_in_kind_values_in_exported_files,
105106
partner_form_fields: [],
106107
request_unit_names: []
107108
)

app/controllers/requests_controller.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ def start
4242
redirect_to new_distribution_path(request_id: request.id)
4343
end
4444

45+
def print_picklist
46+
request = current_organization
47+
.requests
48+
.includes(:item_requests, partner: [:profile])
49+
.find(params[:id])
50+
51+
respond_to do |format|
52+
format.any do
53+
pdf = PicklistsPdf.new(current_organization, [request])
54+
send_data pdf.compute_and_render,
55+
filename: format("Picklists_%s.pdf", Time.current.to_fs(:long)),
56+
type: "application/pdf",
57+
disposition: "inline"
58+
end
59+
end
60+
end
61+
4562
def print_unfulfilled
4663
requests = current_organization
4764
.requests

app/helpers/items_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def dollar_value(value)
1212
end
1313

1414
def cents_to_dollar(value_in_cents)
15-
value_in_cents.to_f / 100
15+
Money.new(value_in_cents).to_f
1616
end
1717

1818
def selected_item_request_units(item)

app/models/donation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def storage_view
119119
end
120120

121121
def in_kind_value_money
122-
Money.new(value_per_itemizable)
122+
Money.new(value_per_itemizable).to_f
123123
end
124124

125125
private

app/models/organization.rb

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,39 @@
22
#
33
# Table name: organizations
44
#
5-
# id :integer not null, primary key
6-
# city :string
7-
# deadline_day :integer
8-
# default_storage_location :integer
9-
# distribute_monthly :boolean default(FALSE), not null
10-
# email :string
11-
# enable_child_based_requests :boolean default(TRUE), not null
12-
# enable_individual_requests :boolean default(TRUE), not null
13-
# enable_quantity_based_requests :boolean default(TRUE), not null
14-
# hide_package_column_on_receipt :boolean default(FALSE)
15-
# hide_value_columns_on_receipt :boolean default(FALSE)
16-
# intake_location :integer
17-
# invitation_text :text
18-
# latitude :float
19-
# longitude :float
20-
# name :string
21-
# one_step_partner_invite :boolean default(FALSE), not null
22-
# partner_form_fields :text default([]), is an Array
23-
# receive_email_on_requests :boolean default(FALSE), not null
24-
# reminder_day :integer
25-
# repackage_essentials :boolean default(FALSE), not null
26-
# short_name :string
27-
# signature_for_distribution_pdf :boolean default(FALSE)
28-
# state :string
29-
# street :string
30-
# url :string
31-
# ytd_on_distribution_printout :boolean default(TRUE), not null
32-
# zipcode :string
33-
# created_at :datetime not null
34-
# updated_at :datetime not null
35-
# account_request_id :integer
36-
# ndbn_member_id :bigint
5+
# id :integer not null, primary key
6+
# city :string
7+
# deadline_day :integer
8+
# default_storage_location :integer
9+
# distribute_monthly :boolean default(FALSE), not null
10+
# email :string
11+
# enable_child_based_requests :boolean default(TRUE), not null
12+
# enable_individual_requests :boolean default(TRUE), not null
13+
# enable_quantity_based_requests :boolean default(TRUE), not null
14+
# hide_package_column_on_receipt :boolean default(FALSE)
15+
# hide_value_columns_on_receipt :boolean default(FALSE)
16+
# include_in_kind_values_in_exported_files :boolean default(FALSE), not null
17+
# intake_location :integer
18+
# invitation_text :text
19+
# latitude :float
20+
# longitude :float
21+
# name :string
22+
# one_step_partner_invite :boolean default(FALSE), not null
23+
# partner_form_fields :text default([]), is an Array
24+
# receive_email_on_requests :boolean default(FALSE), not null
25+
# reminder_day :integer
26+
# repackage_essentials :boolean default(FALSE), not null
27+
# short_name :string
28+
# signature_for_distribution_pdf :boolean default(FALSE)
29+
# state :string
30+
# street :string
31+
# url :string
32+
# ytd_on_distribution_printout :boolean default(TRUE), not null
33+
# zipcode :string
34+
# created_at :datetime not null
35+
# updated_at :datetime not null
36+
# account_request_id :integer
37+
# ndbn_member_id :bigint
3738
#
3839

3940
class Organization < ApplicationRecord

app/pdfs/picklists_pdf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "prawn/table"
2+
13
# Configures a Prawn PDF template for generating Distribution manifests
24
class PicklistsPdf
35
include Prawn::View

app/services/exports/export_distributions_csv_service.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,31 @@ def item_headers
136136
return @item_headers if @item_headers
137137

138138
@item_headers = @organization.items.select("DISTINCT ON (LOWER(name)) items.name").order("LOWER(name) ASC").map(&:name)
139+
@item_headers = @item_headers.flat_map { |header| [header, "#{header} In-Kind Value"] } if @organization.include_in_kind_values_in_exported_files
140+
141+
@item_headers
139142
end
140143

141144
def build_row_data(distribution)
142145
row = base_table.values.map { |closure| closure.call(distribution) }
143-
144-
row += Array.new(item_headers.size, 0)
146+
row += make_item_quantity_and_value_slots
145147

146148
distribution.line_items.each do |line_item|
147149
item_name = line_item.item.name
148150
item_column_idx = headers_with_indexes[item_name]
149151
next unless item_column_idx
150152

151153
row[item_column_idx] += line_item.quantity
154+
row[item_column_idx + 1] += Money.new(line_item.value_per_line_item) if @organization.include_in_kind_values_in_exported_files
152155
end
153156

154157
row
155158
end
159+
160+
def make_item_quantity_and_value_slots
161+
slots = Array.new(item_headers.size, 0)
162+
slots = slots.map.with_index { |value, index| index.odd? ? Money.new(0) : value } if @organization.include_in_kind_values_in_exported_files
163+
slots
164+
end
156165
end
157166
end

app/services/exports/export_donations_csv_service.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Exports
22
class ExportDonationsCSVService
3-
def initialize(donation_ids:)
3+
def initialize(donation_ids:, organization:)
44
# Use a where lookup so that I can eager load all the resources
55
# needed rather than depending on external code to do it for me.
66
# This makes this code more self contained and efficient!
@@ -13,6 +13,8 @@ def initialize(donation_ids:)
1313
).where(
1414
id: donation_ids,
1515
).order(created_at: :asc)
16+
17+
@organization = organization
1618
end
1719

1820
def generate_csv
@@ -80,7 +82,7 @@ def base_table
8082
"Variety of Items" => ->(donation) {
8183
donation.line_items.map(&:name).uniq.size
8284
},
83-
"In-Kind Value" => ->(donation) {
85+
"In-Kind Total" => ->(donation) {
8486
donation.in_kind_value_money
8587
},
8688
"Comments" => ->(donation) {
@@ -105,20 +107,30 @@ def item_headers
105107
end
106108

107109
@item_headers = item_names.sort
110+
111+
@item_headers = @item_headers.flat_map { |header| [header, "#{header} In-Kind Value"] } if @organization.include_in_kind_values_in_exported_files
112+
113+
@item_headers
108114
end
109115

110116
def build_row_data(donation)
111117
row = base_table.values.map { |closure| closure.call(donation) }
112-
113-
row += Array.new(item_headers.size, 0)
118+
row += make_item_quantity_and_value_slots
114119

115120
donation.line_items.each do |line_item|
116121
item_name = line_item.item.name
117122
item_column_idx = headers_with_indexes[item_name]
118123
row[item_column_idx] += line_item.quantity
124+
row[item_column_idx + 1] += Money.new(line_item.value_per_line_item) if @organization.include_in_kind_values_in_exported_files
119125
end
120126

121127
row
122128
end
129+
130+
def make_item_quantity_and_value_slots
131+
slots = Array.new(item_headers.size, 0)
132+
slots = slots.map.with_index { |value, index| index.odd? ? Money.new(0) : value } if @organization.include_in_kind_values_in_exported_files
133+
slots
134+
end
123135
end
124136
end

0 commit comments

Comments
 (0)