Class: Lead

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/entities/lead.rb

Overview

Schema Information

Table name: leads

id              :integer         not null, primary key
user_id         :integer
campaign_id     :integer
assigned_to     :integer
first_name      :string(64)      default(""), not null
last_name       :string(64)      default(""), not null
access          :string(8)       default("Public")
title           :string(64)
company         :string(64)
source          :string(32)
status          :string(32)
referred_by     :string(64)
email           :string(64)
alt_email       :string(64)
phone           :string(32)
mobile          :string(32)
blog            :string(128)
linkedin        :string(128)
facebook        :string(128)
twitter         :string(128)
rating          :integer         default(0), not null
do_not_call     :boolean         default(FALSE), not null
deleted_at      :datetime
created_at      :datetime
updated_at      :datetime
background_info :string(255)
skype           :string(128)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.first_name_positionObject



96
# File 'app/models/entities/lead.rb', line 96

def self.first_name_position ; "before" ; end

.outlineObject



95
# File 'app/models/entities/lead.rb', line 95

def self.outline  ; "long"              ; end

.per_pageObject

Default values provided through class methods.




94
# File 'app/models/entities/lead.rb', line 94

def self.per_page ; 20                  ; end

Instance Method Details

#attach!(task) ⇒ Object

Attach a task to the lead if it hasn’t been attached already.




145
146
147
148
149
# File 'app/models/entities/lead.rb', line 145

def attach!(task)
  unless self.task_ids.include?(task.id)
    self.tasks << task
  end
end

#convertObject




134
135
136
# File 'app/models/entities/lead.rb', line 134

def convert
  update_attribute(:status, "converted")
end

#discard!(task) ⇒ Object

Discard a task from the lead.




153
154
155
# File 'app/models/entities/lead.rb', line 153

def discard!(task)
  task.update_attribute(:asset, nil)
end

#full_name(format = nil) ⇒ Object Also known as: name




158
159
160
161
162
163
164
# File 'app/models/entities/lead.rb', line 158

def full_name(format = nil)
  if format.nil? || format == "before"
    "#{self.first_name} #{self.last_name}"
  else
    "#{self.last_name}, #{self.first_name}"
  end
end

#promote(params) ⇒ Object

Promote the lead by creating contact and optional opportunity. Upon successful promotion Lead status gets set to :converted.




125
126
127
128
129
130
131
# File 'app/models/entities/lead.rb', line 125

def promote(params)
       = Account.create_or_select_for(self, params[:account], params[:users])
  opportunity = Opportunity.create_for(self, , params[:opportunity], params[:users])
  contact     = Contact.create_for(self, , opportunity, params)

  [, opportunity, contact]
end

#rejectObject




139
140
141
# File 'app/models/entities/lead.rb', line 139

def reject
  update_attribute(:status, "rejected")
end

#save_with_permissions(params) ⇒ Object

Save the lead along with its permissions.




100
101
102
103
104
105
106
107
# File 'app/models/entities/lead.rb', line 100

def save_with_permissions(params)
  self.campaign = Campaign.find(params[:campaign]) unless params[:campaign].blank?
  if self.access == "Campaign" && self.campaign # Copy campaign permissions.
    save_with_model_permissions(Campaign.find(self.campaign_id))
  else
    super(params[:users]) # invoke :save_with_permissions in plugin.
  end
end

#update_with_permissions(attributes, users) ⇒ Object

Update lead attributes taking care of campaign lead counters when necessary.




111
112
113
114
115
116
117
118
119
120
# File 'app/models/entities/lead.rb', line 111

def update_with_permissions(attributes, users)
  if self.campaign_id == attributes[:campaign_id] # Same campaign (if any).
    super(attributes, users)                      # See lib/fat_free_crm/permissions.rb
  else                                            # Campaign has been changed -- update lead counters...
    decrement_leads_count                         # ..for the old campaign...
    lead = super(attributes, users)               # Assign new campaign.
    increment_leads_count                         # ...and now for the new campaign.
    lead
  end
end