Module: CustomersHelper
- Defined in:
- app/helpers/customers_helper.rb
Overview
View helper: customers.
Instance Method Summary collapse
-
#account_manager_display(label, employee) ⇒ Object
Renders an account manager row with avatar for panels (larger display).
- #account_manager_options(c) ⇒ Object
- #catalog_options_for_select(customer) ⇒ Object
- #contact_point_display_with_highlight(cp, contact_point_details_to_highlight = []) ⇒ Object
- #customer_accounting_command_options(customer) ⇒ Object
- #customer_address_panel(customer, type) ⇒ Object
- #customer_command_options(customer = @customer) ⇒ Object
-
#customer_delete_link(customer = @customer, options = {}) ⇒ String?
Renders a delete link for a customer, when permitted.
- #customer_flag_image(c) ⇒ Object
- #customer_multiple_visits_link(customer, most_recent) ⇒ Object
- #customer_quick_info(customer = @customer) ⇒ Object
- #customer_rating_symbol(rating) ⇒ Object
- #customer_sales_reps(customer) ⇒ Object
- #customer_single_visit_link(most_recent) ⇒ Object
- #customer_state_with_drop_reason(customer) ⇒ Object
- #customer_tab_options ⇒ Object
- #customer_visits_link(customer) ⇒ Object
- #customer_watch_symbol(c) ⇒ Object
- #customer_watch_symbol_raw(watch, open_sales_activity) ⇒ Object
- #dealer_locator_status(customer) ⇒ Object
- #display_contact_banner(contact) ⇒ Object
- #display_customer_banner(customer, inline: false) ⇒ Object
- #display_customer_update_alerts(order, inline: false) ⇒ Object
-
#employee_badge(employee, title: nil, size: 18) ⇒ Object
Renders an employee badge with avatar and name (inline, small) Uses Party.profile_image for the avatar (consolidated from employee_record.profile_picture).
-
#employee_profile_avatar(employee, size: 20) ⇒ Object
Renders an employee profile picture or initials fallback Uses Party.profile_image (consolidated storage for all party types).
-
#font_class_symbol(result_class, options = {}) ⇒ String
Maps a search-result class name to its Font Awesome icon.
- #local_sales_rep_input(f) ⇒ Object
- #parent_org_name(customer) ⇒ Object
- #primary_sales_rep_input(f) ⇒ Object
- #render_customer_contact_points(customer, _highlight = true) ⇒ Object
- #rep_input(f, rep_type) ⇒ Object
- #secondary_sales_rep_input(f) ⇒ Object
- #setup_customer(c) ⇒ Object
- #setup_customer_channels(c) ⇒ Object
- #setup_customer_contact_points(c) ⇒ Object
- #setup_customer_record(c) ⇒ Object
Instance Method Details
#account_manager_display(label, employee) ⇒ Object
Renders an account manager row with avatar for panels (larger display)
249 250 251 252 253 254 255 256 257 |
# File 'app/helpers/customers_helper.rb', line 249 def account_manager_display(label, employee) return nil unless employee avatar = employee_profile_avatar(employee, size: 32) employee_info = content_tag(:span, class: 'd-inline-flex align-items-center gap-2') do safe_join([avatar, link_to(employee.full_name, employee_path(employee))]) end attr_display(label, employee_info) end |
#account_manager_options(c) ⇒ Object
82 83 84 85 86 87 |
# File 'app/helpers/customers_helper.rb', line 82 def (c) = [] << link_to('Account Managers', edit_customer_path(c, anchor: 'account_team')) << link_to('Drop Events', drop_events_customer_path(c)) raw .join(' | ') end |
#catalog_options_for_select(customer) ⇒ Object
14 15 16 17 18 |
# File 'app/helpers/customers_helper.rb', line 14 def (customer) catalogs = Catalog.active catalogs = catalogs.where(name: %w[WarmlyYours-CA WarmlyYours-US]) unless user_has_role?('edi_admin') catalogs.map { |c| ["#{c.name} #{' (current)' if c.id == customer.catalog_id}", c.id] } end |
#contact_point_display_with_highlight(cp, contact_point_details_to_highlight = []) ⇒ Object
381 382 383 384 385 386 |
# File 'app/helpers/customers_helper.rb', line 381 def contact_point_display_with_highlight(cp, contact_point_details_to_highlight = []) display_icon = contact_point_category_icon(cp[0]) display = cp[1] display = content_tag(:mark, display) if contact_point_details_to_highlight.include?(cp[1]) display_icon + ' '.html_safe + display end |
#customer_accounting_command_options(customer) ⇒ Object
207 208 209 210 211 212 213 214 215 216 |
# File 'app/helpers/customers_helper.rb', line 207 def (customer) [].tap do |opts| opts << link_to('Bankrupt', event_customer_path(customer, event: 'enter_bankrupcy')) if can? :bankrupt, customer opts << link_to('Exit Bankrupcy', event_customer_path(customer, event: 'exit_bankrupcy')) if can? :exit_bankrupcy, customer if can? :destroy, customer opts << link_to('Edit Catalog', edit_catalog_customer_path(customer)) opts << link_to('Delete', customer_path(customer), class: 'btn btn-outline-primary', data: { turbo_confirm: 'Are you sure?', turbo_method: :delete }) end end end |
#customer_address_panel(customer, type) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'app/helpers/customers_helper.rb', line 345 def customer_address_panel(customer, type) case type when :billing_address address = customer.billing_address panel_title = "Billing Address #{fa_icon('sitemap') if address.try(:party).try(:use_parent_billing_address)}" when :shipping_address address = customer.shipping_address panel_title = 'Shipping Address' else address = customer.mailing_address panel_title ' Mailing Address' end panel_title += " (has #{customer.addresses.count} addresses)" panel(panel_title, true, mode: :dropdown) do |section| case section when :dropdown opts = [] opts << content_tag(:li, link_to('Edit', customer_addresses_path(customer), class: 'dropdown-item')) opts << content_tag(:li, link_to('Shipping Preferences', edit_shipping_preferences_customer_path(customer), class: 'dropdown-item')) if type == :shipping_address opts.join.html_safe else render partial: '/address', locals: { address: address } if address end end end |
#customer_command_options(customer = @customer) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'app/helpers/customers_helper.rb', line 172 def (customer = @customer) [].tap do |opts| opts << link_to('Name and Preferences', edit_customer_path(customer)) # opts << link_to('Profile', edit_profile_customer_path(customer)) unless customer.guest? opts << link_to('Pricing', edit_pricing_customer_path(customer)) if can? :edit_pricing, customer opts << link_to('Account Team', edit_account_team_customer_path(customer)) opts << link_to('Parent Organization', edit_structure_customer_path(customer)) if customer.is_organization? opts << link_to('Shipping Preferences', edit_shipping_preferences_customer_path(customer)) opts << link_to("Online Account #{customer.account ? '✓' : '∅'}", customer_account_path(customer)) end opts << link_to('Change Catalog', edit_catalog_customer_path(customer)) # Lead Enrichment is manager-only while it's in pilot. if customer.enrichable_via_research? && current_account&.is_manager? opts << link_to(fa_icon('wand-magic-sparkles', text: 'Enrich'), new_customer_party_research_run_path(customer), data: { turbo_frame: '_top' }) end opts << customer_delete_link(customer) end.compact end |
#customer_delete_link(customer = @customer, options = {}) ⇒ String?
Renders a delete link for a customer, when permitted
201 202 203 204 205 |
# File 'app/helpers/customers_helper.rb', line 201 def customer_delete_link(customer = @customer, = {}) return unless customer.ok_to_delete? && can?(:destroy, customer) link_to(fa_icon('trash', text: 'Delete'), customer_path(customer), data: { turbo_confirm: 'Are you sure?', turbo_method: :delete }, **) end |
#customer_flag_image(c) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/customers_helper.rb', line 40 def customer_flag_image(c) return unless c.catalog_country_iso3 flag_image(c.catalog_country_iso3.downcase) end |
#customer_multiple_visits_link(customer, most_recent) ⇒ Object
151 152 153 154 155 |
# File 'app/helpers/customers_helper.rb', line 151 def customer_multiple_visits_link(customer, most_recent) display_text = String.new(pluralize(customer..size, 'visit')) display_text << " (Last was #{time_ago_in_words(most_recent.started_at)} ago)" link_to(fa_icon('magnifying-glass-plus', text: display_text), customer_visits_path(customer)) end |
#customer_quick_info(customer = @customer) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/helpers/customers_helper.rb', line 218 def customer_quick_info(customer = @customer) info = [] return info if customer.blank? info << clipboard_copy("CN#{customer.id}", mode: :text, url: customer_url(customer), button_class: 'clipboard-btn px-2 nav-link') info << employee_badge(customer.primary_sales_rep, title: 'Primary Sales Rep') if customer.primary_sales_rep info << fa_icon('head-side', text: [customer.profile&.name, customer.&.name].compact.join(' - '), title: 'Profile & Buying Group') info << fa_icon('user-helmet-safety', text: 'Certified Installer', title: 'Certified Installer') if customer.is_certified_installer? info << fa_icon('book', text: customer.catalog.name, title: 'Catalog') unless customer.catalog_id.in?([1, 2]) info << fa_icon('hand-holding-dollar', text: customer.pricing_program_description, title: 'Pricing Program') info << fa_icon('bow-arrow', text: customer.source.name, title: "Source: #{customer.source.full_name}") info end |
#customer_rating_symbol(rating) ⇒ Object
20 21 22 23 24 |
# File 'app/helpers/customers_helper.rb', line 20 def () return if .blank? content_tag(:span, , class: 'badge bg-secondary', data: { rating: }) end |
#customer_sales_reps(customer) ⇒ Object
453 454 455 456 457 458 |
# File 'app/helpers/customers_helper.rb', line 453 def customer_sales_reps(customer) reps = [] reps << fa_icon('user-headset', text: customer.primary_sales_rep_name) if customer.primary_sales_rep_name reps << fa_icon('user-headset', text: customer.secondary_sales_rep_name) if customer.secondary_sales_rep_name safe_join(reps, '<br>'.html_safe) end |
#customer_single_visit_link(most_recent) ⇒ Object
157 158 159 160 |
# File 'app/helpers/customers_helper.rb', line 157 def customer_single_visit_link(most_recent) display_text = "#{time_ago_in_words(most_recent.started_at)} ago" link_to(fa_icon('magnifying-glass-plus', text: display_text), visit_path(most_recent)) end |
#customer_state_with_drop_reason(customer) ⇒ Object
408 409 410 411 412 413 414 415 |
# File 'app/helpers/customers_helper.rb', line 408 def customer_state_with_drop_reason(customer) s = customer.human_state_name if customer.closed? reasons = customer.customer_drop_events.distinct.pluck(:reason_code) s << " (#{reasons.join(', ')})" if reasons.present? end s end |
#customer_tab_options ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'app/helpers/customers_helper.rb', line 284 def hsh = {} hsh[:activities] = { counter: @customer.open_activities_counter, remote_href: tab_activities_customer_path(@customer, selected_activity: params[:selected_activity]) } hsh[:main_profile] = { remote_href: tab_main_profile_customer_path(@customer) } hsh[:addresses] = { remote_href: tab_addresses_customer_path(@customer), counter: @customer.addresses.size } hsh[:marketing] = { remote_href: tab_marketing_customer_path(@customer) } hsh[:contacts] = { counter: @customer.contacts.active.size, remote_href: tab_contacts_customer_path(@customer) } hsh[:communications] = { remote_href: tab_communications_customer_path(@customer) } hsh[:sms] = { remote_href: tab_sms_customer_path(@customer), counter: @customer..unread.size } hsh[:opportunities] = { counter: @customer.opportunities.open_opportunities.size, remote_href: tab_opportunities_customer_path(@customer) } hsh[:orders] = { counter: @customer.orders.non_credit.in_progress.size, remote_href: tab_orders_customer_path(@customer) } hsh[:accounting] = { remote_href: tab_accounting_customer_path(@customer) } if @customer.outlet_purchases.any? hsh[:outlet_purchases] = { title: 'Outlet Purchases', counter: @customer.outlet_purchases.size, remote_href: tab_outlet_purchases_customer_path(@customer) } end hsh[:attachments] = { counter: @customer.all_uploads.size, remote_href: (@customer) } hsh[:topics] = { remote_href: tab_profiling_customer_path(@customer) } hsh[:showcases] = { remote_href: tab_showcases_customer_path(@customer) } hsh[:training] = { remote_href: tab_training_customer_path(@customer) } if @customer.contacts.present? hsh[:certifications] = { remote_href: tab_certifications_customer_path(@customer) } if @customer.can_be_certified? hsh[:tickets] = { title: 'Tickets', counter_html: tech_counter_badge(@customer.all_support_cases), remote_href: tab_tickets_customer_path(@customer) } hsh[:rmas] = { counter: @customer.rmas.awaiting_return.count, remote_href: search_and_show_searches_path( type: 'RmaSearch', query_params: { customer_id_eq: @customer.id }, selected_columns: %i[rma state description contact_name customer_reference returned_reasons original_po_number order invoice created_at], sort_columns: ['awaiting_return desc', 'rma desc'], links: { 'New RMA' => new_rma_path(customer_id: @customer.id, return_path: customer_path(@customer)) }, target_id: 'rmas' ) } hsh[:receipts] = { remote_href: tab_receipts_customer_path(@customer) } hsh[:promotions] = { remote_href: promotions_customer_path(@customer) } hsh[:lead_protections] = { counter: @customer.protected_leads.size, remote_href: tab_lead_protections_customer_path(@customer) } if @customer.protected_leads.present? hsh[:subsidiaries] = { counter: @customer.child_organizations.size, remote_href: tab_subsidiaries_customer_path(@customer) } if @customer.child_organizations.present? hsh[:reviews] = { remote_href: tab_product_reviews_customer_path(@customer) } hsh[:warranties] = { counter: @customer.warranties.count, remote_href: tab_warranty_customer_path(@customer) } hsh[:digital_assets] = { counter: @customer.digital_assets.size, remote_href: tab_digital_assets_customer_path(@customer) } hsh[:stats] = { remote_href: tab_stats_customer_path(@customer) } if @customer.customer_record&.profiling_data_last_calculated_at hsh[:duplicates] = { remote_href: duplicates_customer_path(@customer) } hsh end |
#customer_visits_link(customer) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/customers_helper.rb', line 139 def customer_visits_link(customer) # TODO: this line takes 7-10 seconds on customer pages most_recent = customer..order(:started_at).reverse_order.first return '-' unless most_recent if customer..size > 1 customer_multiple_visits_link(customer, most_recent) else customer_single_visit_link(most_recent) end end |
#customer_watch_symbol(c) ⇒ Object
36 37 38 |
# File 'app/helpers/customers_helper.rb', line 36 def customer_watch_symbol(c) customer_watch_symbol_raw(c.watch, c.has_open_sales_activity?) end |
#customer_watch_symbol_raw(watch, open_sales_activity) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/customers_helper.rb', line 26 def customer_watch_symbol_raw(watch, open_sales_activity) return unless %w[watch_auto watch_forced].include?(watch) if open_sales_activity fa_icon('heart', style: 'color: red') else fa_icon('heart', family: 'far') end end |
#dealer_locator_status(customer) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'app/helpers/customers_helper.rb', line 388 def dealer_locator_status(customer) status = [] if customer.locator_record.nil? status << 'None' elsif customer.locator_record.is_inactive? status << 'Inactive' else status << 'Active' status << if customer.locator_record.address "in #{customer.locator_record.address.zip}" else 'No Address' end status << "and #{friendly_status(customer.locator_record.state)}" end status << '[W]' if customer.locator_white_listing status << '[B]' if customer.locator_black_listing status.join(' ') end |
#display_contact_banner(contact) ⇒ Object
167 168 169 170 |
# File 'app/helpers/customers_helper.rb', line 167 def (contact) contact ||= @contact render partial: '/shared/contact_banner', locals: { contact: contact } end |
#display_customer_banner(customer, inline: false) ⇒ Object
162 163 164 165 |
# File 'app/helpers/customers_helper.rb', line 162 def (customer, inline: false) customer ||= @customer render partial: '/shared/customer_banner', locals: { customer: customer, inline: inline } end |
#display_customer_update_alerts(order, inline: false) ⇒ Object
460 461 462 |
# File 'app/helpers/customers_helper.rb', line 460 def display_customer_update_alerts(order, inline: false) render partial: '/shared/customer_alerts', locals: { order: order, inline: inline } end |
#employee_badge(employee, title: nil, size: 18) ⇒ Object
Renders an employee badge with avatar and name (inline, small)
Uses Party.profile_image for the avatar (consolidated from employee_record.profile_picture)
237 238 239 240 241 242 243 244 |
# File 'app/helpers/customers_helper.rb', line 237 def employee_badge(employee, title: nil, size: 18) return nil unless employee avatar = employee_profile_avatar(employee, size: size) content_tag(:span, class: 'd-inline-flex align-items-center gap-1', title: title) do safe_join([avatar, employee.name_and_extension]) end end |
#employee_profile_avatar(employee, size: 20) ⇒ Object
Renders an employee profile picture or initials fallback
Uses Party.profile_image (consolidated storage for all party types)
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'app/helpers/customers_helper.rb', line 263 def employee_profile_avatar(employee, size: 20) return unless employee profile_pic = employee.profile_image if profile_pic image_tag(profile_pic.image_url(width: size * 2, height: size * 2), class: 'rounded-circle', style: "width: #{size}px; height: #{size}px; object-fit: cover;", alt: employee.try(:show_name_4) || employee.full_name, title: employee.full_name) else # Fallback: show initials in a colored circle initials = employee.full_name.to_s.split.map(&:first).join.upcase.first(2) content_tag(:span, initials, class: 'rounded-circle d-inline-flex align-items-center justify-content-center bg-secondary text-white', style: "width: #{size}px; height: #{size}px; font-size: #{size * 0.45}px;", title: employee.full_name) end end |
#font_class_symbol(result_class, options = {}) ⇒ String
Maps a search-result class name to its Font Awesome icon
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/customers_helper.rb', line 97 def font_class_symbol(result_class, = {}) ic = case result_class when 'Organization' 'users' when 'Homeowner' 'user' when 'Contact' 'user' when 'Employee' 'star' when 'RoomConfiguration' 'home' when 'Order' 'shopping-cart' when 'Quote' 'quote-right' when 'Opportunity' 'gift' when 'Rma' 'reply' when 'Address' 'map-marker' when 'Activity' 'bell' when 'Invoice' 'book' when 'Item' 'glass' when 'PresetJob' 'power-off' when 'LocatorRecord' 'search' when 'PurchaseOrder' 'truck' when 'SupportCase' 'ticket' else 'search' end fa_icon ic, end |
#local_sales_rep_input(f) ⇒ Object
449 450 451 |
# File 'app/helpers/customers_helper.rb', line 449 def local_sales_rep_input(f) rep_input f, :local_sales_rep end |
#parent_org_name(customer) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/helpers/customers_helper.rb', line 5 def parent_org_name(customer) parent = customer.parent_organization name = +'' name << parent.full_name name << " in #{parent.main_address.city}, #{parent.main_address.state_code}" if parent.main_address name << " [#{parent.id}]" name end |
#primary_sales_rep_input(f) ⇒ Object
441 442 443 |
# File 'app/helpers/customers_helper.rb', line 441 def primary_sales_rep_input(f) rep_input f, :primary_sales_rep end |
#render_customer_contact_points(customer, _highlight = true) ⇒ Object
373 374 375 376 377 378 379 |
# File 'app/helpers/customers_helper.rb', line 373 def render_customer_contact_points(customer, _highlight = true) content_tag :ul, class: 'list-unstyled' do customer.contacts_and_self_contact_points_by_category(ContactPoint::CAN_DIAL + [ContactPoint::EMAIL]).pluck(:category, :detail).uniq.sort.map do |cp| content_tag :li, contact_point_display_with_highlight(cp) end.join.html_safe end end |
#rep_input(f, rep_type) ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'app/helpers/customers_helper.rb', line 417 def rep_input(f, rep_type) customer = f.object reps = [] if can?(:assign_sales_rep, customer) collection_method = :"#{rep_type}_options_for_select" reps = Employee.send(collection_method) include_blank = true end selections = reps.uniq.sort input_label = "#{rep_type.to_s.humanize}:" if selections.present? f.input :"#{rep_type}_id", label: input_label, as: :tom_select, collection: selections, include_blank: include_blank elsif (current_rep = customer.send(rep_type)) form_style_attribute_display input_label, current_rep.full_name else form_style_attribute_display input_label, 'Manager Assignable Only' end end |
#secondary_sales_rep_input(f) ⇒ Object
445 446 447 |
# File 'app/helpers/customers_helper.rb', line 445 def secondary_sales_rep_input(f) rep_input f, :secondary_sales_rep end |
#setup_customer(c) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/customers_helper.rb', line 46 def setup_customer(c) c.tap do |c| if c.new_record? if c.addresses.empty? country_iso3 = c.catalog.try(:store).try(:country_iso3) || 'USA' c.addresses.build(country_iso3: country_iso3) end c.contacts.build if c.contacts.empty? end c.identification_numbers.build if c.identification_numbers.empty? c.tax_exemptions.build if c.tax_exemptions.empty? c.build_customer_record unless c.customer_record setup_customer_contact_points(c) end end |
#setup_customer_channels(c) ⇒ Object
70 71 72 73 74 |
# File 'app/helpers/customers_helper.rb', line 70 def setup_customer_channels(c) c.tap do c.notification_channels.build if c.notification_channels.empty? end end |
#setup_customer_contact_points(c) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/helpers/customers_helper.rb', line 62 def setup_customer_contact_points(c) c.tap do [ContactPoint::PHONE, ContactPoint::FAX, ContactPoint::EMAIL].each do |cp| c.contact_points.build(category: cp) if c.contact_points.none? { |ccp| ccp.category == cp } end end end |
#setup_customer_record(c) ⇒ Object
76 77 78 79 80 |
# File 'app/helpers/customers_helper.rb', line 76 def setup_customer_record(c) c.tap do |c| c.build_customer_record unless c.customer_record end end |