spree_print_invoice 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +48 -0
- data/app/controllers/spree/admin/orders_controller_decorator.rb +13 -0
- data/app/models/spree/print_invoice_configuration.rb +6 -0
- data/app/overrides/layouts_admin_print_buttons_decorator.rb +5 -0
- data/app/views/spree/admin/orders/_address.pdf.prawn +61 -0
- data/app/views/spree/admin/orders/_bye.pdf.prawn +6 -0
- data/app/views/spree/admin/orders/_footer.pdf.prawn +13 -0
- data/app/views/spree/admin/orders/_header.pdf.prawn +8 -0
- data/app/views/spree/admin/orders/_line_items_box.pdf.prawn +67 -0
- data/app/views/spree/admin/orders/_print.pdf.prawn +35 -0
- data/app/views/spree/admin/orders/_print_buttons.html.erb +7 -0
- data/app/views/spree/admin/orders/_totals.pdf.prawn +21 -0
- data/app/views/spree/admin/orders/invoice.pdf.prawn +2 -0
- data/app/views/spree/admin/orders/packaging_slip.pdf.prawn +3 -0
- data/config/routes.rb +11 -0
- data/lib/prawn_handler.rb +29 -0
- data/lib/spree_print_invoice.rb +10 -0
- data/lib/spree_print_invoice/engine.rb +25 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6226ae4203203a3712b04b61f5aad9788404788a
|
4
|
+
data.tar.gz: 220792d7059a2ea3da797614f80cbb7318efd6ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 237a2fb90f15da99d6e0278d0e3bd4a1ecee52cd2abca1f67bd6d282cba00bb4e16a9173b7b06e80347bd7525556e23779099e8bd21c32e3b55e6eefecd496d3
|
7
|
+
data.tar.gz: 1227d4ae8e10d3b3a00ec90a97ad8dd4628b47a2e303c591ce5641dd8a2f42df041e698e27ef64364ac50077a8df5edc3bba268c0b6e2688da245eba689a34aa
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
SUMMARY
|
2
|
+
=======
|
3
|
+
|
4
|
+
*This is just a fork of spree/spree_print_invoice. There are no modifications apart from setting the version so I could push it to rubygems.
|
5
|
+
|
6
|
+
This extension provides a "Print Invoice" button on the Admin Orders view screen which generates a PDF of the order details.
|
7
|
+
|
8
|
+
|
9
|
+
INSTALLATION
|
10
|
+
============
|
11
|
+
|
12
|
+
1. The gem relies only on the prawn gem, to install you need to add the following lines to your Gemfile
|
13
|
+
|
14
|
+
gem 'spree_print_invoice' , :git => 'git://github.com/spree/spree_print_invoice.git'
|
15
|
+
|
16
|
+
2. run bundler
|
17
|
+
|
18
|
+
bundle install
|
19
|
+
|
20
|
+
3. Enjoy! now displays the items variant options
|
21
|
+
|
22
|
+
Configuration
|
23
|
+
==============
|
24
|
+
|
25
|
+
1. Set the logo path preference to include your store / company logo.
|
26
|
+
|
27
|
+
Spree::PrintInvoice::Config.set(:print_invoice_logo_path => "/path/to/public/images/company-logo.png")
|
28
|
+
|
29
|
+
2. Add your own own footer texts to the locale. The current footer works with :footer_left1 , :footer_left2 and :footer_right1, :footer_right2 where the 1 version is on the left in bold, and the 2 version the "value" on the right.
|
30
|
+
|
31
|
+
3. Override any of the partial templates. they are address, footer, totals, header, bye , and the line_items. In bye the text :thanks is printed. The :extra_note hook has been deprecated as Spree no longer supports hooks.
|
32
|
+
|
33
|
+
4. Set :suppress_anonymous_address option to get blank addresses for anonymous email addresses (as created by my spree_last_address extension for empty/unknown user info)
|
34
|
+
|
35
|
+
5. Enable packaging slips, by setting
|
36
|
+
|
37
|
+
Spree::PrintInvoice::Config.set(:print_buttons => "invoice,packaging_slip") #comma separated list
|
38
|
+
|
39
|
+
Use above feature for your own template if you want. For each button_name, define button_name_print text in your locale.
|
40
|
+
|
41
|
+
Plans
|
42
|
+
=====
|
43
|
+
Next receipts and then product related stuff with barcodes.
|
44
|
+
|
45
|
+
|
46
|
+
Contributions welcome
|
47
|
+
|
48
|
+
Torsten
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Spree::Admin::OrdersController.class_eval do
|
2
|
+
respond_to :pdf
|
3
|
+
|
4
|
+
def show
|
5
|
+
load_order
|
6
|
+
respond_with(@order) do |format|
|
7
|
+
format.pdf do
|
8
|
+
template = params[:template] || "invoice"
|
9
|
+
render :layout => false , :template => "spree/admin/orders/#{template}.pdf.prawn"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Address Stuff
|
2
|
+
|
3
|
+
bill_address = @order.bill_address
|
4
|
+
ship_address = @order.ship_address
|
5
|
+
anonymous = @order.email =~ /@example.net$/
|
6
|
+
|
7
|
+
|
8
|
+
bounding_box [0,600], :width => 540 do
|
9
|
+
move_down 2
|
10
|
+
data = [[Prawn::Table::Cell.new( :text => Spree.t(:billing_address), :font_style => :bold ),
|
11
|
+
Prawn::Table::Cell.new( :text => Spree.t(:shipping_address), :font_style => :bold )]]
|
12
|
+
|
13
|
+
table data,
|
14
|
+
:position => :center,
|
15
|
+
:border_width => 0.5,
|
16
|
+
:vertical_padding => 2,
|
17
|
+
:horizontal_padding => 6,
|
18
|
+
:font_size => 9,
|
19
|
+
:border_style => :underline_header,
|
20
|
+
:column_widths => { 0 => 270, 1 => 270 }
|
21
|
+
|
22
|
+
move_down 2
|
23
|
+
horizontal_rule
|
24
|
+
|
25
|
+
bounding_box [0,0], :width => 540 do
|
26
|
+
move_down 2
|
27
|
+
if anonymous and Spree::Config[:suppress_anonymous_address]
|
28
|
+
data2 = [[" "," "]] * 6
|
29
|
+
else
|
30
|
+
data2 = [["#{bill_address.firstname} #{bill_address.lastname}", "#{ship_address.firstname} #{ship_address.lastname}"],
|
31
|
+
[bill_address.address1, ship_address.address1]]
|
32
|
+
data2 << [bill_address.address2, ship_address.address2] unless
|
33
|
+
bill_address.address2.blank? and ship_address.address2.blank?
|
34
|
+
data2 << ["#{@order.bill_address.zipcode} #{@order.bill_address.city} #{(@order.bill_address.state ? @order.bill_address.state.abbr : "")} ",
|
35
|
+
"#{@order.ship_address.zipcode} #{@order.ship_address.city} #{(@order.ship_address.state ? @order.ship_address.state.abbr : "")}"]
|
36
|
+
data2 << [bill_address.country.name, ship_address.country.name]
|
37
|
+
data2 << [bill_address.phone, ship_address.phone]
|
38
|
+
shipping_method_name = @order.shipments.map{|sh| sh.shipping_method.try(:name)}.compact.uniq.join(', ')
|
39
|
+
data2 << [shipping_method_name, shipping_method_name]
|
40
|
+
end
|
41
|
+
|
42
|
+
table data2,
|
43
|
+
:position => :center,
|
44
|
+
:border_width => 0.0,
|
45
|
+
:vertical_padding => 0,
|
46
|
+
:horizontal_padding => 6,
|
47
|
+
:font_size => 9,
|
48
|
+
:column_widths => { 0 => 270, 1 => 270 }
|
49
|
+
end
|
50
|
+
|
51
|
+
move_down 2
|
52
|
+
|
53
|
+
stroke do
|
54
|
+
line_width 0.5
|
55
|
+
line bounds.top_left, bounds.top_right
|
56
|
+
line bounds.top_left, bounds.bottom_left
|
57
|
+
line bounds.top_right, bounds.bottom_right
|
58
|
+
line bounds.bottom_left, bounds.bottom_right
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# To get a simple text, use the line below with your own footer_message
|
2
|
+
# text_box footer_message, :at => [margin_box.left -10, margin_box.bottom + 40], :size => 8 , :position => :left
|
3
|
+
|
4
|
+
repeat :all do
|
5
|
+
table [[Prawn::Table::Cell.new( :text => Spree.t(:footer_left), :font_style => :bold ),
|
6
|
+
Prawn::Table::Cell.new( :text => Spree.t(:footer_left2)),
|
7
|
+
Prawn::Table::Cell.new( :text => Spree.t(:footer_right), :font_style => :bold ),
|
8
|
+
Prawn::Table::Cell.new( :text => Spree.t(:footer_right2))]],
|
9
|
+
:border_width => 0,
|
10
|
+
:vertical_padding => 2,
|
11
|
+
:font_size => 9,
|
12
|
+
:column_widths => { 0 => 80, 1 => 190, 2 => 75, 3 => 190 }
|
13
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
if @hide_prices
|
2
|
+
@column_widths = { 0 => 100, 1 => 165, 2 => 75, 3 => 75 }
|
3
|
+
@align = { 0 => :left, 1 => :left, 2 => :right, 3 => :right }
|
4
|
+
else
|
5
|
+
@column_widths = { 0 => 75, 1 => 205, 2 => 75, 3 => 50, 4 => 75, 5 => 60 }
|
6
|
+
@align = { 0 => :left, 1 => :left, 2 => :left, 3 => :right, 4 => :right, 5 => :right}
|
7
|
+
end
|
8
|
+
|
9
|
+
# Line Items
|
10
|
+
bounding_box [0,cursor], :width => 540, :height => 430 do
|
11
|
+
move_down 2
|
12
|
+
header = [Prawn::Table::Cell.new( :text => Spree.t(:sku), :font_style => :bold),
|
13
|
+
Prawn::Table::Cell.new( :text => Spree.t(:item_description), :font_style => :bold ) ]
|
14
|
+
header << Prawn::Table::Cell.new( :text => Spree.t(:options), :font_style => :bold )
|
15
|
+
header << Prawn::Table::Cell.new( :text => Spree.t(:price), :font_style => :bold ) unless @hide_prices
|
16
|
+
header << Prawn::Table::Cell.new( :text => Spree.t(:qty), :font_style => :bold, :align => 1 )
|
17
|
+
header << Prawn::Table::Cell.new( :text => Spree.t(:total), :font_style => :bold ) unless @hide_prices
|
18
|
+
|
19
|
+
table [header],
|
20
|
+
:position => :center,
|
21
|
+
:border_width => 1,
|
22
|
+
:vertical_padding => 2,
|
23
|
+
:horizontal_padding => 6,
|
24
|
+
:font_size => 9,
|
25
|
+
:column_widths => @column_widths ,
|
26
|
+
:align => @align
|
27
|
+
|
28
|
+
move_down 4
|
29
|
+
|
30
|
+
bounding_box [0,cursor], :width => 540 do
|
31
|
+
move_down 2
|
32
|
+
content = []
|
33
|
+
@order.line_items.each do |item|
|
34
|
+
row = [ item.variant.product.sku, item.variant.product.name]
|
35
|
+
row << item.variant.option_values.map {|ov| "#{ov.option_type.presentation}: #{ov.presentation}"}.concat(item.respond_to?('ad_hoc_option_values') ? item.ad_hoc_option_values.map {|pov| "#{pov.option_value.option_type.presentation}: #{pov.option_value.presentation}"} : []).join(', ')
|
36
|
+
row << item.single_display_amount.to_s unless @hide_prices
|
37
|
+
row << item.quantity
|
38
|
+
row << item.display_total.to_s unless @hide_prices
|
39
|
+
content << row
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
table content,
|
44
|
+
:position => :center,
|
45
|
+
:border_width => 0.5,
|
46
|
+
:vertical_padding => 5,
|
47
|
+
:horizontal_padding => 6,
|
48
|
+
:font_size => 9,
|
49
|
+
:column_widths => @column_widths ,
|
50
|
+
:align => @align
|
51
|
+
end
|
52
|
+
|
53
|
+
font "Helvetica", :size => 9
|
54
|
+
|
55
|
+
render :partial => "totals" unless @hide_prices
|
56
|
+
|
57
|
+
move_down 2
|
58
|
+
|
59
|
+
stroke do
|
60
|
+
line_width 0.5
|
61
|
+
line bounds.top_left, bounds.top_right
|
62
|
+
line bounds.top_left, bounds.bottom_left
|
63
|
+
line bounds.top_right, bounds.bottom_right
|
64
|
+
line bounds.bottom_left, bounds.bottom_right
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'prawn/layout'
|
2
|
+
|
3
|
+
font "Helvetica"
|
4
|
+
|
5
|
+
im = Rails.application.assets.find_asset(Spree::PrintInvoice::Config[:print_invoice_logo_path])
|
6
|
+
image im , :at => [0,720] #, :scale => 0.35
|
7
|
+
|
8
|
+
fill_color "E99323"
|
9
|
+
if @hide_prices
|
10
|
+
text Spree.t(:packaging_slip), :align => :right, :style => :bold, :size => 18
|
11
|
+
else
|
12
|
+
text Spree.t(:customer_invoice), :align => :right, :style => :bold, :size => 18
|
13
|
+
end
|
14
|
+
fill_color "000000"
|
15
|
+
|
16
|
+
move_down 4
|
17
|
+
|
18
|
+
font "Helvetica", :size => 9, :style => :bold
|
19
|
+
text "#{Spree.t(:order_number)} #{@order.number}", :align => :right
|
20
|
+
|
21
|
+
move_down 2
|
22
|
+
font "Helvetica", :size => 9
|
23
|
+
text "#{I18n.l @order.completed_at.to_date}", :align => :right
|
24
|
+
|
25
|
+
|
26
|
+
render :partial => "address"
|
27
|
+
|
28
|
+
move_down 30
|
29
|
+
|
30
|
+
render :partial => "line_items_box"
|
31
|
+
|
32
|
+
move_down 8
|
33
|
+
|
34
|
+
# Footer
|
35
|
+
# render :partial => "footer"
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<% if @order and @order.completed_at? %>
|
2
|
+
<% buttons = Spree::PrintInvoice::Config[:print_buttons]
|
3
|
+
buttons = buttons.split(",").collect{|b| b.strip } %>
|
4
|
+
<% buttons.each do |button| %>
|
5
|
+
<li><%= link_to(Spree.t(button.to_s + "_print"), spree.admin_order_path(@order, :pdf , :template => button), :class => "button icon-print") %></li>
|
6
|
+
<% end %>
|
7
|
+
<% end %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
totals = []
|
2
|
+
|
3
|
+
totals << [Prawn::Table::Cell.new( :text => Spree.t(:subtotal), :font_style => :bold), @order.display_item_total.to_s]
|
4
|
+
|
5
|
+
@order.adjustments.each do |charge|
|
6
|
+
totals << [Prawn::Table::Cell.new( :text => charge.label + ":", :font_style => :bold), charge.display_amount.to_s]
|
7
|
+
end
|
8
|
+
|
9
|
+
totals << [Prawn::Table::Cell.new( :text => Spree.t(:order_total), :font_style => :bold), @order.display_total.to_s]
|
10
|
+
|
11
|
+
bounding_box [bounds.right - 500, bounds.bottom + (totals.length * 18)], :width => 500 do
|
12
|
+
table totals,
|
13
|
+
:position => :right,
|
14
|
+
:border_width => 0,
|
15
|
+
:vertical_padding => 2,
|
16
|
+
:horizontal_padding => 6,
|
17
|
+
:font_size => 9,
|
18
|
+
:column_widths => { 0 => 425, 1 => 75 } ,
|
19
|
+
:align => { 0 => :right, 1 => :right }
|
20
|
+
|
21
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Template::Handlers
|
5
|
+
class Prawn
|
6
|
+
def self.register!
|
7
|
+
Template.register_template_handler :prawn, self
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.call(template)
|
11
|
+
%(extend #{DocumentProxy}; #{template.source}; pdf.render)
|
12
|
+
end
|
13
|
+
|
14
|
+
module DocumentProxy
|
15
|
+
def pdf
|
16
|
+
@pdf ||= ::Prawn::Document.new
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def method_missing(method, *args, &block)
|
22
|
+
pdf.respond_to?(method) ? pdf.send(method, *args, &block) : super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActionView::Template::Handlers::Prawn.register!
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SpreePrintInvoice
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
engine_name 'spree_print_invoice'
|
4
|
+
|
5
|
+
initializer "spree.print_invoice.environment", :before => :load_config_initializers do |app|
|
6
|
+
Spree::PrintInvoice::Config = Spree::PrintInvoiceConfiguration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer "spree.print_invoice.mimetypes" do |app|
|
10
|
+
Mime::Type.register('application/pdf', :pdf) unless Mime::Type.lookup_by_extension(:pdf)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.activate
|
14
|
+
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
|
16
|
+
Rails.application.config.cache_classes ? require(c) : load(c)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
22
|
+
config.to_prepare &method(:activate).to_proc
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_print_invoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spree Community
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: prawn
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: spree_core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- README.md
|
48
|
+
- lib/prawn_handler.rb
|
49
|
+
- lib/spree_print_invoice/engine.rb
|
50
|
+
- lib/spree_print_invoice.rb
|
51
|
+
- app/controllers/spree/admin/orders_controller_decorator.rb
|
52
|
+
- app/models/spree/print_invoice_configuration.rb
|
53
|
+
- app/overrides/layouts_admin_print_buttons_decorator.rb
|
54
|
+
- app/views/spree/admin/orders/_address.pdf.prawn
|
55
|
+
- app/views/spree/admin/orders/_bye.pdf.prawn
|
56
|
+
- app/views/spree/admin/orders/_footer.pdf.prawn
|
57
|
+
- app/views/spree/admin/orders/_header.pdf.prawn
|
58
|
+
- app/views/spree/admin/orders/_line_items_box.pdf.prawn
|
59
|
+
- app/views/spree/admin/orders/_print.pdf.prawn
|
60
|
+
- app/views/spree/admin/orders/_print_buttons.html.erb
|
61
|
+
- app/views/spree/admin/orders/_totals.pdf.prawn
|
62
|
+
- app/views/spree/admin/orders/invoice.pdf.prawn
|
63
|
+
- app/views/spree/admin/orders/packaging_slip.pdf.prawn
|
64
|
+
- config/routes.rb
|
65
|
+
homepage: https://github.com/spree/spree_print_invoice
|
66
|
+
licenses: []
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.7
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements:
|
83
|
+
- none
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.1.11
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Print invoices from a spree order
|
89
|
+
test_files: []
|