Class: Lead
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lead
- Defined in:
- app/models/entities/lead.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
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
-
.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_lead_counters(attributes) ⇒ Object
Update lead attributes taking care of campaign lead counters when necessary.
-
#update_with_permissions(attributes, _users = nil) ⇒ Object
Deprecated: see update_with_lead_counters —————————————————————————-.
Class Method Details
.first_name_position ⇒ Object
88 89 90 |
# File 'app/models/entities/lead.rb', line 88 def self.first_name_position "before" end |
.per_page ⇒ Object
Default values provided through class methods.
85 86 87 |
# File 'app/models/entities/lead.rb', line 85 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.
152 153 154 155 156 |
# File 'app/models/entities/lead.rb', line 152 def attach!(task) unless task_ids.include?(task.id) tasks << task end end |
#convert ⇒ Object
141 142 143 |
# File 'app/models/entities/lead.rb', line 141 def convert update_attribute(:status, "converted") end |
#discard!(task) ⇒ Object
Discard a task from the lead.
160 161 162 |
# File 'app/models/entities/lead.rb', line 160 def discard!(task) task.update_attribute(:asset, nil) end |
#full_name(format = nil) ⇒ Object Also known as: name
165 166 167 168 169 170 171 |
# File 'app/models/entities/lead.rb', line 165 def full_name(format = nil) if format.nil? || format == "before" "#{first_name} #{last_name}" else "#{last_name}, #{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.
129 130 131 132 133 134 135 136 137 138 |
# File 'app/models/entities/lead.rb', line 129 def promote(params) account_params = params[:account] ? params[:account] : {} opportunity_params = params[:opportunity] ? params[:opportunity] : {} account = Account.create_or_select_for(self, account_params) opportunity = Opportunity.create_for(self, account, opportunity_params) contact = Contact.create_for(self, account, opportunity, params) [account, opportunity, contact] end |
#reject ⇒ Object
146 147 148 |
# File 'app/models/entities/lead.rb', line 146 def reject update_attribute(:status, "rejected") end |
#save_with_permissions(params) ⇒ Object
Save the lead along with its permissions.
94 95 96 97 98 99 100 101 102 |
# File 'app/models/entities/lead.rb', line 94 def (params) self.campaign = Campaign.find(params[:campaign]) unless params[:campaign].blank? if params[:lead][:access] == "Campaign" && campaign # Copy campaign permissions. (Campaign.find(campaign_id)) else self.attributes = params[:lead] save end end |
#update_with_lead_counters(attributes) ⇒ Object
Update lead attributes taking care of campaign lead counters when necessary.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/entities/lead.rb', line 113 def update_with_lead_counters(attributes) if campaign_id == attributes[:campaign_id] # Same campaign (if any). self.attributes = attributes save else # Campaign has been changed -- update lead counters... decrement_leads_count # ..for the old campaign... self.attributes = attributes # Assign new campaign. lead = save increment_leads_count # ...and now for the new campaign. lead end end |
#update_with_permissions(attributes, _users = nil) ⇒ Object
Deprecated: see update_with_lead_counters
106 107 108 109 |
# File 'app/models/entities/lead.rb', line 106 def (attributes, _users = nil) ActiveSupport::Deprecation.warn "lead.update_with_permissions is deprecated and may be removed from future releases, use user_ids and group_ids inside attributes instead and call lead.update_with_lead_counters" update_with_lead_counters(attributes) end |