Class: Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Account
- 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
-
.create_or_select_for(model, params) ⇒ Object
Class methods.
-
.per_page ⇒ Object
Default values provided through class methods.
Instance Method Summary collapse
-
#attach!(attachment) ⇒ Object
Attach given attachment to the account if it hasn’t been attached already.
-
#discard!(attachment) ⇒ Object
Discard given attachment from the account.
-
#location ⇒ Object
Extract last line of billing address and get rid of numeric zipcode.
Class Method Details
.create_or_select_for(model, params) ⇒ Object
Class methods.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/entities/account.rb', line 117 def self.create_or_select_for(model, params) # Attempt to find existing account return Account.find(params[:id]) if params[:id].present? if params[:name].present? account = Account.find_by(name: params[:name]) return account if account end # Fallback to create new account params[:user] = model.user if model account = Account.new(params) if account.access != "Lead" || model.nil? account.save else account.(model) end account end |
.per_page ⇒ Object
Default values provided through class methods.
86 87 88 |
# File 'app/models/entities/account.rb', line 86 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.
101 102 103 |
# File 'app/models/entities/account.rb', line 101 def attach!() send(.class.name.tableize) << unless send("#{.class.name.downcase}_ids").include?(.id) end |
#discard!(attachment) ⇒ Object
Discard given attachment from the account.
107 108 109 110 111 112 113 |
# File 'app/models/entities/account.rb', line 107 def discard!() if .is_a?(Task) .update_attribute(:asset, nil) else # Contacts, Opportunities send(.class.name.tableize).delete() end end |
#location ⇒ Object
Extract last line of billing address and get rid of numeric zipcode.
92 93 94 95 96 97 |
# File 'app/models/entities/account.rb', line 92 def location return "" unless self[:billing_address] location = self[:billing_address].strip.split("\n").last location&.gsub(/(^|\s+)\d+(:?\s+|$)/, " ")&.strip end |