tsubaiso-sdk 1.0.0 → 1.1.0

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +22 -326
  3. data/lib/tsubaiso_sdk.rb +599 -47
  4. data/test/test_tsubaiso_sdk.rb +731 -48
  5. metadata +31 -26
  6. data/README-j.md +0 -347
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a427717922d3d59b6816207cffd61f417e78ddf
4
+ data.tar.gz: 93becc79ecf8a3cbb692707cdfa536f60c409b00
5
+ SHA512:
6
+ metadata.gz: c2376f73fe25ff678949e42baf73c991d0dc21ee829d8ceb592a0c66010fcaec176fc62d024c0e80745ecc21b8f5717cb8bb2fe04988f7c285be99b002b0085f
7
+ data.tar.gz: fdf3f55f2847df47042ca9ef8f7badd9c032cc2f9781b42fba06394cacdea0da1a157a81625bbc06f7871b494bf22c7d875e1b73ac70535e670d2b756ee82817
data/README.md CHANGED
@@ -1,345 +1,41 @@
1
- # Tsubaiso API (beta)
1
+ # Tsubaiso SDK (Ruby)
2
2
 
3
- This is the documentation for the beta version of the Tsubaiso API. The beta version currently handles accounts receivables and accounts payable transactions. Future versions of this API will add new endpoints to access other modules of the Tsubaiso system.
3
+ The Tsubaiso SDK is a library of methods that directly uses Tsubaiso API web endpoints.
4
4
 
5
- ## Root Endpoint
5
+ ## API Endpoint Documentation
6
6
 
7
- ```sh
8
- https://tsubaiso.net
9
- ```
10
-
11
-
12
- ## Request Format
13
-
14
- We ask that all requests to the API be made using JSON.
15
-
16
- ## Authentication
17
-
18
- The user must provide their access token in order to access the Tsubaiso API.
19
-
20
- ```
21
- $ curl -i -H "Access-Token: xxxxxxxxxxxxxxxxx" -H "Accept: application/json" -H "Content-Type: application/json" https://tsubaiso.net/ar/list
22
- ```
23
-
24
- ## Response Codes and Error Handling
25
-
26
- Code | Description
27
- --- | ---
28
- `200 OK` | A successful request was made. |
29
- `204 No Content` | A successful request was made but no content is passed back.
30
- `401 Not Authorized` | The access token was not provided or was incorrect.
31
- `403 Forbidden` | You do not have the correct privileges to make this request.
32
- `404 Not found` | Path is incorrect or resource was not found at the specified path.
33
- `422 Unprocessable Entity` | One or more parameters were incorrect or insufficient. The error message will tell you the reason.
34
- `500 Internal Server Error` | There was an error on the server.
35
- `503 Service Unavailable` | This error occurs when there are too many requests coming from your IP address. Wait a little bit to make your next request.
36
-
37
- ## Resources
38
-
39
- #### Accounts Receivables
40
-
41
- **/ar/list/:year/:month**
42
-
43
- Description: This endpoint returns a list of accounts receivables transactions for a particular month. If no year and month parameters are provided. It returns the transactions for the current month.
44
-
45
- Method: GET
46
-
47
- URL Structure:
48
- ```sh
49
- https://tsubaiso.net/ar/list/2015/10
50
- ```
51
-
52
- Sample JSON response:
53
- ```
54
- [
55
- {
56
- "ar_reason_master_id": 0,
57
- "ar_receipt_attachments_count": null,
58
- "code": null,
59
- "created_at": "2015/10/05 15:26:43 +0900",
60
- "customer_master_id": 101,
61
- "dc": "d",
62
- "dept_code": "DEPT A",
63
- "id": 8833,
64
- "memo": "500 widgets",
65
- "realization_timestamp": "2015/10/31 00:00:00 +0900",
66
- "regist_user_code": "sample_user",
67
- "sales_journal_dc_id": 6832,
68
- "scheduled_memo": null,
69
- "scheduled_receive_timestamp": null,
70
- "update_user_code": null,
71
- "updated_at": "2015/10/05 15:26:43 +0900",
72
- "account_code": "501",
73
- "sales_price": 5000,
74
- "sales_tax": 400,
75
- "sales_tax_type": 18
76
- }, {
77
- "ar_reason_master_id": 121278,
78
- "ar_receipt_attachments_count": null,
79
- "code": null,
80
- "created_at": "2015/10/05 17:39:34 +0900",
81
- "customer_master_id": 895820,
82
- "dc": "d",
83
- "dept_code": "DEPT B",
84
- "id": 8834,
85
- "memo": "100 clocks",
86
- "realization_timestamp": "2015/10/31 00:00:00 +0900",
87
- "regist_user_code": "sample_user",
88
- "sales_journal_dc_id": 8834,
89
- "scheduled_memo": null,
90
- "scheduled_receive_timestamp": null,
91
- "update_user_code": null,
92
- "updated_at": "2015/10/05 17:39:34 +0900",
93
- "account_code": "500",
94
- "sales_price": 10000,
95
- "sales_tax": 800,
96
- "sales_tax_type": 0
97
- }
98
- ]
99
- ```
100
-
101
- **/ar/show/:id**
102
-
103
- Description: This endpoint returns a single accounts receivable transaction.
104
-
105
- Method: GET
106
-
107
- URL Structure:
108
- ``` sh
109
- https://tsubaiso.net/ar/show/8833
110
- ```
111
-
112
- Sample JSON response:
113
- ```
114
- {
115
- "ar_reason_master_id": 0,
116
- "ar_receipt_attachments_count": null,
117
- "code": null,
118
- "created_at": "2015/10/05 15:26:43 +0900",
119
- "customer_master_id": 101,
120
- "dc": "d",
121
- "dept_code": "DEPT A",
122
- "id": 8833,
123
- "memo": "500 widgets",
124
- "realization_timestamp": "2015/10/31 00:00:00 +0900",
125
- "regist_user_code": "sample_user",
126
- "sales_journal_dc_id": 6832,
127
- "scheduled_memo": null,
128
- "scheduled_receive_timestamp": null,
129
- "update_user_code": null,
130
- "updated_at": "2015/10/05 15:26:43 +0900",
131
- "account_code": "501",
132
- "sales_price": 5000,
133
- "sales_tax": 400,
134
- "sales_tax_type": 18
135
- }
136
- ```
137
-
138
- **/ar/create**
139
-
140
- Description: Creates a new accounts receivable transaction. The created transaction will be sent back as JSON if successful.
7
+ [English](https://github.com/tsubaiso/tsubaiso-api-documentation)
141
8
 
142
- Method: POST
9
+ [Japanese](https://github.com/tsubaiso/tsubaiso-api-documentation/blob/master/README-j.md)
143
10
 
144
- URL Structure:
145
- ```sh
146
- https://tsubaiso.net/ar/create
147
- ```
148
-
149
- Parameters:
150
-
151
- Parameter | Necessity | Type | Description
152
- --- | --- | --- | ---
153
- `price` | *required* | Integer | Amount of the transaction.
154
- `realization_timestamp` | *required* | String | Actual date of the transaction. Format must be "YYYY-MM-DD"
155
- `customer_master_code` | *required* | String | Code of the transaction party.
156
- `reason_master_code` | *required* | String | Reason of the transaction. This is used to create the journal entry.
157
- `dc` | *required* | String | 'd' if the transaction was a debit to AR, 'c' if it was a credit.
158
- `memo` | *required* | String | Memo for the transaction. Can be blank but must be provided.
159
- `tax_code` | *required* | Integer | Tax code for the transaction.
160
- `year` | *optional* | Integer | Year of the transaction.
161
- `month` | *optional* | Integer | Month of the transaction.
162
- `dept_code` | *optional* | String | Code of the internal department involved.
163
- `sales_tax` | *optional* | Integer | Sales tax on the transaction. Is automatically calculated if not provided.
164
- `scheduled_receipt_timestamp` | *optional* | String | Date of receipt. Format must be “YYYY-MM-DD”.
165
- `scheduled_memo` | *optional* | String | Optional memo regarding receipt of funds.
166
-
167
- Sample Request:
168
- ```sh
169
- curl -i -H "Content-Type: application/json" -H "Accept: application/json" -H "Access-Token: XXXXXXXXXXXXXX" -X POST -d '{"year": 2015, "month": 10, "price": 5000, "realization_timestamp": "2015-10-31", "customer_master_code": "101", "dept_code": "DEPT A", "reason_master_code": "SALES", "dc": "d", "memo": "500 widgets", "tax_code": 0}' https://tsubaiso.net/ar/create
170
- ```
171
-
172
- **/ar/destroy/:id**
173
-
174
- Description: Destroys the accounts receivable transaction specified as the id. Returns a status of 204 No Content.
175
-
176
- Method: POST
177
-
178
- URL Structure:
179
- ```sh
180
- https://tsubaiso.net/ar/destroy/8833
181
- ```
182
-
183
- #### Accounts Payables
184
-
185
- **/ap_payments/list/:year/:month**
186
-
187
- Description: Returns a list of accounts payables transactions for a particular month. If no year and month parameters are provided. It returns the transactions for the current month.
11
+ ## Installation
188
12
 
189
- Method: GET
13
+ Add this line to your application's Gemfile:
190
14
 
191
- URL Structure:
192
- ``` sh
193
- https://tsubaiso.net/ap_payments/list/2015/10
194
- ```
195
-
196
- Sample JSON response:
197
- ```
198
- [
199
- {
200
- "accrual_timestamp": "2015/10/31 00:00:00 +0900",
201
- "ap_payment_attachments_count": null,
202
- "ap_reason_master_id": 1,
203
- "buying_journal_dc_id": 9835,
204
- "code": null,
205
- "created_at": "2015/10/06 15:45:21 +0900",
206
- "customer_master_id": 8201,
207
- "dc": "c",
208
- "dept_code": "DEPT C",
209
- "id": 6621,
210
- "memo": "Office Supplies for Frank",
211
- "need_tax_deduction": null,
212
- "port_type": 1,
213
- "preset_withholding_tax_amount": null,
214
- "regist_user_code": "sample_user",
215
- "scheduled_memo": null,
216
- "scheduled_pay_timestamp": null,
217
- "update_user_code": null,
218
- "updated_at": "2015/10/06 15:45:21 +0900",
219
- "withholding_tax_base": null,
220
- "withholding_tax_segment": null,
221
- "account_code": "604",
222
- "buying_price": 5000,
223
- "buying_tax": 400,
224
- "buying_tax_type": 0
225
- }, {
226
- "accrual_timestamp": "2015/10/31 00:00:00 +0900",
227
- "ap_payment_attachments_count": null,
228
- "ap_reason_master_id": 1,
229
- "buying_journal_dc_id": 9836,
230
- "code": null,
231
- "created_at": "2015/10/06 15:48:42 +0900",
232
- "customer_master_id": 101,
233
- "dc": "c",
234
- "dept_code": "SETSURITSU",
235
- "id": 622,
236
- "memo": "Television for Cafeteria",
237
- "need_tax_deduction": null,
238
- "port_type": 1,
239
- "preset_withholding_tax_amount": null,
240
- "regist_user_code": "client_user",
241
- "scheduled_memo": null,
242
- "scheduled_pay_timestamp": null,
243
- "update_user_code": null,
244
- "updated_at": "2015/10/06 15:48:42 +0900",
245
- "withholding_tax_base": null,
246
- "withholding_tax_segment": null,
247
- "account_code": "604",
248
- "buying_price": 10000,
249
- "buying_tax": 800,
250
- "buying_tax_type": 0
251
- }
252
- ]
253
- ```
15
+ gem 'tsubaiso-sdk'
254
16
 
255
- **/ap_payments/show/:id**
256
-
257
- Description: This endpoint returns a single accounts payable transaction.
258
-
259
- Method: GET
260
-
261
- URL Structure:
262
- ``` sh
263
- https://tsubaiso.net/ap_payments/show/6621
264
- ```
17
+ And then execute:
265
18
 
266
- Sample JSON response:
267
- ```
268
- {
269
- "accrual_timestamp": "2015/10/31 00:00:00 +0900",
270
- "ap_payment_attachments_count": null,
271
- "ap_reason_master_id": 1,
272
- "buying_journal_dc_id": 9835,
273
- "code": null,
274
- "created_at": "2015/10/06 15:45:21 +0900",
275
- "customer_master_id": 8201,
276
- "dc": "c",
277
- "dept_code": "DEPT C",
278
- "id": 6621,
279
- "memo": "Office Supplies for Frank",
280
- "need_tax_deduction": null,
281
- "port_type": 1,
282
- "preset_withholding_tax_amount": null,
283
- "regist_user_code": "sample_user",
284
- "scheduled_memo": null,
285
- "scheduled_pay_timestamp": null,
286
- "update_user_code": null,
287
- "updated_at": "2015/10/06 15:45:21 +0900",
288
- "withholding_tax_base": null,
289
- "withholding_tax_segment": null,
290
- "account_code": "604",
291
- "buying_price": 5000,
292
- "buying_tax": 400,
293
- "buying_tax_type": 0
294
- }
295
- ```
19
+ $ bundle
296
20
 
297
- **/ap_payments/create**
21
+ Or install it yourself as:
298
22
 
299
- Description: Creates a new accounts payable transaction. The created transaction will be sent back as JSON if successful.
23
+ $ gem install tsubaiso-sdk
300
24
 
301
- Method: POST
25
+ ## Usage
302
26
 
303
- URL Structure:
304
27
  ```sh
305
- https://tsubaiso.net/ap_payments/create
306
- ```
307
-
308
- Parameters:
309
-
310
- Parameter | Necessity | Type | Description
311
- --- | --- | --- | ---
312
- `price` | *required* | Integer | Amount of the transaction.
313
- `accrual_timestamp` | *required* | String | Actual date of the transaction. Format must be "YYYY-MM-DD"
314
- `customer_master_code` | *required* | String | Code of the transaction party.
315
- `reason_master_code` | *required* | String | Reason of the transaction. This is used to create the journal entry.
316
- `dc` | *required* | String | 'd' if the transaction was a debit to AP, 'c' if it was a credit.
317
- `memo` | *required* | String | Memo for the transaction. Can be blank but must be provided.
318
- `tax_code` | *required* | Integer | Tax code for the transaction.
319
- `port_type` | *required* | Integer | 1 for domestic transaction. 2 for foreign transaction.
320
- `year` | *optional* | Integer | Year of the transaction. If provided, month must be provided as well. Will use current year if not provided.
321
- `month` | *optional* | Integer | Month of the transaction. If provided, year must be provided as well. Will use current month if not provided.
322
- `dept_code` | *optional* | String | Code of the internal department involved.
323
- `buying_tax` | *optional* | Integer | Sales tax on the transaction. Is automatically calculated if not provided.
324
- `scheduled_pay_timestamp` | *optional* | String | Date of payment. Format must be "YYYY-MM-DD".
325
- `scheduled_memo` | *optional* | String | Optional memo regarding payment of funds.
326
- `need_tax_deduction` | *optional* | Integer | 1 if tax needs to be withheld. 0 if not necessary.
327
- `preset_withholding_tax_amount` | *optional* | Integer | Withholding tax amount
328
- `withholding_tax_base` | *optional* | Integer | 1 if withholding tax includes sales tax, 2 if it does not.
329
- `withholding_tax_segment` | *optional* | String | National Tax Agency tax code (ex: "nta2795" references https://www.nta.go.jp/taxanswer/gensen/2795.htm)
330
-
331
- Sample Request:
332
- ``` sh
333
- curl -i -H "Content-Type: application/json" -H "Accept: application/json" -H "Access-Token: XXXXXXXXXXXXXX" -X POST -d '{"year": 2015, "month": 8, "price": 5000, "accrual_timestamp": "2015-10-31", "customer_master_code": "8201", "dept_code": "DEPT C", "reason_master_code": "BUYING_IN", "dc": "c", "memo": "Office Supplies for Frank", "tax_code": 0, "port_type": 1 }' https://tsubaiso.net/ap_payments/create
28
+ > require 'tsubaiso_sdk'
29
+ > sdk = TsubaisoSDK.new(access_token: 'XXXXX')
30
+ > sdk.create_sale({ price: 10000, year: 2015, month: 10, realization_timestamp: "2015-10-01", customer_master_code: "101", dept_code: "Dept A", reason_master_code: "SALES", dc: 'd', memo: "500 widgets", tax_code: 1007})
31
+ => {:status=>"200", :json=>{:ar_reason_master_id=>4403, :ar_receipt_attachments_count=>nil, :code=>nil, :created_at=>"2015/10/21 11:17:39 +0900", :customer_master_id=>31304, :dc=>"d", :dept_code=>"Dept A", :id=>280959, :memo=>"500 widgets", :realization_timestamp=>"2015/10/01", :regist_user_code=>"XXXXX", :sales_journal_dc_id=>1813416, :scheduled_memo=>nil, :scheduled_receive_timestamp=>nil, :update_user_code=>nil, :updated_at=>"2015/10/21 11:17:39 +0900", :account_code=>"500", :sales_price=>9260, :sales_tax=>740, :sales_tax_type=>1007}}
334
32
  ```
335
33
 
336
- **/ap/destroy/:id**
337
-
338
- Description: Destroys the accounts payable transaction specified as the id. Returns a status of 204 No Content.
339
-
340
- Method: POST
34
+ ## Testing
341
35
 
342
- URL Structure:
343
36
  ```sh
344
- https://tsubaiso.net/ap/destroy/6621
37
+ $ cd /~tsubaiso-sdk-1.0.0
38
+ $ export SDK_BASE_URL="https://tsubaiso.net"
39
+ $ export SDK_ACCESS_TOKEN="XXXXX"
40
+ $ rake
345
41
  ```
data/lib/tsubaiso_sdk.rb CHANGED
@@ -1,52 +1,311 @@
1
1
  class TsubaisoSDK
2
2
  require "net/http"
3
3
  require "json"
4
-
4
+
5
5
  def initialize(options = {})
6
6
  @base_url = options[:base_url] || 'https://tsubaiso.net'
7
7
  @access_token = options[:access_token]
8
8
  end
9
-
9
+
10
10
  def list_sales(year, month)
11
11
  params = { "year" => year,
12
12
  "month" => month,
13
13
  "format" => "json"
14
14
  }
15
- uri = URI.parse(@base_url + "/ar/list/?year=#{year}&month=#{month}")
15
+ uri = URI.parse(@base_url + "/ar/list/")
16
+ api_request(uri, "GET", params)
17
+ end
18
+
19
+ def list_sales_and_account_balances(year, month, options = {})
20
+ params = { "year" => year,
21
+ "month" => month,
22
+ "customer_master_code" => options[:customer_master_code],
23
+ "ar_segment" => options[:ar_segment],
24
+ "format" => "json"
25
+ }
26
+ uri = URI.parse(@base_url + "/ar_receipts/balance/")
16
27
  api_request(uri, "GET", params)
17
28
  end
18
-
29
+
19
30
  def list_purchases(year, month)
20
31
  params = { "year" => year,
21
32
  "month" => month,
22
33
  "format" => "json"
23
34
  }
24
- uri = URI.parse(@base_url + "/ap_payments/list/?year=#{year}&month=#{month}")
35
+ uri = URI.parse(@base_url + "/ap_payments/list/")
25
36
  api_request(uri, "GET", params)
26
37
  end
27
-
28
- def show_sale(voucher)
29
- sale_id = voucher.scan(/\d/).join("")
30
- params = { "id" => sale_id,
38
+
39
+ def list_purchases_and_account_balances(year, month, options = {})
40
+ params = { "year" => year,
41
+ "month" => month,
42
+ "customer_master_id" => options[:customer_master_id],
43
+ "ap_segment" => options[:ap_segment],
31
44
  "format" => "json"
45
+ }
46
+ uri = URI.parse(@base_url + "/ap_payments/balance/")
47
+ api_request(uri, "GET", params)
48
+ end
49
+
50
+ def list_customers
51
+ params = { "format" => "json" }
52
+ uri = URI.parse(@base_url + "/customer_masters/list/")
53
+ api_request(uri, "GET", params)
54
+ end
55
+
56
+ def list_payrolls(year, month)
57
+ params = { "format" => "json",
58
+ "year" => year,
59
+ "month" => month
32
60
  }
61
+ uri = URI.parse(@base_url + "/payrolls/list/")
62
+ api_request(uri, "GET", params)
63
+ end
64
+
65
+ def list_staff
66
+ params = { "format" => "json"}
67
+ uri = URI.parse(@base_url + "/staffs/list/")
68
+ api_request(uri, "GET", params)
69
+ end
70
+
71
+ def list_staff_data(staff_id)
72
+ params = {"format" => "json",
73
+ "staff_id" => staff_id}
74
+ uri = URI.parse(@base_url + "/staff_data/list/")
75
+ api_request(uri, "GET", params)
76
+ end
77
+
78
+ def list_staff_datum_masters
79
+ params = { "format" => "json" }
80
+ uri = URI.parse(@base_url + "/staff_datum_masters/list/")
81
+ api_request(uri, "GET", params)
82
+ end
83
+
84
+ def list_reimbursements(year, month)
85
+ params = { "format" => "json",
86
+ "year" => year,
87
+ "month" => month
88
+ }
89
+ uri = URI.parse(@base_url + "/reimbursements/list/")
90
+ api_request(uri, "GET", params)
91
+ end
92
+
93
+ def list_reimbursement_transactions(reimbursement_id)
94
+ params = { "format" => "json",
95
+ "id" => reimbursement_id.to_i
96
+ }
97
+ uri = URI.parse(@base_url + "/reimbursement_transactions/list/")
98
+ api_request(uri, "GET", params)
99
+ end
100
+
101
+ def list_reimbursement_reason_masters
102
+ params = { "format" => "json" }
103
+ uri = URI.parse(@base_url + "/reimbursement_reason_masters/list/")
104
+ api_request(uri, "GET", params)
105
+ end
106
+
107
+ def list_manual_journals(year = nil, month = nil)
108
+ params = { "year" => year,
109
+ "month" => month,
110
+ "format" => "json"
111
+ }
112
+ uri = URI.parse(@base_url + "/manual_journals/list/")
113
+ api_request(uri, "GET", params)
114
+ end
115
+
116
+ def list_journals(options)
117
+ params = { "start_date" => options[:start_date],
118
+ "finish_date" => options[:finish_date],
119
+ "start_created_at" => options[:start_created_at],
120
+ "finish_created_at" => options[:finish_created_at],
121
+ "timestamp_order" => options[:timestamp_order],
122
+ "account_code" => options[:account_code],
123
+ "price" => options[:price],
124
+ "memo" => options[:memo],
125
+ "dept_code" => options[:dept_code],
126
+ "tag_list" => options[:tag_list],
127
+ "id" => options[:id],
128
+ "format" => "json"
129
+ }
130
+ uri = URI.parse(@base_url + "/journals/list/")
131
+ api_request(uri, "GET", params)
132
+ end
133
+
134
+ def list_depts
135
+ params = { "format" => "json" }
136
+ uri = URI.parse(@base_url + "/depts/list/")
137
+ api_request(uri, "GET", params)
138
+ end
139
+
140
+ def list_tags
141
+ params = { "format" => "json" }
142
+ uri = URI.parse(@base_url + "/tags/list/")
143
+ api_request(uri, "GET", params)
144
+ end
145
+
146
+ def list_bonuses(bonus_no, target_year)
147
+ params = { "format" => "json",
148
+ "bonus_no" => bonus_no,
149
+ "target_year" => target_year
150
+ }
151
+ uri = URI.parse(@base_url + "/bonuses/list/")
152
+ api_request(uri, "GET", params)
153
+ end
154
+
155
+ def list_ap_reason_masters
156
+ params = { "format" => "json" }
157
+ uri = URI.parse(@base_url + "/ap_reason_masters/list")
158
+ api_request(uri, "GET", params)
159
+ end
160
+
161
+ def list_ar_reason_masters
162
+ params = { "format" => "json" }
163
+ uri = URI.parse(@base_url + "/ar_reason_masters/list/")
164
+ api_request(uri, "GET", params)
165
+ end
166
+
167
+ def show_sale(voucher)
168
+ sale_id = voucher.scan(/\d/).join("")
169
+ params = { "format" => "json" }
33
170
  uri = URI.parse(@base_url + "/ar/show/#{sale_id}")
34
171
  api_request(uri, "GET", params)
35
172
  end
36
-
173
+
37
174
  def show_purchase(voucher)
38
175
  purchase_id = voucher.scan(/\d/).join("")
39
- params = { "id" => purchase_id,
40
- "format" => "json"
41
- }
176
+ params = { "format" => "json" }
42
177
  uri = URI.parse(@base_url + "/ap_payments/show/#{purchase_id}")
43
178
  api_request(uri, "GET", params)
44
179
  end
45
-
180
+
181
+ def show_customer(customer_id)
182
+ customer_id = customer_id.to_i
183
+ params = { "format" => "json" }
184
+ uri = URI.parse(@base_url + "/customer_masters/show/#{customer_id}")
185
+ api_request(uri, "GET", params)
186
+ end
187
+
188
+ def show_staff(staff_id)
189
+ staff_id = staff_id.to_i
190
+ params = { "format" => "json" }
191
+ uri = URI.parse(@base_url + "/staffs/show/#{staff_id}")
192
+ api_request(uri, "GET", params)
193
+ end
194
+
195
+ def show_staff_data(options)
196
+ if options.is_a?(Hash)
197
+ params = { "staff_id" => options[:staff_id],
198
+ "code" => options[:code],
199
+ "time" => options[:time],
200
+ "format" => "json"
201
+ }
202
+ id = options[:id]
203
+ else
204
+ params = { "format" => "json" }
205
+ id = options
206
+ end
207
+ uri = URI.parse(@base_url + "/staff_data/show/#{id}")
208
+ api_request(uri, "GET", params)
209
+ end
210
+
211
+ def show_staff_datum_master(options)
212
+ if options.is_a?(Hash)
213
+ params = { "code" => options[:code],
214
+ "format" => "json"
215
+ }
216
+ id = options[:id]
217
+ else
218
+ params = { "format" => "json" }
219
+ id = options
220
+ end
221
+ uri = URI.parse(@base_url + "/staff_datum_masters/show/#{id}")
222
+ api_request(uri, "GET", params)
223
+ end
224
+
225
+ def show_manual_journal(manual_journal_id)
226
+ params = { "format" => "json" }
227
+ uri = URI.parse(@base_url + "/manual_journals/show/#{manual_journal_id}")
228
+ api_request(uri, "GET", params)
229
+ end
230
+
231
+ def show_journal(journal_id)
232
+ params = { "format" => "json" }
233
+ uri = URI.parse(@base_url + "/journals/show/#{journal_id}")
234
+ api_request(uri, "GET", params)
235
+ end
236
+
237
+ def show_reimbursement(reimbursement_id)
238
+ params = { "format" => "json" }
239
+ uri = URI.parse(@base_url + "/reimbursements/show/#{reimbursement_id}")
240
+ api_request(uri, "GET", params)
241
+ end
242
+
243
+ def show_reimbursement_transaction(reimbursement_transaction_id)
244
+ params = { "format" => "json" }
245
+ uri = URI.parse(@base_url + "/reimbursement_transactions/show/#{reimbursement_transaction_id}")
246
+ api_request(uri, "GET", params)
247
+ end
248
+
249
+ def show_reimbursement_reason_master(reimbursement_reason_master_id)
250
+ params = { "format" => "json" }
251
+ uri = URI.parse(@base_url + "/reimbursement_reason_masters/show/#{reimbursement_reason_master_id}")
252
+ api_request(uri, "GET", params)
253
+ end
254
+
255
+ def show_dept(dept_id)
256
+ params = { "format" => "json" }
257
+ uri = URI.parse(@base_url + "/depts/show/#{dept_id}")
258
+ api_request(uri, "GET", params)
259
+ end
260
+
261
+ def show_tag(tag_id)
262
+ params = { "format" => "json" }
263
+ uri = URI.parse(@base_url + "/tags/show/#{tag_id}")
264
+ api_request(uri, "GET", params)
265
+ end
266
+
267
+ def show_bonus(bonus_id)
268
+ params = { "format" => "json" }
269
+ uri = URI.parse(@base_url + "/bonuses/show/#{bonus_id}")
270
+ api_request(uri, "GET", params)
271
+ end
272
+
273
+ def show_payroll(payroll_id)
274
+ params = { "format" => "json" }
275
+ uri = URI.parse(@base_url + "/payrolls/show/#{payroll_id}")
276
+ api_request(uri, "GET", params)
277
+ end
278
+
279
+ def show_ar_reason_master(ar_reason_master_id)
280
+ params = { "format" => "json" }
281
+ uri = URI.parse(@base_url + "/ar_reason_masters/show/#{ar_reason_master_id}")
282
+ api_request(uri, "GET", params)
283
+ end
284
+
285
+ def show_ap_reason_master(ap_reason_master_id)
286
+ params = { "format" => "json" }
287
+ uri = URI.parse(@base_url + "/ap_reason_masters/show/#{ap_reason_master_id}")
288
+ api_request(uri, "GET", params)
289
+ end
290
+
291
+ def create_customer(options)
292
+ params = { "name" => options[:name],
293
+ "name_kana" => options[:name_kana],
294
+ "code" => options[:code],
295
+ "tax_type_for_remittance_charge" => options[:tax_type_for_remittance_charge],
296
+ "used_in_ar" => options[:used_in_ar],
297
+ "used_in_ap" => options[:used_in_ap],
298
+ "ar_account_code" => options[:ar_account_code],
299
+ "ap_account_code" => options[:ap_account_code],
300
+ "is_valid" => options[:is_valid],
301
+ "format" => "json"
302
+ }
303
+ uri = URI.parse(@base_url + '/customer_masters/create')
304
+ api_request(uri, "POST", params)
305
+ end
306
+
46
307
  def create_sale(options)
47
- params = { "price" => options[:price],
48
- "year" => options[:year],
49
- "month" => options[:month],
308
+ params = { "price_including_tax" => options[:price_including_tax],
50
309
  "realization_timestamp" => options[:realization_timestamp],
51
310
  "customer_master_code" => options[:customer_master_code],
52
311
  "dept_code" => options[:dept_code],
@@ -57,16 +316,16 @@ class TsubaisoSDK
57
316
  "sales_tax" => options[:sales_tax],
58
317
  "scheduled_memo" => options[:scheduled_memo],
59
318
  "scheduled_receive_timestamp" => options[:scheduled_receive_timestamp],
319
+ "tag_list" => options[:tag_list],
320
+ "data_partner" => options[:data_partner],
60
321
  "format" => "json"
61
322
  }
62
- uri = URI.parse(@base_url + '/ar/create')
323
+ uri = URI.parse(@base_url + '/ar/create')
63
324
  api_request(uri, "POST", params)
64
325
  end
65
-
326
+
66
327
  def create_purchase(options)
67
- params = { "price" => options[:price],
68
- "year" => options[:year],
69
- "month" => options[:month],
328
+ params = { "price_including_tax" => options[:price_including_tax],
70
329
  "accrual_timestamp" => options[:accrual_timestamp],
71
330
  "customer_master_code" => options[:customer_master_code],
72
331
  "dept_code" => options[:dept_code],
@@ -75,61 +334,354 @@ class TsubaisoSDK
75
334
  "memo" => options[:memo],
76
335
  "tax_code" => options[:tax_code],
77
336
  "port_type" => options[:port_type],
337
+ "tag_list" => options[:tag_list],
338
+ "data_partner" => options[:data_partner],
78
339
  "format" => "json"
79
340
  }
80
341
  uri = URI.parse(@base_url + '/ap_payments/create')
81
342
  api_request(uri, "POST", params)
82
343
  end
83
-
84
- def destroy_sale(voucher)
85
- sale_id = voucher.scan(/\d/).join("")
86
- params = { "id" => sale_id,
344
+
345
+ def create_staff_data(options)
346
+ params = { "staff_id" => options[:staff_id],
347
+ "code" => options[:code],
348
+ "memo" => options[:memo],
349
+ "value" => options[:value],
350
+ "start_timestamp" => options[:start_timestamp],
351
+ "format" => "json"
352
+ }
353
+
354
+ if options[:finish_timestamp]
355
+ params[:finish_timestamp] = options[:finish_timestamp]
356
+ elsif options[:no_finish_timestamp]
357
+ params[:no_finish_timestamp] = options[:no_finish_timestamp]
358
+ end
359
+
360
+ uri = URI.parse(@base_url + '/staff_data/create')
361
+ api_request(uri, "POST", params)
362
+ end
363
+
364
+ def create_manual_journal(options)
365
+ params = { "journal_timestamp" => options[:journal_timestamp],
366
+ "journal_dcs" => make_journal_dcs(options[:journal_dcs]),
367
+ "data_partner" => options[:data_partner],
368
+ "format" => "json" }
369
+
370
+ uri = URI.parse(@base_url + '/manual_journals/create')
371
+ api_request(uri, "POST", params)
372
+ end
373
+
374
+ def create_reimbursement(options)
375
+ params = { "format" => "json",
376
+ "applicant" => options[:applicant],
377
+ "application_term" => options[:application_term],
378
+ "staff_code" => options[:staff_code],
379
+ "dept_code" => options[:dept_code],
380
+ "memo" => options[:memo]
381
+ }
382
+ uri = URI.parse(@base_url + "/reimbursements/create/")
383
+ api_request(uri, "POST", params)
384
+ end
385
+
386
+ def create_reimbursement_transaction(options)
387
+ params = { "format" => "json",
388
+ "reimbursement_id" => options[:reimbursement_id].to_i,
389
+ "transaction_timestamp" => options[:transaction_timestamp],
390
+ "price_value" => options[:price_value],
391
+ "reason_code" => options[:reason_code],
392
+ "port_type" => options[:port_type],
393
+ "dc" => options[:dc],
394
+ "brief" => options[:brief],
395
+ "memo" => options[:memo],
396
+ "tag_list" => options[:tag_list],
397
+ "tax_type" => options[:tax_type],
398
+ "data_partner" => options[:data_partner]
399
+ }
400
+ uri = URI.parse(@base_url + '/reimbursement_transactions/create/')
401
+ api_request(uri, "POST", params)
402
+ end
403
+
404
+ def create_dept(options)
405
+ params = { "format" => "json",
406
+ "sort_no" => options[:sort_no],
407
+ "code" => options[:code],
408
+ "name" => options[:name],
409
+ "name_abbr" => options[:name_abbr],
410
+ "color" => options[:color],
411
+ "memo" => options[:memo],
412
+ "start_date" => options[:start_date],
413
+ "finish_date" => options[:finish_date]
414
+ }
415
+ uri = URI.parse(@base_url + '/depts/create/')
416
+ api_request(uri, "POST", params)
417
+ end
418
+
419
+ def create_tag(options)
420
+ params = { "format" => "json",
421
+ "code" => options[:code],
422
+ "name" => options[:name],
423
+ "sort_no" => options[:sort_no],
424
+ "tag_group_code" => options[:tag_group_code],
425
+ "start_ymd" => options[:start_ymd],
426
+ "finish_ymd" => options[:finish_ymd]
427
+ }
428
+ uri = URI.parse(@base_url + '/tags/create/')
429
+ api_request(uri, "POST", params)
430
+ end
431
+
432
+ def update_sale(options)
433
+ params = { "price_including_tax" => options[:price_including_tax],
434
+ "realization_timestamp" => options[:realization_timestamp],
435
+ "customer_master_code" => options[:customer_master_code],
436
+ "dept_code" => options[:dept_code],
437
+ "reason_master_code" => options[:reason_master_code],
438
+ "dc" => options[:dc],
439
+ "memo" => options[:memo],
440
+ "tax_code" => options[:tax_code],
441
+ "sales_tax" => options[:sales_tax],
442
+ "scheduled_memo" => options[:scheduled_memo],
443
+ "scheduled_receive_timestamp" => options[:scheduled_receive_timestamp],
444
+ "tag_list" => options[:tag_list],
445
+ "data_partner" => options[:data_partner],
446
+ "format" => "json"
447
+ }
448
+ uri = URI.parse(@base_url + "/ar/update/#{options[:id]}")
449
+ api_request(uri, "POST", params)
450
+ end
451
+
452
+ def update_purchase(options)
453
+ params = { "price_including_tax" => options[:price_including_tax],
454
+ "accrual_timestamp" => options[:accrual_timestamp],
455
+ "customer_master_code" => options[:customer_master_code],
456
+ "dept_code" => options[:dept_code],
457
+ "reason_master_code" => options[:reason_master_code],
458
+ "dc" => options[:dc],
459
+ "memo" => options[:memo],
460
+ "tax_code" => options[:tax_code],
461
+ "port_type" => options[:port_type],
462
+ "tag_list" => options[:tag_list],
463
+ "data_partner" => options[:data_partner],
464
+ "format" => "json"}
465
+
466
+ uri = URI.parse(@base_url + "/ap_payments/update/#{options[:id]}")
467
+ api_request(uri, "POST", params)
468
+ end
469
+
470
+ def update_customer(options)
471
+ params = { "name" => options[:name],
472
+ "name_kana" => options[:name_kana],
473
+ "code" => options[:code],
474
+ "tax_type_for_remittance_charge" => options[:tax_type_for_remittance_charge],
475
+ "used_in_ar" => options[:used_in_ar],
476
+ "used_in_ap" => options[:used_in_ap],
477
+ "ar_account_code" => options[:ar_account_code],
478
+ "ap_account_code" => options[:ap_account_code],
479
+ "is_valid" => options[:is_valid],
480
+ "format" => "json"
481
+ }
482
+
483
+ uri = URI.parse(@base_url + "/customer_masters/update/#{options[:id]}")
484
+ api_request(uri, "POST", params)
485
+ end
486
+
487
+ def update_staff_data(options)
488
+ params = { "memo" => options[:memo],
489
+ "value" => options[:value],
490
+ "start_timestamp" => options[:start_timestamp],
87
491
  "format" => "json"
88
492
  }
493
+
494
+ if options[:finish_timestamp]
495
+ params[:finish_timestamp] = options[:finish_timestamp]
496
+ elsif options[:no_finish_timestamp]
497
+ params[:no_finish_timestamp] = options[:no_finish_timestamp]
498
+ end
499
+
500
+ uri = URI.parse(@base_url + "/staff_data/update/#{options[:id]}")
501
+ api_request(uri, "POST", params)
502
+ end
503
+
504
+ def update_manual_journal(options)
505
+ params = { "journal_timestamp" => options[:journal_timestamp],
506
+ "journal_dcs" => make_journal_dcs(options[:journal_dcs]),
507
+ "data_partner" => options[:data_partner],
508
+ "format" => "json" }
509
+
510
+ uri = URI.parse(@base_url + "/manual_journals/update/#{options[:id]}")
511
+ api_request(uri, "POST", params)
512
+ end
513
+
514
+ def update_reimbursement(reimbursement_id, options)
515
+ params = { "format" => "json",
516
+ "applicant" => options[:applicant],
517
+ "application_term" => options[:application_term],
518
+ "staff_code" => options[:staff_code],
519
+ "dept_code" => options[:dept_code],
520
+ "memo" => options[:memo]
521
+ }
522
+ uri = URI.parse(@base_url + "/reimbursements/update/#{reimbursement_id}")
523
+ api_request(uri, "POST", params)
524
+ end
525
+
526
+ def update_reimbursement_transaction(options)
527
+ params = { "format" => "json",
528
+ "port_type" => options[:port_type],
529
+ "transaction_timestamp" => options[:transaction_timestamp],
530
+ "price_value" => options[:price_value],
531
+ "dc" => options[:dc],
532
+ "reason_code" => options[:reason_code],
533
+ "brief" => options[:brief],
534
+ "memo" => options[:memo],
535
+ "tag_list" => options[:tag_list],
536
+ "tax_type" => options[:tax_type],
537
+ "data_partner" => options[:data_partner]
538
+ }
539
+ uri = URI.parse(@base_url + "/reimbursement_transactions/update/#{options[:id]}")
540
+ api_request(uri, "POST", params)
541
+ end
542
+
543
+ def update_dept(dept_id, options)
544
+ params = { "format" => "json",
545
+ "sort_no" => options[:sort_no],
546
+ "code" => options[:code],
547
+ "name" => options[:name],
548
+ "name_abbr" => options[:name_abbr],
549
+ "color" => options[:color],
550
+ "memo" => options[:memo],
551
+ "start_date" => options[:start_date],
552
+ "finish_date" => options[:finish_date]
553
+ }
554
+ uri = URI.parse(@base_url + "/depts/update/#{dept_id}")
555
+ api_request(uri, "POST", params)
556
+ end
557
+
558
+ def update_tag(tag_id, options)
559
+ params = { "format" => "json",
560
+ "code" => options[:code],
561
+ "name" => options[:name],
562
+ "sort_no" => options[:sort_no],
563
+ "tag_group_code" => options[:tag_group_code],
564
+ "start_ymd" => options[:start_ymd],
565
+ "finish_ymd" => options[:finish_ymd]
566
+ }
567
+ uri = URI.parse(@base_url + "/tags/update/#{tag_id}")
568
+ api_request(uri, "POST", params)
569
+ end
570
+
571
+ def destroy_sale(voucher)
572
+ sale_id = voucher.scan(/\d/).join("")
573
+ params = { "format" => "json" }
89
574
  uri = URI.parse(@base_url + "/ar/destroy/#{sale_id}")
90
575
  api_request(uri, "POST", params)
91
576
  end
92
-
577
+
93
578
  def destroy_purchase(voucher)
94
579
  purchase_id = voucher.scan(/\d/).join("")
95
- params = { "id" => purchase_id,
96
- "format" => "json"
97
- }
580
+ params = { "format" => "json" }
98
581
  uri = URI.parse(@base_url + "/ap/destroy/#{purchase_id}")
99
582
  api_request(uri, "POST", params)
100
583
  end
101
-
584
+
585
+ def destroy_customer(customer_id)
586
+ params = { "format" => "json" }
587
+ uri = URI.parse(@base_url + "/customer_masters/destroy/#{customer_id}")
588
+ api_request(uri, "POST", params)
589
+ end
590
+
591
+ def destroy_staff_data(staff_data_id)
592
+ params = { "format" => "json" }
593
+ uri = URI.parse(@base_url + "/staff_data/destroy/#{staff_data_id}")
594
+ api_request(uri, "POST", params)
595
+ end
596
+
597
+ def destroy_manual_journal(manual_journal_id)
598
+ params = { "format" => "json" }
599
+ uri = URI.parse(@base_url + "/manual_journals/destroy/#{manual_journal_id}")
600
+ api_request(uri, "POST", params)
601
+ end
602
+
603
+ def destroy_reimbursement(reimbursement_id)
604
+ params = { "format" => "json" }
605
+ uri = URI.parse(@base_url + "/reimbursements/destroy/#{reimbursement_id}")
606
+ api_request(uri, "POST", params)
607
+ end
608
+
609
+ def destroy_reimbursement_transaction(reimbursement_transaction_id)
610
+ params = { "format" => "json" }
611
+ uri = URI.parse(@base_url + "/reimbursement_transactions/destroy/#{reimbursement_transaction_id}")
612
+ api_request(uri, "POST", params)
613
+ end
614
+
615
+ def destroy_dept(dept_id)
616
+ params = { "format" => "json" }
617
+ uri = URI.parse(@base_url + "/depts/destroy/#{dept_id}")
618
+ api_request(uri, "POST", params)
619
+ end
620
+
621
+ def destroy_tag(tag_id)
622
+ params = { "format" => "json" }
623
+ uri = URI.parse(@base_url + "/tags/destroy/#{tag_id}")
624
+ api_request(uri, "POST", params)
625
+ end
626
+
102
627
  private
103
-
628
+
104
629
  def api_request(uri, http_verb, params)
105
630
  http = Net::HTTP.new(uri.host, uri.port)
631
+ initheader = {'Content-Type' => 'application/json'}
106
632
  http.use_ssl = true if @base_url =~ /^https/
107
633
  if http_verb == "GET"
108
- request = Net::HTTP::Get.new(uri.path)
634
+ request = Net::HTTP::Get.new(uri.path, initheader)
109
635
  else
110
- request = Net::HTTP::Post.new(uri.path)
636
+ request = Net::HTTP::Post.new(uri.path, initheader)
111
637
  end
112
638
  request["Access-Token"] = @access_token
113
- request.set_form_data(params)
639
+ request.body = params.to_json
114
640
  response = http.request(request)
115
641
  if response.body
116
- return {:status => response.code, :json => symbolize_keys(JSON.load(response.body))}
117
- else
118
- return response.code
642
+ begin
643
+ {:status => response.code, :json => recursive_symbolize_keys(JSON.load(response.body))}
644
+ rescue
645
+ response.body
646
+ end
647
+ else
648
+ response.code
119
649
  end
120
650
  end
121
651
 
122
- def symbolize_keys(data)
123
- if data.class == Array
124
- data.each_with_index do |hash, index|
125
- data[index] = hash.each_with_object({}) do |(k,v), memo|
126
- memo[k.to_sym] = v
652
+ def recursive_symbolize_keys(data)
653
+ case data
654
+ when Hash
655
+ Hash[
656
+ data.map do |k, v|
657
+ [ k.respond_to?(:to_sym) ? k.to_sym : k, recursive_symbolize_keys(v) ]
127
658
  end
128
- end
659
+ ]
660
+ when Enumerable
661
+ data.map { |v| recursive_symbolize_keys(v) }
129
662
  else
130
- data = data.each_with_object({}) do |(k,v), memo|
131
- memo[k.to_sym] = v
132
- end
663
+ data
133
664
  end
134
665
  end
666
+
667
+ def make_journal_dcs(journal_dcs)
668
+ return nil if journal_dcs.nil?
669
+ journal_dcs.map {|journal_dc| make_journal_dc(journal_dc)}
670
+ end
671
+
672
+ def make_journal_dc(journal_dc)
673
+ { "debit" => make_journal_dc_oneside(journal_dc[:debit]),
674
+ "credit" => make_journal_dc_oneside(journal_dc[:credit]),
675
+ "dept_code" => journal_dc[:dept_code],
676
+ "memo" => journal_dc[:memo] }
677
+ end
678
+
679
+ def make_journal_dc_oneside(side)
680
+ return nil if side.nil?
681
+ { "account_code" => side[:account_code].to_s,
682
+ "price_including_tax" => side[:price_including_tax],
683
+ "tax_type" => side[:tax_type],
684
+ "sales_tax" => side[:sales_tax]
685
+ }
686
+ end
135
687
  end