Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.4 stable working #1

Open
wants to merge 2 commits into
base: 3-0-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 15 additions & 15 deletions app/controllers/spree/admin/reports_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/report/sales_and_stock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions app/models/spree/report/sales_for_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/report/sales_for_month.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/report/sales_for_promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -38,4 +38,4 @@ def self.to_csv(dates)
end
end

end
end
4 changes: 2 additions & 2 deletions app/models/spree/report/sales_for_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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,
SUM(spree_orders.item_total + spree_orders.adjustment_total) AS total").
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
Expand Down
7 changes: 4 additions & 3 deletions app/models/spree/report/sales_sku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ 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").
joins("INNER JOIN spree_variants ON spree_variants.id = spree_line_items.variant_id").
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)
Expand Down
10 changes: 7 additions & 3 deletions app/models/spree/report/sales_total.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/models/spree/report/stock_detail.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/models/spree/report/variant_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions app/views/spree/admin/reports/sales_for_client.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<th><%= Spree.t(:total) %></th>
<th><%= Spree.t(:email) %></th>
<th><%= Spree.t(:client_name) %></th>
<th><%= Spree.t(:run) %></th>
<th><%= Spree.t(:address) %></th>
<th><%= Spree.t(:state_address) %></th>
<th><%= Spree.t(:order) %></th>
Expand All @@ -45,7 +44,6 @@
<td><%= display_money(item[:total]) %></td>
<td><%= item[:email] %></td>
<td><%= full_name(item) %></td>
<td><%= run_format(item) %></td>
<td><%= full_address(item) %></td>
<td><%= item[:state_address] %></td>
<td><%= item[:order_number] %></td>
Expand All @@ -57,4 +55,4 @@

<div>
<%= paginate @items %>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/spree/admin/reports/sales_for_month.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<td><%= link_to(item[:number], edit_admin_order_path(item[:number])) %></td>
<td><%= item[:email] %></td>
<td><%= item[:items_quant] %></td>
<td><%= display_price(item[:total]) %></td>
<td><%= item[:total] %></td>
</tr>
<% end %>
</tbody>
Expand All @@ -43,4 +43,4 @@

<div>
<%= paginate @items %>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/spree/admin/reports/sales_for_state.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<td><%= item[:state] %></td>
<td><%= item[:city] %></td>
<td><%= item[:orders_quant] %></td>
<td><%= display_price(item[:total]) %></td>
<td><%= item[:total] %></td>
</tr>
<% end %>
</tbody>
</table>

<%= paginate @items %>
<%= paginate @items %>
2 changes: 1 addition & 1 deletion app/views/spree/admin/reports/sales_sku.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<td><%= link_to item[:sku], edit_admin_product_path(item[:product_id]) %></td>
<td><%= item[:name] %></td>
<td><%= item[:items_quant] %></td>
<td><%= display_price(item[:total]) %></td>
<td><%= item[:total] %></td>
</tr>
<% end %>
</tbody>
Expand Down
6 changes: 5 additions & 1 deletion app/views/spree/admin/reports/sales_total.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
<th><%= Spree.t(:shipment) %></th>
<th>
<span data-toggle="tooltip" data-placement="top" title="TOTAL + ENVÍO">
<%= Spree.t(:order_total) %></th>
<%= Spree.t(:order_total) %>
</span>
</th>
<th>Payment State</th>

</tr>
</thead>
<tbody>
Expand All @@ -35,6 +38,7 @@
<td><%= display_money(item[:total]) %></td>
<td><%= display_money(item[:shipment_total]) %></td>
<td><%= display_money(item[:order_total]) %></td>
<td><%= item[:payment_state] %></td>
</tr>
<% end %>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/reports/stock_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<td><%= item[:name] %></td>
<td><%= item[:location_name] %></td>
<td><%= item[:stock] %></td>
<td><%= Spree.t("available.#{product_available?(item)}") %></td>
<td><%= item[:available_on].strftime("%m/%d/%Y") %></td>
</tr>
<% end %>
</tbody>
Expand All @@ -33,4 +33,4 @@

<div>
<%= paginate @items %>
</div>
</div>
4 changes: 1 addition & 3 deletions app/views/spree/admin/reports/variants_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<th><%= Spree.t(:taxons) %></th>
<th><%= Spree.t(:description) %></th>
<th><%= Spree.t(:brand) %></th>
<th><%= Spree.t(:availability) %></th>
<th><%= Spree.t(:price) %></th>
</tr>
</thead>
Expand All @@ -26,7 +25,6 @@
<td><%= item[:taxons].join(', ') %></td>
<td><%= item[:name] %></td>
<td><%= brand(item) %></td>
<td><%= Spree.t("available.#{product_available?(item)}") %></td>
<td><%= display_money(item[:price]) %></td>
</tr>
<% end %>
Expand All @@ -36,4 +34,4 @@

<div>
<%= paginate @items %>
</div>
</div>
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spree_custom_reports.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down