reports_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930
  1. class ReportsController < ApplicationController
  2. ##--- Breadcrum_rails
  3. add_breadcrumb I18n.t("breadcrumbs." + controller_name), :reports_path
  4. add_breadcrumb "Reporte de mínimos y máximos", :min_max_path, only: :min_max
  5. def min_max
  6. @pointsales = Pointsale.activos
  7. respond_to do |format|
  8. if params[:pointsale_id].present?
  9. @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)
  10. @products = get_products_category(@products, params[:category], params[:subcategory]) if params[:category].present?
  11. format.js
  12. else
  13. @products = AvailableProduct.where(pointsale_id: @pointsales.first.id).where("available_products.stock <= available_products.stock_min and available_products.stock_min > ?", 0)
  14. format.html
  15. end
  16. end
  17. end
  18. def get_products_category(products, category, subcategory)
  19. ids =
  20. if subcategory.present?
  21. subcategory
  22. else
  23. category = Category.find(category)
  24. [category.id, category.children.ids].flatten
  25. end
  26. products.where(categories: { id: ids })
  27. end
  28. end