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
ОКПО.
-
#oktmo ⇒ String
ОКТМО.
-
#ownership ⇒ String
Форма собственности.
-
#reg_date ⇒ String
Дата регистрации юр.
-
#sme_type_id ⇒ Integer
Малое или среднее предпринимательство.
-
#status ⇒ Integer
Статус записи(0-новая, 1-активная, 2-старая, 3-неактивная).
-
#user_id ⇒ Integer
ИД автора.
Class Method Summary collapse
-
.create_from_b2b(hash) ⇒ Object
Создаёт контрагента.
- .extract_form(bank_inn) ⇒ Object
- .extract_ownership(org_name_short) ⇒ Object
- .extract_resident(country) ⇒ Object
-
.find_by_inn(inn, kpp = nil) ⇒ Integer[]
Поиск id контрагентов по ИНН.
Methods inherited from Base
attr_accessor, attributes, #initialize, #to_h, torg_resource
Constructor Details
This class inherits a constructor from TorgApi::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 |
#oktmo ⇒ String
Returns ОКТМО.
50 51 52 |
# File 'lib/torg_api/api/contractor.rb', line 50 def oktmo @oktmo end |
#ownership ⇒ String
Returns Форма собственности.
22 23 24 |
# File 'lib/torg_api/api/contractor.rb', line 22 def ownership @ownership end |
#reg_date ⇒ String
Returns Дата регистрации юр. лица.
52 53 54 |
# File 'lib/torg_api/api/contractor.rb', line 52 def reg_date @reg_date 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) ⇒ Object
Создаёт контрагента
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/torg_api/api/contractor.rb', line 77 def create_from_b2b(hash) c = Contractor.new c.name = hash[:org_name_short].gsub('"','') c.fullname = hash[:org_name] c.inn = hash[:bank_inn] c.kpp = hash[:bank_kpp] c.ogrn = hash[:ogrn] c.okpo = hash[:code_okpo] c.ownership = extract_ownership(hash[:org_name_short]) c.status = 0 c.form = extract_form(hash[:bank_inn]) c.legal_addr = hash[:jury_address] c.user_id = Settings.service_user[:id] 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 c.oktmo = 0 responce = JSON.parse( torg_resource["contractors"].post( contractor: c.to_h, accept: :json, content_type: :json, format: :json ), symbolize_names: true ) c.id = responce[:id] c end |
.extract_form(bank_inn) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/torg_api/api/contractor.rb', line 114 def extract_form(bank_inn) case bank_inn.size when 12 then "businessman" when 10 then "company" else "foreign" end end |
.extract_ownership(org_name_short) ⇒ Object
110 111 112 |
# File 'lib/torg_api/api/contractor.rb', line 110 def extract_ownership(org_name_short) org_name_short[/^([\w\-]+)/] end |
.extract_resident(country) ⇒ Object
122 123 124 |
# File 'lib/torg_api/api/contractor.rb', line 122 def extract_resident(country) country == 643 end |
.find_by_inn(inn, kpp = nil) ⇒ Integer[]
Поиск id контрагентов по ИНН
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/torg_api/api/contractor.rb', line 58 def find_by_inn(inn, kpp = nil) responce = JSON.parse( torg_resource["contractors/find_by_inn"].get( params: { inn: inn, kpp: kpp }, accept: :json, content_type: :json, format: :json ), symbolize_names: true, quirks_mode: true ) responce && new(responce) end |