crunchaccounting-api 1.0.2 → 1.0.3

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/crunchaccounting-api.rb +72 -0
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0419084eb489b5419b3fb4f986b027d78217700a'
4
- data.tar.gz: ca55b6ae3a4fa1a4ff1b3cca16136f9e01ddedfd
3
+ metadata.gz: '08c3520a2ee06f5d3f04c8e846108e72f0f140b1'
4
+ data.tar.gz: 4c2c3d66052945bbcb4ee1dc3eb080f8fc73c80b
5
5
  SHA512:
6
- metadata.gz: 62442f5874a78e3cce2cc8fd38accd8674d39f436481a43a72c2446967cd5c193beba359ac1fcb34fab5945642d21bcadb471063663287c80df1e8913132700a
7
- data.tar.gz: 6072559b0f710c50a408f93247355557c765413d39a467d579264ca602e2c8457bfe64177087b9c3cc5a338bb547f9091fc3c4937851b2541a3d988eb675f742
6
+ metadata.gz: 9c076c3d8f5c8ee5e9a36ea4c7115b99719cf8a1d669bab5901a96b0c03df150f0530d04d90d3c10db09b9449ca8970ccebcc00e0d7afda0610e30c4d60256c3
7
+ data.tar.gz: 1e86a39c4cba43daf56e6932f5aa1feffbd653eb6575a829fbafc390f061f7b20ffc1d086fc544bd32d7f6792605c78d8b005bd43004b4abefa2bf098f3c397d
@@ -193,6 +193,8 @@ class CrunchAPI
193
193
  "MILEAGE_ALLOWANCE",
194
194
  "MEDICAL_INSURANCE_CONTRIBUTIONS",
195
195
  "BANK_CHARGES",
196
+ "PENSION_SCHEME_CONTRIBUTIONS",
197
+ "PUBLIC_TRANSPORT"
196
198
  ].include? expense_type
197
199
  return false
198
200
  end
@@ -277,6 +279,76 @@ class CrunchAPI
277
279
  post "/rest/v2/expenses", expense
278
280
  end
279
281
 
282
+ def update_expense(expense_id:, supplier_id:, date:, payment_date:, payment_method: nil, bank_account_id:, amount:, expense_type:, description:, director_id:nil, invoice:nil)
283
+ !payment_method and payment_method = "EFT"
284
+
285
+ if subject_to_vat?(expense_type)
286
+ gross_amount = amount
287
+ vat_amount = ((amount / 100) * @vat_rate).round(2)
288
+ net_amount = (amount - vat_amount).round(2)
289
+ else
290
+ gross_amount = amount
291
+ vat_amount = 0
292
+ net_amount = amount
293
+ end
294
+
295
+ expense = {
296
+ "expenseId" => expense_id,
297
+ "amount" => amount,
298
+ "expenseDetails" => {
299
+ "supplier" => {
300
+ "supplierId" => supplier_id
301
+ },
302
+ "postingDate" => date
303
+ },
304
+ "paymentDetails" => {
305
+ "payment" => [{
306
+ "paymentDate" => payment_date,
307
+ "paymentMethod" => payment_method,
308
+ "bankAccount" => {
309
+ "accountId" => bank_account_id
310
+ },
311
+ "amount" => amount
312
+ }]
313
+ },
314
+ "expenseLineItems" => {
315
+ "count": 1,
316
+ "lineItemGrossTotal": gross_amount,
317
+ "expenseLineItems" => [
318
+ {
319
+ "expenseType" => expense_type,
320
+ "benefitingDirector": director_id,
321
+ "lineItemDescription" => description,
322
+ "lineItemAmount" => {
323
+ "currencyCode": "GBP",
324
+ "netAmount" => net_amount,
325
+ "grossAmount" => gross_amount,
326
+ "vatAmount" => vat_amount
327
+ }
328
+ }
329
+ ]
330
+ }
331
+ }
332
+
333
+ if invoice
334
+ mimetype = file_mimetype(invoice)
335
+ filename = invoice.split("/").last
336
+
337
+ expense["receipts"] = {
338
+ "count" => 1,
339
+ "receipt" => [
340
+ {
341
+ "fileName" => filename,
342
+ "contentType" => mimetype,
343
+ "fileData": Base64.encode64(File.read(invoice))
344
+ }
345
+ ]
346
+ }
347
+ end
348
+
349
+ put "/rest/v2/expenses", expense
350
+ end
351
+
280
352
  def file_mimetype(filename)
281
353
  esc = Shellwords.escape(filename)
282
354
  `/usr/bin/file -bi #{esc}`.chomp.gsub(/;.*\z/, '')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crunchaccounting-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - m4rkw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 2.5.2
54
+ rubygems_version: 2.5.2.1
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: Crunch Accounting API