Class: Customer::Watch

Inherits:
BaseService show all
Defined in:
app/services/customer/watch.rb

Overview

Service object: watch.

Defined Under Namespace

Classes: Result

Constant Summary collapse

WATCH_CAP =

Watch cap.

2_000
WATCH_STATES =

Recognised watch states.

%w[prospect customer].freeze
UNWATCHABLE_PROFILE_IDS =

Unwatchable profile ids.

[ProfileConstants::HOMEOWNER].freeze

Instance Attribute Summary

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

#initialize(options = {}) ⇒ Watch

Returns a new instance of Watch.

Parameters:

  • options (Hash) (defaults to: {})

    service options (passed to BaseService)

Options Hash (options):

  • logger (Logger)

    logger to use (defaults to Rails.logger)



18
19
20
21
22
23
# File 'app/services/customer/watch.rb', line 18

def initialize(options = {})
  super
  @open_activity_flag_resetter = Customer::ResetOpenActivityFlag.new(logger:)
  @fill_sales_activity = Customer::FillSalesActivity.new(logger:)
  @prune_touchbase = Customer::PruneTouchbase.new(logger:)
end

Instance Method Details

#process(options = {}) ⇒ Result

This key method will perform 5 essential functions

  1. The open sales activity flag will be calculated for all of a rep's accounts. Pass :skip_calculate_open_activity => true to skip
  2. Each customer in the sales rep account base will be scored and the result stored in the Sales Priority index. Pass :skip_scoring => true to skip
  3. The top 2000 customers by Sales Priority Index are marked as watched accounts minus those on forced watch. Pass :skip_reset_sales_watch => true to skip
  4. A touchbase sales activity is filled in on all watched accounts who don't have one. The new activites are prioritized from their assignement date 6 weeks from now. Pass :skip_fill_sales_activity => true to skip
  5. Past due activities are prioritized and distributed starting the next business day. Pass :skip_prioritization => true to skip

Parameters:

  • options (Hash) (defaults to: {})

    process options

Options Hash (options):

  • employee_id (Integer, nil)

    restrict the reset to this sales rep

  • skip_scoring (Boolean)

    skip the sales priority scoring step

  • skip_reset_sales_watch (Boolean)

    skip the watch list reset step

  • skip_fill_sales_activity (Boolean)

    skip the touchbase fill step

  • skip_calculate_open_activity (Boolean)

    skip the open activity flag recalculation

  • skip_prune_touchbase (Boolean)

    skip the touchbase pruning step

Returns:

  • (Result)

    the process result



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/services/customer/watch.rb', line 39

def process(options = {})
  options = options.with_indifferent_access

  logger.debug("Processing full reset for sales watch", employee_id: options[:employee_id])

  reset_sales_watch_for_unassigned
  reset_sales_watch_for_invalid_states

  score_customers(employee_id: options[:employee_id]) unless options[:skip_scoring]

  employees = Employee.all
  employees = if options[:employee_id]
                employees.where(id: options[:employee_id])
              else
                employees.active_employees.sales_reps.sorted
              end

  employees.each do |e|
    logger.info "Processing full reset for employee #{e.full_name}/#{e.id}"
    reset_sales_watch_list(e.id) unless options[:skip_reset_sales_watch]
    fill_sales_activity(e.id) unless options[:skip_fill_sales_activity]
    reset_open_activity_flag(employee_id: e.id) unless options[:skip_calculate_open_activity]
  end
  # Prune must go through all to be effective (since rep might drop off accounts), unless the watch method is
  # called on a specific employee in which case the focus will be narrowed
  prune_touchbase(primary_sales_rep_id: options[:employee_id]) unless options[:skip_prune_touchbase]

  Result.new(success: true)
end