Class: Lead
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lead
- Defined in:
- app/models/base/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
- .first_name_position ⇒ Object
- .outline ⇒ Object
-
.per_page ⇒ Object
Default values provided through class methods.
Instance Method Summary collapse
-
#attach!(task) ⇒ Object
Attach a task to the lead if it hasn’t been attached already.
-
#convert ⇒ Object
—————————————————————————-.
-
#discard!(task) ⇒ Object
Discard a task from the lead.
-
#full_name(format = nil) ⇒ Object
(also: #name)
—————————————————————————-.
-
#promote(params) ⇒ Object
Promote the lead by creating contact and optional opportunity.
-
#reject ⇒ Object
—————————————————————————-.
-
#save_with_permissions(params) ⇒ Object
Save the lead along with its permissions.
-
#update_with_permissions(attributes, users) ⇒ Object
Update lead attributes taking care of campaign lead counters when necessary.
Class Method Details
.first_name_position ⇒ Object
95 |
# File 'app/models/base/lead.rb', line 95 def self.first_name_position ; "before" ; end |
.outline ⇒ Object
94 |
# File 'app/models/base/lead.rb', line 94 def self.outline ; "long" ; end |
.per_page ⇒ Object
Default values provided through class methods.
93 |
# File 'app/models/base/lead.rb', line 93 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.
144 145 146 147 148 |
# File 'app/models/base/lead.rb', line 144 def attach!(task) unless self.task_ids.include?(task.id) self.tasks << task end end |
#convert ⇒ Object
133 134 135 |
# File 'app/models/base/lead.rb', line 133 def convert update_attribute(:status, "converted") end |
#discard!(task) ⇒ Object
Discard a task from the lead.
152 153 154 |
# File 'app/models/base/lead.rb', line 152 def discard!(task) task.update_attribute(:asset, nil) end |
#full_name(format = nil) ⇒ Object Also known as: name
157 158 159 160 161 162 163 |
# File 'app/models/base/lead.rb', line 157 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.
124 125 126 127 128 129 130 |
# File 'app/models/base/lead.rb', line 124 def promote(params) account = Account.create_or_select_for(self, params[:account], params[:users]) opportunity = Opportunity.create_for(self, account, params[:opportunity], params[:users]) contact = Contact.create_for(self, account, opportunity, params) return account, opportunity, contact end |
#reject ⇒ Object
138 139 140 |
# File 'app/models/base/lead.rb', line 138 def reject update_attribute(:status, "rejected") end |
#save_with_permissions(params) ⇒ Object
Save the lead along with its permissions.
99 100 101 102 103 104 105 106 |
# File 'app/models/base/lead.rb', line 99 def (params) self.campaign = Campaign.find(params[:campaign]) unless params[:campaign].blank? if self.access == "Campaign" && self.campaign # Copy campaign 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.
110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/base/lead.rb', line 110 def (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 |