Display header for Xero invoices report

This commit is contained in:
Rohan Mitchell
2015-05-01 11:59:52 +10:00
parent f4df227ef0
commit a6cecdcc25
5 changed files with 73 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ require 'open_food_network/customers_report'
require 'open_food_network/users_and_enterprises_report'
require 'open_food_network/order_cycle_management_report'
require 'open_food_network/sales_tax_report'
require 'open_food_network/xero_invoices_report'
Spree::Admin::ReportsController.class_eval do
@@ -14,10 +15,10 @@ Spree::Admin::ReportsController.class_eval do
REPORT_TYPES = {
orders_and_fulfillment: [
['Order Cycle Supplier Totals',:order_cycle_supplier_totals],
['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor],
['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier],
['Order Cycle Customer Totals',:order_cycle_customer_totals]
['Order Cycle Supplier Totals', :order_cycle_supplier_totals],
['Order Cycle Supplier Totals by Distributor', :order_cycle_supplier_totals_by_distributor],
['Order Cycle Distributor Totals by Supplier', :order_cycle_distributor_totals_by_supplier],
['Order Cycle Customer Totals', :order_cycle_customer_totals]
],
products_and_inventory: [
['All products', :all_products],
@@ -30,13 +31,16 @@ Spree::Admin::ReportsController.class_eval do
order_cycle_management: [
["Payment Methods Report", :payment_methods],
["Delivery Report", :delivery]
],
xero_invoices: [
["Xero Invoices Report", :xero_invoices]
]
}
# Fetches user's distributors, suppliers and order_cycles
before_filter :load_data, only: [:customers, :products_and_inventory, :order_cycle_management]
# Render a partial for orders and fulfillment description
# Render a partial for various section descriptions
respond_override :index => { :html => { :success => lambda {
@reports[:orders_and_fulfillment][:description] =
render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe
@@ -672,7 +676,13 @@ Spree::Admin::ReportsController.class_eval do
render_report(@report.header, @report.table, params[:csv], "users_and_enterprises_#{timestamp}.csv")
end
def render_report (header, table, create_csv, csv_file_name)
def xero_invoices
@report = OpenFoodNetwork::XeroInvoicesReport.new params
render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv")
end
def render_report(header, table, create_csv, csv_file_name)
unless create_csv
render :html => table
else
@@ -709,7 +719,9 @@ Spree::Admin::ReportsController.class_eval do
:sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" },
:users_and_enterprises => { :name => "Users & Enterprises", :description => "Enterprise Ownership & Status" },
:order_cycle_management => {:name => "Order Cycle Management", :description => ''},
:sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" }
:sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" },
:xero_invoices => { :name => "Xero invoices", :description => 'Invoices for import into Xero' }
}
# Return only reports the user is authorized to view.
reports.select { |action| can? action, :report }

View File

@@ -0,0 +1,13 @@
%table#listing_invoices.index
%thead
%tr
- @report.header.each do |header|
%th= header
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)

View File

@@ -134,6 +134,7 @@ Spree::Core::Engine.routes.prepend do
match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management"
match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post]
match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post]
match '/admin/reports/xero_invoices' => 'admin/reports#xero_invoices', :as => "xero_invoices_admin_reports", :via => [:get, :post]
match '/admin', :to => 'admin/overview#index', :as => :admin
match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get

View File

@@ -0,0 +1,15 @@
module OpenFoodNetwork
class XeroInvoicesReport
def initialize(params={})
@params = params
end
def header
%w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme)
end
def table
[[]]
end
end
end

View File

@@ -297,4 +297,29 @@ feature %q{
].sort
end
end
describe "Xero invoices report" do
let!(:enterprise1) { create( :enterprise, owner: create_enterprise_user ) }
let!(:enterprise2) { create( :enterprise, owner: create_enterprise_user ) }
let!(:enterprise3) { create( :enterprise, owner: create_enterprise_user ) }
before do
enterprise3.enterprise_roles.build( user: enterprise1.owner ).save
login_to_admin_section
click_link 'Reports'
click_link 'Xero invoices'
end
it "shows Xero invoices report" do
rows = find("table#listing_invoices").all("tr")
table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } }
table.should == [
%w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme),
[]
]
end
end
end