Class: RS::DictionaryRequest

Inherits:
BaseRequest show all
Includes:
Singleton
Defined in:
lib/rs/requests/dict.rb

Constant Summary

Constants inherited from BaseRequest

BaseRequest::DEFAULTS, BaseRequest::INVOICE_SERVICE_URL, BaseRequest::WAYBILL_SERVICE_URL

Instance Attribute Summary

Attributes inherited from BaseRequest

#last_error_code

Instance Method Summary collapse

Methods inherited from BaseRequest

#format_date, #invoice_client, #validate_presence_of, #waybill_client

Instance Method Details

#corporate_tin?(tin) ⇒ Boolean

Checks whether given argument is a correct corporate TIN.

Returns:

  • (Boolean)


130
131
132
# File 'lib/rs/requests/dict.rb', line 130

def corporate_tin?(tin)
  tin =~ /^[0-9]{9}$/
end

#get_name_from_tin(params = {}) ⇒ Object

Returns name by given TIN number.



116
117
118
119
120
121
122
# File 'lib/rs/requests/dict.rb', line 116

def get_name_from_tin(params = {})
  validate_presence_of(params, :su, :sp, :tin)
  response = waybill_client.request 'get_name_from_tin' do
    soap.body = params
  end
  response.to_hash[:get_name_from_tin_response][:get_name_from_tin_result]
end

#get_payer_info(params = {}) ⇒ Object

Returns information about payer (name, id) from it’s TIN number.



94
95
96
97
98
99
100
101
102
103
# File 'lib/rs/requests/dict.rb', line 94

def get_payer_info(params = {})
  validate_presence_of(params, :su, :sp, :tin)
  user_id = params[:user_id] || payer_user_id(params)
  response = invoice_client.request 'get_un_id_from_tin' do
    soap.body = {'user_id' => user_id, 'tin' => params[:tin], 'su' => params[:su], 'sp' => params[:sp]}
  end.to_hash
  p_id = response[:get_un_id_from_tin_response][:get_un_id_from_tin_result].to_i
  name = response[:get_un_id_from_tin_response][:name]
  { payer_id: p_id, name: name }
end

#is_vat_payer(params = {}) ⇒ Object

Is given organization a vat payer?



106
107
108
109
110
111
112
113
# File 'lib/rs/requests/dict.rb', line 106

def is_vat_payer(params = {})
  validate_presence_of(params, :su, :sp, :tin)
  payer_id = get_payer_info(su: params[:su], sp: params[:sp], tin: params[:tin])[:payer_id]
  response = waybill_client.request 'is_vat_payer' do
    soap.body = { 'su' => params[:su], 'sp' => params[:sp], 'un_id' => payer_id }
  end.to_hash
  response[:is_vat_payer_response][:is_vat_payer_result]
end

#payer_user_id(params = {}) ⇒ Object

Returns user_id for the service users’s payer.



85
86
87
88
89
90
91
# File 'lib/rs/requests/dict.rb', line 85

def payer_user_id(params = {})
  validate_presence_of(params, :su, :sp)
  response = invoice_client.request 'chek' do
    soap.body = {'su' => params[:su], 'sp' => params[:sp]}
  end
  response.to_hash[:chek_response][:user_id].to_i
end

#personal_tin?(tin) ⇒ Boolean

Checks whether given argument is a correct personal TIN.

Returns:

  • (Boolean)


125
126
127
# File 'lib/rs/requests/dict.rb', line 125

def personal_tin?(tin)
  tin =~ /^[0-9]{11}$/
end

#transport_types(opts = {}) ⇒ Object

Returns RS.GE transport types.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rs/requests/dict.rb', line 71

def transport_types(opts = {})
  validate_presence_of(opts, :su, :sp)
  response = waybill_client.request 'get_trans_types' do
    soap.body = { 'su' => opts[:su], 'sp' => opts[:sp] }
  end
  resp = response.to_hash[:get_trans_types_response][:get_trans_types_result][:transport_types][:transport_type]
  types = {}
  resp.each do |type|
    types[type[:id].to_i] = type[:name]
  end
  types
end

#units(opts = {}) ⇒ Object

Returns RS.GE units.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rs/requests/dict.rb', line 43

def units(opts = {})
  validate_presence_of(opts, :su, :sp)
  response = waybill_client.request 'get_waybill_units' do
    soap.body = { 'su' => opts[:su], 'sp' => opts[:sp] }
  end
  resp = response.to_hash[:get_waybill_units_response][:get_waybill_units_result][:waybill_units][:waybill_unit]
  units = {}
  resp.each do |unit|
    units[unit[:id].to_i] = unit[:name]
  end
  units
end

#waybill_types(opts = {}) ⇒ Object

Returns RS.GE waybill types.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rs/requests/dict.rb', line 57

def waybill_types(opts = {})
  validate_presence_of(opts, :su, :sp)
  response = waybill_client.request 'get_waybill_types' do
    soap.body = { 'su' => opts[:su], 'sp' => opts[:sp] }
  end
  resp = response.to_hash[:get_waybill_types_response][:get_waybill_types_result][:waybill_types][:waybill_type]
  types = {}
  resp.each do |type|
    types[type[:id].to_i] = type[:name]
  end
  types
end