Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class BookkeepingDocumentsController < ResourceController
def show
respond_with(@bookkeeping_document) do |format|
format.pdf do
send_data @bookkeeping_document.pdf, type: 'application/pdf', disposition: 'inline'
send_data @bookkeeping_document.pdf,
type: 'application/pdf',
disposition: 'inline',
filename: pdf_filename
end
end
end
Expand Down Expand Up @@ -39,6 +42,10 @@ def order_focused?
def load_order
@order = Spree::Order.find_by(number: params[:order_id])
end

def pdf_filename
"#{@bookkeeping_document.template}_#{@bookkeeping_document.number}_#{@bookkeeping_document.printable.bill_address.firstname}_#{@bookkeeping_document.printable.completed_at.to_i}.pdf"
end
end
end
end
7 changes: 6 additions & 1 deletion app/models/spree/bookkeeping_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class BookkeepingDocument < ActiveRecord::Base
:number
]

def self.ransackable_attributes(auth_object = nil)
["created_at", "email", "firstname", "id", "id_value", "lastname", "number", "printable_id", "printable_type", "template", "total", "updated_at"]
end

# Spree::BookkeepingDocument cares about creating PDFs. Whenever it needs to know
# anything about the document to send to the view, it asks a view object.
#
Expand Down Expand Up @@ -108,7 +112,8 @@ def storage_path
#
def render_pdf
ApplicationController.render(
template: "#{template_name}.pdf.prawn",
template: template_name,
formats: [:pdf],
assigns: { doc: self }
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module SpreePrintInvoice
module Admin
module MainMenu
class PrintInvoiceBuilder
include ::Spree::Core::Engine.routes.url_helpers

def build
items = [
::Spree::Admin::MainMenu::ItemBuilder.new('invoices', ::Spree::Core::Engine.routes.url_helpers.admin_bookkeeping_documents_path(q: { template_eq: 'invoice' })).
with_label_translation_key('admin.tab.invoices').
with_manage_ability_check(::Spree::BookkeepingDocument).
with_match_path('/bookkeeping_documents?q%5Btemplate_eq%5D=invoice').
build,
::Spree::Admin::MainMenu::ItemBuilder.new('packaging_slips', ::Spree::Core::Engine.routes.url_helpers.admin_bookkeeping_documents_path(q: { template_eq: 'packaging_slip' })).
with_label_translation_key('admin.tab.packaging_slips').
with_manage_ability_check(::Spree::BookkeepingDocument).
with_match_path('/bookkeeping_documents?q%5Btemplate_eq%5D=packaging_slip').
build
]

::Spree::Admin::MainMenu::SectionBuilder.new('documents', 'file.svg').
with_manage_ability_check(::Spree::BookkeepingDocument).
with_label_translation_key('admin.documents').
with_items(items).
build
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Spree
module SpreePrintInvoice
module OrderDecorator
def self.prepended(base)
base.has_many :bookkeeping_documents, as: :printable, dependent: :destroy
Expand Down Expand Up @@ -42,9 +42,11 @@ def pdf_storage_path(template)
end

def invoice_for_order
return if bookkeeping_documents.exists?(template: 'invoice') && bookkeeping_documents.exists?(template: 'packaging_slip')
bookkeeping_documents.create(template: 'invoice')
bookkeeping_documents.create(template: 'packaging_slip')
end
end
end
::Spree::Order.prepend Spree::OrderDecorator

::Spree::Order.prepend SpreePrintInvoice::OrderDecorator
17 changes: 0 additions & 17 deletions app/overrides/add_documents_to_main_navigation.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/overrides/add_print_invoice_links_to_admin_order_tabs.rb

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/spree/admin/shared/menu/_documents_tab.html.erb

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/spree/printables/shared/_header.pdf.prawn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
im = (Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application)).find_asset(Spree::PrintInvoice::Config[:logo_path])

if im && File.exist?(im.pathname)
if im && File.exist?(im.filename)
pdf.image im.filename, vposition: :top, height: 40, scale: Spree::PrintInvoice::Config[:logo_scale]
end

Expand All @@ -11,4 +11,4 @@ pdf.grid([0,3], [1,4]).bounding_box do
pdf.text Spree.t(:invoice_number, scope: :print_invoice, number: printable.number), align: :right
pdf.move_down 2
pdf.text Spree.t(:invoice_date, scope: :print_invoice, date: I18n.l(printable.date)), align: :right
end
end
18 changes: 18 additions & 0 deletions config/initializers/print_invoice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Rails.application.config.after_initialize do
if Spree::Core::Engine.backend_available?
Rails.application.config.spree_backend.main_menu.insert_after('dashboard', ::SpreePrintInvoice::Admin::MainMenu::PrintInvoiceBuilder.new.build)

Rails.application.config.spree_backend.tabs[:order].add(
::Spree::Admin::Tabs::TabBuilder.new(::Spree.t(:documents, scope: [:print_invoice]), ->(resource) { ::Spree::Core::Engine.routes.url_helpers.admin_order_bookkeeping_documents_path(resource) }).
with_icon_key('file.svg').
with_active_check.
build
)

Rails.application.config.spree_backend.main_menu.add_to_section('settings',
::Spree::Admin::MainMenu::ItemBuilder.new('print_invoice.settings', ::Spree::Core::Engine.routes.url_helpers.edit_admin_print_invoice_settings_path).
with_manage_ability_check(::Spree::BookkeepingDocument).
build
)
end
end
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
en:
spree:
printable_number: Printable Number
bookkeeping_documents: Bookkeeping Documents
print_invoice_settings: Print Invoice Settings
documents: Documents
admin:
tab:
invoices: Invoices
Expand Down
2 changes: 1 addition & 1 deletion lib/spree_print_invoice/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

initializer 'spree.print_invoice.preferences', before: :load_config_initializers do
config.after_initialize do
Spree::PrintInvoice::Config = Spree::PrintInvoiceSetting.new
end

Expand Down
4 changes: 2 additions & 2 deletions spree-print-invoice.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_runtime_dependency 'prawn-rails', '~> 1.3'
s.add_runtime_dependency 'spree_core', '>= 3.1.0', '< 5.0'
s.add_runtime_dependency 'prawn-rails', '~> 1.4.2'
s.add_runtime_dependency 'spree_core', '>= 4.8.0', '< 5.0'
s.add_runtime_dependency 'spree_extension'

s.add_development_dependency 'capybara'
Expand Down