Class: TorgApi::Api::Contractor
- Defined in:
- lib/torg_api/api/contractor.rb
Overview
Контрагент
Constant Summary collapse
- STATUS_ORDER =
Порядок сортировки по значению поля status enum status: { orig: 0, active: 1, old: 2, inactive: 3 }
[1, 0, 3, 2]
- STATUS_ORDER_NUMS =
[].tap do |mas| STATUS_ORDER.each_with_index { |o, i| mas << [o, i] } end.flatten.join(', ')
- DECODE_STATUS_ORDER =
"decode(status, #{STATUS_ORDER_NUMS})"
Constants inherited from Base
Instance Attribute Summary collapse
-
#form ⇒ Integer
Вид контрагента (0-ИП, 1-юр. лицо, 2-иностран., 3-физ. лицо).
-
#fullname ⇒ String
Полное наименование.
-
#id ⇒ Integer
Id контрагента.
-
#inn ⇒ String
ИНН.
-
#is_dzo ⇒ Boolean
ДЗО?.
-
#is_resident ⇒ Boolean
Резидент?.
-
#is_sme ⇒ Boolean
Субъект малого и среднего предпринимательства?.
-
#jsc_form_id ⇒ Integer
Форма акционерного общества.
-
#kpp ⇒ String
КПП.
-
#legal_addr ⇒ String
Юридический адрес.
-
#name ⇒ String
Наименование.
-
#ogrn ⇒ String
ОГРН.
-
#okpo ⇒ String
ОКПО.
-
#ownership ⇒ String
Форма собственности.
-
#sme_type_id ⇒ Integer
Малое или среднее предпринимательство.
-
#status ⇒ Integer
Статус записи(0-новая, 1-активная, 2-старая, 3-неактивная).
-
#user_id ⇒ Integer
ИД автора.
Class Method Summary collapse
-
.create_from_b2b(hash, user) ⇒ Integer
Создаёт контрагента.
- .extract_form(bank_inn) ⇒ Object
- .extract_ownership(org_name_short) ⇒ Object
- .extract_resident(country) ⇒ Object
-
.find_by_inn(inn) ⇒ Integer[]
Поиск id контрагентов по ИНН.
Methods inherited from Base
Instance Attribute Details
#form ⇒ Integer
Returns Вид контрагента (0-ИП, 1-юр. лицо, 2-иностран., 3-физ. лицо).
34 35 36 |
# File 'lib/torg_api/api/contractor.rb', line 34 def form @form end |
#fullname ⇒ String
Returns Полное наименование.
20 21 22 |
# File 'lib/torg_api/api/contractor.rb', line 20 def fullname @fullname end |
#id ⇒ Integer
Returns id контрагента.
16 17 18 |
# File 'lib/torg_api/api/contractor.rb', line 16 def id @id end |
#inn ⇒ String
Returns ИНН.
24 25 26 |
# File 'lib/torg_api/api/contractor.rb', line 24 def inn @inn end |
#is_dzo ⇒ Boolean
Returns ДЗО?.
42 43 44 |
# File 'lib/torg_api/api/contractor.rb', line 42 def is_dzo @is_dzo end |
#is_resident ⇒ Boolean
Returns Резидент?.
40 41 42 |
# File 'lib/torg_api/api/contractor.rb', line 40 def is_resident @is_resident end |
#is_sme ⇒ Boolean
Returns Субъект малого и среднего предпринимательства?.
44 45 46 |
# File 'lib/torg_api/api/contractor.rb', line 44 def is_sme @is_sme end |
#jsc_form_id ⇒ Integer
Returns Форма акционерного общества.
46 47 48 |
# File 'lib/torg_api/api/contractor.rb', line 46 def jsc_form_id @jsc_form_id end |
#kpp ⇒ String
Returns КПП.
26 27 28 |
# File 'lib/torg_api/api/contractor.rb', line 26 def kpp @kpp end |
#legal_addr ⇒ String
Returns Юридический адрес.
36 37 38 |
# File 'lib/torg_api/api/contractor.rb', line 36 def legal_addr @legal_addr end |
#name ⇒ String
Returns Наименование.
18 19 20 |
# File 'lib/torg_api/api/contractor.rb', line 18 def name @name end |
#ogrn ⇒ String
Returns ОГРН.
28 29 30 |
# File 'lib/torg_api/api/contractor.rb', line 28 def ogrn @ogrn end |
#okpo ⇒ String
Returns ОКПО.
30 31 32 |
# File 'lib/torg_api/api/contractor.rb', line 30 def okpo @okpo end |
#ownership ⇒ String
Returns Форма собственности.
22 23 24 |
# File 'lib/torg_api/api/contractor.rb', line 22 def ownership @ownership end |
#sme_type_id ⇒ Integer
Returns Малое или среднее предпринимательство.
48 49 50 |
# File 'lib/torg_api/api/contractor.rb', line 48 def sme_type_id @sme_type_id end |
#status ⇒ Integer
Returns Статус записи(0-новая, 1-активная, 2-старая, 3-неактивная).
32 33 34 |
# File 'lib/torg_api/api/contractor.rb', line 32 def status @status end |
#user_id ⇒ Integer
Returns ИД автора.
38 39 40 |
# File 'lib/torg_api/api/contractor.rb', line 38 def user_id @user_id end |
Class Method Details
.create_from_b2b(hash, user) ⇒ Integer
Создаёт контрагента
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/torg_api/api/contractor.rb', line 66 def create_from_b2b(hash, user) c = Contractor.new c.name = hash[:org_name_short] c.fullname = hash[:org_name] c.ownership = extract_ownership(hash[:org_name_short]) c.inn = hash[:bank_inn] c.kpp = hash[:bank_kpp] c.ogrn = hash[:ogrn] c.okpo = hash[:code_okpo] c.status = 0 # enum status: { orig: 0, active: 1, old: 2, inactive: 3 } c.form = extract_form(hash[:bank_inn]) c.legal_addr = hash[:jury_address] c.user_id = user c.is_resident = extract_resident(hash[:country]) c.is_dzo = nil c.is_sme = hash[:is_smb] c.jsc_form_id = nil c.sme_type_id = nil TorgApi::Models::Contractor.create!(c.to_h).id end |
.extract_form(bank_inn) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/torg_api/api/contractor.rb', line 92 def extract_form(bank_inn) # enum form: { businessman: 0, company: 1, foreign: 2, person: 3 } case bank_inn.size when 12 then 0 when 10 then 1 else 2 end end |
.extract_ownership(org_name_short) ⇒ Object
88 89 90 |
# File 'lib/torg_api/api/contractor.rb', line 88 def extract_ownership(org_name_short) org_name_short[/^([\w\-]+)/] end |
.extract_resident(country) ⇒ Object
101 102 103 |
# File 'lib/torg_api/api/contractor.rb', line 101 def extract_resident(country) country == 643 end |
.find_by_inn(inn) ⇒ Integer[]
Поиск id контрагентов по ИНН
54 55 56 57 58 59 60 |
# File 'lib/torg_api/api/contractor.rb', line 54 def find_by_inn(inn) TorgApi::Models::Contractor .where(inn: inn) .where(next_id: nil) .order("#{DECODE_STATUS_ORDER}, updated_at desc") .pluck('id') end |