lucabook 0.2.15 → 0.2.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.21'
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.21
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord
@@ -84,11 +84,12 @@ files:
84
84
  - lib/luca_book/import.rb
85
85
  - lib/luca_book/journal.rb
86
86
  - lib/luca_book/list.rb
87
- - lib/luca_book/report.rb
88
87
  - lib/luca_book/setup.rb
89
88
  - lib/luca_book/state.rb
89
+ - lib/luca_book/templates/base-jp.xbrl.erb
90
90
  - lib/luca_book/templates/dict-en.tsv
91
91
  - lib/luca_book/templates/dict-jp.tsv
92
+ - lib/luca_book/util.rb
92
93
  - lib/luca_book/version.rb
93
94
  homepage: https://github.com/chumaltd/luca/tree/master/lucabook
94
95
  licenses:
@@ -1,3 +0,0 @@
1
- # move to LucaBook::State
2
- class LucaBookReport
3
- end