public
Created

  • Download Gist
show.pdf.prawn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
require 'prawn/layout'
require 'prawn/format'
 
bill_address = @order.bill_address
ship_address = @order.ship_address
 
font "Helvetica"
 
image Spree::PrintInvoice::Config[:print_invoice_logo_path], :at => [0,720], :scale => 0.65
 
fill_color "005D99"
text "Customer Invoice", :at => [200,698], :style => :bold, :size => 22
fill_color "000000"
 
move_down 55
 
font "Helvetica", :style => :bold, :size => 14
text "Order Number: #{@order.number}"
 
font "Helvetica", :size => 8
text @order.created_at.to_s(:long)
text (@order.user ? @order.user.email : @order.email)
 
# Address Stuff
bounding_box [0,600], :width => 540 do
move_down 2
data = [[Prawn::Table::Cell.new( :text => "Billing Address", :font_style => :bold ),
Prawn::Table::Cell.new( :text =>"Shipping Address", :font_style => :bold )]]
 
table data,
:position => :center,
:border_width => 0.5,
:vertical_padding => 2,
:horizontal_padding => 6,
:font_size => 9,
:border_style => :underline_header,
:column_widths => { 0 => 270, 1 => 270 }
 
move_down 2
horizontal_rule
 
bounding_box [0,0], :width => 540 do
move_down 2
data2 = [["#{bill_address.firstname} #{bill_address.lastname}", "#{ship_address.firstname} #{ship_address.lastname}"],
[bill_address.address1, ship_address.address1]]
data2 << [bill_address.address2, ship_address.address2] unless bill_address.address2.blank? and ship_address.address2.blank?
data2 << ["#{@order.bill_address.city}, #{(@order.bill_address.state ? @order.bill_address.state.abbr : @order.bill_address.state_name || "")} #{@order.bill_address.zipcode}",
"#{@order.ship_address.city}, #{(@order.ship_address.state ? @order.ship_address.state.abbr : @order.ship_address.state_name || "")} #{@order.ship_address.zipcode}"]
data2 << [bill_address.country.name, ship_address.country.name]
data2 << [bill_address.phone, ship_address.phone]
 
table data2,
:position => :center,
:border_width => 0.0,
:vertical_padding => 0,
:horizontal_padding => 6,
:font_size => 9,
:column_widths => { 0 => 270, 1 => 270 }
end
 
move_down 2
 
stroke do
line_width 0.5
line bounds.top_left, bounds.top_right
line bounds.top_left, bounds.bottom_left
line bounds.top_right, bounds.bottom_right
line bounds.bottom_left, bounds.bottom_right
end
 
end
 
move_down 30
 
# Line Items
bounding_box [0,cursor], :width => 540, :height => 450 do
move_down 2
data = [[Prawn::Table::Cell.new( :text => "SKU", :font_style => :bold),
Prawn::Table::Cell.new( :text =>"Item Description", :font_style => :bold ),
Prawn::Table::Cell.new( :text =>"Price", :font_style => :bold ),
Prawn::Table::Cell.new( :text =>"Qty", :font_style => :bold, :align => 1 ),
Prawn::Table::Cell.new( :text =>"Total", :font_style => :bold )]]
 
table data,
:position => :center,
:border_width => 0,
:vertical_padding => 2,
:horizontal_padding => 6,
:font_size => 9,
:column_widths => { 0 => 75, 1 => 290, 2 => 75, 3 => 50, 4 => 50 } ,
:align => { 0 => :left, 1 => :left, 2 => :right, 3 => :right, 4 => :right }
 
move_down 4
horizontal_rule
move_down 2
 
bounding_box [0,cursor], :width => 540 do
move_down 2
data2 = []
@order.line_items.each do |item|
data2 << [[([item.variant.product.sku] + (item.variant.product.assembly? ? item.variant.product.parts.collect{|x| ' ' + x.count + 'x [' + x.product.sku + ']'} : [])).join("\n")],
[item.variant.product.name],
number_to_currency(item.price),
item.quantity,
number_to_currency(item.price * item.quantity)]
end
 
 
table data2,
:position => :center,
:border_width => 0,
:vertical_padding => 5,
:horizontal_padding => 6,
:font_size => 9,
:column_widths => { 0 => 175, 1 => 200, 2 => 65, 3 => 50, 4 => 50 },
:align => { 0 => :left, 1 => :left, 2 => :right, 3 => :right, 4 => :right }
end
 
font "Helvetica", :size => 9
 
totals = []
 
totals << [Prawn::Table::Cell.new( :text => "Subtotal:", :font_style => :bold), number_to_currency(@order.item_total)]
 
@order.charges.each do |charge|
totals << [Prawn::Table::Cell.new( :text => charge.description + ":", :font_style => :bold), number_to_currency(charge.amount)]
end
@order.credits.each do |credit|
totals << [Prawn::Table::Cell.new( :text => credit.description + ":", :font_style => :bold), number_to_currency(credit.amount)]
end
 
totals << [Prawn::Table::Cell.new( :text => "Order Total:", :font_style => :bold), number_to_currency(@order.total)]
 
bounding_box [bounds.right - 500, bounds.bottom + (totals.length * 15)], :width => 500 do
table totals,
:position => :right,
:border_width => 0,
:vertical_padding => 2,
:horizontal_padding => 6,
:font_size => 9,
:column_widths => { 0 => 425, 1 => 75 } ,
:align => { 0 => :right, 1 => :right }
 
end
 
move_down 2
 
stroke do
line_width 0.5
line bounds.top_left, bounds.top_right
line bounds.top_left, bounds.bottom_left
line bounds.top_right, bounds.bottom_right
line bounds.bottom_left, bounds.bottom_right
end
 
end
 
footer [margin_box.left, margin_box.bottom + 30] do
font "Helvetica", :size => 8
 
text "Shipping is not refundable. | Special orders are non-refundable."
text "In order to return a product prior authorization with a RMA number is mandatory"
text "All returned items must be in original un-opened packaging with seal intact."
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.