Module: RS

Defined in:
lib/rs.rb,
lib/rs/car.rb,
lib/rs/sys.rb,
lib/rs/dict.rb,
lib/rs/print.rb,
lib/rs/invoice.rb,
lib/rs/version.rb,
lib/rs/waybill.rb

Defined Under Namespace

Classes: BarCode, Error, ExciseCode, TransportType, User, Waybill, WaybillItem, WaybillType, WaybillUnit

Constant Summary collapse

WAYBILL_SERVICE_URL =

ელქტრონული ზედნადების ფორმის WSDL მისამართი

'http://services.rs.ge/WayBillService/WayBillService.asmx?WSDL'
INVOICE_SERVICE_URL =

ელექტრონული ა/ფ WSDL მისამართი

'https://www.revenue.mof.ge/ntosservice/ntosservice.asmx?WSDL'
OPEN_SU =

მომხმარებელი, რომელიც შეგიძლიათ გამოიყენოთ ღია სერვისებში.

'dimitri1979'
OPEN_SP =

პაროლის ღია მომხმარებლისთვის.

'123456'
VERSION =
'0.0.14'

Class Method Summary collapse

Class Method Details

.activate_waybill(params) ⇒ Object

ზედნადების აქტივაცია.

გადაეცემა შემდეგი პარამეტრები: waybill_id – ზედნადების ID su – სერვისის მომხმარებელი sp – სერვისის მომხმარებლის პაროლი

აბრუნებს ამ ზედნადების ID-ს



406
407
408
409
410
411
412
413
414
# File 'lib/rs/waybill.rb', line 406

def self.activate_waybill(params)
  RS.validate_presence_of(params, 'waybill_id', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'send_waybill' do |soap|
    soap.body = params.merge({:order => ['su', 'sp', 'waybill_id']})
  end
  #puts response.to_hash[:send_waybill_response][:send_waybill_result].to_i
  response.to_hash[:send_waybill_response][:send_waybill_result].to_i
end

.check_service_user(params) ⇒ Object

სერვისის მომხმარებლის პაროლის შემოწმება.

გადაეცემა შემდეგი პარამეტრები:

su – სერვისის მომხმარებელი sp – სერვისის მომხმარებლის პაროლი

აბრუნებს #User ობიექტს, ცარიელი ip-თი ან nil-ს თუ არასწორი მომხმარებელია.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rs/sys.rb', line 73

def self.check_service_user(params)
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'chek_service_user' do
    soap.body = params
  end
  if response[:chek_service_user_response][:chek_service_user_result]
    payer_id = response[:chek_service_user_response][:un_id]
    user_id  = response[:chek_service_user_response][:s_user_id]
    user = User.new
    user.id = user_id
    user.user_name = params['su']
    user.payer_id = payer_id
    user
  end
end

.close_waybill(params) ⇒ Object

ზედნადების დახურვა.

გადაეცემა შემდეგი პარამეტრები: waybill_id – ზედნადების ID su – სერვისის მომხმარებელი sp – სერვისის მომხმარებლის პაროლი

აბრუნებს true თუ დაიხურა.



424
425
426
427
428
429
430
431
432
# File 'lib/rs/waybill.rb', line 424

def self.close_waybill(params)
  RS.validate_presence_of(params, 'waybill_id', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'close_waybill' do |soap|
    soap.body = params.merge({:order => ['su', 'sp', 'waybill_id']})
  end
  #puts response.to_hash
  response.to_hash[:close_waybill_response][:close_waybill_result].to_i == 1
end

.create_service_user(params) ⇒ Object

ქმნის ახალ მომხმარებელს.

გადაეცემა შემდეგი პარამეტრები:

user_name – მომხმარებლის სახელი user_password – მომხმარებლის პაროლი ip – მანქანის IP მისამართი, რომლიდანაც უნდა მოხდეს ამ მომხმარებლის შემოსვლა name – მაღაზიის სახელი su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი



27
28
29
30
31
32
33
34
# File 'lib/rs/sys.rb', line 27

def self.create_service_user(params)
  RS.validate_presence_of(params, 'user_name', 'user_password', 'ip', 'name', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'create_service_user' do
    soap.body = params
  end
  response.to_hash[:create_service_user_response][:create_service_user_result]
end

.deactivate_waybill(params) ⇒ Object

აქტიური/დასრულებული ზედნადების გაუქმება. ეს მეთოდი არ გამოდგება შენახული ზედნადების გასაუქმებლად.

გადაეცემა შემდეგი პარამეტრები: waybill_id – ზედნადების ID su – სერვისის მომხმარებელი sp – სერვისის მომხმარებლის პაროლი

აბრუნებს true თუ წაიშალა.



462
463
464
465
466
467
468
469
470
# File 'lib/rs/waybill.rb', line 462

def self.deactivate_waybill(params)
  RS.validate_presence_of(params, 'waybill_id', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'ref_waybill' do |soap|
    soap.body = params.merge({:order => ['su', 'sp', 'waybill_id']})
  end
  #puts response.to_hash
  response.to_hash[:ref_waybill_response][:ref_waybill_result].to_i == 1
end

.delete_bar_code(params) ⇒ Object

შტრიხკოდის წაშლის მეთოდი.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი bar_code – შტრიხკოდის მნიშვნელობა



218
219
220
221
222
223
224
225
226
227
# File 'lib/rs/dict.rb', line 218

def self.delete_bar_code(params)
  RS.validate_presence_of(params, 'su', 'sp', 'bar_code')
  params['order!'] = ['su', 'sp', 'bar_code']
  client = RS.waybill_service
  response = client.request 'delete_bar_code' do
    soap.body = params
  end
  resp = response.to_hash[:delete_bar_code_response][:delete_bar_code_result]
  resp.to_i == 1 # success!
end

.delete_waybill(params) ⇒ Object

ზედნადების წაშლა. ეს მეთოდი არ გამოდგება აქტიური/დასრულებული ზედნადების წასაშლელად.

გადაეცემა შემდეგი პარამეტრები: waybill_id – ზედნადების ID su – სერვისის მომხმარებელი sp – სერვისის მომხმარებლის პაროლი

აბრუნებს true თუ წაიშალა.



443
444
445
446
447
448
449
450
451
# File 'lib/rs/waybill.rb', line 443

def self.delete_waybill(params)
  RS.validate_presence_of(params, 'waybill_id', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'del_waybill' do |soap|
    soap.body = params.merge({:order => ['su', 'sp', 'waybill_id']})
  end
  #puts response.to_hash
  response.to_hash[:del_waybill_response][:del_waybill_result].to_i == 1
end

.get_bar_codes(params) ⇒ Object

შტრიხკოდების მიღების მეთოდი.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი bar_code – შტრიხკოდის მნიშვნელობა, რომლის მსგავსის ამოღებაც გვინდა



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/rs/dict.rb', line 236

def self.get_bar_codes(params)
  RS.validate_presence_of(params, 'su', 'sp', 'bar_code')
  params['order!']= ['su', 'sp', 'bar_code']
  client = RS.waybill_service
  response = client.request 'get_bar_codes' do
    soap.body = params
  end
  codes_hash = response.to_hash[:get_bar_codes_response][:bar_codes][:bar_codes][:bar_code]
  codes_hash = [codes_hash] if codes_hash.instance_of? Hash
  codes = []
  codes_hash.each do |hash|
    code = BarCode.new
    code.code = hash[:code]
    code.name = hash[:name]
    code.unit_id = hash[:unit_id].to_i
    code.unit_name = hash[:unit_txt]
    code.excise_id = hash[:a_id].to_i == 0 ? nil : hash[:a_id].to_i
    codes << code
  end
  codes
end

.get_excise_codes(params) ⇒ Object

აქციზის კოდების სიის მიღება.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი normilize – კი/არა, გამოიყენოს თუ არა სახელების ნორმალიზებული მნიშვნელობები (საწყისად ნორმალიზებულია)



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rs/dict.rb', line 85

def self.get_excise_codes(params)
  RS.ensure_open_user(params)
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'get_akciz_codes' do
    soap.body = params
  end
  normalize = params['normilize'] || true
  codes_hash = response.to_hash[:get_akciz_codes_response][:get_akciz_codes_result][:akciz_codes][:akciz_code]
  codes = []
  codes_hash.each do |hash|
    code = ExciseCode.new
    code.id = hash[:id]
    code.name = normalize ? normalize_excise_name(hash[:title]) : hash([:title])
    code.measure = hash[:measurement]
    code.code = hash[:sakon_kodi]
    code.value = hash[:akcis_ganakv].to_f
    codes << code
  end
  codes
end

.get_name_from_tin(params) ⇒ Object

აბრუნებს ორგანიზაციის/პიროვნების სახელს მისი საიდენტიფიკაციო ნომრიდან.

გადაეცემა შემდეგი პარამეტრები:

su – მომხამრებლის სახელი sp – პაროლი tin – საიდენტიფიკაციო ნომერი



118
119
120
121
122
123
124
125
126
# File 'lib/rs/sys.rb', line 118

def self.get_name_from_tin(params)
  RS.ensure_open_user(params)
  RS.validate_presence_of(params, 'su', 'sp', 'tin')
  client = RS.waybill_service
  response = 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_service_users(params) ⇒ Object

აბრუნებს სერვისის მომხმარებლელბის სიას.

გადაეცემა შემდეგი პარამეტრები:

user_name – მომხმარებლის სახელი user_password – მომხმარებლი პაროლი

ბრუნდება #User-ების მასივი.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rs/sys.rb', line 44

def self.get_service_users(params)
  RS.validate_presence_of(params, 'user_name', 'user_password')
  client = RS.waybill_service
  response = client.request 'get_service_users' do
    soap.body = params
  end
  users_hash_array = response.to_hash[:get_service_users_response][:get_service_users_result][:service_users][:service_user]
  #puts users_hash_array
  users = []
  users_hash_array.each do |user_hash|
    user = User.new
    user.id        = user_hash[:id]
    user.user_name = user_hash[:user_name]
    user.payer_id  = user_hash[:un_id]
    user.ip        = user_hash[:ip]
    user.name      = user_hash[:name]
    users << user
  end
  users
end

.get_transport_types(params) ⇒ Object

ტრანსპორტის სახეობების მიღება.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rs/dict.rb', line 163

def self.get_transport_types(params)
  RS.ensure_open_user(params)
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'get_trans_types' do
    soap.body = params
  end
  types_hash = response.to_hash[:get_trans_types_response][:get_trans_types_result][:transport_types][:transport_type]
  types = []
  types_hash.each do |hash|
    type = TransportType.new
    type.id = hash[:id]
    type.name = hash[:name]
    #puts "#{type.id}: #{type.name}"
    types << type
  end
  types
end

.get_waybill(params) ⇒ Object

ზედნადების გამოტანა.

გადაცემა შემდეგი პარამეტრები: waybill_id – ზედნადების ID su – სერვისის მომხმარებელი sp – სერვისის მომხმარებლის პაროლი



388
389
390
391
392
393
394
395
396
# File 'lib/rs/waybill.rb', line 388

def self.get_waybill(params)
  RS.validate_presence_of(params, 'waybill_id', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'get_waybill' do |soap|
    soap.body = params.merge({:order => ['su', 'sp', 'waybill_id']})
  end
  #puts response.to_hash[:get_waybill_response][:get_waybill_result][:waybill]
  Waybill.init_from_hash(response.to_hash[:get_waybill_response][:get_waybill_result][:waybill])
end

.get_waybill_types(params) ⇒ Object

ზედნადების ტიპების მიღება.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/rs/dict.rb', line 113

def self.get_waybill_types(params)
  RS.ensure_open_user(params)
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'get_waybill_types' do
    soap.body = params
  end
  types_hash = response.to_hash[:get_waybill_types_response][:get_waybill_types_result][:waybill_types][:waybill_type]
  types = []
  types_hash.each do |hash|
    type = WaybillType.new
    type.id = hash[:id]
    type.name = hash[:name]
    #puts "#{type.id}: #{type.name}"
    types << type
  end
  types
end

.get_waybill_units(params) ⇒ Object

ზედნადების ზომის ერთეულების მიღება.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rs/dict.rb', line 138

def self.get_waybill_units(params)
  RS.ensure_open_user(params)
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'get_waybill_units' do
    soap.body = params
  end
  units_hash = response.to_hash[:get_waybill_units_response][:get_waybill_units_result][:waybill_units][:waybill_unit]
  units = []
  units_hash.each do |hash|
    unit = WaybillUnit.new
    unit.id = hash[:id]
    unit.name = hash[:name]
    #puts "#{unit.id}: #{unit.name}"
    units << unit
  end
  units
end

.is_valid_corporate_tin(tin) ⇒ Object

ამოწმებს თუ რამდენად სწორია საწარმოს საიდენტიფიკაციო ნომრის ჩანაწერი (გარდა ინდ. მეწარმისა). საწარმოს საიდენტიფიკაციო ნომერი უნდა შედგებოდს ზუსტად 9 ციფრისაგან.



23
24
25
# File 'lib/rs/waybill.rb', line 23

def self.is_valid_corporate_tin(tin)
  tin =~ /^[0-9]{9}$/
end

.is_valid_personal_tin(tin) ⇒ Object

ამოწმებს თუ რამდენად სწორია პირადი ნომრის ჩანაწერი. პირადი ნომერი უნდა შედგებოდს ზუსტად 11 ციფრისაგან.



16
17
18
# File 'lib/rs/waybill.rb', line 16

def self.is_valid_personal_tin(tin)
  tin =~ /^[0-9]{11}$/
end


7
8
9
10
11
# File 'lib/rs/print.rb', line 7

def self.print_waybill(waybill, file, opts = {})
  C12::PDF::Document.generate file, :page_size => 'A4', :margin => [15, 15] do |pdf|
    build_pdf waybill, pdf, opts
  end
end

.render_waybill(waybill, opts = {}) ⇒ Object



13
14
15
16
17
# File 'lib/rs/print.rb', line 13

def self.render_waybill(waybill, opts = {})
  pdf = C12::PDF::Document.new :page_size => 'A4', :margin => [15, 15]
  build_pdf waybill, pdf, opts
  pdf.render
end

.save_bar_code(params) ⇒ Object

შტრიხკოდის შენახვის მეთოდი.

უნდა გადაეცეს შემდეგი პარამეტრები:

su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი bar_code – შტრიხკოდის მნიშვნელობა prod_name – საქონლის დასახელება (შეესაბამება goods_name RS-ის სპეციფიკაციაში) unit_id – ზომის ერთეულის კოდი unit_name – ზომის ერთეულის დასახელება, როდესაც #unit_id ტოლია #RS::WaybillUnit::OTHERS,

სხვა მნიშვნელობისთვის ეს პარამეტრი არ უნდა გადმოეცეს
(შეესანამება <code>unit_txt</code> პარამეტრს RS-ის სპეციფიკაციაში)

excise_id – აქციზის კოდი. ან nil, თუ აქციზის კოდი არ უყენდება ამ საქონელს

(შეესაბამება <code>a_id</code> პარამეტრს RS-ის სპეციფიკაციაში)


196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/rs/dict.rb', line 196

def self.save_bar_code(params)
  RS.validate_presence_of(params, 'su', 'sp', 'bar_code', 'prod_name', 'unit_id')
  params2 = {'su' => params['su'], 'sp' => params['sp'], 'bar_code' => params['bar_code'],
    'goods_name' => params['prod_name'], 'unit_id' => params['unit_id'],
    'unit_txt' => params['unit_name'], 'a_id' => params['excise_id']}
  prepare_params(params2)
  params2['order!'] = ['su', 'sp', 'bar_code', 'goods_name', 'unit_id', 'unit_txt', 'a_id']
  client = RS.waybill_service
  response = client.request 'save_bar_code' do
    soap.body = params2
  end
  resp = response.to_hash[:save_bar_code_response][:save_bar_code_result]
  resp.to_i == 1 # success!
end

.save_waybill(waybill, params) ⇒ Object

ზედნადების შენახვის მეთოდი

გადაეცემა: waybill – ზედნადები params – პარამეტრები

პარამეტრების შემდეგი მნიშვნელობებია დასაშვები: su – სერვისის მომხმარებლის სახელი sp – სერვისის მომხმარებლის პაროლი

ინახავს ამ ზედნადებს და განაახლებს მის მონაცემებს.



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/rs/waybill.rb', line 355

def self.save_waybill(waybill, params)
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'save_waybill' do |soap|
    soap.body do |xml|
      xml.ins0 :su, params['su']
      xml.ins0 :sp, params['sp']
      xml.ins0 :waybill do |b|
        waybill.to_xml b
      end
    end
  end
  hash_results = response.to_hash[:save_waybill_response][:save_waybill_result][:result]
  if hash_results[:status].to_i == 0
    waybill.id = hash_results[:id].to_i == 0 ? nil : hash_results[:id].to_i
    waybill.error_code = 0
    items_hash = hash_results[:goods_list][:goods]
    items_hash = [items_hash] if items_hash.instance_of? Hash
    (0..items_hash.size-1).each do |i|
      waybill.items[i].id = items_hash[i][:id].to_i
      #waybill.items[i].error_code = items_hash[i][:error].to_i
    end
  else
    waybill.error_code = hash_results[:status].to_i
  end
end

.save_waybill_invoice(waybill, params = {}) ⇒ Object

ქმნის ფაქტურას მოცემული ზედნადებისთვის.

ზედნადებზე ფაქტურის გამოწერა ხდება მხოლოდ დახურულ მდგომარეობაში.



8
9
10
11
12
13
14
15
16
# File 'lib/rs/invoice.rb', line 8

def self.save_waybill_invoice(waybill, params = {})
  RS.validate_presence_of(params, 'su', 'sp')
  client = RS.waybill_service
  params2 = params.merge( 'waybill_id' => waybill.id, 'in_inv_id' => 0 )
  response = client.request 'save_invoice' do |soap|
    soap.body = params2
  end
  waybill.invoice_id = response[:save_invoice_response][:out_inv_id].to_i
end

.update_service_user(params) ⇒ Object

სერვისის მომხმარებლის მონაცემების შეცვლა.

გადაეცემა შემდეგი პარამეტრები:

user_name – მომხმარებლის სახელი user_password – პაროლი ip – მანქანის მისამართი, name – მაღაზიის დასახელება su – მომხამრებლის სახელი sp – პაროლი



100
101
102
103
104
105
106
107
108
109
# File 'lib/rs/sys.rb', line 100

def self.update_service_user(params)
  RS.validate_presence_of(params, 'user_name', 'user_password', 'ip', 'name', 'su', 'sp')
  client = RS.waybill_service
  response = client.request 'update_service_user' do
    soap.body = params
  end
  #puts params
  #puts response.to_hash
  response.to_hash[:update_service_user_response][:update_service_user_result]
end

.valid_vehicle_number?(num) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/rs/car.rb', line 3

def self.valid_vehicle_number?(num)
  not not (num =~ /^[a-zA-Z]{3}[0-9]{3}$/)
end

.what_is_my_ipObject

აბრუნებს თქვენი კომპიუტერის გარე IP მისამართს.



11
12
13
14
15
# File 'lib/rs/sys.rb', line 11

def self.what_is_my_ip
  client = RS.waybill_service
  response = client.request 'what_is_my_ip'
  response.to_hash[:what_is_my_ip_response][:what_is_my_ip_result]
end