From 0b1af8ba3a61c5fae69db1c6446c54abe4c9f1ee Mon Sep 17 00:00:00 2001 From: Rob Daniels Date: Fri, 18 May 2018 08:56:47 -0400 Subject: [PATCH 1/2] 3.4 working --- Gemfile | 4 +-- .../admin/reports_controller_decorator.rb | 30 +++++++++---------- app/models/spree/report/sales_and_stock.rb | 4 +-- app/models/spree/report/sales_for_client.rb | 6 ++-- app/models/spree/report/sales_for_month.rb | 4 +-- .../spree/report/sales_for_promotion.rb | 4 +-- app/models/spree/report/sales_for_state.rb | 4 +-- app/models/spree/report/sales_sku.rb | 7 +++-- app/models/spree/report/sales_total.rb | 10 +++++-- app/models/spree/report/stock_detail.rb | 6 ++-- app/models/spree/report/variant_data.rb | 4 ++- .../admin/reports/sales_for_client.html.erb | 4 +-- .../admin/reports/sales_for_month.html.erb | 4 +-- .../admin/reports/sales_for_state.html.erb | 4 +-- .../spree/admin/reports/sales_sku.html.erb | 2 +- .../spree/admin/reports/sales_total.html.erb | 6 +++- .../admin/reports/stock_details.html.erb | 4 +-- .../admin/reports/variants_data.html.erb | 4 +-- config/routes.rb | 9 ++++++ spree_custom_reports.gemspec | 2 +- 20 files changed, 69 insertions(+), 53 deletions(-) diff --git a/Gemfile b/Gemfile index de698e4..9e4ab1f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' -gem 'spree', github: 'spree/spree', branch: '3-0-stable' +gem 'spree', '~>3.4' # Provides basic authentication functionality for testing parts of your engine -gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable' +gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master' gemspec diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index d92e3c0..eeed2fb 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -46,23 +46,23 @@ def sales_for_month end end - def sales_click_go - respond_to do |format| - format.html do - @items = Spree::Report::SalesClickGo.compute(@dates) + # def sales_click_go + # respond_to do |format| + # format.html do + # @items = Spree::Report::SalesClickGo.compute(@dates) - @totals = { - total_amount: @items.inject(0){ |sum,i| sum + i[:total] }, - items: @items.inject(0){ |sum,i| sum + i[:quantity] }, - orders: @items.flat_map{ |i| i.number }.uniq.count - } + # @totals = { + # total_amount: @items.inject(0){ |sum,i| sum + i[:total] }, + # items: @items.inject(0){ |sum,i| sum + i[:quantity] }, + # orders: @items.flat_map{ |i| i.number }.uniq.count + # } - @items = Kaminari.paginate_array(@items.to_a).page(params[:page]).per(20) - end + # @items = Kaminari.paginate_array(@items.to_a).page(params[:page]).per(20) + # end - format.csv { send_file(report_klass: Spree::Report::SalesClickGo, dates: @dates) } - end - end + # format.csv { send_file(report_klass: Spree::Report::SalesClickGo, dates: @dates) } + # end + # end def sales_for_state respond_to do |format| @@ -141,7 +141,7 @@ def add_custom_reports Spree::Admin::ReportsController.add_available_report!(:sales_for_promotion) Spree::Admin::ReportsController.add_available_report!(:variants_data) Spree::Admin::ReportsController.add_available_report!(:stock_details) - Spree::Admin::ReportsController.add_available_report!(:sales_click_go) + # Spree::Admin::ReportsController.add_available_report!(:sales_click_go) end def set_dates diff --git a/app/models/spree/report/sales_and_stock.rb b/app/models/spree/report/sales_and_stock.rb index 9d3ba31..fc6da73 100644 --- a/app/models/spree/report/sales_and_stock.rb +++ b/app/models/spree/report/sales_and_stock.rb @@ -6,7 +6,7 @@ def self.headers def self.compute(dates) Spree::Variant. select("spree_variants.id, spree_products.id AS product_id, spree_variants.sku, - COALESCE(spree_variants.variant_name, spree_products.name) as name, + spree_products.name as name, spree_stock_items.count_on_hand AS stock, spree_prices.amount, ARRAY_AGG(DISTINCT(spree_taxons.name)) AS taxons, ARRAY_AGG(DISTINCT(spree_properties.name)) AS properties, ARRAY_AGG(DISTINCT(spree_product_properties.value)) AS property_values"). joins(:product). @@ -16,7 +16,7 @@ def self.compute(dates) joins(:stock_locations, :stock_items). joins(line_items: [order: :payments]). where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }). + # where(spree_payments: { state: :completed }). group("spree_variants.id, spree_products.id, spree_variants.sku, spree_prices.amount, stock") end diff --git a/app/models/spree/report/sales_for_client.rb b/app/models/spree/report/sales_for_client.rb index db20384..f975180 100644 --- a/app/models/spree/report/sales_for_client.rb +++ b/app/models/spree/report/sales_for_client.rb @@ -9,7 +9,7 @@ def self.headers def self.compute(dates) Spree::LineItem. select("spree_line_items.id AS line_item_id, spree_variants.id, spree_products.id AS product_id, - spree_variants.sku, COALESCE(spree_variants.variant_name, spree_products.name) as name, + spree_variants.sku, spree_products.name as name, spree_line_items.quantity, (spree_line_items.price + spree_line_items.adjustment_total/spree_line_items.quantity) AS unit_price, (spree_line_items.price * spree_line_items.quantity + spree_line_items.adjustment_total) AS total, @@ -25,9 +25,9 @@ def self.compute(dates) joins("LEFT JOIN spree_products_taxons ON spree_products_taxons.product_id = spree_products.id LEFT JOIN spree_taxons ON spree_taxons.id = spree_products_taxons.taxon_id"). joins("LEFT JOIN spree_product_properties ON spree_product_properties.product_id = spree_products.id LEFT JOIN spree_properties ON spree_properties.id = spree_product_properties.property_id"). where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }). + # where(spree_payments: { state: :completed }). group("spree_line_items.id, spree_variants.id, spree_products.id, spree_variants.sku, spree_line_items.quantity, spree_line_items.price, - spree_addresses.firstname, spree_addresses.lastname, spree_addresses.address1, spree_addresses.address2, county, state_address, spree_orders.number, spree_orders.email") + spree_addresses.firstname, spree_addresses.lastname, spree_addresses.address1, spree_addresses.address2, state_address, spree_orders.number, spree_orders.email") end def self.to_csv(dates) diff --git a/app/models/spree/report/sales_for_month.rb b/app/models/spree/report/sales_for_month.rb index e80b7b0..93352bb 100644 --- a/app/models/spree/report/sales_for_month.rb +++ b/app/models/spree/report/sales_for_month.rb @@ -12,8 +12,8 @@ def self.compute(dates) spree_orders.item_count AS items_quant, (spree_orders.item_total + spree_orders.adjustment_total) AS total"). joins(:payments). - where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }) + where(spree_orders: { state: :complete, completed_at: dates }) + # .where(spree_payments: { state: :completed }) end def self.to_csv(dates) diff --git a/app/models/spree/report/sales_for_promotion.rb b/app/models/spree/report/sales_for_promotion.rb index b296a90..4e37375 100644 --- a/app/models/spree/report/sales_for_promotion.rb +++ b/app/models/spree/report/sales_for_promotion.rb @@ -10,7 +10,7 @@ def self.compute(dates) joins(:promotions). joins(:bill_address, :payments). where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }). + # where(spree_payments: { state: :completed }). group("spree_orders.id, spree_promotions.name, spree_promotions.code, spree_orders.number, spree_addresses.firstname, spree_addresses.lastname, spree_orders.email, spree_orders.completed_at, spree_orders.total"). @@ -38,4 +38,4 @@ def self.to_csv(dates) end end -end \ No newline at end of file +end diff --git a/app/models/spree/report/sales_for_state.rb b/app/models/spree/report/sales_for_state.rb index e3f85a3..9d5b1c1 100644 --- a/app/models/spree/report/sales_for_state.rb +++ b/app/models/spree/report/sales_for_state.rb @@ -4,9 +4,9 @@ def self.headers end def self.compute(dates) + # UPPER(spree_counties.name), Spree::Order. select("UPPER(spree_states.name) AS state, - UPPER(COALESCE(spree_counties.name, UPPER(TRIM(spree_addresses.city)) AS city, COUNT(spree_orders.id) AS orders_quant, SUM(spree_orders.item_count) AS items_quant, @@ -14,7 +14,7 @@ def self.compute(dates) joins(:payments, :bill_address). joins("LEFT JOIN spree_states ON spree_addresses.state_id = spree_states.id"). where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }). + # where(spree_payments: { state: :completed }). group("UPPER(spree_states.name), spree_states.id, UPPER(TRIM(spree_addresses.city))"). order("spree_states.id") end diff --git a/app/models/spree/report/sales_sku.rb b/app/models/spree/report/sales_sku.rb index b17d89f..26483d1 100644 --- a/app/models/spree/report/sales_sku.rb +++ b/app/models/spree/report/sales_sku.rb @@ -4,9 +4,10 @@ def self.headers end def self.compute(dates) + # COALESCE(spree_variants.variant_name, spree_products.name as name, Spree::LineItem. select("spree_line_items.variant_id, spree_products.id AS product_id, spree_variants.sku, - COALESCE(spree_variants.variant_name, spree_products.name) as name, + spree_products.name , ARRAY_AGG(DISTINCT(spree_orders.id)) AS order_ids, SUM(spree_line_items.quantity) AS items_quant, SUM(spree_line_items.price * spree_line_items.quantity + spree_line_items.adjustment_total) AS total"). @@ -14,8 +15,8 @@ def self.compute(dates) joins("INNER JOIN spree_products ON spree_variants.product_id = spree_products.id"). joins(order: :payments). where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }). - group("spree_line_items.variant_id, spree_products.id, spree_variants.sku, spree_variants.variant_name, spree_products.name").order("total DESC") + # where(spree_payments: { state: :completed }). + group("spree_line_items.variant_id, spree_products.id, spree_variants.sku, spree_products.name").order("total DESC") end def self.to_csv(dates) diff --git a/app/models/spree/report/sales_total.rb b/app/models/spree/report/sales_total.rb index 67793bd..4b1560b 100644 --- a/app/models/spree/report/sales_total.rb +++ b/app/models/spree/report/sales_total.rb @@ -1,6 +1,6 @@ class Spree::Report::SalesTotal < Spree::Report def self.headers - [ Spree.t(:item_total), Spree.t(:discount_total), "#{Spree.t(:total)} ( #{Spree.t(:item_total)} + #{Spree.t(:discount_total)} )", Spree.t(:shipment), "#{Spree.t(:order_total)} (#{Spree.t(:total)} + #{Spree.t(:shipment)})" ] + [ Spree.t(:item_total), Spree.t(:discount_total), "#{Spree.t(:total)} ( #{Spree.t(:item_total)} + #{Spree.t(:discount_total)} )", Spree.t(:shipment), "#{Spree.t(:order_total)} (#{Spree.t(:total)} + #{Spree.t(:shipment)})", Spree.t(:state) ] end def self.compute(dates) @@ -9,10 +9,13 @@ def self.compute(dates) SUM(spree_orders.adjustment_total) AS adjustment_total, SUM(spree_orders.item_total + spree_orders.adjustment_total) AS total, SUM(spree_orders.shipment_total) AS shipment_total, - SUM(total) AS order_total"). + SUM(total) AS order_total, + spree_payments.state AS payment_state"). joins(:payments). where(spree_orders: { state: :complete, completed_at: dates }). - where(spree_payments: { state: :completed }) + # where(spree_payments: { state: :completed }) + group("spree_payments.state") + # .order("total DESC") end def self.to_csv(dates) @@ -27,6 +30,7 @@ def self.to_csv(dates) values << display_money(item[:total]) values << display_money(item[:shipment_total]) values << display_money(item[:order_total]) + values << item[:payment_state] csv << values end diff --git a/app/models/spree/report/stock_detail.rb b/app/models/spree/report/stock_detail.rb index 8fa49cb..c6424b9 100644 --- a/app/models/spree/report/stock_detail.rb +++ b/app/models/spree/report/stock_detail.rb @@ -1,11 +1,11 @@ class Spree::Report::StockDetail < Spree::Report def self.headers - [Spree.t(:sku), Spree.t(:brand), Spree.t(:name), Spree.t(:stock_location), Spree.t(:stock_available), Spree.t(:availability)] + [Spree.t(:sku), Spree.t(:brand), Spree.t(:name), Spree.t(:stock_location), Spree.t(:stock_available), Spree.t(:available_on)] end def self.compute Spree::Variant. - select("spree_variants.id, spree_products.id AS product_id, spree_variants.sku, COALESCE(spree_variants.variant_name, spree_products.name) AS name, spree_prices.amount, + select("spree_variants.id, spree_products.id AS product_id, spree_variants.sku, spree_products.name as name, spree_prices.amount, spree_stock_locations.name AS location_name, spree_stock_items.count_on_hand AS stock, spree_variants.deleted_at, spree_products.available_on, spree_products.deleted_at AS product_deleted_at, @@ -21,7 +21,7 @@ def self.compute joins("LEFT JOIN spree_product_properties ON spree_product_properties.product_id = spree_products.id LEFT JOIN spree_properties ON spree_properties.id = spree_product_properties.property_id"). joins(:default_price). joins(:stock_locations, :stock_items). - salable_variants. + # salable_variants. group("spree_variants.id, spree_products.id, spree_variants.sku, spree_prices.amount, location_name, stock, total, spree_variants.deleted_at, spree_products.available_on, spree_products.deleted_at"). order("spree_variants.id, location_name, total DESC") end diff --git a/app/models/spree/report/variant_data.rb b/app/models/spree/report/variant_data.rb index a190056..c8f7687 100644 --- a/app/models/spree/report/variant_data.rb +++ b/app/models/spree/report/variant_data.rb @@ -10,7 +10,9 @@ def self.compute joins(:product, :default_price). joins("LEFT JOIN spree_products_taxons ON spree_products_taxons.product_id = spree_products.id LEFT JOIN spree_taxons ON spree_taxons.id = spree_products_taxons.taxon_id"). joins("LEFT JOIN spree_product_properties ON spree_product_properties.product_id = spree_products.id LEFT JOIN spree_properties ON spree_properties.id = spree_product_properties.property_id"). - group("spree_variants.id, spree_products.id, spree_products.name, spree_variants.sku, price, spree_variants.deleted_at, spree_products.available_on, product_deleted_at") + group("spree_variants.id, spree_products.id, spree_products.name, spree_variants.sku, price, spree_variants.deleted_at, spree_products.available_on, product_deleted_at"). + order("spree_variants.sku, spree_products.name") + end def self.to_csv diff --git a/app/views/spree/admin/reports/sales_for_client.html.erb b/app/views/spree/admin/reports/sales_for_client.html.erb index 61e0a6f..88e98ad 100644 --- a/app/views/spree/admin/reports/sales_for_client.html.erb +++ b/app/views/spree/admin/reports/sales_for_client.html.erb @@ -27,7 +27,6 @@ <%= Spree.t(:total) %> <%= Spree.t(:email) %> <%= Spree.t(:client_name) %> - <%= Spree.t(:run) %> <%= Spree.t(:address) %> <%= Spree.t(:state_address) %> <%= Spree.t(:order) %> @@ -45,7 +44,6 @@ <%= display_money(item[:total]) %> <%= item[:email] %> <%= full_name(item) %> - <%= run_format(item) %> <%= full_address(item) %> <%= item[:state_address] %> <%= item[:order_number] %> @@ -57,4 +55,4 @@
<%= paginate @items %> -
\ No newline at end of file + diff --git a/app/views/spree/admin/reports/sales_for_month.html.erb b/app/views/spree/admin/reports/sales_for_month.html.erb index 2491df1..3aa979d 100644 --- a/app/views/spree/admin/reports/sales_for_month.html.erb +++ b/app/views/spree/admin/reports/sales_for_month.html.erb @@ -34,7 +34,7 @@ <%= link_to(item[:number], edit_admin_order_path(item[:number])) %> <%= item[:email] %> <%= item[:items_quant] %> - <%= display_price(item[:total]) %> + <%= item[:total] %> <% end %> @@ -43,4 +43,4 @@
<%= paginate @items %> -
\ No newline at end of file + diff --git a/app/views/spree/admin/reports/sales_for_state.html.erb b/app/views/spree/admin/reports/sales_for_state.html.erb index 795188e..4fce98d 100644 --- a/app/views/spree/admin/reports/sales_for_state.html.erb +++ b/app/views/spree/admin/reports/sales_for_state.html.erb @@ -29,10 +29,10 @@ <%= item[:state] %> <%= item[:city] %> <%= item[:orders_quant] %> - <%= display_price(item[:total]) %> + <%= item[:total] %> <% end %> -<%= paginate @items %> \ No newline at end of file +<%= paginate @items %> diff --git a/app/views/spree/admin/reports/sales_sku.html.erb b/app/views/spree/admin/reports/sales_sku.html.erb index a574b91..c8a1b55 100644 --- a/app/views/spree/admin/reports/sales_sku.html.erb +++ b/app/views/spree/admin/reports/sales_sku.html.erb @@ -29,7 +29,7 @@ <%= link_to item[:sku], edit_admin_product_path(item[:product_id]) %> <%= item[:name] %> <%= item[:items_quant] %> - <%= display_price(item[:total]) %> + <%= item[:total] %> <% end %> diff --git a/app/views/spree/admin/reports/sales_total.html.erb b/app/views/spree/admin/reports/sales_total.html.erb index d424143..d52d5a3 100644 --- a/app/views/spree/admin/reports/sales_total.html.erb +++ b/app/views/spree/admin/reports/sales_total.html.erb @@ -23,8 +23,11 @@ <%= Spree.t(:shipment) %> - <%= Spree.t(:order_total) %> + <%= Spree.t(:order_total) %> + + Payment State + @@ -35,6 +38,7 @@ <%= display_money(item[:total]) %> <%= display_money(item[:shipment_total]) %> <%= display_money(item[:order_total]) %> + <%= item[:payment_state] %> <% end %> diff --git a/app/views/spree/admin/reports/stock_details.html.erb b/app/views/spree/admin/reports/stock_details.html.erb index e02e752..564afc9 100644 --- a/app/views/spree/admin/reports/stock_details.html.erb +++ b/app/views/spree/admin/reports/stock_details.html.erb @@ -24,7 +24,7 @@ <%= item[:name] %> <%= item[:location_name] %> <%= item[:stock] %> - <%= Spree.t("available.#{product_available?(item)}") %> + <%= item[:available_on].strftime("%m/%d/%Y") %> <% end %> @@ -33,4 +33,4 @@
<%= paginate @items %> -
\ No newline at end of file + diff --git a/app/views/spree/admin/reports/variants_data.html.erb b/app/views/spree/admin/reports/variants_data.html.erb index 7d5bea4..c045c73 100644 --- a/app/views/spree/admin/reports/variants_data.html.erb +++ b/app/views/spree/admin/reports/variants_data.html.erb @@ -15,7 +15,6 @@ <%= Spree.t(:taxons) %> <%= Spree.t(:description) %> <%= Spree.t(:brand) %> - <%= Spree.t(:availability) %> <%= Spree.t(:price) %> @@ -26,7 +25,6 @@ <%= item[:taxons].join(', ') %> <%= item[:name] %> <%= brand(item) %> - <%= Spree.t("available.#{product_available?(item)}") %> <%= display_money(item[:price]) %> <% end %> @@ -36,4 +34,4 @@
<%= paginate @items %> -
\ No newline at end of file + diff --git a/config/routes.rb b/config/routes.rb index 87e10d9..97597ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,15 @@ post :total_sales_for_months get :sales_for_promotion post :sales_for_promotion + + get :sales_for_client + post :sales_for_client + get :sales_and_stock + post :sales_and_stock + get :variants_data + post :variants_data + # get :sales_click_go + # post :sales_click_go end end end diff --git a/spree_custom_reports.gemspec b/spree_custom_reports.gemspec index 3a129bc..cd303e3 100644 --- a/spree_custom_reports.gemspec +++ b/spree_custom_reports.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.requirements << 'none' - s.add_dependency 'spree_core', '~> 3.0.10' + s.add_dependency 'spree_core', '~> 3.4' s.add_dependency 'iconv' s.add_development_dependency 'capybara', '~> 2.6' From 1480e4110087f2c35397e271c2c5277dbfdfdb42 Mon Sep 17 00:00:00 2001 From: Rob Daniels Date: Fri, 18 May 2018 08:59:31 -0400 Subject: [PATCH 2/2] readme update --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1991e9e..f415352 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ Introduction goes here. ```ruby gem 'spree_custom_reports', github: 'engarcia/spree_custom_reports', branch: '3-0-stable' ``` + or + ```ruby + gem 'spree_custom_reports', github: 'engarcia/spree_custom_reports', branch: '3-4-stable' + ``` The `branch` option is important: it must match the version of Spree you're using. For example, use `3-0-stable` if you're using Spree `3-0-stable` or any `3.0.x` version.