|
@@ -133,16 +133,17 @@ class AvailableProductsController < ApplicationController
|
|
|
location_id = params[:location][2, params[:location].length] unless location.blank?
|
|
location_id = params[:location][2, params[:location].length] unless location.blank?
|
|
|
|
|
|
|
|
if (current_user.usertype == 'S' && location.blank?) || (!location.blank? && location.first == 'W')
|
|
if (current_user.usertype == 'S' && location.blank?) || (!location.blank? && location.first == 'W')
|
|
|
- stock = WarehouseStock.activos.(:warehouse, :categories).where(warehouse_id: (location_id.blank? ? current_user.warehouse_id : location_id)).where('stock > 0')
|
|
|
|
|
|
|
+ stock = WarehouseStock.activos.includes(:warehouse, :categories).where(warehouse_id: (location_id.blank? ? current_user.warehouse_id : location_id)).where('stock > 0')
|
|
|
elsif (current_user.usertype != 'S' && location.blank?) || (!location.blank? && location.first == 'P')
|
|
elsif (current_user.usertype != 'S' && location.blank?) || (!location.blank? && location.first == 'P')
|
|
|
- stock = AvailableProduct.activos.(:pointsale, :categories).where(pointsale_id: (location_id.blank? ? current_user.pointsale_id : location_id)).where('stock > 0')
|
|
|
|
|
|
|
+ stock = AvailableProduct.activos.includes(:pointsale, :categories).where(pointsale_id: (location_id.blank? ? current_user.pointsale_id : location_id)).where('stock > 0')
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
if sub_category.present?
|
|
if sub_category.present?
|
|
|
stock = stock.joins(:categories).where('categories.id = ?', sub_category)
|
|
stock = stock.joins(:categories).where('categories.id = ?', sub_category)
|
|
|
elsif category.present?
|
|
elsif category.present?
|
|
|
- subs_ids = Category.activos.where(parent_id: category).pluck(:id)
|
|
|
|
|
- stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
|
|
|
|
|
|
|
+ category = Category.find(category)
|
|
|
|
|
+ children = category.children
|
|
|
|
|
+ stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
if size != 0
|
|
if size != 0
|
|
@@ -181,8 +182,9 @@ class AvailableProductsController < ApplicationController
|
|
|
if sub_category.present?
|
|
if sub_category.present?
|
|
|
stock = stock.joins(:categories).where('categories.id = ?', sub_category)
|
|
stock = stock.joins(:categories).where('categories.id = ?', sub_category)
|
|
|
elsif category.present?
|
|
elsif category.present?
|
|
|
- subs_ids = Category.activos.where(parent_id: category).pluck(:id)
|
|
|
|
|
- stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
|
|
|
|
|
|
|
+ category = Category.find(category)
|
|
|
|
|
+ children = category.children
|
|
|
|
|
+ stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
total_prods = stock.sum(:stock)
|
|
total_prods = stock.sum(:stock)
|
|
@@ -204,8 +206,9 @@ class AvailableProductsController < ApplicationController
|
|
|
if sub_category.present?
|
|
if sub_category.present?
|
|
|
stock = stock.joins(:categories).where('categories.id = ?', sub_category)
|
|
stock = stock.joins(:categories).where('categories.id = ?', sub_category)
|
|
|
elsif category.present?
|
|
elsif category.present?
|
|
|
- subs_ids = Category.activos.where(parent_id: category).pluck(:id)
|
|
|
|
|
- stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
|
|
|
|
|
|
|
+ category = Category.find(category)
|
|
|
|
|
+ children = category.children
|
|
|
|
|
+ stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
obj = Hash.new
|
|
obj = Hash.new
|