mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Allow both invoice layouts to coexist
Add a new "Invoice" page in the admin backend with a checkbox to toggle between layouts
This commit is contained in:
committed by
Rob Harrington
parent
cc1ef5b28b
commit
2fe25c6219
13
app/controllers/admin/invoice_settings_controller.rb
Normal file
13
app/controllers/admin/invoice_settings_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Admin::InvoiceSettingsController < Spree::Admin::BaseController
|
||||
|
||||
def update
|
||||
Spree::Config.set(params[:preferences])
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to main_app.edit_admin_invoice_settings_path
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -77,7 +77,8 @@ Spree::Admin::OrdersController.class_eval do
|
||||
end
|
||||
|
||||
def invoice
|
||||
pdf = render_to_string pdf: "invoice-#{@order.number}.pdf", template: "spree/admin/orders/invoice", formats: [:html], encoding: "UTF-8"
|
||||
template = if Spree::Config.invoice_style2? then "spree/admin/orders/invoice2" else "spree/admin/orders/invoice" end
|
||||
pdf = render_to_string pdf: "invoice-#{@order.number}.pdf", template: template, formats: [:html], encoding: "UTF-8"
|
||||
Spree::OrderMailer.invoice_email(@order.id, pdf).deliver
|
||||
flash[:success] = t(:invoice_email_sent)
|
||||
|
||||
@@ -85,7 +86,8 @@ Spree::Admin::OrdersController.class_eval do
|
||||
end
|
||||
|
||||
def print
|
||||
render pdf: "invoice-#{@order.number}", template: "spree/admin/orders/invoice", encoding: "UTF-8"
|
||||
template = if Spree::Config.invoice_style2? then "spree/admin/orders/invoice2" else "spree/admin/orders/invoice" end
|
||||
render pdf: "invoice-#{@order.number}", template: template, encoding: "UTF-8"
|
||||
end
|
||||
|
||||
def update_distribution_charge
|
||||
|
||||
@@ -32,4 +32,7 @@ Spree::AppConfiguration.class_eval do
|
||||
|
||||
# External services
|
||||
preference :bugherd_api_key, :string, default: nil
|
||||
|
||||
# Invoice layout
|
||||
preference :invoice_style2?, :boolean, default: false
|
||||
end
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// insert_bottom "[data-hook='admin_configurations_sidebar_menu']"
|
||||
|
||||
%li
|
||||
= link_to t('admin.invoice_settings.edit.invoice_settings'), main_app.edit_admin_invoice_settings_path
|
||||
14
app/views/admin/invoice_settings/edit.html.haml
Normal file
14
app/views/admin/invoice_settings/edit.html.haml
Normal file
@@ -0,0 +1,14 @@
|
||||
= render :partial => 'spree/admin/shared/configuration_menu'
|
||||
|
||||
- content_for :page_title do
|
||||
= t('.invoice_settings')
|
||||
|
||||
= form_tag main_app.admin_invoice_settings_path, :method => :put do
|
||||
|
||||
.field.align-center
|
||||
= hidden_field_tag 'preferences[invoice_style2?]', '0'
|
||||
= check_box_tag 'preferences[invoice_style2?]', '1', Spree::Config[:invoice_style2?]
|
||||
= label_tag nil, t('.invoice_style2?')
|
||||
|
||||
.form-buttons{"data-hook" => "buttons"}
|
||||
= button t(:update), 'icon-refresh'
|
||||
@@ -2,16 +2,13 @@
|
||||
%thead
|
||||
%tr
|
||||
%th{:align => "left"}
|
||||
%h5= t(:invoice_column_item)
|
||||
%h4= t(:invoice_column_item)
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= t(:invoice_column_qty)
|
||||
%h4= t(:invoice_column_qty)
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= @order.has_taxes_included ? t(:invoice_column_unit_price_with_taxes) : t(:invoice_column_unit_price_without_taxes)
|
||||
%h4= @order.total_tax > 0 ? t(:invoice_column_tax) : ""
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= @order.has_taxes_included ? t(:invoice_column_price_with_taxes) : t(:invoice_column_price_without_taxes)
|
||||
- if @order.total_tax > 0
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= t(:invoice_column_tax_rate)
|
||||
%h4= t(:invoice_column_price)
|
||||
%tbody
|
||||
- @order.line_items.sort_by{ |li| li.product.name }.each do |item|
|
||||
%tr
|
||||
@@ -20,39 +17,34 @@
|
||||
%td{:align => "right"}
|
||||
= item.quantity
|
||||
%td{:align => "right"}
|
||||
= item.single_display_amount_with_adjustments
|
||||
= item.included_tax > 0 ? item.display_included_tax : ""
|
||||
%td{:align => "right"}
|
||||
= item.display_amount_with_adjustments
|
||||
- if @order.total_tax > 0
|
||||
%td{:align => "right"}
|
||||
= display_line_item_tax_rates(item)
|
||||
- checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
|
||||
%tr
|
||||
%td
|
||||
%strong= "#{raw(adjustment.label)}"
|
||||
%td{:align => "right"}
|
||||
1
|
||||
%td{:align => "right"}
|
||||
= adjustment.included_tax > 0 ? adjustment.display_included_tax : ""
|
||||
%td{:align => "right"}
|
||||
= adjustment.display_amount
|
||||
- if @order.total_tax > 0
|
||||
%td{:align => "right"}
|
||||
= display_adjustment_tax_rates(adjustment)
|
||||
%tfoot
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
%strong= @order.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= @order.has_taxes_included ? @order.display_total : display_checkout_total_less_tax(@order)
|
||||
- display_checkout_taxes_hash(@order).each do |tax_rate, tax_value|
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
= t(:tax_total, rate: tax_rate)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
= tax_value
|
||||
%strong GST Total:
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= display_checkout_tax_total(@order)
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
= @order.has_taxes_included ? t(:total_excl_tax) : t(:total_incl_tax)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
= @order.has_taxes_included ? display_checkout_total_less_tax(@order) : @order.display_total
|
||||
%strong Total (Excl. GST):
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= display_checkout_total_less_tax(@order)
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong Total (Incl. GST):
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= @order.display_total
|
||||
%p
|
||||
|
||||
|
||||
58
app/views/spree/admin/orders/_invoice_table2.html.haml
Normal file
58
app/views/spree/admin/orders/_invoice_table2.html.haml
Normal file
@@ -0,0 +1,58 @@
|
||||
%table.order-summary{:width => "100%"}
|
||||
%thead
|
||||
%tr
|
||||
%th{:align => "left"}
|
||||
%h5= t(:invoice_column_item)
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= t(:invoice_column_qty)
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= @order.has_taxes_included ? t(:invoice_column_unit_price_with_taxes) : t(:invoice_column_unit_price_without_taxes)
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= @order.has_taxes_included ? t(:invoice_column_price_with_taxes) : t(:invoice_column_price_without_taxes)
|
||||
- if @order.total_tax > 0
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= t(:invoice_column_tax_rate)
|
||||
%tbody
|
||||
- @order.line_items.sort_by{ |li| li.product.name }.each do |item|
|
||||
%tr
|
||||
%td
|
||||
= render 'spree/shared/line_item_name', line_item: item
|
||||
%td{:align => "right"}
|
||||
= item.quantity
|
||||
%td{:align => "right"}
|
||||
= item.single_display_amount_with_adjustments
|
||||
%td{:align => "right"}
|
||||
= item.display_amount_with_adjustments
|
||||
- if @order.total_tax > 0
|
||||
%td{:align => "right"}
|
||||
= display_line_item_tax_rates(item)
|
||||
- checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
|
||||
%tr
|
||||
%td
|
||||
%strong= "#{raw(adjustment.label)}"
|
||||
%td{:align => "right"}
|
||||
%td{:align => "right"}
|
||||
%td{:align => "right"}
|
||||
= adjustment.display_amount
|
||||
- if @order.total_tax > 0
|
||||
%td{:align => "right"}
|
||||
= display_adjustment_tax_rates(adjustment)
|
||||
%tfoot
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
%strong= @order.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= @order.has_taxes_included ? @order.display_total : display_checkout_total_less_tax(@order)
|
||||
- display_checkout_taxes_hash(@order).each do |tax_rate, tax_value|
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
= t(:tax_total, rate: tax_rate)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
= tax_value
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
= @order.has_taxes_included ? t(:total_excl_tax) : t(:total_incl_tax)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
= @order.has_taxes_included ? display_checkout_total_less_tax(@order) : @order.display_total
|
||||
%p
|
||||
|
||||
@@ -2,55 +2,40 @@
|
||||
|
||||
%table{:width => "100%"}
|
||||
%tbody
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left", colspan: 3 }
|
||||
%h6= "Issued on: #{Time.zone.now.strftime("%F")}"
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
%h4
|
||||
= t(:tax_invoice)
|
||||
- if @order.distributor.display_invoice_logo? && @order.distributor.logo.present?
|
||||
%td{ :align => "right", rowspan: 2 }
|
||||
= wicked_pdf_image_tag @order.distributor.logo(:small), width: 150, height: 150
|
||||
= "TAX INVOICE: "
|
||||
= "#{@order.number}"
|
||||
%td{width: "10%" }
|
||||
|
||||
%td{ :align => "right" }
|
||||
%h4= @order.order_cycle.andand.name
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
%strong= @order.distributor.name
|
||||
%br
|
||||
= @order.distributor.address.address_part1
|
||||
%br
|
||||
= @order.distributor.address.address_part2
|
||||
%br
|
||||
= @order.distributor.email_address
|
||||
- if @order.distributor.phone.present?
|
||||
%br
|
||||
= @order.distributor.phone
|
||||
%strong= "From: #{@order.distributor.name}"
|
||||
- if @order.distributor.abn.present?
|
||||
%br
|
||||
= "#{t :abn} #{@order.distributor.abn}"
|
||||
- if @order.distributor.acn.present?
|
||||
%br
|
||||
= "#{t :acn} #{@order.distributor.acn}"
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left", colspan: 2 }
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
= "ABN: #{@order.distributor.abn}"
|
||||
%br
|
||||
= t :invoice_issued_on
|
||||
= l Time.zone.now.to_date
|
||||
= @order.distributor.address.full_address
|
||||
%br
|
||||
= t :date_of_transaction
|
||||
= l @order.completed_at.to_date
|
||||
%br
|
||||
= t :order_number
|
||||
= @order.number
|
||||
= @order.distributor.email
|
||||
%td{width: "10%" }
|
||||
|
||||
%td{ :align => "right" }
|
||||
= t :invoice_billing_address
|
||||
%br
|
||||
%strong= @order.ship_address.full_name
|
||||
%strong= "To: #{@order.ship_address.full_name}"
|
||||
- if @order.customer.code.present?
|
||||
%br
|
||||
= "Code: #{@order.customer.code}"
|
||||
%br
|
||||
= @order.ship_address.address_part1
|
||||
= @order.ship_address.full_address
|
||||
%br
|
||||
= @order.ship_address.address_part2
|
||||
= "#{@order.customer.email},"
|
||||
= "#{@order.bill_address.phone}"
|
||||
|
||||
= render 'spree/admin/orders/invoice_table'
|
||||
|
||||
@@ -63,8 +48,4 @@
|
||||
%p
|
||||
|
||||
|
||||
- if @order.distributor.invoice_text.present?
|
||||
%p
|
||||
= @order.distributor.invoice_text
|
||||
|
||||
= render 'spree/order_mailer/payment'
|
||||
|
||||
71
app/views/spree/admin/orders/invoice2.html.haml
Normal file
71
app/views/spree/admin/orders/invoice2.html.haml
Normal file
@@ -0,0 +1,71 @@
|
||||
= wicked_pdf_stylesheet_link_tag "mail/all"
|
||||
|
||||
|
||||
%table{:width => "100%"}
|
||||
%tbody
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
%h4
|
||||
= t :tax_invoice
|
||||
- if @order.distributor.display_invoice_logo? && @order.distributor.logo.present?
|
||||
%td{ :align => "right", rowspan: 2 }
|
||||
= wicked_pdf_image_tag @order.distributor.logo(:small), width: 150, height: 150
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
%strong= @order.distributor.name
|
||||
%br
|
||||
= @order.distributor.address.address_part1
|
||||
%br
|
||||
= @order.distributor.address.address_part2
|
||||
%br
|
||||
= @order.distributor.email_address
|
||||
- if @order.distributor.phone.present?
|
||||
%br
|
||||
= @order.distributor.phone
|
||||
- if @order.distributor.abn.present?
|
||||
%br
|
||||
= "#{t :abn} #{@order.distributor.abn}"
|
||||
- if @order.distributor.acn.present?
|
||||
%br
|
||||
= "#{t :acn} #{@order.distributor.acn}"
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left", colspan: 2 }
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
%br
|
||||
= t :invoice_issued_on
|
||||
= l Time.zone.now.to_date
|
||||
%br
|
||||
= t :date_of_transaction
|
||||
= l @order.completed_at.to_date
|
||||
%br
|
||||
= t :order_number
|
||||
= @order.number
|
||||
%td{ :align => "right" }
|
||||
= t :invoice_billing_address
|
||||
%br
|
||||
%strong= @order.ship_address.full_name
|
||||
- if @order.customer.code.present?
|
||||
%br
|
||||
= "Code: #{@order.customer.code}"
|
||||
%br
|
||||
= @order.ship_address.address_part1
|
||||
%br
|
||||
= @order.ship_address.address_part2
|
||||
|
||||
= render 'spree/admin/orders/invoice_table2'
|
||||
|
||||
- if @order.special_instructions.present?
|
||||
%p.callout
|
||||
%strong
|
||||
= t :customer_instructions
|
||||
%p
|
||||
%em= @order.special_instructions
|
||||
%p
|
||||
|
||||
|
||||
- if @order.distributor.invoice_text.present?
|
||||
%p
|
||||
= @order.distributor.invoice_text
|
||||
|
||||
= render 'spree/order_mailer/payment'
|
||||
@@ -527,9 +527,15 @@ en:
|
||||
require_customer_login: "This shop is for customers only."
|
||||
require_login_html: "Please %{login} if you have an account already. Otherwise, %{register} to become a customer."
|
||||
require_customer_html: "Please %{contact} %{enterprise} to become a customer."
|
||||
invoice_settings:
|
||||
edit:
|
||||
invoice_settings: Invoice
|
||||
invoice_style2?: Use the alternative invoice model that includes total tax breakdown per rate and tax rate info per item (not yet suitable for countries displaying prices excluding tax)
|
||||
|
||||
# Printable Invoice Columns
|
||||
invoice_billing_address: "Billing address:"
|
||||
invoice_column_tax: "GST"
|
||||
invoice_column_price: "Price"
|
||||
invoice_column_item: "Item"
|
||||
invoice_column_qty: "Qty"
|
||||
invoice_column_unit_price_with_taxes: "Unit price (Incl. tax)"
|
||||
|
||||
@@ -464,6 +464,10 @@ fr:
|
||||
shared:
|
||||
user_guide_link:
|
||||
user_guide: Guide l'utilisateur
|
||||
invoice_settings:
|
||||
edit:
|
||||
invoice_settings: Apparence de la facture
|
||||
invoice_style2?: Utiliser le modèle de facture alternaltif qui comprend une séparation des taxes par taux et une indication du taux appliqué par item (pas encore adapté pour les pays affichant des prix hors taxe)
|
||||
|
||||
home:
|
||||
hubs:
|
||||
@@ -484,6 +488,8 @@ fr:
|
||||
require_customer_html: "Veuillez %{contact} %{enterprise} pour devenir membre."
|
||||
|
||||
invoice_billing_address: "Adresse de facturation :"
|
||||
invoice_column_tax: "TVA"
|
||||
invoice_column_price: "Prix"
|
||||
invoice_column_item: "Produit"
|
||||
invoice_column_qty: "Qté"
|
||||
invoice_column_unit_price_with_taxes: "Prix unitaire (TTC)"
|
||||
|
||||
@@ -145,6 +145,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
resources :column_preferences, only: [], format: :json do
|
||||
put :bulk_update, on: :collection
|
||||
end
|
||||
|
||||
resource :invoice_settings, only: [:edit, :update]
|
||||
end
|
||||
|
||||
namespace :api do
|
||||
|
||||
Reference in New Issue
Block a user