Class: ConsumablesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/consumables_controller.rb

Instance Method Summary collapse

Instance Method Details

#categoryObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/consumables_controller.rb', line 42

def category
  category_id = (params[:id] == "All") ? "145200000" : params[:id]
  @category = MercatorBechlem::Vcategory.where(IDCATEGORY: category_id).first
  @ancestors = try_to { @category.ancestors }
  @children = @category ? @category.children : MercatorBechlem::Vcategory.ivellio_top_categories

  @printers = MercatorBechlem::VitemSupply.for_category_id(params[:id])

  if @printers && @category && @category.parent
    printer_alternative_numbers = @printers.collect { |printer| "#{printer.ARTNR.gsub("\s", '')}" }
                                           .uniq
    @products = Inventory.where(alternative_number: printer_alternative_numbers).*
                         .product
                         .uniq
    @active_products = @products.find_all{|product| product.state == "active" }
  end
end

#printersObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/consumables_controller.rb', line 19

def printers
  @printerserie = params[:id]

  @printer_series = MercatorBechlem::VitemPrinter.where(brand: "HP")
                                                 .where.not(printerseries: nil)
                                                 .order(PRINTERSERIES: :asc)
  @printer_series_names = @printer_series.*.PRINTERSERIES.uniq

  if @printerserie == "All"
    @printer_names = MercatorBechlem::VitemPrinter.where(brand: "HP")
                                                  .order(DESCRIPTION: :asc).*
                                                  .DESCRIPTION
                                                  .uniq
  else
    @printer_names = MercatorBechlem::VitemPrinter.where(brand: "HP", printerseries: @printerserie)
                                                  .order(DESCRIPTION: :asc).*
                                                  .DESCRIPTION.uniq
    @printers = MercatorBechlem::VitemPrinter.where(brand: "HP", printerseries: @printerserie)
                                             .select("CATEGORY, BRAND, DESCRIPTION, IDITEM")
                                             .order(DESCRIPTION: :asc)
  end
end

#productsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/consumables_controller.rb', line 5

def products
  @printer = params[:id]
  @printer ||= try_to{ MercatorBechlem::VitemPrinter.where(brand: "HP", DESCRIPTION: params[:printer]).first.IDITEM }

  if @printer
    icecat_products = MercatorBechlem::Vitem2item.where(IDITEM: @printer )
    @printer_description = MercatorBechlem::VitemPrinter.where(IDITEM: @printer).first.DESCRIPTION
    alternative_numbers = icecat_products.collect { |product| "#{product.ARTNR.gsub("\s", '')}" }.uniq
                                                            # gsub removes whitespace characters, compact removes nil elements
    @products = Inventory.where(alternative_number: alternative_numbers).*.product.uniq
    @active_products = @products.find_all{|product| product.state == "active" }
  end
end