Class: Customer

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveDisablable, StringHelper
Defined in:
app/models/customer.rb

Constant Summary collapse

VALID_NAME_REGEX =
/\A([[[:alpha:]]0-9.,;\s\'\"\-–\/&\*\(\)`´%!\+])+\z/i

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StringHelper

#name_or_empty, #name_or_nothing

Methods included from ActiveDisablable

#destroy, #destroy_fully, #disable, #disabled?, #enable, #enabled?, included, #recovery

Class Method Details

.search_by_name(customers, name) ⇒ Object

————————————————————————-> validates



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/customer.rb', line 60

def self.search_by_name(customers, name)
  conditions = []
  conditions_and = []
  conditions_params = []
  if name
    name = name.upcase
    conditions_and << 'upper(name) LIKE ?'
    conditions_params << "%#{name}%"
  end

  conditions << conditions_and.join(" and ")
  conditions_params.each { |p| conditions << p  }

  if conditions.count>0
    logger.debug customers
    ret = customers.where(conditions)
  else
    []
  end

end

Instance Method Details

#a_customer?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'app/models/customer.rb', line 106

def a_customer?
  self.is_customer || (self.businesses.count>0)
end

#businessesOpenStruct

The bussinesses done at the time

Returns:

  • (OpenStruct)

    The struct containing CompanyBusiness as :business and Last Time of Business Deal as business_at



53
54
55
56
57
# File 'app/models/customer.rb', line 53

def businesses
  resolution = SystemTaskResolution.RESOLVED_WITH_BUSINESS
  businesses = self.tasks.unscoped.joins(:type).select("company_business_id, max(finish_time) AS business_at").where({resolution_id: 4, interested_id: self}).group(:company_business_id)
  businesses.collect { |b| OpenStruct.new(business: CompanyBusiness.find(b.company_business_id), business_at: b.business_at) }
end

#can_complete?Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/customer.rb', line 94

def can_complete?
  raise "erros not empty" if self.errors.count>0
  old_complete = self.complete

  self.complete = true;
  ret = self.valid?

  self.complete = old_complete
  self.errors.clear
  ret
end

#complete?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/customer.rb', line 90

def complete?
  self.complete
end

#doc_needs?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'app/models/customer.rb', line 86

def doc_needs?
  self.complete? || (doc !="" && doc != "0"*11 && doc != "0"*14)
end

#format_addressObject



82
83
84
# File 'app/models/customer.rb', line 82

def format_address
  (self.address ? self.address : "") + ", " + name_or_empty(self.district) + ", " + name_or_empty(self.city) + ", " + name_or_empty(self.state)
end