diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 006a318a4b..6dbd8576f4 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -98,6 +98,7 @@ def organization_params :ndbn_member_id, :enable_child_based_requests, :enable_individual_requests, :enable_quantity_based_requests, :ytd_on_distribution_printout, :one_step_partner_invite, + :hide_value_columns_on_receipt, :hide_package_column_on_receipt, partner_form_fields: [] ) end diff --git a/app/models/organization.rb b/app/models/organization.rb index b7f577d6e7..3ed09d962a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -11,6 +11,8 @@ # enable_child_based_requests :boolean default(TRUE), not null # enable_individual_requests :boolean default(TRUE), not null # enable_quantity_based_requests :boolean default(TRUE), not null +# hide_package_column_on_receipt :boolean default(FALSE) +# hide_value_columns_on_receipt :boolean default(FALSE) # intake_location :integer # invitation_text :text # latitude :float diff --git a/app/pdfs/distribution_pdf.rb b/app/pdfs/distribution_pdf.rb index f51beff39b..cafc458064 100644 --- a/app/pdfs/distribution_pdf.rb +++ b/app/pdfs/distribution_pdf.rb @@ -81,6 +81,9 @@ def compute_and_render data = @distribution.request ? request_data : non_request_data has_request = @distribution.request.present? + hide_columns(data) + hidden_columns_length = column_names_to_hide.length + font_size 11 # Line item table table(data) do @@ -109,7 +112,7 @@ def compute_and_render row(-2).borders = [:top] row(-2).padding = [2, 0, 2, 0] - column(0).width = 190 + column(0).width = 190 + (hidden_columns_length * 60) # Quantity column column(1..-1).row(1..-3).borders = [:left] @@ -212,4 +215,21 @@ def non_request_data @distribution.line_items.total, ""]] end + + def hide_columns(data) + column_names_to_hide.each do |col_name| + col_index = data.first.find_index(col_name) + data.each { |line| line.delete_at(col_index) } if col_index.present? + end + end + + private + + def column_names_to_hide + in_kind_column_name = @distribution.request.present? ? "In-Kind Value Received" : "In-Kind Value" + columns_to_hide = [] + columns_to_hide.push("Value/item", in_kind_column_name) if @organization.hide_value_columns_on_receipt + columns_to_hide.push("Packages") if @organization.hide_package_column_on_receipt + columns_to_hide + end end diff --git a/app/views/organizations/_details.html.erb b/app/views/organizations/_details.html.erb index b30547f3e6..af0a3fbd00 100644 --- a/app/views/organizations/_details.html.erb +++ b/app/views/organizations/_details.html.erb @@ -158,6 +158,18 @@ <%= humanize_boolean(@organization.one_step_partner_invite) %>
++ <%= humanize_boolean(@organization.hide_value_columns_on_receipt) %> +
++ <%= humanize_boolean(@organization.hide_package_column_on_receipt) %> +
+%{partner_name}
, %{delivery_method}
, %{distribution_date}
, and %{comment}
to include the partner's name, delivery method, distribution date, and comments sent in the request." %>
<%= f.input :default_email_text, label: "Distribution Email Content", hint: default_email_text_hint.html_safe do %>
diff --git a/db/migrate/20240411181624_add_hide_options_for_distribution_printing_to_organizations.rb b/db/migrate/20240411181624_add_hide_options_for_distribution_printing_to_organizations.rb
new file mode 100644
index 0000000000..72b56df63b
--- /dev/null
+++ b/db/migrate/20240411181624_add_hide_options_for_distribution_printing_to_organizations.rb
@@ -0,0 +1,9 @@
+class AddHideOptionsForDistributionPrintingToOrganizations < ActiveRecord::Migration[7.0]
+ def change
+ add_column :organizations, :hide_value_columns_on_receipt, :boolean
+ add_column :organizations, :hide_package_column_on_receipt, :boolean
+ # Followed strong migration advice, with Backfill migration too
+ change_column_default :organizations, :hide_value_columns_on_receipt, false
+ change_column_default :organizations, :hide_package_column_on_receipt, false
+ end
+end
diff --git a/db/migrate/20240411183741_backfill_add_hide_options_for_distribution_printing_to_organizations.rb b/db/migrate/20240411183741_backfill_add_hide_options_for_distribution_printing_to_organizations.rb
new file mode 100644
index 0000000000..bcc8e830a3
--- /dev/null
+++ b/db/migrate/20240411183741_backfill_add_hide_options_for_distribution_printing_to_organizations.rb
@@ -0,0 +1,8 @@
+class BackfillAddHideOptionsForDistributionPrintingToOrganizations < ActiveRecord::Migration[7.0]
+ def change
+ Organization.unscoped.in_batches do |relation|
+ relation.update_all hide_value_columns_on_receipt: false, hide_package_column_on_receipt: false
+ sleep(0.01)
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 32461cf2ca..5bcbd91bc4 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -484,6 +484,8 @@
t.boolean "enable_quantity_based_requests", default: true, null: false
t.boolean "ytd_on_distribution_printout", default: true, null: false
t.boolean "one_step_partner_invite", default: false, null: false
+ t.boolean "hide_value_columns_on_receipt", default: false
+ t.boolean "hide_package_column_on_receipt", default: false
t.index ["latitude", "longitude"], name: "index_organizations_on_latitude_and_longitude"
t.index ["short_name"], name: "index_organizations_on_short_name"
end
diff --git a/spec/factories/organizations.rb b/spec/factories/organizations.rb
index 12016cbf02..d712c9627e 100644
--- a/spec/factories/organizations.rb
+++ b/spec/factories/organizations.rb
@@ -11,6 +11,8 @@
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
+# hide_package_column_on_receipt :boolean default(FALSE)
+# hide_value_columns_on_receipt :boolean default(FALSE)
# intake_location :integer
# invitation_text :text
# latitude :float
diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb
index aa6314c2b1..854717e375 100644
--- a/spec/models/organization_spec.rb
+++ b/spec/models/organization_spec.rb
@@ -11,6 +11,8 @@
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
+# hide_package_column_on_receipt :boolean default(FALSE)
+# hide_value_columns_on_receipt :boolean default(FALSE)
# intake_location :integer
# invitation_text :text
# latitude :float
diff --git a/spec/pdfs/distribution_pdf_spec.rb b/spec/pdfs/distribution_pdf_spec.rb
index 6dba1d7b3d..da99c1b087 100644
--- a/spec/pdfs/distribution_pdf_spec.rb
+++ b/spec/pdfs/distribution_pdf_spec.rb
@@ -1,13 +1,19 @@
# avoid Rubocop failing with an infinite loop when it checks this cop
# rubocop:disable Layout/ArrayAlignment
-RSpec.describe DistributionPdf, seed_db: false do
+describe DistributionPdf, seed_db: false do
let(:organization) { create(:organization, skip_items: true) }
let(:distribution) { create(:distribution, organization: organization) }
+ let(:item1) { FactoryBot.create(:item, name: "Item 1", package_size: 50, value_in_cents: 100) }
+ let(:item2) { FactoryBot.create(:item, name: "Item 2", value_in_cents: 200) }
+ let(:item3) { FactoryBot.create(:item, name: "Item 3", value_in_cents: 300) }
+ let(:item4) { FactoryBot.create(:item, name: "Item 4", package_size: 25, value_in_cents: 400) }
- let(:item1) { create(:item, name: "Item 1", package_size: 50, value_in_cents: 100) }
- let(:item2) { create(:item, name: "Item 2", value_in_cents: 200) }
- let(:item3) { create(:item, name: "Item 3", value_in_cents: 300) }
- let(:item4) { create(:item, name: "Item 4", package_size: 25, value_in_cents: 400) }
+ let(:org_hiding_packages_and_values) do
+ FactoryBot.create(:organization, name: DEFAULT_TEST_ORGANIZATION_NAME,
+ hide_value_columns_on_receipt: true, hide_package_column_on_receipt: true)
+ end
+ let(:org_hiding_packages) { FactoryBot.create(:organization, name: DEFAULT_TEST_ORGANIZATION_NAME, hide_package_column_on_receipt: true) }
+ let(:org_hiding_values) { FactoryBot.create(:organization, name: DEFAULT_TEST_ORGANIZATION_NAME, hide_value_columns_on_receipt: true) }
before(:each) do
create(:line_item, itemizable: distribution, item: item1, quantity: 50)
@@ -40,5 +46,89 @@
["Total Items Received", "", "$250.00", 150, ""]
])
end
+
+ context "with request data" do
+ describe "#hide_columns" do
+ it "hides value and package columns when true on organization" do
+ pdf = described_class.new(org_hiding_packages_and_values, distribution)
+ data = pdf.request_data
+ pdf.hide_columns(data)
+ expect(data).to eq([
+ ["Items Received", "Requested", "Received"],
+ ["Item 1", "", 50],
+ ["Item 2", 30, 100],
+ ["Item 3", 50, ""],
+ ["Item 4", 120, ""],
+ ["", "", ""],
+ ["Total Items Received", 200, 150]
+ ])
+ end
+
+ it "hides value columns when true on organization" do
+ pdf = described_class.new(org_hiding_values, distribution)
+ data = pdf.request_data
+ pdf.hide_columns(data)
+ expect(data).to eq([
+ ["Items Received", "Requested", "Received", "Packages"],
+ ["Item 1", "", 50, "1"],
+ ["Item 2", 30, 100, nil],
+ ["Item 3", 50, "", nil],
+ ["Item 4", 120, "", nil],
+ ["", "", ""],
+ ["Total Items Received", 200, 150, ""]
+ ])
+ end
+ end
+ end
+
+ context "with non request data" do
+ it "hides value and package columns when true on organization" do
+ pdf = described_class.new(org_hiding_packages_and_values, distribution)
+ data = pdf.request_data
+ pdf.hide_columns(data)
+ expect(data).to eq([
+ ["Items Received", "Requested", "Received"],
+ ["Item 1", "", 50],
+ ["Item 2", 30, 100],
+ ["Item 3", 50, ""],
+ ["Item 4", 120, ""],
+ ["", "", ""],
+ ["Total Items Received", 200, 150]
+ ])
+ end
+
+ it "hides value columns when true on organization" do
+ pdf = described_class.new(org_hiding_values, distribution)
+ data = pdf.request_data
+ pdf.hide_columns(data)
+ expect(data).to eq([
+ ["Items Received", "Requested", "Received", "Packages"],
+ ["Item 1", "", 50, "1"],
+ ["Item 2", 30, 100, nil],
+ ["Item 3", 50, "", nil],
+ ["Item 4", 120, "", nil],
+ ["", "", ""],
+ ["Total Items Received", 200, 150, ""]
+ ])
+ end
+ end
+ context "regardles of request data" do
+ describe "#hide_columns" do
+ it "hides package column when true on organization" do
+ pdf = described_class.new(org_hiding_packages, distribution)
+ data = pdf.request_data
+ pdf.hide_columns(data)
+ expect(data).to eq([
+ ["Items Received", "Requested", "Received", "Value/item", "In-Kind Value Received"],
+ ["Item 1", "", 50, "$1.00", "$50.00"],
+ ["Item 2", 30, 100, "$2.00", "$200.00"],
+ ["Item 3", 50, "", "$3.00", nil],
+ ["Item 4", 120, "", "$4.00", nil],
+ ["", "", "", "", ""],
+ ["Total Items Received", 200, 150, "", "$250.00"]
+ ])
+ end
+ end
+ end
end
# rubocop:enable Layout/ArrayAlignment