Module: QuotesHelper

Defined in:
app/helpers/quotes_helper.rb

Overview

View helper: quotes.

Instance Method Summary collapse

Instance Method Details

#build_quote_party_hash(quote) ⇒ Object



42
43
44
45
46
47
48
49
# File 'app/helpers/quotes_helper.rb', line 42

def build_quote_party_hash(quote)
  parties_hash = {
    "#{quote.primary_party.full_name} (Primary)" => quote.primary_party,
    "#{quote.customer.full_name} (Billing Customer)" => { party: quote.customer, collapsed: false }
  }
  append_opportunity_participants_hash(quote.opportunity, parties_hash) if quote.opportunity
  parties_hash
end

#display_pre_pack_alerts(quote) ⇒ Object



61
62
63
# File 'app/helpers/quotes_helper.rb', line 61

def display_pre_pack_alerts(quote)
  render partial: '/shared/pre_pack_alerts', locals: { quote: quote }
end

#display_ship_insurance_alerts(quote) ⇒ Object



65
66
67
# File 'app/helpers/quotes_helper.rb', line 65

def display_ship_insurance_alerts(quote)
  render partial: '/shared/ship_insurance_alerts', locals: { ship_quotable: quote }
end

#fields_for_shipping_cost(shipping_cost) ⇒ Object



51
52
53
54
# File 'app/helpers/quotes_helper.rb', line 51

def fields_for_shipping_cost(shipping_cost, &)
  prefix = shipping_cost.new_record? ? 'new' : 'existing'
  fields_for("delivery[#{prefix}_shipping_cost_attributes][]", shipping_cost, &)
end

#gather_quote_phones(_opp) ⇒ Object



56
57
58
59
# File 'app/helpers/quotes_helper.rb', line 56

def gather_quote_phones(_opp)
  phones = [] + @quote.primary_party.contact_points.voice_callable.limit(3) + @opportunity.customer.contact_points.voice_callable.limit(3)
  phones.compact.uniq
end

#get_quote_profit_label(quote) ⇒ Object



35
36
37
38
39
40
# File 'app/helpers/quotes_helper.rb', line 35

def get_quote_profit_label(quote)
  profit_label = +'Profit: '
  profit_label << colored_profit_status(quote)
  profit_label << " (#{colored_profit(quote)}, min: #{quote.min_profit_markup} %)"
  profit_label.html_safe
end

#quote_command_options(quote = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/helpers/quotes_helper.rb', line 69

def quote_command_options(quote = nil)
  quote ||= @quote
  opts = []
  opts << quote.human_state_name.titleize
  opts << link_to(fa_icon('envelope', text: 'Transmit'), select_pdf_template_quote_path(quote)) if quote.can_be_transmitted?
  opts << if quote.can_convert? && can?(:place_orders, quote.customer)
            link_to(fa_icon('circle-dollar', text: 'Convert to Order'), convert_to_order_quote_path(quote),
                    { class: 'transactional', data: { controller: 'ui-blocker', turbo_method: :put } })
          else
            { content: 'Cannot be converted to order', class: 'dropdown-item-text text-muted' }
          end
  has_active_pre_pack = quote.has_pre_pack_deliveries?

  if quote.complete?
    requote_data = { controller: 'ui-blocker', turbo_method: :post }
    requote_data[:turbo_confirm] = 'WARNING: This quote has an active pre-pack in the warehouse. Requoting will notify the warehouse to stop. Continue?' if has_active_pre_pack
    opts << link_to(fa_icon('clone', text: 'Requote/Redesign'), requote_quote_path(quote), { class: 'transactional', data: requote_data })
  end
  opts << link_to(fa_icon('file', text: 'Preview Quote pdf'), quote_path(quote, format: :pdf))
  opts << link_to(fa_icon('file', text: 'Get Quote link'), link_quote_path(quote))
  opts << link_to(fa_icon('file', text: 'Preview Materials pdf'), quote_path(quote, materials_only: true, format: :pdf))
  opts << link_to(fa_icon('forward', text: 'Process Quote'), shipping_quote_path(quote)) if quote.pending?
  if can?(:manage_profit_margins, quote)
    opts << link_to(fa_icon('chart-pie', text: 'Review/Update Profit Margins'),
                    profit_margins_quote_path(quote))
  end
  opts << link_to(fa_icon('face-frown', text: 'Opportunity Lost'), workflow_action_opportunity_path(quote.opportunity, wf_action: 'lose')) if quote.opportunity.can_lose?
  cancel_confirm = has_active_pre_pack ? { event: :cancel, prompt: 'WARNING: This quote has an active pre-pack in the warehouse. Cancelling will notify the warehouse to stop. Continue?' } : {}
  if (events = available_events_links(quote, {}, cancel_confirm, ['request_estimated_packaging'])).present?
    opts << { class: 'divider' }
    opts += events
    opts << { class: 'divider' }
  end
  pp_disabled = (show_quote_pre_pack_option(quote) ? false : true)
  pp_label = pp_disabled ? 'Already packaged, contact Warehouse to request repackaging' : 'Request Estimated Packaging'
  pp_link_opts = pp_disabled ? { class: 'disabled', aria: { disabled: true }, tabindex: -1 } : {}
  opts << link_to(fa_icon('right-from-bracket', text: pp_label),
                  (pp_disabled ? '#' : workflow_action_quote_path(quote, wf_action: 'request_estimated_packaging')),
                  pp_link_opts)

  opts << link_to(fa_icon('right-from-bracket', text: 'Move'), move_quote_path(quote))
  opts << link_to(fa_icon('copy', text: 'Copy'), copy_quote_path(quote))

  opts << link_to(fa_icon('pen-to-square', text: 'Edit'), edit_quote_path(quote)) if can?(:update, quote)
  if can? :destroy, quote
    opts << link_to(fa_icon('trash', text: 'Delete'),
                    quote_path(quote),
                    data: { turbo_confirm: 'Are you sure want to delete this quote?', turbo_method: :delete })
  end

  opts
end

#quote_quick_info(quote = @quote) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/quotes_helper.rb', line 10

def quote_quick_info(quote = @quote)
  info = []
  info << if @quote.hold_for_transmission
            fa_icon('ban', style: 'color: red', text: 'Hold for transmission')
          else
            fa_icon('check', style: 'color: green', text: 'Release when ready')
          end
  info << fa_icon('clock', text: quote.priority.titleize, style: { 'same day' => 'color:red', 'next day' => 'color:orange' }[quote.priority])
  info << fa_icon('right-left', text: 'RMA Redesign') if quote.rma
  info << employee_badge(quote.primary_sales_rep, title: 'Primary Sales Rep') if quote.primary_sales_rep
  info << fa_icon('file-invoice-dollar', text: number_to_currency(quote.total, unit: quote.currency_symbol))
  info << fa_icon('tags', text: "Effective Discount: #{quote.effective_discount} %".html_safe)
  if quote.is_sales_quote? && quote.track_profit?
    if can?(:manage_profit_margins, quote)
      profit_info = link_to(profit_margins_quote_path(quote), class: 'px-2 nav-link') do
        safe_join([fa_icon('chart-pie'), (:span, get_quote_profit_label(quote), class: 'copy-target')], ' ')
      end
      info << profit_info
    else
      info << (:span, fa_icon('chart-pie', text: "Profit Status: #{colored_profit_status(quote)}".html_safe))
    end
  end
  info
end

#quote_tab_optionsObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/helpers/quotes_helper.rb', line 122

def quote_tab_options
  {
    line_items: { remote_href: tab_line_items_quote_path(@quote) },
    material_alerts: { remote_href: tab_material_alerts_quote_path(@quote) },
    main: { remote_href: tab_main_quote_path(@quote) },
    contacts: { remote_href: tab_contacts_quote_path(@quote) },
    shipping: { remote_href: tab_shipping_quote_path(@quote) },
    rooms: {
      counter: @quote.room_configurations.size,
      title: +'Rooms & Areas',
      remote_href: tab_rooms_quote_path(@quote)
    },
    activities: {
      counter: @quote.open_activities_counter,
      remote_href: tab_activities_quote_path(@quote, selected_activity: params[:selected_activity])
    },
    communications: { remote_href: tab_communications_quote_path(@quote) },
    sms: {
      remote_href: tab_sms_quote_path(@quote),
      counter: @quote.sms_messages.unread.size
    },
    attachments: { remote_href: tab_attachments_quote_path(@quote) },
    tickets: {
      title: 'Tickets',
      counter_html: tech_counter_badge(@quote.support_cases),
      remote_href: tab_tickets_quote_path(@quote)
    },
    inventory: { remote_href: tab_inventory_quote_path(@quote) },
    revisions: { remote_href: tab_revisions_quote_path(@quote) }
  }
end

#setup_quote(quote) ⇒ Object



4
5
6
7
8
# File 'app/helpers/quotes_helper.rb', line 4

def setup_quote(quote)
  quote.tap do |q|
    q.quote_type ||= quote.prefix_for_reference_number
  end
end

#show_quote_pre_pack_option(quote) ⇒ Object



154
155
156
# File 'app/helpers/quotes_helper.rb', line 154

def show_quote_pre_pack_option(quote)
  (quote.deliveries.any? && quote.deliveries.any? { |d| d.shipments.any? { |s| !s.packed_or_pre_packed? } }) || (current_user&.has_role?('warehouse_rep') || current_user&.is_manager?)
end