Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/entities/account.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: accounts

id              :integer         not null, primary key
user_id         :integer
assigned_to     :integer
name            :string(64)      default(""), not null
access          :string(8)       default("Public")
website         :string(64)
toll_free_phone :string(32)
phone           :string(32)
fax             :string(32)
deleted_at      :datetime
created_at      :datetime
updated_at      :datetime
email           :string(64)
background_info :string(255)
rating          :integer         default(0), not null
category        :string(32)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_or_select_for(model, params) ⇒ Object

Class methods.




113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/entities/account.rb', line 113

def self.create_or_select_for(model, params)
  if params[:id].present?
     = Account.find(params[:id])
  else
     = Account.new(params)
    if .access != "Lead" || model.nil?
      .save
    else
      .save_with_model_permissions(model)
    end
  end
  
end

.per_pageObject

Default values provided through class methods.




83
# File 'app/models/entities/account.rb', line 83

def self.per_page ; 20 ; end

Instance Method Details

#attach!(attachment) ⇒ Object

Attach given attachment to the account if it hasn’t been attached already.




95
96
97
98
99
# File 'app/models/entities/account.rb', line 95

def attach!(attachment)
  unless self.send("#{attachment.class.name.downcase}_ids").include?(attachment.id)
    self.send(attachment.class.name.tableize) << attachment
  end
end

#discard!(attachment) ⇒ Object

Discard given attachment from the account.




103
104
105
106
107
108
109
# File 'app/models/entities/account.rb', line 103

def discard!(attachment)
  if attachment.is_a?(Task)
    attachment.update_attribute(:asset, nil)
  else # Contacts, Opportunities
    self.send(attachment.class.name.tableize).delete(attachment)
  end
end

#locationObject

Extract last line of billing address and get rid of numeric zipcode.




87
88
89
90
91
# File 'app/models/entities/account.rb', line 87

def location
  return "" unless self[:billing_address]
  location = self[:billing_address].strip.split("\n").last
  location.gsub(/(^|\s+)\d+(:?\s+|$)/, " ").strip if location
end