Class: EducodeSales::Business

Inherits:
ApplicationRecord show all
Defined in:
app/models/educode_sales/business.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.include_steps(type) ⇒ Object



73
74
75
76
77
78
79
# File 'app/models/educode_sales/business.rb', line 73

def self.include_steps(type)
  {
    '已中标' => ['已中标','已签单','已验收','回款中', '服务中','已结束'],
    '已签单' => ['已签单','已验收','回款中', '服务中','已结束'],
    '应收款' => ['已中标','已签单','已验收','回款中', '服务中','已结束']
  }[type]
end

.include_types(type) ⇒ Object



65
66
67
68
69
70
71
# File 'app/models/educode_sales/business.rb', line 65

def self.include_types(type)
  {
    '1' => %w[a_class b_class c_class d_class e_class],
    'a' => ['a_class'],
    'b' => ['b_class'],
  }[type]
end

Instance Method Details

#change_diliverObject

创建商机交付课程数据



83
84
85
86
87
88
89
90
# File 'app/models/educode_sales/business.rb', line 83

def change_diliver

  if previous_changes["last_follow_up_id"].present?
    last_clazz_id = previous_changes["last_follow_up_id"][-1]
    common_type = FollowUp.find_by(id: last_clazz_id)&.stage&.name == "已中标"
    BusinessDeliverSubject.find_or_create_by(business_id: self.id) if common_type
  end
end

#p_recycleObject



61
62
63
# File 'app/models/educode_sales/business.rb', line 61

def p_recycle
  self.update(p_deleted_at: nil, p_deleter_id: nil)
end

#p_soft_destroy(staff_id) ⇒ Object



57
58
59
# File 'app/models/educode_sales/business.rb', line 57

def p_soft_destroy(staff_id)
  self.update(p_deleted_at: Time.now, p_deleter_id: staff_id)
end

#school_nameObject



92
93
94
# File 'app/models/educode_sales/business.rb', line 92

def school_name
  department&.school&.name || "--"
end

#soft_destroy(user_id) ⇒ Object



48
49
50
51
52
53
54
55
# File 'app/models/educode_sales/business.rb', line 48

def soft_destroy(user_id)
  self.update(deleted_at: Time.now, state_id: 2)
  self.sale_plans.each do |d|
    d.soft_destroy(user_id)
  end
  self.follow_ups.update_all(deleted_at: Time.now)
  EducodeSales::Recycle.create(source: self, deleter_id: user_id)
end

#staff_nameObject



96
97
98
# File 'app/models/educode_sales/business.rb', line 96

def staff_name
  last_follow_up&.assign_follow_ups.present? ? (last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("")) : staff&.user&.real_name
end