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/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. 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 @@