Skip to content

Commit

Permalink
4481 Print Individual Donation Receipts Requested Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdphillips375 committed Jul 7, 2024
1 parent 025c2f6 commit 595b819
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ group :test do
gem "webmock", "~> 3.23"
# Interface capybara to chrome headless
gem "cuprite"
# Read PDF files for tests
gem "pdf-reader"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
Ascii85 (1.1.1)
actioncable (7.1.3.4)
actionpack (= 7.1.3.4)
activesupport (= 7.1.3.4)
Expand Down Expand Up @@ -77,6 +78,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
afm (0.2.2)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
Expand Down Expand Up @@ -288,6 +290,7 @@ GEM
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashdiff (1.1.0)
hashery (2.1.2)
hashie (5.0.0)
httparty (0.22.0)
csv
Expand Down Expand Up @@ -441,6 +444,12 @@ GEM
ast (~> 2.4.1)
racc
pdf-core (0.9.0)
pdf-reader (2.12.0)
Ascii85 (~> 1.0)
afm (~> 0.2.1)
hashery (~> 2.0)
ruby-rc4
ttfunk
pg (1.5.6)
popper_js (2.11.8)
prawn (2.4.0)
Expand Down Expand Up @@ -591,6 +600,7 @@ GEM
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5)
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -756,6 +766,7 @@ DEPENDENCIES
omniauth-rails_csrf_protection
orderly (~> 0.1)
paper_trail
pdf-reader
pg (~> 1.5.6)
prawn-rails
pry-doc
Expand Down Expand Up @@ -787,4 +798,4 @@ DEPENDENCIES
webmock (~> 3.23)

BUNDLED WITH
2.5.11
2.5.14
15 changes: 7 additions & 8 deletions app/pdfs/donation_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ class DonationPdf
class DonorInfo
attr_reader :name, :address, :email

def initialize(donation = nil)
def initialize(donation)
if donation.nil?
@name = @address = @email = nil
return
raise "Must pass a Donation object"
end
case donation.source
when "Donation Site"
when Donation::SOURCES[:donation_site]
@name = donation.donation_site.name
@address = donation.donation_site.address
@email = donation.donation_site.email
when "Manufacturer"
when Donation::SOURCES[:manufacturer]
@name = donation.manufacturer.name
@address = nil
@email = nil
when "Product Drive"
when Donation::SOURCES[:product_drive]
@name = donation.product_drive_participant.business_name
@address = donation.product_drive_participant.address
@email = donation.product_drive_participant.email
when "Misc. Donation"
when Donation::SOURCES[:misc]
@name = "Misc. Donation"
@address = nil
@email = nil
Expand Down Expand Up @@ -80,7 +79,7 @@ def compute_and_render

font_size 12
money_raised = "$0.00"
if !@donation.money_raised.nil? && @donation.money_raised > 0
if @donation.money_raised && @donation.money_raised > 0
money_raised = dollar_value(@donation.money_raised)
end
text "<strong>Money Raised In Dollars: </strong>#{money_raised}", inline_format: true
Expand Down
20 changes: 19 additions & 1 deletion spec/pdfs/donation_pdf_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe DonationPdf do
let(:donation_site) { create(:donation_site) }
let(:organization) { create(:organization) }
let(:donation) { create(:donation, organization: organization, donation_site: donation_site) }
let(:donation) { create(:donation, organization: organization, donation_site: donation_site, source: Donation::SOURCES[:donation_site]) }
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) }
Expand Down Expand Up @@ -44,4 +44,22 @@
])
end
end

context "render pdf" do
it "renders correctly" do
pdf = described_class.new(organization, donation)
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
expect(pdf_test.page(1).text).to include(donation_site.name)
expect(pdf_test.page(1).text).to include(donation_site.address)
expect(pdf_test.page(1).text).to include(donation_site.email)
if donation.comment
expect(pdf_test.page(1).text).to include(donation.comment)
end
expect(pdf_test.page(1).text).to include("Money Raised In Dollars: $0.00")
expect(pdf_test.page(1).text).to include("Items Received")
expect(pdf_test.page(1).text).to match(/Item 1\s+\$1\.00\s+\$50\.00\s+50/)
expect(pdf_test.page(1).text).to match(/Item 2\s+\$2\.00\s+\$200\.00\s+100/)
expect(pdf_test.page(1).text).to include("Total Items Received")
end
end
end

0 comments on commit 595b819

Please sign in to comment.