rs.ge 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rs.gemspec
4
+ gemspec
@@ -0,0 +1,23 @@
1
+ # RS.GE ვებ-სერვისები
2
+
3
+ ეს ბიბლიოთეკა განკუთვნილია RS.GE-ს ვებ სერვისების გამოყენებაზე.
4
+ ამ ბიბლიოთეკის მეშვეობით ადვილად მოახერხებთ ყველა ოპერაციის ჩატარებას,
5
+ რასაც აღნიშნული ვებ სერვისი ითვალისწინებს.
6
+
7
+ ## გამოყენება
8
+
9
+ გამოყენებისათვის უნდა ჩასვათ შემდეგი ხაზი თქვენს Gemfile-ში:
10
+
11
+ gem 'rs'
12
+
13
+ შემდეგი გამოყენება ძალიან მარტივია:
14
+
15
+ ```ruby
16
+ require 'rs'
17
+
18
+ puts RS.what_is_my_ip # თქვენს IP მისამართს დაბეჭდავს კონსოლში
19
+ ```
20
+
21
+ ## სხვა ფუნქციები
22
+
23
+ TODO: აქ დასაწერია თუ როგორ უნდა გამოიყენოთ სხვა ფუნქციები (დასალაგებბელია თემეტურად)
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ # RSpec
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:test) do |spec|
7
+ spec.rspec_opts = ["--color", "--format progress"]
8
+ spec.pattern = 'spec/**/*.rb'
9
+ spec.verbose = false
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,55 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'savon'
3
+ require 'rs/version'
4
+ require 'rs/sys'
5
+ require 'rs/dict'
6
+ require 'rs/waybill'
7
+
8
+ module RS
9
+ # ელქტრონული ზედნადების ფორმის WSDL მისამართი
10
+ WAYBILL_SERVICE_URL = 'http://services.rs.ge/WayBillService/WayBillService.asmx?WSDL'
11
+
12
+ # ელექტრონული ა/ფ WSDL მისამართი
13
+ INVOICE_SERVICE_URL = 'https://www.revenue.mof.ge/ntosservice/ntosservice.asmx?WSDL'
14
+
15
+ # შეცდომის კლასი
16
+ class Error < RuntimeError
17
+ end
18
+
19
+ protected
20
+
21
+ # ელექტრონული ზედნადების SOAP კლიენტის მიღება
22
+ def self.waybill_service
23
+ Savon::Client.new do
24
+ wsdl.document = WAYBILL_SERVICE_URL
25
+ end
26
+ end
27
+
28
+ # ანგარიშ-ფაქტურის SOAP კლიენტის მიღება
29
+ def self.invoice_service
30
+ Savon::Client.new do
31
+ wsdl.document = INVOICE_SERVICE_URL
32
+ end
33
+ end
34
+
35
+ # ამოწმებს, რომ მოცემულ პარამეტრებში ყველას მნიშვნელობა განსხვავდებოდეს <code>nil</code>-სგან.
36
+ def self.validate_presence_of(params, *options)
37
+ options.each do |opt|
38
+ val = params[opt.to_s]
39
+ raise RS::Error.new("#{opt.to_s} required") if val.nil? or (val.instance_of? String and val.strip.empty?)
40
+ end if options
41
+ end
42
+
43
+ # უზრუნველყოფს <code>nil</code> მნიშვნელობების სწორად ჩაწერას.
44
+ def self.prepare_params(params)
45
+ attributes = {}
46
+ params.each do |k, v|
47
+ if v.nil?
48
+ params.delete k
49
+ attributes[k] = {'xsi:nil' => true}
50
+ end
51
+ end
52
+ params['attributes!'] = attributes unless attributes.empty?
53
+ end
54
+
55
+ end
@@ -0,0 +1,247 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module RS
4
+
5
+ # ეს არის აქციზის კოდის აღმწერი კლასი.
6
+ class ExciseCode
7
+ # name -- აქციზის დასახელება
8
+ # measure -- ზომის ერთეული
9
+ # code -- აქციზის კოდი
10
+ # value -- აქციზის განაკვეთი
11
+ attr_accessor :id, :name, :measure, :code, :value
12
+ end
13
+
14
+ # ეს არის ზედნადების ტიპის კლასი.
15
+ class WaybillType
16
+ INNER = 1
17
+ TRANSPORTATION = 2
18
+ WITHOUT_TRANSPORTATION = 3
19
+ DISTRIBUTION = 4
20
+ RETURN = 5
21
+ SUB_WAYBILL = 6
22
+ NAMES = {
23
+ INNER => 'შიდა გადაზიდვა', TRANSPORTATION => 'ტრანსპორტირებით', WITHOUT_TRANSPORTATION => 'ტრანსპორტირების გარეშე',
24
+ DISTRIBUTION => 'დისტრიბუცია', RETURN => 'უკან დაბრუნება', SUB_WAYBILL => 'ქვე-ზედნადები'
25
+ }
26
+ attr_accessor :id, :name
27
+ def self.create_from_id(id)
28
+ type = WaybillType.new
29
+ type.id = id
30
+ type.name = NAMES[id]
31
+ type
32
+ end
33
+ end
34
+
35
+ # ზედნადების ერთეულების განსაზღვრა.
36
+ class WaybillUnit
37
+ attr_accessor :id, :name
38
+
39
+ # ეს კოდი შეესაბამება ზომის ერთეულს 'სხვა'.
40
+ OTHERS = 99
41
+ end
42
+
43
+ # ტრანსპორტირების ტიპი
44
+ class TransportType
45
+ VEHICLE = 1
46
+ RAILWAY = 2
47
+ AIR = 3
48
+ OTHERS = 4
49
+ NAMES = { VEHICLE => 'საავტომობილო', RAILWAY => 'სარკინიგზო', AIR => 'საავიაციო', OTHERS => 'სხვა' }
50
+ attr_accessor :id, :name
51
+ def self.create_from_id(id)
52
+ type = TransportType.new
53
+ type.id = id
54
+ type.name = NAMES[id]
55
+ type
56
+ end
57
+ end
58
+
59
+ # შტრიხკოდის აღმწერი კლასი
60
+ class BarCode
61
+ attr_accessor :code, :name, :unit_id, :unit_name, :excise_id
62
+ end
63
+
64
+ protected
65
+
66
+ def normalize_excise_name(name)
67
+ index = name =~ /\([0-9]+\)/
68
+ index ? name[0..index-1].strip : name
69
+ end
70
+
71
+ public
72
+
73
+ # აქციზის კოდების სიის მიღება.
74
+ #
75
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
76
+ #
77
+ # su -- სერვისის მომხმარებლის სახელი
78
+ # sp -- სერვისის მომხმარებლის პაროლი
79
+ def self.get_excise_codes(params)
80
+ RS.validate_presence_of(params, 'su', 'sp')
81
+ client = RS.waybill_service
82
+ response = client.request 'get_akciz_codes' do
83
+ soap.body = params
84
+ end
85
+ codes_hash = response.to_hash[:get_akciz_codes_response][:get_akciz_codes_result][:akciz_codes][:akciz_code]
86
+ codes = []
87
+ codes_hash.each do |hash|
88
+ code = ExciseCode.new
89
+ code.id = hash[:id]
90
+ code.name = normalize_excise_name(hash[:title])
91
+ code.measure = hash[:measurement]
92
+ code.code = hash[:sakon_kodi]
93
+ code.value = hash[:akcis_ganakv].to_f
94
+ codes << code
95
+ end
96
+ codes
97
+ end
98
+
99
+ # ზედნადების ტიპების მიღება.
100
+ #
101
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
102
+ #
103
+ # su -- სერვისის მომხმარებლის სახელი
104
+ # sp -- სერვისის მომხმარებლის პაროლი
105
+ def self.get_waybill_types(params)
106
+ RS.validate_presence_of(params, 'su', 'sp')
107
+ client = RS.waybill_service
108
+ response = client.request 'get_waybill_types' do
109
+ soap.body = params
110
+ end
111
+ types_hash = response.to_hash[:get_waybill_types_response][:get_waybill_types_result][:waybill_types][:waybill_type]
112
+ types = []
113
+ types_hash.each do |hash|
114
+ type = WaybillType.new
115
+ type.id = hash[:id]
116
+ type.name = hash[:name]
117
+ #puts "#{type.id}: #{type.name}"
118
+ types << type
119
+ end
120
+ types
121
+ end
122
+
123
+ # ზედნადების ზომის ერთეულების მიღება.
124
+ #
125
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
126
+ #
127
+ # su -- სერვისის მომხმარებლის სახელი
128
+ # sp -- სერვისის მომხმარებლის პაროლი
129
+ def self.get_waybill_units(params)
130
+ RS.validate_presence_of(params, 'su', 'sp')
131
+ client = RS.waybill_service
132
+ response = client.request 'get_waybill_units' do
133
+ soap.body = params
134
+ end
135
+ units_hash = response.to_hash[:get_waybill_units_response][:get_waybill_units_result][:waybill_units][:waybill_unit]
136
+ units = []
137
+ units_hash.each do |hash|
138
+ unit = WaybillUnit.new
139
+ unit.id = hash[:id]
140
+ unit.name = hash[:name]
141
+ #puts "#{unit.id}: #{unit.name}"
142
+ units << unit
143
+ end
144
+ units
145
+ end
146
+
147
+ # ტრანსპორტის სახეობების მიღება.
148
+ #
149
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
150
+ #
151
+ # su -- სერვისის მომხმარებლის სახელი
152
+ # sp -- სერვისის მომხმარებლის პაროლი
153
+ def self.get_transport_types(params)
154
+ RS.validate_presence_of(params, 'su', 'sp')
155
+ client = RS.waybill_service
156
+ response = client.request 'get_trans_types' do
157
+ soap.body = params
158
+ end
159
+ types_hash = response.to_hash[:get_trans_types_response][:get_trans_types_result][:transport_types][:transport_type]
160
+ types = []
161
+ types_hash.each do |hash|
162
+ type = TransportType.new
163
+ type.id = hash[:id]
164
+ type.name = hash[:name]
165
+ #puts "#{type.id}: #{type.name}"
166
+ types << type
167
+ end
168
+ types
169
+ end
170
+
171
+ # შტრიხკოდის შენახვის მეთოდი.
172
+ #
173
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
174
+ #
175
+ # su -- სერვისის მომხმარებლის სახელი
176
+ # sp -- სერვისის მომხმარებლის პაროლი
177
+ # bar_code -- შტრიხკოდის მნიშვნელობა
178
+ # prod_name -- საქონლის დასახელება (შეესაბამება <code>goods_name</code> RS-ის სპეციფიკაციაში)
179
+ # unit_id -- ზომის ერთეულის კოდი
180
+ # unit_name -- ზომის ერთეულის დასახელება, როდესაც #{unit_id} ტოლია #{WaybillUnit::OTHERS},
181
+ # სხვა მნიშვნელობისთვის ეს პარამეტრი არ უნდა გადმოეცეს
182
+ # (შეესანამება <code>unit_txt</code> პარამეტრს RS-ის სპეციფიკაციაში)
183
+ # excise_id -- აქციზის კოდი. ან <code>nil</code>, თუ აქციზის კოდი არ უყენდება ამ საქონელს
184
+ # (შეესაბამება <code>a_id</code> პარამეტრს RS-ის სპეციფიკაციაში)
185
+ def self.save_bar_code(params)
186
+ RS.validate_presence_of(params, 'su', 'sp', 'bar_code', 'prod_name', 'unit_id')
187
+ params2 = {'su' => params['su'], 'sp' => params['sp'], 'bar_code' => params['bar_code'],
188
+ 'goods_name' => params['prod_name'], 'unit_id' => params['unit_id'],
189
+ 'unit_txt' => params['unit_name'], 'a_id' => params['excise_id']}
190
+ prepare_params(params2)
191
+ params2['order!'] = ['su', 'sp', 'bar_code', 'goods_name', 'unit_id', 'unit_txt', 'a_id']
192
+ client = RS.waybill_service
193
+ response = client.request 'save_bar_code' do
194
+ soap.body = params2
195
+ end
196
+ resp = response.to_hash[:save_bar_code_response][:save_bar_code_result]
197
+ resp.to_i == 1 # success!
198
+ end
199
+
200
+ # შტრიხკოდის წაშლის მეთოდი.
201
+ #
202
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
203
+ #
204
+ # su -- სერვისის მომხმარებლის სახელი
205
+ # sp -- სერვისის მომხმარებლის პაროლი
206
+ # bar_code -- შტრიხკოდის მნიშვნელობა
207
+ def self.delete_bar_code(params)
208
+ RS.validate_presence_of(params, 'su', 'sp', 'bar_code')
209
+ params['order!'] = ['su', 'sp', 'bar_code']
210
+ client = RS.waybill_service
211
+ response = client.request 'delete_bar_code' do
212
+ soap.body = params
213
+ end
214
+ resp = response.to_hash[:delete_bar_code_response][:delete_bar_code_result]
215
+ resp.to_i == 1 # success!
216
+ end
217
+
218
+ # შტრიხკოდების მიღების მეთოდი.
219
+ #
220
+ # უნდა გადაეცეს შემდეგი პარამეტრები:
221
+ #
222
+ # su -- სერვისის მომხმარებლის სახელი
223
+ # sp -- სერვისის მომხმარებლის პაროლი
224
+ # bar_code -- შტრიხკოდის მნიშვნელობა, რომლის მსგავსის ამოღებაც გვინდა
225
+ def self.get_bar_codes(params)
226
+ RS.validate_presence_of(params, 'su', 'sp', 'bar_code')
227
+ params['order!']= ['su', 'sp', 'bar_code']
228
+ client = RS.waybill_service
229
+ response = client.request 'get_bar_codes' do
230
+ soap.body = params
231
+ end
232
+ codes_hash = response.to_hash[:get_bar_codes_response][:bar_codes][:bar_codes][:bar_code]
233
+ codes_hash = [codes_hash] if codes_hash.instance_of? Hash
234
+ codes = []
235
+ codes_hash.each do |hash|
236
+ code = BarCode.new
237
+ code.code = hash[:code]
238
+ code.name = hash[:name]
239
+ code.unit_id = hash[:unit_id].to_i
240
+ code.unit_name = hash[:unit_txt]
241
+ code.excise_id = hash[:a_id].to_i == 0 ? nil : hash[:a_id].to_i
242
+ codes << code
243
+ end
244
+ codes
245
+ end
246
+
247
+ end
@@ -0,0 +1,127 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module RS
4
+
5
+ # სერვისის მომხმარებლის კლასი.
6
+ class User
7
+ attr_accessor :id, :user_name, :payer_id, :ip, :name
8
+ end
9
+
10
+ # აბრუნებს თქვენი კომპიუტერის გარე IP მისამართს.
11
+ def self.what_is_my_ip
12
+ client = RS.waybill_service
13
+ response = client.request 'what_is_my_ip'
14
+ response.to_hash[:what_is_my_ip_response][:what_is_my_ip_result]
15
+ end
16
+
17
+ # ქმნის ახალ მომხმარებელს.
18
+ #
19
+ # გადაეცემა შემდეგი პარამეტრები:
20
+ #
21
+ # user_name -- მომხმარებლის სახელი
22
+ # user_password -- მომხმარებლის პაროლი
23
+ # ip -- მანქანის IP მისამართი, რომლიდანაც უნდა მოხდეს ამ მომხმარებლის შემოსვლა
24
+ # name -- მაღაზიის სახელი
25
+ # su -- სერვისის მომხმარებლის სახელი
26
+ # sp -- სერვისის მომხმარებლის პაროლი
27
+ def self.create_service_user(params)
28
+ RS.validate_presence_of(params, 'user_name', 'user_password', 'ip', 'name', 'su', 'sp')
29
+ client = RS.waybill_service
30
+ response = client.request 'create_service_user' do
31
+ soap.body = params
32
+ end
33
+ response.to_hash[:create_service_user_response][:create_service_user_result]
34
+ end
35
+
36
+ # აბრუნებს სერვისის მომხმარებლელბის სიას.
37
+ #
38
+ # გადაეცემა შემდეგი პარამეტრები:
39
+ #
40
+ # user_name -- მომხმარებლის სახელი
41
+ # user_password -- მომხმარებლი პაროლი
42
+ #
43
+ # ბრუნდება #{User}-ების მასივი.
44
+ def self.get_service_users(params)
45
+ RS.validate_presence_of(params, 'user_name', 'user_password')
46
+ client = RS.waybill_service
47
+ response = client.request 'get_service_users' do
48
+ soap.body = params
49
+ end
50
+ users_hash_array = response.to_hash[:get_service_users_response][:get_service_users_result][:service_users][:service_user]
51
+ #puts users_hash_array
52
+ users = []
53
+ users_hash_array.each do |user_hash|
54
+ user = User.new
55
+ user.id = user_hash[:id]
56
+ user.user_name = user_hash[:user_name]
57
+ user.payer_id = user_hash[:un_id]
58
+ user.ip = user_hash[:ip]
59
+ user.name = user_hash[:name]
60
+ users << user
61
+ end
62
+ users
63
+ end
64
+
65
+ # სერვისის მომხმარებლის პაროლის შემოწმება.
66
+ #
67
+ # გადაეცემა შემდეგი პარამეტრები:
68
+ #
69
+ # su -- სერვისის მომხმარებელი
70
+ # sp -- სერვისის მომხმარებლის პაროლი
71
+ #
72
+ # აბრუნებს #{User} ობიექტს, ცარიელი ip-თი ან <code>nil</code>-ს თუ არასწორი მომხმარებელია.
73
+ def self.check_service_user(params)
74
+ RS.validate_presence_of(params, 'su', 'sp')
75
+ client = RS.waybill_service
76
+ response = client.request 'chek_service_user' do
77
+ soap.body = params
78
+ end
79
+ if response[:chek_service_user_response][:chek_service_user_result]
80
+ payer_id = response[:chek_service_user_response][:un_id]
81
+ user_id = response[:chek_service_user_response][:s_user_id]
82
+ user = User.new
83
+ user.id = user_id
84
+ user.user_name = params['su']
85
+ user.payer_id = payer_id
86
+ user
87
+ end
88
+ end
89
+
90
+ # სერვისის მომხმარებლის მონაცემების შეცვლა.
91
+ #
92
+ # გადაეცემა შემდეგი პარამეტრები:
93
+ #
94
+ # user_name -- მომხმარებლის სახელი
95
+ # user_password -- პაროლი
96
+ # ip -- მანქანის მისამართი,
97
+ # name -- მაღაზიის დასახელება
98
+ # su -- მომხამრებლის სახელი
99
+ # sp -- პაროლი
100
+ def self.update_service_user(params)
101
+ RS.validate_presence_of(params, 'user_name', 'user_password', 'ip', 'name', 'su', 'sp')
102
+ client = RS.waybill_service
103
+ response = client.request 'update_service_user' do
104
+ soap.body = params
105
+ end
106
+ #puts params
107
+ #puts response.to_hash
108
+ response.to_hash[:update_service_user_response][:update_service_user_result]
109
+ end
110
+
111
+ # აბრუნებს ორგანიზაციის/პიროვნების სახელს მისი საიდენტიფიკაციო ნომრიდან.
112
+ #
113
+ # გადაეცემა შემდეგი პარამეტრები:
114
+ #
115
+ # su -- მომხამრებლის სახელი
116
+ # sp -- პაროლი
117
+ # tin -- საიდენტიფიკაციო ნომერი
118
+ def self.get_name_from_tin(params)
119
+ RS.validate_presence_of(params, 'su', 'sp', 'tin')
120
+ client = RS.waybill_service
121
+ response = client.request 'get_name_from_tin' do
122
+ soap.body = params
123
+ end
124
+ response.to_hash[:get_name_from_tin_response][:get_name_from_tin_result]
125
+ end
126
+
127
+ end