Module: MyInstantQuotesHelper

Defined in:
app/helpers/my_instant_quotes_helper.rb

Instance Method Summary collapse

Instance Method Details

#class_for_zip(country_iso3) ⇒ Object



2
3
4
5
6
7
8
9
# File 'app/helpers/my_instant_quotes_helper.rb', line 2

def class_for_zip(country_iso3)
  case country_iso3
  when 'USA'
    'zip_code'
  else
    'canadian_postal_code'
  end
end

#display_iq_discounted_price_for_option_group(og, extra_included_room_line_items = []) ⇒ Object



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

def display_iq_discounted_price_for_option_group(og, extra_included_room_line_items = [])
  currency_symbol = begin
    og.room_configuration.currency_symbol
  rescue StandardError
    Money::Currency.new('USD').symbol
  end
  price = og.price
  discounted_price = og.discounted_price
  extra_included_room_line_items.each do |li|
    price += li.quantity * li.catalog_item.amount
    discounted_price += li.quantity * li.catalog_item.discounted_price(li.resource.customer, li.resource)
  end
  if discounted_price < price
    tag.del(number_to_currency(price, unit: currency_symbol)) + ' ' +
      (:span, number_to_currency(discounted_price, unit: currency_symbol), class: 'text-danger fw-bold')
  else
    number_to_currency(price, unit: currency_symbol)
  end
end

#display_iq_room_discounted_total(room, include_controls = true, include_accessories_and_install_kits = true) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/my_instant_quotes_helper.rb', line 25

def display_iq_room_discounted_total(room, include_controls = true, include_accessories_and_install_kits = true)
  tot = 0.0
  l_items = room.line_items.heating_elements
  l_items += room.line_items.controls.to_a + room.line_items.integration_kits.to_a + room.line_items.powers.to_a if include_controls
  l_items += room.line_items.accessories.to_a - room.line_items.membranes.to_a if include_accessories_and_install_kits
  l_items += room.line_items.membranes.to_a # always include membranes
  l_items.each do |li|
    tot += li.quantity * li.catalog_item.discounted_price(room.customer, room)
  end
  number_to_currency(tot, unit: begin
    room.currency_symbol
  rescue StandardError
    Money::Currency.new('USD').symbol
  end)
end

#display_iq_room_quote_total(room) ⇒ Object



17
18
19
20
21
22
23
# File 'app/helpers/my_instant_quotes_helper.rb', line 17

def display_iq_room_quote_total(room)
  number_to_currency(room.quotes.first.total, unit: begin
    room.currency_symbol
  rescue StandardError
    Money::Currency.new('USD').symbol
  end)
end

#shorten_name(name, max = 40) ⇒ Object



11
12
13
14
15
# File 'app/helpers/my_instant_quotes_helper.rb', line 11

def shorten_name(name, max = 40)
  res = name.to_s
  res = res[0..(max - 4)] + '...' if res.length > max
  res
end