Class: CartDecorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
app/decorators/cart_decorator.rb

Instance Method Summary collapse

Instance Method Details

#approvals_by_statusObject


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/decorators/cart_decorator.rb', line 20

def approvals_by_status
  object.approver_approvals.order(
    # http://stackoverflow.com/a/6332081/358804
    <<-SQL
      CASE status
      WHEN 'approved' THEN 1
      WHEN 'rejected' THEN 2
      WHEN 'pending' THEN 3
      ELSE 4
      END
    SQL
  )
end

#approvals_in_list_orderObject


34
35
36
37
38
39
40
# File 'app/decorators/cart_decorator.rb', line 34

def approvals_in_list_order
  if object.flow == 'linear'
    object.ordered_approvals
  else
    self.approvals_by_status
  end
end

#cart_template_nameObject


66
67
68
69
70
71
72
73
# File 'app/decorators/cart_decorator.rb', line 66

def cart_template_name
  origin_name = self.getProp('origin')
  if Cart::ORIGINS.include? origin_name
    "#{origin_name}_cart"
  else
    'cart_mail'
  end
end

#completed_status_messageObject


58
59
60
# File 'app/decorators/cart_decorator.rb', line 58

def completed_status_message
  "All #{number_approved} of #{total_approvers} approvals have been received. Please move forward with the purchase  of Cart ##{object.external_id}."
end

#display_statusObject


42
43
44
45
46
47
48
# File 'app/decorators/cart_decorator.rb', line 42

def display_status
  if cart.status == 'pending'
    'pending approval'
  else
    cart.status
  end
end

#generate_status_messageObject


50
51
52
53
54
55
56
# File 'app/decorators/cart_decorator.rb', line 50

def generate_status_message
  if self.all_approvals_received?
    completed_status_message
  else
    progress_status_message
  end
end

#number_approvedObject


12
13
14
# File 'app/decorators/cart_decorator.rb', line 12

def number_approved
  object.approved_approvals.count
end

#prefix_template_nameObject


75
76
77
78
79
80
81
# File 'app/decorators/cart_decorator.rb', line 75

def prefix_template_name
  if self.getProp('origin') == 'navigator'
    'navigator_prefix'
  else
    nil
  end
end

#progress_status_messageObject


62
63
64
# File 'app/decorators/cart_decorator.rb', line 62

def progress_status_message
  "#{number_approved} of #{total_approvers} approved."
end

#property_exclusionsObject


83
84
85
86
87
88
89
90
91
92
# File 'app/decorators/cart_decorator.rb', line 83

def property_exclusions
  case self.getProp('origin')
  when 'navigator'
    ['origin', 'contractingVehicle', 'location', 'configType']
  when 'ncr'
    ['origin']
  else
    []
  end
end

#total_approversObject


16
17
18
# File 'app/decorators/cart_decorator.rb', line 16

def total_approvers
  object.approver_approvals.count
end

#total_priceObject


4
5
6
7
8
9
10
# File 'app/decorators/cart_decorator.rb', line 4

def total_price
  if self.getProp('origin') == 'ncr'
    self.getProp('amount').to_f
  else
    object.cart_items.reduce(0) { |sum,citem| sum + citem.subtotal }
  end
end