Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gem "uglifier", ">= 1.3.0"
gem "therubyracer", "~> 0.12", platforms: :ruby
gem "yajl-ruby"
gem "toastr-rails"
gem "sucker_punch", "~> 2.0"

group :development, :test do
gem "awesome_print"
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ GEM
net-ssh (>= 2.8.0)
sshkit-interactive (0.3.0)
sshkit (~> 1.12)
sucker_punch (2.1.1)
concurrent-ruby (~> 1.0)
terminal-notifier (2.0.0)
terminal-notifier-guard (1.7.0)
terrapin (0.6.0)
Expand Down Expand Up @@ -492,6 +494,7 @@ DEPENDENCIES
spring
spring-watcher-listen
sprockets (~> 3.7.2)
sucker_punch (~> 2.0)
terminal-notifier
terminal-notifier-guard
therubyracer (~> 0.12)
Expand All @@ -507,4 +510,4 @@ RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.6
1.16.6
15 changes: 14 additions & 1 deletion app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ class DistributionsController < ApplicationController

def print
@distribution = Distribution.find(params[:id])
@filename = format("%s %s.pdf", @distribution.partner.name, sortable_date(@distribution.created_at))
respond_to do |format|
format.any do
pdf = DistributionPdf.new(current_organization, @distribution)
send_data pdf.render,
filename: format("%s %s.pdf", @distribution.partner.name, sortable_date(@distribution.created_at)),
type: "application/pdf",
disposition: "inline"
end
end
end

def reclaim
Expand Down Expand Up @@ -37,6 +45,7 @@ def create
@distribution.storage_location.distribute!(@distribution)

if @distribution.save
send_notification(current_organization, @distribution)
flash[:notice] = "Distribution created!"
redirect_to distributions_path
else
Expand Down Expand Up @@ -107,6 +116,10 @@ def insufficient_amount!

private

def send_notification(org, dist)
PartnerMailerJob.perform_async(org, dist) if Flipper.enabled?(:email_active)
end

def distribution_params
params.require(:distribution).permit(:comment, :agency_rep, :issued_at, :partner_id, :storage_location_id, line_items_attributes: %i(item_id quantity _destroy))
end
Expand Down
8 changes: 8 additions & 0 deletions app/jobs/partner_mailer_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class PartnerMailerJob
include SuckerPunch::Job
workers 2

def perform(current_organization, distribution)
DistributionMailer.partner_mailer(current_organization, distribution)
end
end
13 changes: 13 additions & 0 deletions app/mailers/distribution_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class DistributionMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.distribution_mailer.partner_mailer.subject
#
def partner_mailer(current_organization, distribution)
@partner = distribution.partner
@distribution = distribution
attachments[format("%s %s.pdf", @partner.name, @distribution.created_at.strftime("%Y-%m-%d"))] = DistributionPdf.new(current_organization, @distribution).render
mail to: @partner.email
end
end
125 changes: 125 additions & 0 deletions app/pdfs/distribution_pdf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
class DistributionPdf
include Prawn::View

def initialize(organization, distribution)
@distribution = distribution
image organization.logo_path, fit: [325, 110]
bounding_box [bounds.right - 225, bounds.top - 20], width: 225 do
text organization.name, align: :right
text organization.address, align: :right
text organization.email, align: :right
end
data = [["Items Received", "Quantity"]]
data += @distribution.line_items.sorted.map do |c|
[c.item.name, c.quantity]
end
data += [["", ""], ["Total Items Received", @distribution.line_items.total]]

move_down 55

font "Helvetica"
text "Issued to:", style: :bold
text @distribution.partner.name
move_down 10

text "Issued on:", style: :bold
text @distribution.distributed_at
move_down 10

text "Comments:", style: :bold
text @distribution.comment

move_down 20

# Line item table
table(data) do
self.header = true
self.cell_style = {
padding: [5, 20, 5, 20]
}
self.row_colors = %w(dddddd ffffff)

cells.borders = []

# Header row
row(0).borders = [:bottom]
row(0).border_width = 2
row(0).font_style = :bold
row(0).column(-1).borders = %i(bottom left)

# Total Items footer row
row(-1).borders = [:top]
row(-1).font_style = :bold
row(-1).column(-1).borders = %i(top left)

# Footer spacing row
row(-2).borders = [:top]
row(-2).padding = [2, 0, 2, 0]

column(0).width = 400

# Quantity column
column(1).row(1..-3).borders = [:left]
column(1).row(1..-3).border_left_color = "aaaaaa"
column(1).style align: :right
end

move_down 50

summary = [["Distribution Breakdown", "Quantity"]]
summary += @distribution.line_items.quantities_by_category.to_a

table(summary) do
self.header = true
self.cell_style = {
padding: [5, 20, 5, 20]
}
self.row_colors = %w(dddddd ffffff)

cells.borders = []

# Header row
row(0).borders = [:bottom]
row(0).border_width = 2
row(0).font_style = :bold
row(0).column(-1).borders = %i(bottom left)

column(0).width = 400

# Quantity column
column(1).row(1..-1).borders = [:left]
column(1).row(1..-1).border_left_color = "aaaaaa"
column(1).style align: :right
end

number_pages "Page <page> of <total>",
start_count_at: 1,
at: [bounds.right - 130, 22],
align: :right

repeat :all do
# Page footer
bounding_box [bounds.left, bounds.bottom + 35], width: bounds.width do
stroke_bounds
font "Helvetica"
stroke_horizontal_rule
move_down(5)
# table([
# [organization.name, organization.address_inline, ""],
# ]) do
# self.width = bounds.width
# cells.borders = []
# column(0).width = 125
# column(2).width = 125
# column(1).style align: :center
# column(2).style align: :right
# end
logo_offset = (bounds.width - 190) / 2
bounding_box([logo_offset, 0], width: 190, height: 33) do
text "Lovingly created with", valign: :center
image Organization::DIAPER_APP_LOGO, width: 75, vposition: :center, position: :right
end
end
end
end
end
9 changes: 9 additions & 0 deletions app/views/distribution_mailer/partner_mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>
Hi <%= @partner.name %>,
<%= @distribution.inspect %>
<br>
Please find an attached pdf containg details about your distribution.
</p>
<p>
You can pick up your distribution
</p>
3 changes: 3 additions & 0 deletions app/views/distribution_mailer/partner_mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Distribution#partner_mailer

<%= @greeting %>, find me in app/views/distribution_mailer/partner_mailer.text.erb
126 changes: 0 additions & 126 deletions app/views/distributions/print.pdf.prawn

This file was deleted.

1 change: 1 addition & 0 deletions app/views/donations/_donation_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
collection: @storage_locations,
label: "Storage Location",
error: "Where is it being stored?",
selected: current_organization.intake_location,
wrapper: :vertical_input_group %>
</div>
</div>
Expand Down
7 changes: 0 additions & 7 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@
<a href="<%= root_path %>" class="logo">
<% end %>
<!-- mini logo for sidebar mini 50x50 pixels -->
<% if Flipper.enabled?(:new_logo) %>
<span class="logo-mini"><img src="/Just-Diaper.svg">
</span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><%= image_tag "Just-Diaper.svg", alt: "DiaperBase Logo", id: "logo" %></span>
<% else %>
<span class="logo-mini"><img src="/apple-icon-180x180.png">
</span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><%= image_tag "DiaperBase-Logo.png", alt: "DiaperBase Logo", id: "logo" %></span>
<% end %>
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top">
Expand Down
Loading