Module: SalesGoalsHelper

Defined in:
app/helpers/sales_goals_helper.rb

Instance Method Summary collapse

Instance Method Details

#progress_meter(percentage) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/sales_goals_helper.rb', line 18

def progress_meter(percentage)
  return unless percentage

  bar_class = if percentage >= 100
                "bg-success"
              elsif percentage >= 75
                "bg-primary"
              elsif percentage >= 50
                "bg-info"
              else
                "bg-warning"
              end

  (:div, class: "progress", style: "min-width: 80px; height: 8px") do
    (:div, "",
                class: "progress-bar #{bar_class}",
                role: "progressbar",
                style: "width: #{[percentage, 100].min}%",
                aria: { valuenow: percentage, valuemin: 0, valuemax: 100 })
  end
end

#render_employee_sales_goalObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/sales_goals_helper.rb', line 2

def render_employee_sales_goal
  @dt_in_quarter = Date.current
  @period_begins = @dt_in_quarter.beginning_of_quarter
  @period_ends = @dt_in_quarter.end_of_quarter
  @sales_goals = SalesGoal.where("sales_goals.period_begins >= ?", @period_begins)
                          .where("sales_goals.period_ends <= ?", @period_ends)
                          .where("sales_goals.period_begins <= ?", @dt_in_quarter)
                          .where(employee_id: @employee.id)
                          .includes(:employee)
                          .order("sales_goals.period_ends, sales_goals.period_begins DESC, sales_goals.report_grouping")
                          .to_a
  @sales_goals += @sales_goals.filter_map(&:prerequisite_goal)
  @sales_goals = @sales_goals.uniq
  render partial: '/sales_goals/employee'
end