Module: CustomersHelper
- Defined in:
- app/helpers/customers_helper.rb
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 = {}) ⇒ Object
- #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 = {}) ⇒ Object
- #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)
228 229 230 231 232 233 234 235 236 |
# File 'app/helpers/customers_helper.rb', line 228 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
81 82 83 84 85 86 |
# File 'app/helpers/customers_helper.rb', line 81 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
13 14 15 16 17 |
# File 'app/helpers/customers_helper.rb', line 13 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
345 346 347 348 349 350 |
# File 'app/helpers/customers_helper.rb', line 345 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
186 187 188 189 190 191 192 193 194 195 |
# File 'app/helpers/customers_helper.rb', line 186 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
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 |
# File 'app/helpers/customers_helper.rb', line 309 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
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'app/helpers/customers_helper.rb', line 163 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)) opts << customer_delete_link(customer) end.compact end |
#customer_delete_link(customer = @customer, options = {}) ⇒ Object
180 181 182 183 184 |
# File 'app/helpers/customers_helper.rb', line 180 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
39 40 41 42 43 |
# File 'app/helpers/customers_helper.rb', line 39 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
142 143 144 145 146 |
# File 'app/helpers/customers_helper.rb', line 142 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
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'app/helpers/customers_helper.rb', line 197 def customer_quick_info(customer = @customer) info = [] return info unless customer.present? 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
19 20 21 22 23 |
# File 'app/helpers/customers_helper.rb', line 19 def () return unless .present? content_tag(:span, , class: 'badge bg-secondary', data: { rating: }) end |
#customer_sales_reps(customer) ⇒ Object
417 418 419 420 421 422 |
# File 'app/helpers/customers_helper.rb', line 417 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
148 149 150 151 |
# File 'app/helpers/customers_helper.rb', line 148 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
372 373 374 375 376 377 378 379 |
# File 'app/helpers/customers_helper.rb', line 372 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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'app/helpers/customers_helper.rb', line 263 def hsh = {} hsh[:activities] = { counter: @customer.open_activities_counter, remote_href: customer_activities_path(@customer, selected_activity: params[:selected_activity]) } hsh[:main_profile] = { remote_href: show_main_profile_tab_customer_path(@customer) } hsh[:addresses] = { remote_href: show_addresses_tab_customer_path(@customer), counter: @customer.addresses.size } hsh[:marketing] = { remote_href: show_marketing_tab_customer_path(@customer) } hsh[:contacts] = { counter: @customer.contacts.active.size, remote_href: contacts_tab_customer_path(@customer) } hsh[:communications] = { remote_href: customer_communications_path(@customer) } hsh[:sms] = { remote_href: (@customer), counter: @customer..unread.size } hsh[:opportunities] = { counter: @customer.opportunities.open_opportunities.size, remote_href: customer_opportunities_path(@customer) } hsh[:orders] = { counter: @customer.orders.non_credit.in_progress.size, remote_href: customer_orders_path(@customer) } hsh[:accounting] = { remote_href: show_accounting_tab_customer_path(@customer) } hsh[:attachments] = { counter: @customer.all_uploads.size, remote_href: customer_uploads_path(@customer) } hsh[:topics] = { remote_href: show_profiling_tab_customer_path(@customer) } hsh[:showcases] = { remote_href: show_showcases_tab_customer_path(@customer) } hsh[:training] = { remote_href: show_training_tab_customer_path(@customer) } if @customer.contacts.present? hsh[:certifications] = { remote_href: show_certifications_tab_customer_path(@customer) } if @customer.can_be_certified? hsh[:tickets] = { title: 'Tickets', counter_html: tech_counter_badge(@customer.all_support_cases), remote_href: show_tickets_tab_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: show_receipts_tab_customer_path(@customer) } hsh[:promotions] = { remote_href: promotions_customer_path(@customer) } hsh[:lead_protections] = { counter: @customer.protected_leads.size, remote_href: show_lead_protections_tab_customer_path(@customer) } if @customer.protected_leads.present? hsh[:subsidiaries] = { counter: @customer.child_organizations.size, remote_href: show_subsidiaries_tab_customer_path(@customer) } if @customer.child_organizations.present? hsh[:reviews] = { remote_href: show_product_reviews_tab_customer_path(@customer) } hsh[:digital_assets] = { counter: @customer.digital_assets.size, remote_href: tab_digital_assets_customer_path(@customer) } hsh[:stats] = { remote_href: show_stats_tab_customer_path(@customer) } if @customer.customer_record && @customer.customer_record.profiling_data_last_calculated_at hsh[:duplicates] = { remote_href: duplicates_customer_path(@customer) } hsh end |
#customer_visits_link(customer) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/helpers/customers_helper.rb', line 130 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
35 36 37 |
# File 'app/helpers/customers_helper.rb', line 35 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
25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/customers_helper.rb', line 25 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
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'app/helpers/customers_helper.rb', line 352 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
158 159 160 161 |
# File 'app/helpers/customers_helper.rb', line 158 def (contact) contact ||= @contact render partial: '/shared/contact_banner', locals: { contact: contact } end |
#display_customer_banner(customer, inline: false) ⇒ Object
153 154 155 156 |
# File 'app/helpers/customers_helper.rb', line 153 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
424 425 426 |
# File 'app/helpers/customers_helper.rb', line 424 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)
216 217 218 219 220 221 222 223 |
# File 'app/helpers/customers_helper.rb', line 216 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)
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'app/helpers/customers_helper.rb', line 242 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 = {}) ⇒ Object
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 121 122 123 124 125 126 127 128 |
# File 'app/helpers/customers_helper.rb', line 88 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
413 414 415 |
# File 'app/helpers/customers_helper.rb', line 413 def local_sales_rep_input(f) rep_input f, :local_sales_rep end |
#parent_org_name(customer) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/helpers/customers_helper.rb', line 4 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
405 406 407 |
# File 'app/helpers/customers_helper.rb', line 405 def primary_sales_rep_input(f) rep_input f, :primary_sales_rep end |
#render_customer_contact_points(customer, _highlight = true) ⇒ Object
337 338 339 340 341 342 343 |
# File 'app/helpers/customers_helper.rb', line 337 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
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'app/helpers/customers_helper.rb', line 381 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
409 410 411 |
# File 'app/helpers/customers_helper.rb', line 409 def secondary_sales_rep_input(f) rep_input f, :secondary_sales_rep end |
#setup_customer(c) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/customers_helper.rb', line 45 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
69 70 71 72 73 |
# File 'app/helpers/customers_helper.rb', line 69 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
61 62 63 64 65 66 67 |
# File 'app/helpers/customers_helper.rb', line 61 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.select { |ccp| ccp.category == cp }.empty? end end end |
#setup_customer_record(c) ⇒ Object
75 76 77 78 79 |
# File 'app/helpers/customers_helper.rb', line 75 def setup_customer_record(c) c.tap do |c| c.build_customer_record unless c.customer_record end end |