spree_advanced_reporting 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +5 -0
  3. data/README.md +23 -0
  4. data/Rakefile +20 -0
  5. data/TODO.txt +3 -0
  6. data/app/assets/images/admin/advanced_reporting/asc.gif +0 -0
  7. data/app/assets/images/admin/advanced_reporting/barchart.png +0 -0
  8. data/app/assets/images/admin/advanced_reporting/bg.gif +0 -0
  9. data/app/assets/images/admin/advanced_reporting/close.png +0 -0
  10. data/app/assets/images/admin/advanced_reporting/desc.gif +0 -0
  11. data/app/assets/images/admin/advanced_reporting/menu-current-opposite.png +0 -0
  12. data/app/assets/images/admin/advanced_reporting/open.png +0 -0
  13. data/app/assets/images/admin/advanced_reporting/save.png +0 -0
  14. data/app/assets/images/admin/advanced_reporting/search.png +0 -0
  15. data/app/assets/images/admin/advanced_reporting/usa.png +0 -0
  16. data/app/assets/images/admin/advanced_reporting/world.png +0 -0
  17. data/app/assets/javascripts/admin/advanced_reporting/advanced_reporting.js +46 -0
  18. data/app/assets/javascripts/admin/advanced_reporting/jquery.tablesorter.min.js +4 -0
  19. data/app/assets/stylesheets/admin/advanced_reporting/advanced_reporting.css.erb +18 -0
  20. data/app/assets/stylesheets/pdf.css +15 -0
  21. data/app/controllers/spree/admin/advanced_report_overview_controller.rb +21 -0
  22. data/app/controllers/spree/admin/reports_controller_decorator.rb +127 -0
  23. data/app/helpers/advanced_report_helper.rb +13 -0
  24. data/app/models/ruport/formatter/html_decorator.rb +29 -0
  25. data/app/models/ruport/formatter/wicked_pdf_decorator.rb +12 -0
  26. data/app/views/spree/admin/advanced_report_overview/index.html.erb +117 -0
  27. data/app/views/spree/admin/reports/_advanced_report_criteria.html.erb +64 -0
  28. data/app/views/spree/admin/reports/geo_base.html.erb +61 -0
  29. data/app/views/spree/admin/reports/increment_base.html.erb +63 -0
  30. data/app/views/spree/admin/reports/outstanding.html.erb +16 -0
  31. data/app/views/spree/admin/reports/top_base.html.erb +17 -0
  32. data/config/locales/en.yml +96 -0
  33. data/config/locales/pt-BR.yml +92 -0
  34. data/config/routes.rb +37 -0
  35. data/lib/spree/advanced_report.rb +225 -0
  36. data/lib/spree/advanced_report/geo_report.rb +2 -0
  37. data/lib/spree/advanced_report/geo_report/geo_profit.rb +44 -0
  38. data/lib/spree/advanced_report/geo_report/geo_revenue.rb +44 -0
  39. data/lib/spree/advanced_report/geo_report/geo_units.rb +42 -0
  40. data/lib/spree/advanced_report/increment_report.rb +78 -0
  41. data/lib/spree/advanced_report/increment_report/count.rb +33 -0
  42. data/lib/spree/advanced_report/increment_report/profit.rb +41 -0
  43. data/lib/spree/advanced_report/increment_report/revenue.rb +40 -0
  44. data/lib/spree/advanced_report/increment_report/units.rb +33 -0
  45. data/lib/spree/advanced_report/top_report.rb +2 -0
  46. data/lib/spree/advanced_report/top_report/top_customers.rb +32 -0
  47. data/lib/spree/advanced_report/top_report/top_products.rb +35 -0
  48. data/lib/spree/advanced_report/transaction_report.rb +79 -0
  49. data/lib/spree_advanced_reporting.rb +25 -0
  50. data/spree_advanced_reporting.gemspec +22 -0
  51. metadata +133 -0
@@ -0,0 +1,64 @@
1
+ <% content_for :head do -%>
2
+ <%= stylesheet_link_tag 'admin/advanced_reporting/advanced_reporting' %>
3
+ <% end -%>
4
+
5
+ <div id="advanced_report_search">
6
+ <h3><%=t "adv_report.advanced_reports"%></h3>
7
+ <%= select(nil, nil, @reports.map { |k, v| [v[:name], send("#{k}_admin_reports_url".to_sym)] }, {selected: request.url }, {name: 'report', id: 'report' }) %>
8
+
9
+ <%= form_for :search do |s| %>
10
+ <% if @stores -%>
11
+ Store:<br /><%= collection_select(:search, :store_id, @stores, :id, :name, { :include_blank => 'All' } ) %><br /><br/>
12
+ <% end -%>
13
+
14
+ <div id="order_type">
15
+ Filter by When Order Was:<br/>
16
+ <%= select(:advanced_reporting, :order_type, [:completed, :shipped], include_blank: t(:report_default), selected: params[:advanced_reporting][:order_type]) %>
17
+ </div>
18
+
19
+ <div>
20
+ Include only orders that are:<br/>
21
+ <%= select(:advanced_reporting, :shipment, [:fully_shipped, :partial_shipped], include_blank: t(:report_default), selected: params[:advanced_reporting][:shipment]) %>
22
+ </div>
23
+
24
+ <div>
25
+ <%= check_box :advanced_reporting, :state_based_on_taxable_address, { :checked => params[:advanced_reporting][:state_based_on_taxable_address] == "1" }, '1', '0' %>
26
+ Match State Based on Taxable Address
27
+ </div>
28
+
29
+ <div id="state_restriction">
30
+ State:<br/>
31
+ <%= collection_select(:advanced_reporting, :state_id, Spree::State.all, :id, :name, { :include_blank => 'All', :selected => params[:advanced_reporting][:state_id] } ) %>
32
+ </div>
33
+
34
+ <div id="taxon_products">
35
+ <% if @taxons -%>
36
+ <%=t "taxons"%>: <br /><%= collection_select(:advanced_reporting, :taxon_id, @taxons, :id, :name, { :include_blank => 'All' } ) %><br />
37
+ <% end -%>
38
+ <%=t :products%>:<br /><%= collection_select(:advanced_reporting, :product_id, @products, :id, :name, { :include_blank => 'All' } ) %><br />
39
+ </div>
40
+
41
+ <%= t("date_range") %><br />
42
+ <div class="yui-g date-range-filter">
43
+ <div class="yui-u sub-field first">
44
+ <%= s.text_field :created_at_gt, :class => 'datepicker', :value => @report.unfiltered_params[:created_at_gt] %><br />
45
+ <label class="sub"><%= t("start") %></label>
46
+ </div>
47
+ <div class="yui-u sub-field">
48
+ <%= s.text_field :created_at_lt, :class => 'datepicker', :value => @report.unfiltered_params[:created_at_lt] %><br />
49
+ <label><%= t("stop") %></label>
50
+ </div>
51
+ </div>
52
+
53
+ <p><%= button t("update") %></p>
54
+ <% end -%>
55
+ </div>
56
+
57
+ <% if params[:advanced_reporting] -%>
58
+ <% if params[:advanced_reporting][:product_id] && params[:advanced_reporting][:product_id] != '' -%>
59
+ <input type="hidden" id="product_id" value="<%= params[:advanced_reporting][:product_id] %>" />
60
+ <% end -%>
61
+ <% if params[:advanced_reporting][:taxon_id] && params[:advanced_reporting][:taxon_id] != '' -%>
62
+ <input type="hidden" id="taxon_id" value="<%= params[:advanced_reporting][:taxon_id] %>" />
63
+ <% end -%>
64
+ <% end -%>
@@ -0,0 +1,61 @@
1
+ <% [:state, :country].each do |type| -%>
2
+ <div id="<%= type.to_s %>_data" <%= 'style=display:none;' if type != :state %> class="advanced_reporting_data">
3
+ <div id="<%= type.to_s %>_canvas" class="canvas"></div>
4
+ <%= raw @report.ruportdata[type].to_html %>
5
+ </div>
6
+ <% end -%>
7
+
8
+ <% content_for :sidebar do -%>
9
+ <div class="report_details">
10
+ <h1><%=t "adv_report." + @report.name.downcase %></h1>
11
+ <p><%= @report.description %></p>
12
+ <%= @report.taxon_text %>
13
+ <%= @report.product_text %>
14
+ </div>
15
+
16
+ <ul id="show_data">
17
+ <li id="state">
18
+ <label><%= t("adv_report.states") %></label><br />
19
+ <%= link_to "CSV", @report.download_url(request.fullpath, 'csv', "state") %>
20
+ <%= link_to "PDF", @report.download_url(request.fullpath, 'pdf', "state") %>
21
+ </li>
22
+ <li id="country">
23
+ <label><%= t("adv_report.countries") %></label><br />
24
+ <%= link_to "CSV", @report.download_url(request.fullpath, 'csv', "country") %>
25
+ <%= link_to "PDF", @report.download_url(request.fullpath, 'pdf', "country") %>
26
+ </li>
27
+ </ul>
28
+ <%= render :partial => 'spree/admin/reports/advanced_report_criteria', :locals => {} %>
29
+ <% end -%>
30
+
31
+ <% content_for :head do -%>
32
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
33
+ <script type="text/javascript">
34
+ google.load('visualization', '1', {'packages': ['geomap']});
35
+ </script>
36
+ <script type="text/javascript">
37
+ google.setOnLoadCallback(drawMaps);
38
+
39
+ function drawMaps() {
40
+ <% [:state, :country].each do |type| -%>
41
+ var data_<%= type.to_s %> = new google.visualization.DataTable();
42
+ data_<%= type.to_s %>.addRows(<%= @report.ruportdata[type].size %>);
43
+ data_<%= type.to_s %>.addColumn('string', '<%= type.to_s.capitalize %>');
44
+ data_<%= type.to_s %>.addColumn('number', '<%= @report.column %>');
45
+ <% @report.ruportdata[type].each_with_index do |p, i| %>
46
+ data_<%= type.to_s %>.setValue(<%= i.to_s %>, 0, "<%= p.data[type.to_s.capitalize] %>");
47
+ data_<%= type.to_s %>.setValue(<%= i.to_s %>, 1, <%= p.data[@report.column].to_s.gsub(/^\$/, '') %>);
48
+ <% end -%>
49
+
50
+ var options_<%= type.to_s %> = { 'width' : '800px', 'height' : '500px' };
51
+ <% if type == :state %>
52
+ options_<%= type.to_s %>['region'] = 'US';
53
+ <% end -%>
54
+
55
+ var <%= type.to_s %>_container = document.getElementById('<%= type.to_s %>_canvas');
56
+ var <%= type.to_s %>_geomap = new google.visualization.GeoMap(<%= type.to_s %>_container);
57
+ <%= type.to_s %>_geomap.draw(data_<%= type.to_s %>, options_<%= type.to_s %>);
58
+ <% end -%>
59
+ };
60
+ </script>
61
+ <% end -%>
@@ -0,0 +1,63 @@
1
+ <% @report.increments.each do |type| -%>
2
+ <div id="<%= type.to_s %>_data" <%= 'style=display:none;' if type.to_s != t("adv_report.daily").downcase %> class="advanced_reporting_data">
3
+ <div id="<%= type.to_s %>_chart"></div>
4
+ <%= raw @report.ruportdata[type].to_html %>
5
+ </div>
6
+ <% end -%>
7
+
8
+ <% content_for :sidebar do %>
9
+ <div class="report_details">
10
+ <h1><%=t "adv_report." + @report.name.downcase.gsub(/ /,"_") %></h1>
11
+ <p class="links">
12
+ <%= link_to "CSV (all)", @report.download_url(request.fullpath, 'csv', "all") %><br/>
13
+ <%= link_to "PDF (all)", @report.download_url(request.fullpath, 'pdf', "all") %>
14
+ </p>
15
+ <%= @report.description %><br />
16
+ <%== @report.product_text %>
17
+ <%== @report.taxon_text %>
18
+ <%= @report.date_text %><br />
19
+ Total: <%= @report.format_total %>
20
+ </div>
21
+
22
+ <ul id="show_data">
23
+ <% @report.increments.each do |inc| %>
24
+ <li id="<%= inc.to_s %>">
25
+ <label><%= inc.to_s.capitalize %></label><br />
26
+ <%= link_to "CSV", @report.download_url(request.fullpath, 'csv', inc) %>
27
+ <%= link_to "PDF", @report.download_url(request.fullpath, 'pdf', inc) %>
28
+ </li>
29
+ <% end -%>
30
+ </ul>
31
+ <%= render :partial => 'spree/admin/reports/advanced_report_criteria', :locals => {} %>
32
+ <% end %>
33
+
34
+ <% content_for :head do -%>
35
+ <script type="text/javascript" src="//www.google.com/jsapi"></script>
36
+ <script type="text/javascript">
37
+ google.load('visualization', '1', {'packages': ['corechart']});
38
+ </script>
39
+ <script type="text/javascript">
40
+ google.setOnLoadCallback(drawChart);
41
+
42
+ function drawChart() {
43
+ <% @report.increments.each do |type| -%>
44
+ var data_<%= type.to_s %> = new google.visualization.DataTable();
45
+ data_<%= type.to_s %>.addColumn('string', 'Display');
46
+ data_<%= type.to_s %>.addColumn('number', '<%= @report.name %>');
47
+ data_<%= type.to_s %>.addRows(<%= @report.ruportdata[type].size %>);
48
+ <% @report.ruportdata[type].each_with_index do |p, i| %>
49
+ data_<%= type.to_s %>.setValue(<%= i.to_s %>, 0, "<%= p.data[type.to_s.capitalize] %>");
50
+ data_<%= type.to_s %>.setValue(<%= i.to_s %>, 1, <%= p.data[@report.column].to_s.gsub(/^\$/, '') %>);
51
+ <% end -%>
52
+ var chart_<%= type.to_s %> = new google.visualization.ColumnChart(document.getElementById('<%= type.to_s %>_chart'));
53
+ chart_<%= type.to_s %>.draw(data_<%= type.to_s %>, {
54
+ width: 800,
55
+ height: 400,
56
+ legend : 'none',
57
+ hAxis: { slantedText: true, slantedTextAngle: 30 },
58
+ title: '<%= type.to_s.capitalize + ' ' + @report.name %>' });
59
+ <% end -%>
60
+
61
+ }
62
+ </script>
63
+ <% end -%>
@@ -0,0 +1,16 @@
1
+ <h1><%= t("adv_report.outstanding") %>: <%= number_to_currency @outstanding_balance %> </h1>
2
+
3
+ <table style="width:40%;">
4
+ <tr>
5
+ <th><%= t(:order) %>:</th>
6
+ <th><%= t(:order_date) %>:</th>
7
+ <th><%= t("adv_report.outstanding") %>:</th>
8
+ </tr>
9
+ <% @orders.each do |order| %>
10
+ <tr>
11
+ <td><%= link_to order.number, admin_order_path(order) %></td>
12
+ <td><%= l order.completed_at.to_date %></td>
13
+ <td><%= order.outstanding_balance %></td>
14
+ </tr>
15
+ <% end %>
16
+ </table>
@@ -0,0 +1,17 @@
1
+ <%== @report.ruportdata.to_html %>
2
+
3
+ <% content_for :sidebar do %>
4
+ <div class="report_details">
5
+ <h1><%=t "adv_report." + @report.name.downcase.gsub(/ /,"_") %></h1>
6
+ <p><%= @report.description %></p>
7
+ <%= @report.taxon_text %>
8
+ <%= @report.product_text %>
9
+ </div>
10
+
11
+ <p class="links">
12
+ <%= link_to "CSV (all)", @report.download_url(request.fullpath, 'csv') %>
13
+ <%= link_to "PDF (all)", @report.download_url(request.fullpath, 'pdf') %>
14
+ </p>
15
+
16
+ <%= render :partial => 'spree/admin/reports/advanced_report_criteria', :locals => {} %>
17
+ <% end %>
@@ -0,0 +1,96 @@
1
+ ---
2
+ en:
3
+ report_default: Report Default
4
+ sales_total_description: "Sales Total"
5
+ sales_total: "Sales Total"
6
+ adv_report:
7
+ increments:
8
+ - daily
9
+ - weekly
10
+ - monthly
11
+ - quarterly
12
+ - yearly
13
+ dashboard: Dashboard
14
+ daily: Daily
15
+ weekly: Weekly
16
+ monthly: Monthly
17
+ quarterly: Quarterly
18
+ yearly: Yearly
19
+ revenue: "Revenue"
20
+ units: "Units"
21
+ profit: "Profit"
22
+ count: "Order Count"
23
+ top_products: "Top Products"
24
+ top_customers: "Top Customers"
25
+ submit: "Submit"
26
+ geo_revenue: "Geo Revenue"
27
+ geo_units: "Geo Units"
28
+ geo_profit: "Geo Profit"
29
+ transactions: Transactions
30
+ outstanding: Outstanding
31
+ states: States
32
+ countries: Countries
33
+ base:
34
+ range: Date Range
35
+ from: From
36
+ after: After
37
+ before: Before
38
+ all: All
39
+ name: "Base Advanced Report"
40
+ description: "Base Advanced Report"
41
+ top_report:
42
+ top_customers:
43
+ table:
44
+ - email
45
+ - Units
46
+ - Revenue
47
+ customer_email: Customer Email
48
+ name: "Top Customers"
49
+ description: "Top purchasing customers, calculated by revenue"
50
+ top_products:
51
+ table:
52
+ - name
53
+ - Units
54
+ - Revenue
55
+ product_name: Name of Product
56
+ name: "Top Selling Products by Revenue"
57
+ description: "Top selling products, calculated by revenue"
58
+ increment_report:
59
+ count:
60
+ name: "Order Count"
61
+ description: "Total number of completed orders"
62
+ column: "Count"
63
+ profit:
64
+ name: "Profit"
65
+ description: "Total profit in orders, where profit is the sum of item quantity times item price minus item cost price"
66
+ column: "Profit"
67
+ revenue:
68
+ name: "Revenue"
69
+ description: "Total order revenue, where revenue is the sum of order item prices, excluding shipping and tax"
70
+ column: "Revenue"
71
+ units:
72
+ name: "Units Sold"
73
+ description: "Total units sold in orders, a sum of the item quantities per order or per item"
74
+ column: "Units"
75
+ geo_report:
76
+ profit:
77
+ table:
78
+ - location
79
+ - Profit
80
+ name: "Profit by Geography"
81
+ description: "Profit divided geographically, into states and countries"
82
+ column: "Profit"
83
+ revenue:
84
+ table:
85
+ - location
86
+ - Revenue
87
+ name: "Revenue by Geography"
88
+ description: "Revenue divided geographically, into states and countries"
89
+ column: "Revenue"
90
+ units:
91
+ table:
92
+ - location
93
+ - Units
94
+ name: "Units Sold by Geography"
95
+ description: "Unit sales divided geographically, into states and countries"
96
+ column: "Units"
@@ -0,0 +1,92 @@
1
+ pt-BR:
2
+ adv_report:
3
+ increments:
4
+ - diario
5
+ - semanal
6
+ - mensal
7
+ - trimestral
8
+ - anual
9
+ dashboard: Dashboard
10
+ daily: Diario
11
+ weekly: Semanal
12
+ monthly: Mensal
13
+ quaterly: Trimestral
14
+ yearly: Anual
15
+ revenue: Receita
16
+ units: Unidades
17
+ profit: Lucro
18
+ count: Num Pedidos
19
+ top_products: "Melhores Produtos"
20
+ top_customers: "Melhores Clientes"
21
+ submit: "Enviar"
22
+ geo_revenue: "Receita por Estado"
23
+ geo_units: "Unidades por Estado"
24
+ geo_profit: "Lucro por Estado"
25
+ outstanding: "Recebiveis"
26
+ outstanding_description: "Valor a ser pago por clientes que parcelaram a compra"
27
+ states: Estados
28
+ countries: Paises
29
+ base:
30
+ range: Intervalo
31
+ from: De
32
+ after: Depois
33
+ before: Antes
34
+ all: Todos
35
+ name: "Relatório avançado base"
36
+ description: "Relatório avançado base"
37
+ top_report:
38
+ top_customers:
39
+ table:
40
+ - email
41
+ - Unidades
42
+ - Receita
43
+ customer_email: Email do cliente
44
+ name: "Melhores Clientes"
45
+ description: "Clientes que mais compraram, calculado pela receita"
46
+ top_products:
47
+ table:
48
+ - name
49
+ - Unidades
50
+ - Receita
51
+ product_name: "Nome do Produto"
52
+ name: "Produtos mais vendidos por receita"
53
+ description: "Produtos mais vendidos, calculado pela receita"
54
+ increment_report:
55
+ count:
56
+ name: "Pedidos"
57
+ description: "Numero total de pedidos completos"
58
+ column: "Pedidos"
59
+ profit:
60
+ name: "Lucro"
61
+ description: "Lucro total em pedidos, onde lucro é a soma das quantidades de produtos vezes seu preço, menos seu custo, sem ajustes"
62
+ column: "Lucro"
63
+ revenue:
64
+ name: "Receita"
65
+ description: "Receita total em pedidos, onde receita é a soma dos preços os itens do pedido sem ajustes, como impostos e frete"
66
+ column: "Receita"
67
+ units:
68
+ name: "Unidades"
69
+ description: "Quantidade de itens vendidos em pedidos, a soma das quantidades de itens por ordem ou por produto"
70
+ column: "Unidades"
71
+ geo_report:
72
+ profit:
73
+ table:
74
+ - location
75
+ - Lucro
76
+ name: "Lucro por Estado"
77
+ description: "Lucro dividido geograficamente em estados"
78
+ column: "Lucro"
79
+ revenue:
80
+ table:
81
+ - location
82
+ - Receita
83
+ name: "Receita por Estado"
84
+ description: "Receita dividida geograficamente em estados"
85
+ column: "Receita"
86
+ units:
87
+ table:
88
+ - location
89
+ - Unidades
90
+ name: "Unidades vendidas por Estado"
91
+ description: Unidades vendidas divididas geograficamente em estados
92
+ column: "Unidades"
@@ -0,0 +1,37 @@
1
+ Spree::Core::Engine.routes.prepend do
2
+ match '/admin/reports/outstanding' => 'admin/reports#outstanding', :via => [:get, :post],
3
+ :as => 'outstanding_admin_reports'
4
+
5
+ match '/admin/reports/revenue' => 'admin/reports#revenue', :via => [:get, :post],
6
+ :as => 'revenue_admin_reports'
7
+
8
+ match '/admin/reports/count' => 'admin/reports#count', :via => [:get, :post],
9
+ :as => 'count_admin_reports'
10
+
11
+ match '/admin/reports/units' => 'admin/reports#units', :via => [:get, :post],
12
+ :as => 'units_admin_reports'
13
+
14
+ match '/admin/reports/profit' => 'admin/reports#profit', :via => [:get, :post],
15
+ :as => 'profit_admin_reports'
16
+
17
+
18
+ match '/admin/reports/top_customers' => 'admin/reports#top_customers', :via => [:get, :post],
19
+ :as => 'top_customers_admin_reports'
20
+
21
+ match '/admin/reports/top_products' => 'admin/reports#top_products', :via => [:get, :post],
22
+ :as => 'top_products_admin_reports'
23
+
24
+ match '/admin/reports/geo_revenue' => 'admin/reports#geo_revenue', :via => [:get, :post],
25
+ :as => 'geo_revenue_admin_reports'
26
+
27
+ match '/admin/reports/geo_units' => 'admin/reports#geo_units', :via => [:get, :post],
28
+ :as => 'geo_units_admin_reports'
29
+
30
+ match '/admin/reports/geo_profit' => 'admin/reports#geo_profit', :via => [:get, :post],
31
+ :as => 'geo_profit_admin_reports'
32
+
33
+ match '/admin/reports/transactions' => 'admin/reports#transactions', :via => [:get, :post],
34
+ :as => 'transactions_admin_reports'
35
+
36
+ # match "/admin" => "admin/advanced_report_overview#index", :as => :admin
37
+ end