spree-print-invoice 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.hound.yml +3 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/CONTRIBUTING.md +30 -0
- data/Gemfile +5 -0
- data/Guardfile +9 -0
- data/LICENSE.md +26 -0
- data/README.md +48 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/admin/spree_print_invoice.js +1 -0
- data/app/assets/stylesheets/admin/spree_print_invoice.css +3 -0
- data/app/controllers/spree/admin/orders_controller_decorator.rb +18 -0
- data/app/controllers/spree/admin/print_invoice_settings_controller.rb +16 -0
- data/app/overrides/add_print_invoice_to_admin_configuration_sidebar.rb +6 -0
- data/app/overrides/layouts_admin_print_buttons_decorator.rb +6 -0
- data/app/views/spree/admin/orders/_print_buttons.html.erb +12 -0
- data/app/views/spree/admin/orders/invoice.pdf.prawn +155 -0
- data/app/views/spree/admin/orders/packaging_slip.pdf.prawn +128 -0
- data/app/views/spree/admin/print_invoice_settings/edit.html.erb +90 -0
- data/bin/rails +7 -0
- data/config/locales/de.yml +37 -0
- data/config/locales/en.yml +37 -0
- data/config/locales/es.yml +37 -0
- data/config/locales/fr.yml +37 -0
- data/config/locales/sv.yml +37 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20140123094547_add_invoice_details_to_spree_orders.rb +6 -0
- data/lib/generators/spree_print_invoice/install/install_generator.rb +19 -0
- data/lib/prawn_handler.rb +29 -0
- data/lib/spree/print_invoice_setting.rb +35 -0
- data/lib/spree_print_invoice.rb +13 -0
- data/lib/spree_print_invoice/engine.rb +29 -0
- data/lib/spree_print_invoice/version.rb +18 -0
- data/spec/features/spree/admin/print_invoice_setting_spec.rb +45 -0
- data/spec/features/spree/admin/print_invoice_spec.rb +60 -0
- data/spec/lib/prawn_handler_spec.rb +30 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/support/capybara.rb +17 -0
- data/spec/support/databse_cleaner.rb +18 -0
- data/spec/support/factory_girl.rb +5 -0
- data/spec/support/i18n.rb +13 -0
- data/spec/support/matchers/have_text_like.rb +8 -0
- data/spec/support/spree.rb +12 -0
- data/spec/support/test.pdf.prawn +2 -0
- data/spec/translations/locale_spec.rb +15 -0
- data/spree_print_invoice.gemspec +47 -0
- metadata +398 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
<%= render 'spree/admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<% content_for :page_title do %>
|
4
|
+
<%= Spree.t(:settings, scope: :print_invoice) %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<%= form_tag(admin_print_invoice_settings_path, method: :put) do %>
|
8
|
+
<fieldset class="no-border-top">
|
9
|
+
<div data-hook="admin_print_invoice_method_form_fields">
|
10
|
+
<div class="row">
|
11
|
+
<div class="alpha six columns" data-hook="pdf">
|
12
|
+
<fieldset class="no-border-bottom">
|
13
|
+
<legend align="center"><%= Spree.t(:pdf_legend, scope: :print_invoice) %></legend>
|
14
|
+
|
15
|
+
<div class="field">
|
16
|
+
<%= check_box_tag('preferences[use_footer]', Spree::PrintInvoice::Config[:use_footer], type: :boolean) %>
|
17
|
+
<%= label_tag Spree.t(:use_footer, scope: [:print_invoice, :preferences]) %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="field">
|
21
|
+
<%= check_box_tag('preferences[use_page_numbers]', Spree::PrintInvoice::Config[:use_page_numbers], type: :boolean) %>
|
22
|
+
<%= label_tag Spree.t(:use_page_numbers, scope: [:print_invoice, :preferences]) %>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="field">
|
26
|
+
<%= label_tag Spree.t(:print_logo_path, scope: [:print_invoice, :preferences]) %><br>
|
27
|
+
<%= text_field_tag('preferences[print_invoice_logo_path]', Spree::PrintInvoice::Config[:print_invoice_logo_path], class: 'fullwidth') %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="field">
|
31
|
+
<%= label_tag Spree.t(:print_buttons, scope: [:print_invoice, :preferences]) %><br>
|
32
|
+
<%= text_field_tag('preferences[print_buttons]', Spree::PrintInvoice::Config[:print_buttons], class: 'fullwidth') %>
|
33
|
+
<span class="info"><%= Spree.t(:print_buttons_info, scope: [:print_invoice, :preferences]) %></span>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="field">
|
37
|
+
<%= label_tag Spree.t(:print_invoice_next_number, scope: [:print_invoice, :preferences]) %><br>
|
38
|
+
<%= number_field_tag('preferences[print_invoice_next_number]', Spree::PrintInvoice::Config[:print_invoice_next_number], class: 'fullwidth') %>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div class="field">
|
42
|
+
<%= label_tag Spree.t(:page_size, scope: [:print_invoice, :preferences]) %><br>
|
43
|
+
<%= select_tag('preferences[page_size]', options_for_select(Spree::PrintInvoice::Config.page_sizes, Spree::PrintInvoice::Config[:page_size]), class: 'fullwidth select2') %>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div class="field">
|
47
|
+
<%= label_tag Spree.t(:page_layout, scope: [:print_invoice, :preferences]) %><br>
|
48
|
+
<%= select_tag('preferences[page_layout]', options_for_select(Spree::PrintInvoice::Config.page_layouts, Spree::PrintInvoice::Config[:page_layout]), class: 'fullwidth select2') %>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
</fieldset>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
<div class="six columns omega" data-hook="invoice">
|
55
|
+
<fieldset class="no-border-bottom">
|
56
|
+
<legend align="center"><%= Spree.t(:invoice_slip_legend, scope: :print_invoice) %></legend>
|
57
|
+
|
58
|
+
<div class="field">
|
59
|
+
<%= label_tag Spree.t(:footer_left, scope: [:print_invoice, :preferences]) %><br>
|
60
|
+
<%= text_area_tag('preferences[footer_left]', Spree::PrintInvoice::Config[:footer_left], class: 'fullwidth') %>
|
61
|
+
<span class="info"><%= Spree.t(:footer_left_info, scope: [:print_invoice, :preferences]) %></span>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<div class="field">
|
65
|
+
<%= label_tag Spree.t(:footer_right, scope: [:print_invoice, :preferences]) %><br>
|
66
|
+
<%= text_area_tag('preferences[footer_right]', Spree::PrintInvoice::Config[:footer_right], class: 'fullwidth') %>
|
67
|
+
<span class="info"><%= Spree.t(:footer_right_info, scope: [:print_invoice, :preferences]) %></span>
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<div class="field">
|
71
|
+
<%= label_tag Spree.t(:return_message, scope: [:print_invoice, :preferences]) %><br>
|
72
|
+
<%= text_area_tag('preferences[return_message]', Spree::PrintInvoice::Config[:return_message], class: 'fullwidth') %>
|
73
|
+
</div>
|
74
|
+
|
75
|
+
<div class="field">
|
76
|
+
<%= label_tag Spree.t(:anomaly_message, scope: [:print_invoice, :preferences]) %><br>
|
77
|
+
<%= text_area_tag('preferences[anomaly_message]', Spree::PrintInvoice::Config[:anomaly_message], class: 'fullwidth') %>
|
78
|
+
</div>
|
79
|
+
|
80
|
+
</fieldset>
|
81
|
+
</div>
|
82
|
+
</div>
|
83
|
+
|
84
|
+
<div class="form-buttons filter-actions actions" data-hook="buttons">
|
85
|
+
<%= button Spree.t('actions.update'), 'icon-refresh' %>
|
86
|
+
</div>
|
87
|
+
|
88
|
+
</div>
|
89
|
+
</fieldset>
|
90
|
+
<% end %>
|
data/bin/rails
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
de:
|
3
|
+
spree:
|
4
|
+
print_invoice:
|
5
|
+
buttons:
|
6
|
+
invoice: Rechnung drucken
|
7
|
+
packaging_slip: Warenbegleitschein drucken
|
8
|
+
invoice: Kundenrechnung
|
9
|
+
item_name: Item Name or SKU
|
10
|
+
of: of
|
11
|
+
via: via
|
12
|
+
on_date: Order Date
|
13
|
+
packaging_slip: Packzettel drucken
|
14
|
+
page: Page
|
15
|
+
payment_via: "%{gateway} Online Payment #%{number} on %{date}"
|
16
|
+
preferences:
|
17
|
+
print_invoice_next_number: Print Invoice Next Number
|
18
|
+
use_footer: Use Footer
|
19
|
+
use_page_numbers: Use Page Numbers
|
20
|
+
anomaly_message: Order Anomaly Message
|
21
|
+
footer_left: Left footer content
|
22
|
+
footer_left_info: E.g. Your company name and address.
|
23
|
+
footer_right: Right footer content
|
24
|
+
footer_right_info: E.g. Your phone and email address.
|
25
|
+
page_layout: Page Layout
|
26
|
+
page_size: Page Size
|
27
|
+
print_buttons: Print Buttons
|
28
|
+
print_buttons_info: Comma separated list.
|
29
|
+
print_logo_path: Print Invoice Logo Path
|
30
|
+
return_message: Order Return Message
|
31
|
+
settings: Print Invoice Settings
|
32
|
+
unprocessed: Unprocessed
|
33
|
+
vat: VAT not applicable
|
34
|
+
pdf_legend: PDF
|
35
|
+
invoice_slip_legend: Invoice / Slip
|
36
|
+
invoice_number: 'Rechnungsnummer %{number}'
|
37
|
+
invoice_date: Rechnungsdatum
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
spree:
|
4
|
+
print_invoice:
|
5
|
+
buttons:
|
6
|
+
invoice: Print Invoice
|
7
|
+
packaging_slip: Print Slip
|
8
|
+
invoice: Customer Invoice
|
9
|
+
item_name: Item Name or SKU
|
10
|
+
of: of
|
11
|
+
via: via
|
12
|
+
on_date: Order Date
|
13
|
+
packaging_slip: Packaging Slip
|
14
|
+
page: Page
|
15
|
+
payment_via: "%{gateway} Online Payment #%{number} on %{date}"
|
16
|
+
preferences:
|
17
|
+
print_invoice_next_number: Print Invoice Next Number
|
18
|
+
use_footer: Use Footer
|
19
|
+
use_page_numbers: Use Page Numbers
|
20
|
+
anomaly_message: Order Anomaly Message
|
21
|
+
footer_left: Left footer content
|
22
|
+
footer_left_info: E.g. Your company name and address.
|
23
|
+
footer_right: Right footer content
|
24
|
+
footer_right_info: E.g. Your phone and email address.
|
25
|
+
page_layout: Page Layout
|
26
|
+
page_size: Page Size
|
27
|
+
print_buttons: Print Buttons
|
28
|
+
print_buttons_info: Comma separated list.
|
29
|
+
print_logo_path: Print Invoice Logo Path
|
30
|
+
return_message: Order Return Message
|
31
|
+
settings: Print Invoice Settings
|
32
|
+
unprocessed: Unprocessed
|
33
|
+
vat: VAT not applicable
|
34
|
+
pdf_legend: PDF
|
35
|
+
invoice_slip_legend: Invoice / Slip
|
36
|
+
invoice_number: 'Invoice Number %{number}'
|
37
|
+
invoice_date: Invoice Date
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
es:
|
3
|
+
spree:
|
4
|
+
print_invoice:
|
5
|
+
buttons:
|
6
|
+
invoice: Imprimir Factura
|
7
|
+
packaging_slip: Imprimir Recibo para el Embalaje
|
8
|
+
invoice: Factura del cliente
|
9
|
+
item_name: Item Name or SKU
|
10
|
+
of: of
|
11
|
+
via: via
|
12
|
+
on_date: Order Date
|
13
|
+
packaging_slip: Recibo para el Embalaje
|
14
|
+
page: Page
|
15
|
+
payment_via: "%{gateway} Online Payment #%{number} on %{date}"
|
16
|
+
preferences:
|
17
|
+
print_invoice_next_number: Print Invoice Next Number
|
18
|
+
use_footer: Use Footer
|
19
|
+
use_page_numbers: Use Page Numbers
|
20
|
+
anomaly_message: Order Anomaly Message
|
21
|
+
footer_left: Left footer content
|
22
|
+
footer_left_info: E.g. Your company name and address.
|
23
|
+
footer_right: Right footer content
|
24
|
+
footer_right_info: E.g. Your phone and email address.
|
25
|
+
page_layout: Page Layout
|
26
|
+
page_size: Page Size
|
27
|
+
print_buttons: Print Buttons
|
28
|
+
print_buttons_info: Comma separated list.
|
29
|
+
print_logo_path: Print Invoice Logo Path
|
30
|
+
return_message: Order Return Message
|
31
|
+
settings: Print Invoice Settings
|
32
|
+
unprocessed: Unprocessed
|
33
|
+
vat: VAT not applicable
|
34
|
+
pdf_legend: PDF
|
35
|
+
invoice_slip_legend: Invoice / Slip
|
36
|
+
invoice_number: 'Invoice Number %{number}'
|
37
|
+
invoice_date: Invoice Date
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
fr:
|
3
|
+
spree:
|
4
|
+
print_invoice:
|
5
|
+
buttons:
|
6
|
+
invoice: Imprimer Facture
|
7
|
+
packaging_slip: Imprimer Bordereau de Livraison
|
8
|
+
invoice: Facture
|
9
|
+
item_name: Nom ou Reference Article
|
10
|
+
of: de
|
11
|
+
via: via
|
12
|
+
on_date: Date de commande
|
13
|
+
packaging_slip: Bordereau de Livraison
|
14
|
+
page: Page
|
15
|
+
payment_via: "Payé en ligne le %{date} via %{gateway} - %{number}"
|
16
|
+
preferences:
|
17
|
+
print_invoice_next_number: Imprimer la facture prochain numéro
|
18
|
+
use_footer: Utilisez le pied de page
|
19
|
+
use_page_numbers: Utilisez des numéros de page
|
20
|
+
anomaly_message: Message d'anomalie
|
21
|
+
footer_left: Contenu pied de gauche
|
22
|
+
footer_left_info: Par exemple Votre nom et adresse d'entreprise.
|
23
|
+
footer_right: Contenu pied de droit
|
24
|
+
footer_right_info: Par exemple Votre téléphone et votre adresse e-mail.
|
25
|
+
page_layout: La mise en page
|
26
|
+
page_size: Taille de la page
|
27
|
+
print_buttons: Boutons Imprimer
|
28
|
+
print_buttons_info: Séparés par des virgules.
|
29
|
+
print_logo_path: Chemin de logo
|
30
|
+
return_message: Message de retour
|
31
|
+
settings: Les paramètres d'impression des factures
|
32
|
+
unprocessed: Non traité
|
33
|
+
vat: "TVA non applicable, article 293 B du Code Général des Impôts"
|
34
|
+
pdf_legend: PDF
|
35
|
+
invoice_slip_legend: Facture / Slip
|
36
|
+
invoice_number: 'Numéro de facture %{number}'
|
37
|
+
invoice_date: Date de la facture
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
sv:
|
3
|
+
spree:
|
4
|
+
print_invoice:
|
5
|
+
buttons:
|
6
|
+
invoice: Skriv ut faktura
|
7
|
+
packaging_slip: Skriv ut följesedel
|
8
|
+
invoice: Kundfaktura
|
9
|
+
item_name: Artikelnamn eller SKU
|
10
|
+
of: av
|
11
|
+
via: via
|
12
|
+
on_date: Order datum
|
13
|
+
packaging_slip: Följesedel
|
14
|
+
page: Sida
|
15
|
+
payment_via: "%{gateway} betalning #%{number} den %{date}"
|
16
|
+
preferences:
|
17
|
+
print_invoice_next_number: Skriv ut faktura nästa nummer
|
18
|
+
use_footer: Använd sidfot
|
19
|
+
use_page_numbers: Använd sidnummer
|
20
|
+
anomaly_message: Avvikelse meddelande
|
21
|
+
footer_left: Vänster sidfot
|
22
|
+
footer_left_info: T.ex. Ditt företagsnamn och adress.
|
23
|
+
footer_right: Höger sidfot
|
24
|
+
footer_right_info: T.ex. Din telefon och e-postadress.
|
25
|
+
page_layout: Sidolayout
|
26
|
+
page_size: Pappers format
|
27
|
+
print_buttons: Utskriftsknappar
|
28
|
+
print_buttons_info: Kommaseparerad lista.
|
29
|
+
print_logo_path: Sökväg för logotyp
|
30
|
+
return_message: Returmeddelande
|
31
|
+
settings: Utskrift inställningar
|
32
|
+
unprocessed: Obearbetad
|
33
|
+
vat: Moms inte tillämpligt
|
34
|
+
pdf_legend: PDF
|
35
|
+
invoice_slip_legend: Faktura / följesedel
|
36
|
+
invoice_number: 'Faktura Nummer %{number}'
|
37
|
+
invoice_date: Faktura Datum
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module SpreePrintInvoice
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: true
|
5
|
+
|
6
|
+
def add_migrations
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_print_invoice'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_migrations
|
11
|
+
if options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask "Would you like to run the migrations now? [Y/n]")
|
12
|
+
run 'bundle exec rake db:migrate'
|
13
|
+
else
|
14
|
+
puts "Skiping rake db:migrate, don't forget to run it!"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -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,35 @@
|
|
1
|
+
module Spree
|
2
|
+
class PrintInvoiceSetting < Preferences::Configuration
|
3
|
+
preference :print_invoice_next_number, :integer, default: nil
|
4
|
+
preference :print_invoice_logo_path, :string, default: Spree::Config[:admin_interface_logo]
|
5
|
+
preference :print_buttons, :string, default: 'invoice,packaging_slip'
|
6
|
+
|
7
|
+
preference :page_size, :string, default: 'LETTER'
|
8
|
+
preference :page_layout, :string, default: 'landscape'
|
9
|
+
preference :footer_left, :string, default: ''
|
10
|
+
preference :footer_right, :string, default: ''
|
11
|
+
preference :return_message, :text, default: ''
|
12
|
+
preference :anomaly_message, :text, default: ''
|
13
|
+
|
14
|
+
preference :use_footer, :boolean, default: false
|
15
|
+
preference :use_page_numbers, :boolean, default: false
|
16
|
+
|
17
|
+
def page_sizes
|
18
|
+
::PDF::Core::PageGeometry::SIZES.keys
|
19
|
+
end
|
20
|
+
|
21
|
+
def page_layouts
|
22
|
+
%w(landscape portrait)
|
23
|
+
end
|
24
|
+
|
25
|
+
def use_sequential_number?
|
26
|
+
print_invoice_next_number.present? && print_invoice_next_number > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def increase_invoice_number
|
30
|
+
current_invoice_number = print_invoice_next_number
|
31
|
+
set_preference(:print_invoice_next_number, current_invoice_number + 1)
|
32
|
+
current_invoice_number
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_print_invoice/engine'
|
3
|
+
require 'spree_print_invoice/version'
|
4
|
+
require 'prawn_handler'
|
5
|
+
require 'coffee_script'
|
6
|
+
|
7
|
+
module Spree
|
8
|
+
module PrintInvoice
|
9
|
+
def self.config(&block)
|
10
|
+
yield(Spree::PrintInvoice::Config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SpreePrintInvoice
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_print_invoice'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
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
|
+
initializer 'spree.print_invoice.environment', before: :load_config_initializers do |app|
|
14
|
+
Spree::PrintInvoice::Config = Spree::PrintInvoiceSetting.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.activate
|
18
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
19
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
20
|
+
end
|
21
|
+
|
22
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/overrides/*.rb')) do |c|
|
23
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
config.to_prepare &method(:activate).to_proc
|
28
|
+
end
|
29
|
+
end
|