lucabook 0.2.15 → 0.2.17

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,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+ require 'luca_support/config'
5
+
6
+ module LucaBook
7
+ module Util
8
+ module_function
9
+
10
+ def validate_balance(items)
11
+ d = items.select { |k, _v| /^[1-4]/.match(k) }
12
+ .inject(BigDecimal('0')) { |sum, (_k, v)| sum + BigDecimal(v[:balance] || 0) }
13
+ c = items.select { |k, _v| /^[5-9]/.match(k) }
14
+ .inject(BigDecimal('0')) { |sum, (_k, v)| sum + BigDecimal(v[:balance] || 0) }
15
+ [d - c, { debit: d, credit: c }]
16
+ end
17
+
18
+ # items assumed as bellows:
19
+ # [{ code: '113', amount: 1000 }, ... ]
20
+ #
21
+ def diff_by_code(items, code)
22
+ calc_diff(amount_by_code(items, code), code)
23
+ end
24
+
25
+ def amount_by_code(items, code)
26
+ items
27
+ .select { |item| item.dig(:code) == code }
28
+ .inject(BigDecimal('0')) { |sum, item| sum + item[:amount] }
29
+ end
30
+
31
+ def calc_diff(num, code)
32
+ num * pn_debit(code.to_s)
33
+ end
34
+
35
+ def pn_debit(code)
36
+ case code
37
+ when /^[0-4BCEGH]/
38
+ 1
39
+ when /^[5-9ADF]/
40
+ -1
41
+ else
42
+ nil
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaBook
4
- VERSION = '0.2.15'
4
+ VERSION = '0.2.17'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucabook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord
@@ -87,8 +87,10 @@ files:
87
87
  - lib/luca_book/report.rb
88
88
  - lib/luca_book/setup.rb
89
89
  - lib/luca_book/state.rb
90
+ - lib/luca_book/templates/base-jp.xbrl.erb
90
91
  - lib/luca_book/templates/dict-en.tsv
91
92
  - lib/luca_book/templates/dict-jp.tsv
93
+ - lib/luca_book/util.rb
92
94
  - lib/luca_book/version.rb
93
95
  homepage: https://github.com/chumaltd/luca/tree/master/lucabook
94
96
  licenses: