From cc1ef5b28b96934028f45f5dca0e01599d084a59 Mon Sep 17 00:00:00 2001 From: Pierre de Lacroix Date: Fri, 3 Mar 2017 10:08:12 +0100 Subject: [PATCH] fixes on invoice and tax report --- app/helpers/checkout_helper.rb | 9 +++++++++ .../admin/orders/_invoice_table.html.haml | 5 +++-- .../spree/admin/orders/invoice.html.haml | 5 ++++- config/locales/en.yml | 19 ++++++++++--------- config/locales/fr.yml | 2 ++ lib/open_food_network/sales_tax_report.rb | 2 +- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index a61b01a60b..ea0854b717 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -53,6 +53,15 @@ module CheckoutHelper line_item.tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ") end + def display_adjustment_tax_rates(adjustment) + tax_rate = (adjustment.included_tax / (adjustment.amount - adjustment.included_tax)).round(2) + if tax_rate == 0 || tax_rate.infinite? + "" + else + number_to_percentage(tax_rate * 100, :precision => 1) + end + end + def display_checkout_total_less_tax(order) Spree::Money.new order.total - order.total_tax, currency: order.currency end diff --git a/app/views/spree/admin/orders/_invoice_table.html.haml b/app/views/spree/admin/orders/_invoice_table.html.haml index a9c189ce19..0941904d8b 100644 --- a/app/views/spree/admin/orders/_invoice_table.html.haml +++ b/app/views/spree/admin/orders/_invoice_table.html.haml @@ -31,11 +31,12 @@ %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"} diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index 7cbcb00d9f..a7356309e2 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -17,7 +17,7 @@ %br = @order.distributor.address.address_part2 %br - = @order.distributor.email + = @order.distributor.email_address - if @order.distributor.phone.present? %br = @order.distributor.phone @@ -31,6 +31,7 @@ %td{ :align => "left", colspan: 2 }   %tr{ valign: "top" } %td{ :align => "left" } + %br = t :invoice_issued_on = l Time.zone.now.to_date %br @@ -40,6 +41,8 @@ = 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 8ced764285..d2fe26e105 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -529,17 +529,18 @@ en: require_customer_html: "Please %{contact} %{enterprise} to become a customer." # Printable Invoice Columns + invoice_billing_address: "Billing address:" invoice_column_item: "Item" invoice_column_qty: "Qty" - invoice_column_unit_price_with_taxes: "Unit price (Incl. GST)" - invoice_column_unit_price_without_taxes: "Unit price (Excl. GST)" - invoice_column_price_with_taxes: "Total price (Incl. GST)" - invoice_column_price_without_taxes: "Total price (Excl. GST)" + invoice_column_unit_price_with_taxes: "Unit price (Incl. tax)" + invoice_column_unit_price_without_taxes: "Unit price (Excl. tax)" + invoice_column_price_with_taxes: "Total price (Incl. tax)" + invoice_column_price_without_taxes: "Total price (Excl. tax)" invoice_column_tax_rate: "Tax rate" tax_invoice: "TAX INVOICE" - tax_total: "GST Total (%{rate}):" - total_excl_tax: "Total (Excl. GST):" - total_incl_tax: "Total (Incl. GST):" + tax_total: "Total tax (%{rate}):" + total_excl_tax: "Total (Excl. tax):" + total_incl_tax: "Total (Incl. tax):" abn: "ABN:" acn: "ACN:" invoice_issued_on: "Invoice issued on:" @@ -1357,8 +1358,8 @@ Please follow the instructions there to make your enterprise visible on the Open report_header_total_tax: "Total Tax (%{currency_symbol})" report_header_customer: "Customer" report_header_distributor: "Distributor" - report_header_total_excl_vat: "Total excl. GST (%{currency_symbol})" - report_header_total_incl_vat: "Total incl. GST (%{currency_symbol})" + report_header_total_excl_vat: "Total excl. tax (%{currency_symbol})" + report_header_total_incl_vat: "Total incl. tax (%{currency_symbol})" initial_invoice_number: "Initial invoice number:" invoice_date: "Invoice date:" due_date: "Due date:" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 7273038c93..b30dc6a818 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -482,6 +482,8 @@ fr: require_customer_login: "La boutique est réservée aux membres." require_login_html: "Déjà inscrit? %{login}. Sinon, %{register} pour pouvoir faire vos achats." require_customer_html: "Veuillez %{contact} %{enterprise} pour devenir membre." + + invoice_billing_address: "Adresse de facturation :" invoice_column_item: "Produit" invoice_column_qty: "Qté" invoice_column_unit_price_with_taxes: "Prix unitaire (TTC)" diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 5d0b850079..edeaa259ff 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -56,7 +56,7 @@ module OpenFoodNetwork orders.map do |order| [order.number, order.total - order.total_tax] + relevant_rates.map { |rate| order.tax_adjustment_totals.fetch(rate, 0) } + - [order.total_tax, order.display_total] + [order.total_tax, order.total] end end end