popbill 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/statement.rb ADDED
@@ -0,0 +1,444 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative './popbill.rb'
3
+
4
+ # 팝빌 전자명세서 API Service Implementation
5
+ class StatementService < BaseService
6
+ class << self
7
+ def instance(linkID, secretKey)
8
+ super(linkID, secretKey)
9
+ @instance ||= new
10
+ @instance.addScope("121")
11
+ @instance.addScope("122")
12
+ @instance.addScope("123")
13
+ @instance.addScope("124")
14
+ @instance.addScope("125")
15
+ @instance.addScope("126")
16
+ return @instance
17
+ end
18
+ private :new
19
+ end
20
+
21
+ def getChargeInfo(corpNum, itemCode, userID = '')
22
+ if corpNum.length != 10
23
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
24
+ end
25
+ httpget("/Statement/ChargeInfo/#{itemCode}", corpNum, userID)
26
+ end
27
+
28
+ def getURL(corpNum, togo, userID = '')
29
+ if corpNum.length != 10
30
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
31
+ end
32
+ httpget("/Statement?TG=#{togo}", corpNum, userID)['url']
33
+ end
34
+
35
+ def getUnitCost(corpNum, itemCode, userID = '')
36
+ if corpNum.length != 10
37
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
38
+ end
39
+ httpget("/Statement/#{itemCode}?cfg=UNITCOST", corpNum, userID)['unitCost']
40
+ end
41
+
42
+ def checkMgtKeyInUse(corpNum, itemCode, mgtKey, userID = '')
43
+ if corpNum.length != 10
44
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
45
+ end
46
+ if mgtKey.to_s == ''
47
+ raise PopbillException.new(-99999999, "현금영수증 문서관리번호가 입력되지 않았습니다.")
48
+ end
49
+
50
+ begin
51
+ response = httpget("/Statement/#{itemCode}/#{mgtKey}", corpNum)
52
+ return response['itemKey'].length != 0
53
+ rescue PopbillException => pe
54
+ if pe.code == -12000004
55
+ return false
56
+ end
57
+ raise PopbillException.new(pe.code, pe.message)
58
+ end
59
+ end
60
+
61
+ def faxSend(corpNum, statement, sendNum, receiveNum, userID = '')
62
+ if corpNum.length != 10
63
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
64
+ end
65
+ if sendNum.to_s == ''
66
+ raise PopbillException.new(-99999999, "팩스 발신번호가 입력되지 않았습니다.")
67
+ end
68
+ if receiveNum.to_s == ''
69
+ raise PopbillException.new(-99999999, "팩스 수신번호가 입력되지 않았습니다.")
70
+ end
71
+
72
+ statement["sendNum"] = sendNum
73
+ statement["receiveNum"] = receiveNum
74
+
75
+ postData = statement.to_json
76
+
77
+ httppost("/Statement", corpNum, postData, "FAX", userID)['receiptNum']
78
+ end
79
+
80
+
81
+ def registIssue(corpNum, statement, memo = '', userID ='')
82
+ if corpNum.length != 10
83
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
84
+ end
85
+
86
+ statement["memo"] = memo
87
+ postData = statement.to_json
88
+ httppost("/Statement", corpNum, postData, "ISSUE", userID)
89
+ end
90
+
91
+
92
+ def register(corpNum, statement, userID = '')
93
+ if corpNum.length != 10
94
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
95
+ end
96
+
97
+ postData = statement.to_json
98
+ httppost("/Statement", corpNum, postData, "", userID)
99
+ end
100
+
101
+
102
+ def update(corpNum, itemCode, mgtKey, statement, userID = '')
103
+ if corpNum.length != 10
104
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
105
+ end
106
+
107
+ postData = statement.to_json
108
+
109
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, postData, "PATCH", userID)
110
+ end
111
+
112
+
113
+ def issue(corpNum, itemCode, mgtKey, memo ='', emailSubject = '', userID ='')
114
+ if corpNum.length != 10
115
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
116
+ end
117
+ postData = {}
118
+ postData["memo"] = memo
119
+ postData["emailSubject"] = emailSubject
120
+ postData = postData.to_json
121
+
122
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, postData, "ISSUE", userID)
123
+ end
124
+
125
+ def cancel(corpNum, itemCode, mgtKey, memo = '', userID = '')
126
+ if corpNum.length != 10
127
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
128
+ end
129
+ postData = {}
130
+ postData["memo"] = memo
131
+ postData = postData.to_json
132
+
133
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, postData, "CANCEL", userID)
134
+ end
135
+
136
+
137
+ def delete(corpNum, itemCode, mgtKey, userID = '')
138
+ if corpNum.length != 10
139
+ raise PopbillException.new(-99999999, "사업자등록번호가 올바르지 않습니다.")
140
+ end
141
+
142
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, "", "DELETE", userID)
143
+ end
144
+
145
+
146
+ def search(corpNum, dType, sDate, eDate, state, itemCode, page, perPage, order,
147
+ qstring= '', userID ='')
148
+ if corpNum.length != 10
149
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
150
+ end
151
+ if dType.to_s == ''
152
+ raise PopbillException.new('-99999999', '검색일자유형이 입력되지 않았습니다.')
153
+ end
154
+
155
+ if sDate.to_s == ''
156
+ raise PopbillException.new('-99999999', '시작일자가 입력되지 않았습니다.')
157
+ end
158
+
159
+ if eDate.to_s == ''
160
+ raise PopbillException.new('-99999999', '종료일자가 입력되지 않았습니다.')
161
+ end
162
+
163
+ uri = "/Statement/Search?DType=#{dType}&SDate=#{sDate}&EDate=#{eDate}"
164
+ uri += "&State=" + state.join(',')
165
+ uri += "&ItemCode=" + itemCode.join(',')
166
+ uri += "&Page=" + page.to_s
167
+ uri += "&PerPage=" + perPage.to_s
168
+ uri += "&Order=" + order
169
+ uri += "&QString=" + qstring
170
+
171
+ httpget(URI.escape(uri), corpNum, userID)
172
+
173
+ end
174
+
175
+
176
+ def getInfo(corpNum, itemCode, mgtKey, userID = '')
177
+ if corpNum.length != 10
178
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
179
+ end
180
+ if mgtKey.to_s == ''
181
+ raise PopbillException.new('-99999999', '문서관리번호 입력되지 않았습니다.')
182
+ end
183
+
184
+ httpget("/Statement/#{itemCode}/#{mgtKey}", corpNum, userID)
185
+ end
186
+
187
+
188
+ def getInfos(corpNum, itemCode, mgtKeyList, userID = '')
189
+ if corpNum.length != 10
190
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
191
+ end
192
+ unless mgtKeyList.any?
193
+ raise PopbillException.new('-99999999', '문서관리번호 배열이 올바르지 않습니다.')
194
+ end
195
+
196
+ postData = mgtKeyList.to_json
197
+
198
+ httppost("/Statement/#{itemCode}", corpNum, postData, "", userID)
199
+ end
200
+
201
+
202
+ def getDetailInfo(corpNum, itemCode, mgtKey, userID = '')
203
+ if corpNum.length != 10
204
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
205
+ end
206
+ if mgtKey.to_s == ''
207
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
208
+ end
209
+
210
+ httpget("/Statement/#{itemCode}/#{mgtKey}", corpNum, userID)
211
+ end
212
+
213
+ def sendEmail(corpNum, itemCode, mgtKey, receiverMail, userID = '')
214
+ if corpNum.length != 10
215
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
216
+ end
217
+ if mgtKey.to_s == ''
218
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
219
+ end
220
+ if receiverMail.to_s == ''
221
+ raise PopbillException.new('-99999999', '수신자 메일주소가 올바르지 않습니다.')
222
+ end
223
+
224
+ postData = {}
225
+ postData["receiver"] = receiverMail
226
+ postData = postData.to_json
227
+
228
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, postData, "EMAIL", userID)
229
+ end
230
+
231
+
232
+ def sendSMS(corpNum, itemCode, mgtKey, senderNum, receiverNum, contents, userID = '')
233
+ if corpNum.length != 10
234
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
235
+ end
236
+ if mgtKey.to_s == ''
237
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
238
+ end
239
+
240
+ if senderNum.to_s == ''
241
+ raise PopbillException.new('-99999999', '발신번호가 입력되지 않았습니다.')
242
+ end
243
+
244
+ if receiverNum.to_s == ''
245
+ raise PopbillException.new('-99999999', '수신번호가 입력되지 않았습니다.')
246
+ end
247
+
248
+ if contents.to_s == ''
249
+ raise PopbillException.new('-99999999', '문자 메시지 내용이 입력되지 않았습니다.')
250
+ end
251
+
252
+ postData = {}
253
+ postData["sender"] = senderNum
254
+ postData["receiver"] = receiverNum
255
+ postData["contents"] = contents
256
+
257
+ postData = postData.to_json
258
+
259
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, postData, "SMS", userID)
260
+ end
261
+
262
+
263
+ def sendFax(corpNum, itemCode, mgtKey, senderNum, receiverNum, userID = '')
264
+ if corpNum.length != 10
265
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
266
+ end
267
+ if mgtKey.to_s == ''
268
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
269
+ end
270
+
271
+ if senderNum.to_s == ''
272
+ raise PopbillException.new('-99999999', '발신번호가 입력되지 않았습니다.')
273
+ end
274
+
275
+ if receiverNum.to_s == ''
276
+ raise PopbillException.new('-99999999', '수신번호가 입력되지 않았습니다.')
277
+ end
278
+
279
+ postData = {}
280
+ postData["sender"] = senderNum
281
+ postData["receiver"] = receiverNum
282
+ postData = postData.to_json
283
+ httppost("/Statement/#{itemCode}/#{mgtKey}", corpNum, postData, "FAX", userID)
284
+ end
285
+
286
+
287
+ def getLogs(corpNum, itemCode, mgtKey, userID = '')
288
+ if corpNum.length != 10
289
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
290
+ end
291
+ if mgtKey.to_s == ''
292
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
293
+ end
294
+
295
+ httpget("/Statement/#{itemCode}/#{mgtKey}/Logs", corpNum, userID)
296
+ end
297
+
298
+ def attachFile(corpNum, itemCode, mgtKey, filePath, userID ='')
299
+ if corpNum.length != 10
300
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
301
+ end
302
+ if mgtKey.to_s == ''
303
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
304
+ end
305
+
306
+ httppostfiles("/Statement/#{itemCode}/#{mgtKey}/Files", corpNum, '', [filePath], userID)
307
+ end
308
+
309
+ def getFiles(corpNum, itemCode, mgtKey, userID = '')
310
+ if corpNum.length != 10
311
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
312
+ end
313
+ if mgtKey.to_s == ''
314
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
315
+ end
316
+
317
+ httpget("/Statement/#{itemCode}/#{mgtKey}/Files", corpNum)
318
+ end
319
+
320
+
321
+ def deleteFile(corpNum, itemCode, mgtKey, fileID, userID = '')
322
+ if corpNum.length != 10
323
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
324
+ end
325
+ if mgtKey.to_s == ''
326
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
327
+ end
328
+ if fileID.to_s == ''
329
+ raise PopbillException.new('-99999999', '파일아이디가 입력되지 않았습니다.')
330
+ end
331
+
332
+ httppost("/Statement/#{itemCode}/#{mgtKey}/Files/#{fileID}", corpNum, '', "DELETE", userID)
333
+ end
334
+
335
+ def getPopUpURL(corpNum, itemCode, mgtKey, userID = '')
336
+ if corpNum.length != 10
337
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
338
+ end
339
+ if mgtKey.to_s == ''
340
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
341
+ end
342
+
343
+ httpget("/Statement/#{itemCode}/#{mgtKey}?TG=POPUP", corpNum, userID)['url']
344
+ end
345
+
346
+
347
+ def getPrintURL(corpNum, itemCode, mgtKey, userID = '')
348
+ if corpNum.length != 10
349
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
350
+ end
351
+ if mgtKey.to_s == ''
352
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
353
+ end
354
+
355
+ httpget("/Statement/#{itemCode}/#{mgtKey}?TG=PRINT", corpNum, userID)['url']
356
+ end
357
+
358
+ def getEPrintURL(corpNum, itemCode, mgtKey, userID = '')
359
+ if corpNum.length != 10
360
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
361
+ end
362
+ if mgtKey.to_s == ''
363
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
364
+ end
365
+
366
+ httpget("/Statement/#{itemCode}/#{mgtKey}?TG=EPRINT", corpNum, userID)['url']
367
+ end
368
+
369
+ def getMailURL(corpNum, itemCode, mgtKey, userID = '')
370
+ if corpNum.length != 10
371
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
372
+ end
373
+ if mgtKey.to_s == ''
374
+ raise PopbillException.new('-99999999', '문서관리번호 올바르지 않습니다.')
375
+ end
376
+
377
+ httpget("/Statement/#{itemCode}/#{mgtKey}?TG=MAIL", corpNum, userID)['url']
378
+ end
379
+
380
+
381
+ def getMassPrintURL(corpNum, itemCode, mgtKeyList, userID = '')
382
+ if corpNum.length != 10
383
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
384
+ end
385
+ unless mgtKeyList.any?
386
+ raise PopbillException.new('-99999999', '문서관리번호 배열이 올바르지 않습니다.')
387
+ end
388
+
389
+ postData = mgtKeyList.to_json
390
+ httppost("/Statement/#{itemCode}?Print", corpNum, postData, "", userID)['url']
391
+ end
392
+
393
+
394
+ def attachStatement(corpNum, itemCode, mgtKey, subItemCode, subMgtKey, userID = '')
395
+ if corpNum.length != 10
396
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
397
+ end
398
+ if mgtKey.to_s == ''
399
+ raise PopbillException.new('-99999999', '문서관리번호가 입력되지 않았습니다.')
400
+ end
401
+ if itemCode.to_s == ''
402
+ raise PopbillException.new('-99999999', '전자명세서 종류코드가 입력되지 않았습니다.')
403
+ end
404
+ if subItemCode.to_s == ''
405
+ raise PopbillException.new('-99999999', '전자명세서 종류코드가 입력되지 않았습니다.')
406
+ end
407
+ if subMgtKey.to_s == ''
408
+ raise PopbillException.new('-99999999', '전자명세서 문서관리번호가 입력되지 않았습니다.')
409
+ end
410
+
411
+ postData = {}
412
+ postData["ItemCode"] = subItemCode
413
+ postData["MgtKey"] = subMgtKey
414
+ postData = postData.to_json
415
+
416
+ httppost("/Statement/#{itemCode}/#{mgtKey}/AttachStmt", corpNum, postData, "", userID)
417
+ end
418
+
419
+ def detachStatement(corpNum, itemCode, mgtKey, subItemCode, subMgtKey, userID = '')
420
+ if corpNum.length != 10
421
+ raise PopbillException.new('-99999999', '사업자등록번호가 올바르지 않습니다.')
422
+ end
423
+ if mgtKey.to_s == ''
424
+ raise PopbillException.new('-99999999', '문서관리번호가 입력되지 않았습니다.')
425
+ end
426
+ if itemCode.to_s == ''
427
+ raise PopbillException.new('-99999999', '전자명세서 종류코드가 입력되지 않았습니다.')
428
+ end
429
+ if subItemCode.to_s == ''
430
+ raise PopbillException.new('-99999999', '전자명세서 종류코드가 입력되지 않았습니다.')
431
+ end
432
+ if subMgtKey.to_s == ''
433
+ raise PopbillException.new('-99999999', '전자명세서 문서관리번호가 입력되지 않았습니다.')
434
+ end
435
+
436
+ postData = {}
437
+ postData["ItemCode"] = subItemCode
438
+ postData["MgtKey"] = subMgtKey
439
+ postData = postData.to_json
440
+
441
+ httppost("/Statement/#{itemCode}/#{mgtKey}/DetachStmt", corpNum, postData, "", userID)
442
+ end
443
+
444
+ end # end of CashbillService