| 123456789101112131415161718192021222324252627282930 |
- class ReportsController < ApplicationController
- ##--- Breadcrum_rails
- add_breadcrumb I18n.t("breadcrumbs." + controller_name), :reports_path
- add_breadcrumb "Reporte de mínimos y máximos", :min_max_path, only: :min_max
- def min_max
- @pointsales = Pointsale.activos
- respond_to do |format|
- if params[:pointsale_id].present?
- @products = AvailableProduct.joins(:product, :categories).activos.where(pointsale_id: params[:pointsale_id]).where("available_products.stock <= available_products.stock_min and available_products.stock_max > ?", 0)
- @products = get_products_category(@products, params[:category], params[:subcategory]) if params[:category].present?
- format.js
- else
- @products = AvailableProduct.where(pointsale_id: @pointsales.first.id).where("available_products.stock <= available_products.stock_min and available_products.stock_min > ?", 0)
- format.html
- end
- end
- end
- def get_products_category(products, category, subcategory)
- ids =
- if subcategory.present?
- subcategory
- else
- category = Category.find(category)
- [category.id, category.children.ids].flatten
- end
- products.where(categories: { id: ids })
- end
- end
|