mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
add tax rates report
This commit is contained in:
committed by
Rob Harrington
parent
7925af30d6
commit
8570471c00
@@ -159,6 +159,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
def sales_tax
|
||||
prepare_date_params params
|
||||
@distributors = Enterprise.is_distributor.managed_by(spree_current_user)
|
||||
@report_type = params[:report_type]
|
||||
|
||||
@report = OpenFoodNetwork::SalesTaxReport.new spree_current_user, params
|
||||
|
||||
|
||||
@@ -5,9 +5,15 @@
|
||||
.four.columns.alpha
|
||||
= label_tag nil, t(:report_distributor)
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, {:include_blank => 'All'}, {:class => "select2 fullwidth"})
|
||||
= label_tag nil, t(:report_customers_type)
|
||||
%br
|
||||
= select_tag(:report_type, options_for_select([[t(:report_tax_rates),:tax_rates],[t(:report_tax_types),:tax_types]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, t(:report_customers_csv)
|
||||
%br
|
||||
%br
|
||||
= button t(:search)
|
||||
|
||||
%br
|
||||
|
||||
@@ -1343,6 +1343,8 @@ Please follow the instructions there to make your enterprise visible on the Open
|
||||
report_order_cycle: "Order Cycle: "
|
||||
report_entreprises: "Enterprises: "
|
||||
report_users: "Users: "
|
||||
report_tax_rates: "Tax rates"
|
||||
report_tax_types: "Tax types"
|
||||
initial_invoice_number: "Initial invoice number:"
|
||||
invoice_date: "Invoice date:"
|
||||
due_date: "Due date:"
|
||||
|
||||
@@ -1225,6 +1225,8 @@ fr:
|
||||
report_order_cycle: "Cycle de vente:"
|
||||
report_entreprises: "Entreprises:"
|
||||
report_users: "Managers:"
|
||||
report_tax_rates: "Taxes par taux"
|
||||
report_tax_types: "Taxes par type"
|
||||
initial_invoice_number: "N° de facture initial:"
|
||||
invoice_date: "Date de facture:"
|
||||
due_date: "Date d'échéance:"
|
||||
|
||||
@@ -9,9 +9,16 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def header
|
||||
["Order number", "Date", "Items", "Items total (#{currency_symbol})", "Taxable Items Total (#{currency_symbol})",
|
||||
"Sales Tax (#{currency_symbol})", "Delivery Charge (#{currency_symbol})", "Tax on Delivery (#{currency_symbol})", "Tax on Fees (#{currency_symbol})",
|
||||
"Total Tax (#{currency_symbol})", "Customer", "Distributor"]
|
||||
case params[:report_type]
|
||||
when "tax_types"
|
||||
["Order number", "Date", "Items", "Items total (#{currency_symbol})", "Taxable Items Total (#{currency_symbol})",
|
||||
"Sales Tax (#{currency_symbol})", "Delivery Charge (#{currency_symbol})", "Tax on Delivery (#{currency_symbol})", "Tax on Fees (#{currency_symbol})",
|
||||
"Total Tax (#{currency_symbol})", "Customer", "Distributor"]
|
||||
else
|
||||
["Order number", "Total excl. VAT"] +
|
||||
relevant_rates.map { |rate| "%s (%.1f%%)" % [rate.name, rate.amount.to_f * 100] } +
|
||||
["Total VAT", "Total incl. VAT"]
|
||||
end
|
||||
end
|
||||
|
||||
def search
|
||||
@@ -24,19 +31,39 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def table
|
||||
orders.map do |order|
|
||||
totals = totals_of order.line_items
|
||||
shipping_cost = shipping_cost_for order
|
||||
case params[:report_type]
|
||||
when "tax_types"
|
||||
orders.map do |order|
|
||||
totals = totals_of order.line_items
|
||||
shipping_cost = shipping_cost_for order
|
||||
|
||||
[order.number, order.created_at, totals[:items], totals[:items_total],
|
||||
totals[:taxable_total], totals[:sales_tax], shipping_cost, order.shipping_tax, order.enterprise_fee_tax, order.total_tax,
|
||||
order.bill_address.full_name, order.distributor.andand.name]
|
||||
[order.number, order.created_at, totals[:items], totals[:items_total],
|
||||
totals[:taxable_total], totals[:sales_tax], shipping_cost, order.shipping_tax, order.enterprise_fee_tax, order.total_tax,
|
||||
order.bill_address.full_name, order.distributor.andand.name]
|
||||
end
|
||||
else
|
||||
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]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def relevant_rates
|
||||
queries = [ search.result.joins(:line_items => {:adjustments => :tax_rate}).select('spree_tax_rates.*').uniq,
|
||||
search.result.joins(:adjustments => :tax_rate).select('spree_tax_rates.*').uniq ]
|
||||
queries.map do |query|
|
||||
ActiveRecord::Base.connection.select_all(query)
|
||||
end.sum.map do
|
||||
|tax_rate| Spree::TaxRate.new(tax_rate, without_protection: true)
|
||||
end
|
||||
end
|
||||
|
||||
def totals_of(line_items)
|
||||
totals = {items: 0, items_total: 0.0, taxable_total: 0.0, sales_tax: 0.0}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user