lucabook 0.2.27 → 0.2.28

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad4b1eba3419508d64bfeade5f776ed2ca0f32313deab25660864aff47767787
4
- data.tar.gz: 57aef956cbc763dbf4d089d5745c9cc4d6a6ed44dd3ff726b9c80fbc6b29629d
3
+ metadata.gz: 0b2cc0f6aefd92521a518af25010f4fcb125e32aff9b71c9a18304b606451556
4
+ data.tar.gz: 6689918d842fca5a64060f998ea419aeb2f8db4350c7b0073e39b6a07b0dbb43
5
5
  SHA512:
6
- metadata.gz: 317b373f1a31c85c107dfa294ec6df0dcc89f13b8ab10277bb004b3bdceaaf0ec58cfa5c2220a088932965b5b156fd71fef1ce67be67c330857bbcea127de365
7
- data.tar.gz: e7456d393a4309bafb9a3622c28da10067e1483c80b0bbbd73a05508bb3d9a6742051e2d190870a1f6e39df5ec10b5dd7d1de698faef969a3bc54efa7b46b153
6
+ metadata.gz: 192298f7a6cd006f5699ec02a109c6f4e10f9240ebc7fc228af277265eab5b467e90bcbd58063f8381b61f258d99732d69155c90af4fac619d9c94da43a2fb27
7
+ data.tar.gz: 1231261012e602b438469cbcd357dc64a58c14357b8a0c63c4b5fa7dbe398f2b5080a3d53c404c63f543ff87f681f7fc38cb183ea35d5528ccbc905cdcebfaa1
data/exe/luca-book CHANGED
@@ -19,7 +19,7 @@ class LucaCmd
19
19
  end
20
20
 
21
21
  def self.list(args, params)
22
- args = gen_range(params[:n] || 1) if args.empty?
22
+ args = gen_range(params[:n]) if args.empty?
23
23
  if params['code']
24
24
  if params['headers']
25
25
  render(LucaBook::ListByHeader.term(*args, code: params['code'], header: params['headers']).list_by_code, params)
@@ -78,11 +78,19 @@ class LucaCmd
78
78
  end
79
79
  end
80
80
 
81
- def self.gen_range(count)
82
- count ||= 3
81
+ def self.gen_range(count = nil)
83
82
  today = Date.today
84
- start = today.prev_month(count - 1)
85
- [start.year, start.month, today.year, today.month]
83
+ if count
84
+ start = today.prev_month(count - 1)
85
+ [start.year, start.month, today.year, today.month]
86
+ else
87
+ start_year = if today.month >= LucaSupport::CONFIG['fy_start'].to_i
88
+ today.year
89
+ else
90
+ today.year - 1
91
+ end
92
+ [start_year, LucaSupport::CONFIG['fy_start'], start_year + 1, LucaSupport::CONFIG['fy_start'].to_i - 1]
93
+ end
86
94
  end
87
95
 
88
96
  def self.render(dat, params)
data/lib/luca_book.rb CHANGED
@@ -13,5 +13,6 @@ module LucaBook
13
13
  autoload :ListByHeader, 'luca_book/list_by_header'
14
14
  autoload :Setup, 'luca_book/setup'
15
15
  autoload :State, 'luca_book/state'
16
+ autoload :Test, 'luca_book/test'
16
17
  autoload :Util, 'luca_book/util'
17
18
  end
@@ -74,7 +74,7 @@ module LucaBook
74
74
 
75
75
  # for assert purpose
76
76
  #
77
- def gross(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, rows: 4, recursive: false)
77
+ def gross(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, rows: 4, recursive: false)
78
78
  if ! date_range.nil?
79
79
  raise if date_range.class != Range
80
80
  # TODO: date based range search
@@ -84,7 +84,7 @@ module LucaBook
84
84
  end_month ||= start_month
85
85
  sum = { debit: {}, credit: {}, debit_count: {}, credit_count: {} }
86
86
  idx_memo = []
87
- term(start_year, start_month, end_year, end_month, code) do |f, _path|
87
+ term(start_year, start_month, end_year, end_month, code, 'journals') do |f, _path|
88
88
  CSV.new(f, headers: false, col_sep: "\t", encoding: 'UTF-8')
89
89
  .each_with_index do |row, i|
90
90
  break if i >= rows
@@ -130,20 +130,20 @@ module LucaBook
130
130
  else
131
131
  Array(code)
132
132
  end
133
- res = { debit: 0, credit: 0, debit_count: 0, credit_count: 0 }
134
- codes.each do |code|
135
- res[:debit] += sum[:debit][code] || BigDecimal('0')
136
- res[:credit] += sum[:credit][code] || BigDecimal('0')
137
- res[:debit_count] += sum[:debit_count][code] || 0
138
- res[:credit_count] += sum[:credit_count][code] || 0
133
+ res = { debit: { code => 0 }, credit: { code => 0 }, debit_count: { code => 0 }, credit_count: { code => 0 } }
134
+ codes.each do |cd|
135
+ res[:debit][code] += sum[:debit][cd] || BigDecimal('0')
136
+ res[:credit][code] += sum[:credit][cd] || BigDecimal('0')
137
+ res[:debit_count][code] += sum[:debit_count][cd] || 0
138
+ res[:credit_count][code] += sum[:credit_count][cd] || 0
139
139
  end
140
140
  res
141
141
  end
142
142
 
143
143
  # netting vouchers in specified term
144
144
  #
145
- def net(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil)
146
- g = gross(start_year, start_month, end_year, end_month, code: code, date_range: date_range)
145
+ def net(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, recursive: false)
146
+ g = gross(start_year, start_month, end_year, end_month, code: code, date_range: date_range, recursive: recursive)
147
147
  idx = (g[:debit].keys + g[:credit].keys).uniq.sort
148
148
  count = {}
149
149
  diff = {}.tap do |sum|
@@ -155,6 +155,58 @@ module LucaBook
155
155
  end
156
156
  [diff, count]
157
157
  end
158
+
159
+ # Override LucaRecord::IO.load_data
160
+ #
161
+ def load_data(io, path = nil)
162
+ io
163
+ end
164
+ end
165
+
166
+ def net_amount(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
167
+ start_year ||= @cursor_start&.year || @start_date.year
168
+ start_month ||= @cursor_start&.month || @start_date.month
169
+ end_year ||= @cursor_end&.year || @end_date.year
170
+ end_month ||= @cursor_end&.month || @end_date.month
171
+ self.class.net(start_year, start_month, end_year, end_month, code: code, recursive: recursive)[0][code]
172
+ end
173
+
174
+ def debit_amount(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
175
+ gross_amount(code, start_year, start_month, end_year, end_month, recursive: recursive)[0]
176
+ end
177
+
178
+ def credit_amount(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
179
+ gross_amount(code, start_year, start_month, end_year, end_month, recursive: recursive)[1]
180
+ end
181
+
182
+ def gross_amount(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
183
+ start_year ||= @cursor_start&.year || @start_date.year
184
+ start_month ||= @cursor_start&.month || @start_date.month
185
+ end_year ||= @cursor_end&.year || @end_date.year
186
+ end_month ||= @cursor_end&.month || @end_date.month
187
+ g = self.class.gross(start_year, start_month, end_year, end_month, code: code, recursive: recursive)
188
+ [g[:debit][code], g[:credit][code]]
189
+ end
190
+
191
+ def debit_count(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
192
+ gross_count(code, start_year, start_month, end_year, end_month, recursive: recursive)[0]
193
+ end
194
+
195
+ def credit_count(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
196
+ gross_count(code, start_year, start_month, end_year, end_month, recursive: recursive)[1]
197
+ end
198
+
199
+ def gross_count(code, start_year = nil, start_month = nil, end_year = nil, end_month = nil, recursive: true)
200
+ start_year ||= @cursor_start&.year || @start_date.year
201
+ start_month ||= @cursor_start&.month || @start_date.month
202
+ end_year ||= @cursor_end&.year || @end_date.year
203
+ end_month ||= @cursor_end&.month || @end_date.month
204
+ g = self.class.gross(start_year, start_month, end_year, end_month, code: code, recursive: recursive)
205
+ [g[:debit_count][code], g[:credit_count][code]]
206
+ end
207
+
208
+ def each_month
209
+ yield
158
210
  end
159
211
  end
160
212
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'luca_support/code'
4
4
  require 'luca_support/config'
5
+ require 'luca_support/range'
5
6
  require 'luca_record/dict'
6
7
  require 'luca_record/io'
7
8
  require 'luca_book'
@@ -10,11 +11,12 @@ require 'pathname'
10
11
 
11
12
  module LucaBook
12
13
  class Dict < LucaRecord::Dict
13
- include Accumulator
14
+ include LucaSupport::Range
15
+ include LucaBook::Util
14
16
  include LucaRecord::IO
17
+ include Accumulator
15
18
 
16
19
  @dirname = 'journals'
17
- @record_type = 'raw'
18
20
  # Column number settings for CSV/TSV convert
19
21
  #
20
22
  # :label
@@ -170,15 +172,5 @@ module LucaBook
170
172
  digest = `git rev-parse HEAD`
171
173
  $?.exitstatus == 0 ? digest.strip : nil
172
174
  end
173
-
174
- def self.term_by_month(start_date, end_date)
175
- Enumerator.new do |yielder|
176
- each_month = start_date
177
- while each_month <= end_date
178
- yielder << each_month
179
- each_month = each_month.next_month
180
- end
181
- end
182
- end
183
175
  end
184
176
  end
@@ -106,11 +106,11 @@ module LucaBook #:nodoc:
106
106
  def set_balance(recursive = false)
107
107
  return BigDecimal('0') if @code.nil? || /^[A-H]/.match(@code)
108
108
 
109
- LucaBook::State.start_balance(@start.year, @start.month, recursive: recursive)
109
+ LucaBook::State.start_balance(@start.year, @start.month, recursive: recursive)[@code] || BigDecimal('0')
110
110
  end
111
111
 
112
112
  def calc_code(recursive: false)
113
- @balance = set_balance(recursive)[@code] || BigDecimal('0')
113
+ @balance = set_balance(recursive)
114
114
  if @code
115
115
  balance = @balance
116
116
  @data.each do |dat|
@@ -17,7 +17,6 @@ module LucaBook
17
17
  include Accumulator
18
18
 
19
19
  @dirname = 'journals'
20
- @record_type = 'raw'
21
20
  @@dict = LucaRecord::Dict.new('base.tsv')
22
21
 
23
22
  attr_reader :statement, :pl_data, :bs_data, :start_balance
@@ -62,15 +61,15 @@ module LucaBook
62
61
  while date <= last_date do
63
62
  diff = {}.tap do |h|
64
63
  g = gross(date.year, date.month, code: code, recursive: recursive)
65
- sum = g.dig(:debit).nil? ? BigDecimal('0') : Util.calc_diff(g[:debit], code)
66
- sum -= g.dig(:credit).nil? ? BigDecimal('0') : Util.calc_diff(g[:credit], code)
64
+ sum = g.dig(:debit, code).nil? ? BigDecimal('0') : Util.calc_diff(g[:debit][code], code)
65
+ sum -= g.dig(:credit, code).nil? ? BigDecimal('0') : Util.calc_diff(g[:credit][code], code)
67
66
  balance += sum
68
67
  h['code'] = code
69
68
  h['label'] = @@dict.dig(code, :label)
70
- h['debit_amount'] = g[:debit]
71
- h['debit_count'] = g[:debit_count]
72
- h['credit_amount'] = g[:credit]
73
- h['credit_count'] = g[:credit_count]
69
+ h['debit_amount'] = g.dig(:debit, code)
70
+ h['debit_count'] = g.dig(:debit_count, code)
71
+ h['credit_amount'] = g.dig(:credit, code)
72
+ h['credit_count'] = g.dig(:credit_count, code)
74
73
  h['net'] = sum
75
74
  h['balance'] = balance
76
75
  h['_d'] = date.to_s
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require 'luca_book'
5
+ require 'luca_record/io'
6
+ require 'luca_support/range'
7
+
8
+ module LucaBook # :nodoc:
9
+ # Provide data testing framework utilizing minitest.
10
+ #
11
+ class Test < MiniTest::Test
12
+ include LucaSupport::Range
13
+ include LucaRecord::IO
14
+ include LucaBook::Accumulator
15
+ include LucaBook::Util
16
+ end
17
+ end
@@ -42,5 +42,15 @@ module LucaBook
42
42
  nil
43
43
  end
44
44
  end
45
+
46
+ def current_fy(date = nil, to: nil)
47
+ date ||= Date.today
48
+ start_month = LucaSupport::CONFIG['fy_start']
49
+ start_year = date.month >= start_month ? date.year : date.year - 1
50
+ @start_date = Date.new(start_year, start_month, 1)
51
+ @end_date = Date.new(start_year + 1, start_month - 1, -1)
52
+ @end_date = [to, @end_date].min if to
53
+ [@start_date, @end_date]
54
+ end
45
55
  end
46
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaBook
4
- VERSION = '0.2.27'
4
+ VERSION = '0.2.28'
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.27
4
+ version: 0.2.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord
@@ -96,6 +96,7 @@ files:
96
96
  - lib/luca_book/templates/dict-jp-edinet.tsv
97
97
  - lib/luca_book/templates/dict-jp.tsv
98
98
  - lib/luca_book/templates/monthly-report.html.erb
99
+ - lib/luca_book/test.rb
99
100
  - lib/luca_book/util.rb
100
101
  - lib/luca_book/version.rb
101
102
  homepage: https://github.com/chumaltd/luca/tree/master/lucabook