Module: QuotesHelper

Defined in:
app/helpers/quotes_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_quote_party_hash(quote) ⇒ Object



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

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



59
60
61
# File 'app/helpers/quotes_helper.rb', line 59

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

#display_ship_insurance_alerts(quote) ⇒ Object



63
64
65
# File 'app/helpers/quotes_helper.rb', line 63

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

#fields_for_shipping_cost(shipping_cost) ⇒ Object



49
50
51
52
# File 'app/helpers/quotes_helper.rb', line 49

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



54
55
56
57
# File 'app/helpers/quotes_helper.rb', line 54

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



33
34
35
36
37
38
# File 'app/helpers/quotes_helper.rb', line 33

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



67
68
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
# File 'app/helpers/quotes_helper.rb', line 67

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 block-ui-on-click', data: { 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 = { 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 block-ui-on-click', 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



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

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



120
121
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
# File 'app/helpers/quotes_helper.rb', line 120

def quote_tab_options
  {
    line_items: { remote_href: tab_line_items_quote_path(@quote) },
    material_alerts: { remote_href: show_material_alerts_tab_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: String.new('Rooms & Areas'),
      remote_href: quote_room_configurations_path(@quote)
    },
    activities: { counter: @quote.open_activities_counter, remote_href: quote_activities_path(@quote, selected_activity: params[:selected_activity]) },
    communications: { remote_href: quote_communications_path(@quote) },
    sms: {
      remote_href: quote_sms_messages_path(@quote),
      counter: @quote.sms_messages.unread.size
    },
    attachments: { remote_href: quote_uploads_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



2
3
4
5
6
# File 'app/helpers/quotes_helper.rb', line 2

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



149
150
151
# File 'app/helpers/quotes_helper.rb', line 149

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