Class: Persona::Creditor
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cnpj ⇒ Object
Returns the value of attribute cnpj.
-
#cpf ⇒ Object
Returns the value of attribute cpf.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Unico::CustomData
#custom_data, #validate_custom_data
Instance Attribute Details
#cnpj ⇒ Object
Returns the value of attribute cnpj.
10 11 12 |
# File 'app/models/persona/creditor.rb', line 10 def cnpj @cnpj end |
#cpf ⇒ Object
Returns the value of attribute cpf.
10 11 12 |
# File 'app/models/persona/creditor.rb', line 10 def cpf @cpf end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'app/models/persona/creditor.rb', line 10 def name @name end |
Class Method Details
.filter(params) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/persona/creditor.rb', line 64 def self.filter(params) person_table = ::Person.arel_table company_table = ::Company.arel_table individual_table = ::Individual.arel_table person_join = arel_table.join(person_table, Arel::Nodes::OuterJoin) .on(person_table[:id].eq(arel_table[:person_id])) company_join = person_join.join(company_table, Arel::Nodes::OuterJoin) .on(person_table[:personable_type].eq('Company').and(person_table[:personable_id].eq(company_table[:id]))) .join_sources individual_join = person_join.join(individual_table, Arel::Nodes::OuterJoin) .on(person_table[:personable_type].eq('Individual').and(person_table[:personable_id].eq(individual_table[:id]))) .join_sources query = all query = query.joins(individual_join) if params[:cpf].present? query = query.joins(company_join) if params[:cnpj].present? query = query.where(person_table[:name].matches("#{params[:name]}%")) if params[:name].present? query = query.where(individual_table[:cpf].eq(params[:cpf])) if params[:cpf].present? query = query.where(company_table[:cnpj].eq(params[:cnpj])) if params[:cnpj].present? query end |
Instance Method Details
#selected_cnaes ⇒ Object
95 96 97 |
# File 'app/models/persona/creditor.rb', line 95 def selected_cnaes cnae_ids | [main_cnae_id] end |
#to_s ⇒ Object
91 92 93 |
# File 'app/models/persona/creditor.rb', line 91 def to_s person.to_s end |
#user? ⇒ Boolean
99 100 101 |
# File 'app/models/persona/creditor.rb', line 99 def user? user.present? && user.persisted? end |