-
-
Save joemsak/46b694b387a0f8650dc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
class PackingSlip < Prawn::Document | |
def initialize(order, view) | |
super(:page_layout => :portrait) | |
@order = order | |
@view = view | |
define_grid(:columns => 3, :rows => 5, :gutter => 5) | |
default_leading 5 | |
font_size(10) do | |
grid(0, 0).bounding_box { logo } | |
grid(1, 0).bounding_box { url } | |
grid(0, 2).bounding_box { shipping_address } | |
grid(2, 2).bounding_box { billing_address } | |
grid([2, 0], [2, 1]).bounding_box { receipt_info } | |
grid([3, 0], [3, 2]).bounding_box { order_table } | |
grid([4, 0], [4, 2]).bounding_box { signoff } | |
end | |
end | |
def logo | |
image "#{Rails.root}/app/assets/images/CLIENT-200x161.png", :align => :center | |
end | |
def url | |
text "www.CLIENT.com", :align => :center | |
end | |
def billing_address | |
text "Billed to:", :style => :bold | |
text @order.view_billing_name | |
text @order.bill_address.address1 | |
text @order.bill_address.address2 | |
text @order.view_billing_region | |
text @order.bill_address.country.name | |
end | |
def shipping_address | |
text "Shipped to:", :style => :bold | |
text @order.view_shipping_name | |
text @order.ship_address.address1 | |
text @order.ship_address.address2 | |
text @order.view_shipping_region | |
text @order.ship_address.country.name | |
end | |
def receipt_info | |
text "Receipt for your order placed #{@order.placed_on}" | |
text @order.view_number | |
end | |
def order_table | |
rows = [header_row] | |
@order.line_items.each { |item| rows << item_row(item) } | |
rows << shipping_row | |
rows << order_total_row | |
table(rows) | |
end | |
def signoff | |
text "Thank you very much for your order!" | |
move_down 10 | |
text "This delivery completes your purchase. If you change your mind, you can return it within 14 calendar days of delivery without stating of reasons. All products must be in the original state and sealed, we cannot accept any opened goods. If your goods arrive damaged—or if you are otherwise unsatisfied with your order—please let us know: info@CLIENT.com." | |
end | |
private | |
def header_row | |
[['Quantity', {}], | |
['Article', { :width => 300 }], | |
['Price per unit €', {}], | |
['Total price €', {}]].map do |content, options| | |
{ :content => content, | |
:borders => [:top, :bottom], | |
:border_widths => [1, 0, 1, 0] | |
}.merge(options) | |
end | |
end | |
def item_row(item) | |
[[item.quantity, {}], | |
[item.product.name, {}], | |
[sprintf("%.2f", item.price), { :align => :right }], | |
[sprintf("%.2f", item.total), { :align => :right }]].map do |content, options| | |
{ :content => content.to_s, | |
:borders => [] | |
}.merge(options) | |
end | |
end | |
def shipping_row | |
[["1", {}], | |
["Shipping & Handling", {}], | |
["0.00", { :align => :right }], | |
["0.00", { :align => :right }]].map do |content, options| | |
{ :content => content, :borders => [] }.merge(options) | |
end | |
end | |
def order_total_row | |
[{ :content => "Total: #{sprintf("%.2f", @order.amount)}", | |
:colspan => 4, | |
:borders => [], | |
:align => :right }] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment