lucabook 0.2.19 → 0.2.24
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 +4 -4
- data/exe/luca-book +66 -16
- data/lib/luca_book.rb +1 -0
- data/lib/luca_book/console.rb +4 -4
- data/lib/luca_book/dict.rb +78 -1
- data/lib/luca_book/import.rb +36 -37
- data/lib/luca_book/import_jp.rb +83 -0
- data/lib/luca_book/journal.rb +98 -23
- data/lib/luca_book/list.rb +17 -10
- data/lib/luca_book/list_by_header.rb +120 -0
- data/lib/luca_book/setup.rb +2 -1
- data/lib/luca_book/state.rb +95 -97
- data/lib/luca_book/templates/config.yml +4 -0
- data/lib/luca_book/templates/dict-en.tsv +45 -50
- data/lib/luca_book/templates/dict-jp.tsv +34 -30
- data/lib/luca_book/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55e730a696b4537183e9a298cff7d715c2a93dfa22fabc10cc889fd18c72b1a1
|
4
|
+
data.tar.gz: f5e579c528ad978533f7df60eed6b4a494dd723a4fdef15180622737fd9be32a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 607110ed2c686b35c1be749b16bd6f4c0827450e55277d44c62ddb5acfb06fbb67d601c9fe475c453f5999afa23a1bf83923d7251ba72a7a24267e0cfc8b4057
|
7
|
+
data.tar.gz: d8fe5540370bc81494847b5f9d975667d19bda4e7979fc852556e81b2adbd644b87ca11bdf7601334454cfe545070698e0e20570895fd2e0eb4bb790eea19711
|
data/exe/luca-book
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
require 'json'
|
3
4
|
require 'optparse'
|
4
5
|
require 'luca_book'
|
5
6
|
|
6
|
-
|
7
|
-
class Journal
|
7
|
+
class LucaCmd
|
8
|
+
class Journal < LucaCmd
|
8
9
|
def self.import(args, params)
|
9
10
|
if params['config']
|
10
11
|
LucaBook::Import.new(args[0], params['config']).import_csv
|
11
12
|
elsif params['json']
|
12
|
-
|
13
|
+
str = args[0].nil? ? STDIN.read : File.read(args[0])
|
14
|
+
LucaBook::Import.import_json(str)
|
13
15
|
else
|
14
16
|
puts 'Usage: luca-book import -c import_config'
|
15
17
|
exit 1
|
@@ -17,42 +19,69 @@ module LucaCmd
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.list(args, params)
|
20
|
-
args =
|
22
|
+
args = gen_range(params[:n] || 1) if args.empty?
|
21
23
|
if params['code']
|
22
|
-
|
24
|
+
if params['headers']
|
25
|
+
render(LucaBook::ListByHeader.term(*args, code: params['code'], header: params['headers']).list_by_code, params)
|
26
|
+
else
|
27
|
+
render(LucaBook::List.term(*args, code: params['code']).list_by_code, params)
|
28
|
+
end
|
23
29
|
else
|
24
|
-
LucaBook::List.term(*args).list_journals
|
30
|
+
render(LucaBook::List.term(*args).list_journals, params)
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
34
|
def self.stats(args, params)
|
29
|
-
args =
|
30
|
-
|
35
|
+
args = gen_range(params[:n]) if args.empty?
|
36
|
+
if params['code']
|
37
|
+
render(LucaBook::State.by_code(params['code'], *args), params)
|
38
|
+
else
|
39
|
+
render(LucaBook::State.range(*args).stats(params[:level]), params)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.add_header(args, params)
|
44
|
+
args = gen_range(params[:n] || 1) if args.empty?
|
45
|
+
if params['code']
|
46
|
+
LucaBook::List.add_header(*args, code: params['code'], header_key: params[:key], header_val: params[:value])
|
47
|
+
else
|
48
|
+
puts 'no code specified.'
|
49
|
+
end
|
31
50
|
end
|
32
51
|
end
|
33
52
|
|
34
|
-
class Report
|
53
|
+
class Report < LucaCmd
|
35
54
|
def self.balancesheet(args, params)
|
36
55
|
level = params[:level] || 3
|
37
56
|
legal = params[:legal] || false
|
38
|
-
args =
|
39
|
-
LucaBook::State.
|
57
|
+
args = gen_range(params[:n] || 1) if args.empty?
|
58
|
+
render(LucaBook::State.range(*args).bs(level, legal: legal), params)
|
40
59
|
end
|
41
60
|
|
42
61
|
def self.profitloss(args, params)
|
43
|
-
|
44
|
-
|
62
|
+
level = params[:level] || 2
|
63
|
+
args = gen_range(params[:n]) if args.empty?
|
64
|
+
render(LucaBook::State.range(*args).pl(level), params)
|
45
65
|
end
|
46
66
|
end
|
47
67
|
|
48
|
-
|
49
|
-
|
50
|
-
def gen_range(count)
|
68
|
+
def self.gen_range(count)
|
51
69
|
count ||= 3
|
52
70
|
today = Date.today
|
53
71
|
start = today.prev_month(count - 1)
|
54
72
|
[start.year, start.month, today.year, today.month]
|
55
73
|
end
|
74
|
+
|
75
|
+
def self.render(dat, params)
|
76
|
+
case params[:output]
|
77
|
+
when 'json'
|
78
|
+
puts JSON.dump(dat)
|
79
|
+
when 'nu'
|
80
|
+
LucaSupport::View.nushell(YAML.dump(dat))
|
81
|
+
else
|
82
|
+
puts YAML.dump(dat)
|
83
|
+
end
|
84
|
+
end
|
56
85
|
end
|
57
86
|
|
58
87
|
def new_pj(args = nil, params = {})
|
@@ -79,15 +108,31 @@ when /journals?/, 'j'
|
|
79
108
|
OptionParser.new do |opt|
|
80
109
|
opt.banner = 'Usage: luca-book journals list [options] [YYYY M]'
|
81
110
|
opt.on('-c', '--code VAL', 'search with code') { |v| params['code'] = v }
|
111
|
+
opt.on('--customer', 'categorize by x-customer header') { |_v| params['headers'] = 'x-customer' }
|
82
112
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
113
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
114
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
83
115
|
opt.on_tail('List records. If you specify code and/or month, search on each criteria.')
|
84
116
|
args = opt.parse!(ARGV)
|
85
117
|
LucaCmd::Journal.list(args, params)
|
86
118
|
end
|
119
|
+
when 'set'
|
120
|
+
OptionParser.new do |opt|
|
121
|
+
opt.banner = 'Usage: luca-book journals set [options] [YYYY M]'
|
122
|
+
opt.on('-c', '--code VAL', 'search with code') { |v| params['code'] = v }
|
123
|
+
opt.on('--header VAL', 'header key') { |v| params[:key] = v }
|
124
|
+
opt.on('--val VAL', 'header value') { |v| params[:value] = v }
|
125
|
+
opt.on_tail('set header to journals on specified code.')
|
126
|
+
args = opt.parse!(ARGV)
|
127
|
+
LucaCmd::Journal.add_header(args, params)
|
128
|
+
end
|
87
129
|
when 'stats'
|
88
130
|
OptionParser.new do |opt|
|
89
131
|
opt.banner = 'Usage: luca-book journals stats [options] [YYYY M]'
|
132
|
+
opt.on('-c', '--code VAL', 'search with code') { |v| params['code'] = v }
|
90
133
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
134
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
135
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
91
136
|
args = opt.parse!(ARGV)
|
92
137
|
LucaCmd::Journal.stats(args, params)
|
93
138
|
end
|
@@ -115,13 +160,18 @@ when /reports?/, 'r'
|
|
115
160
|
opt.banner = 'Usage: luca-book reports bs [options] [YYYY M]'
|
116
161
|
opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
|
117
162
|
opt.on('--legal', 'show legal mandatory account') { |_v| params[:legal] = true }
|
163
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
164
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
118
165
|
args = opt.parse!(ARGV)
|
119
166
|
LucaCmd::Report.balancesheet(args, params)
|
120
167
|
end
|
121
168
|
when 'pl'
|
122
169
|
OptionParser.new do |opt|
|
123
170
|
opt.banner = 'Usage: luca-book reports pl [options] [YYYY M YYYY M]'
|
171
|
+
opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
|
124
172
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
173
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
174
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
125
175
|
args = opt.parse!(ARGV)
|
126
176
|
LucaCmd::Report.profitloss(args, params)
|
127
177
|
end
|
data/lib/luca_book.rb
CHANGED
@@ -9,6 +9,7 @@ module LucaBook
|
|
9
9
|
autoload :Import, 'luca_book/import'
|
10
10
|
autoload :Journal, 'luca_book/journal'
|
11
11
|
autoload :List, 'luca_book/list'
|
12
|
+
autoload :ListByHeader, 'luca_book/list_by_header'
|
12
13
|
autoload :Setup, 'luca_book/setup'
|
13
14
|
autoload :State, 'luca_book/state'
|
14
15
|
autoload :Util, 'luca_book/util'
|
data/lib/luca_book/console.rb
CHANGED
@@ -49,7 +49,7 @@ class LucaBookConsole
|
|
49
49
|
print " " if h[:code].length > 3
|
50
50
|
end
|
51
51
|
puts cnsl_label(h[:label], h[:code])
|
52
|
-
h[:
|
52
|
+
h[:amount].each_slice(6) do |v|
|
53
53
|
puts "#{cnsl_fmt("", 14)} #{v.map{|v| cnsl_fmt(v, 14)}.join}"
|
54
54
|
end
|
55
55
|
end
|
@@ -72,13 +72,13 @@ class LucaBookConsole
|
|
72
72
|
end
|
73
73
|
convert_collection(report).each do |h|
|
74
74
|
if /^[A-Z]/.match(h[:code])
|
75
|
-
total = [h[:
|
75
|
+
total = [h[:amount].inject(:+)] + Array.new(h[:amount].length)
|
76
76
|
if /[^0]$/.match(h[:code])
|
77
77
|
print " "
|
78
78
|
print " " if h[:code].length > 3
|
79
79
|
end
|
80
80
|
puts cnsl_label(h[:label], h[:code])
|
81
|
-
h[:
|
81
|
+
h[:amount].each_slice(6).with_index(0) do |v, i|
|
82
82
|
puts "#{cnsl_fmt(total[i], 14)} #{v.map{|v| cnsl_fmt(v, 14)}.join}"
|
83
83
|
end
|
84
84
|
end
|
@@ -98,7 +98,7 @@ class LucaBookConsole
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
}.sort.map do |k,v|
|
101
|
-
{code: k, label: @report.dict.dig(k, :label),
|
101
|
+
{code: k, label: @report.dict.dig(k, :label), amount: v}
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
data/lib/luca_book/dict.rb
CHANGED
@@ -7,8 +7,85 @@ require 'pathname'
|
|
7
7
|
|
8
8
|
module LucaBook
|
9
9
|
class Dict < LucaRecord::Dict
|
10
|
+
# Column number settings for CSV/TSV convert
|
11
|
+
#
|
12
|
+
# :label
|
13
|
+
# for double entry data
|
14
|
+
# :counter_label
|
15
|
+
# must be specified with label
|
16
|
+
# :debit_label
|
17
|
+
# for double entry data
|
18
|
+
# * debit_amount
|
19
|
+
# :credit_label
|
20
|
+
# for double entry data
|
21
|
+
# * credit_amount
|
22
|
+
# :note
|
23
|
+
# can be the same column as another label
|
24
|
+
#
|
25
|
+
# :encoding
|
26
|
+
# file encoding
|
27
|
+
#
|
28
|
+
def csv_config
|
29
|
+
{}.tap do |config|
|
30
|
+
if @config.dig('label')
|
31
|
+
config[:label] = @config['label'].to_i
|
32
|
+
if @config.dig('counter_label')
|
33
|
+
config[:counter_label] = @config['counter_label']
|
34
|
+
config[:type] = 'single'
|
35
|
+
end
|
36
|
+
elsif @config.dig('debit_label')
|
37
|
+
config[:debit_label] = @config['debit_label'].to_i
|
38
|
+
if @config.dig('credit_label')
|
39
|
+
config[:credit_label] = @config['credit_label'].to_i
|
40
|
+
config[:type] = 'double'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
config[:type] ||= 'invalid'
|
44
|
+
config[:debit_amount] = @config['debit_amount'].to_i if @config.dig('debit_amount')
|
45
|
+
config[:credit_amount] = @config['credit_amount'].to_i if @config.dig('credit_amount')
|
46
|
+
config[:note] = @config['note'] if @config.dig('note')
|
47
|
+
config[:encoding] = @config['encoding'] if @config.dig('encoding')
|
48
|
+
|
49
|
+
config[:year] = @config['year'] if @config.dig('year')
|
50
|
+
config[:month] = @config['month'] if @config.dig('month')
|
51
|
+
config[:day] = @config['day'] if @config.dig('day')
|
52
|
+
config[:default_debit] = @config['default_debit'] if @config.dig('default_debit')
|
53
|
+
config[:default_credit] = @config['default_credit'] if @config.dig('default_credit')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def search(word, default_word = nil, amount = nil)
|
58
|
+
res = super(word, default_word, main_key: 'account_label')
|
59
|
+
if res.is_a?(Array) && res[0].is_a?(Array)
|
60
|
+
filter_amount(res, amount)
|
61
|
+
else
|
62
|
+
res
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Choose setting on Big or small condition.
|
67
|
+
#
|
68
|
+
def filter_amount(settings, amount = nil)
|
69
|
+
return settings[0] if amount.nil?
|
70
|
+
|
71
|
+
settings.each do |item|
|
72
|
+
return item unless item[1].keys.include?(:on_amount)
|
73
|
+
|
74
|
+
condition = item.dig(1, :on_amount)
|
75
|
+
case condition[0]
|
76
|
+
when '>'
|
77
|
+
return item if amount > BigDecimal(condition[1..])
|
78
|
+
when '<'
|
79
|
+
return item if amount < BigDecimal(condition[1..])
|
80
|
+
else
|
81
|
+
return item
|
82
|
+
end
|
83
|
+
end
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
10
87
|
def self.latest_balance
|
11
|
-
dict_dir = Pathname(LucaSupport::
|
88
|
+
dict_dir = Pathname(LucaSupport::PJDIR) / 'data' / 'balance'
|
12
89
|
# TODO: search latest balance dictionary
|
13
90
|
load_tsv_dict(dict_dir / 'start.tsv')
|
14
91
|
end
|
data/lib/luca_book/import.rb
CHANGED
@@ -4,9 +4,14 @@ require 'date'
|
|
4
4
|
require 'json'
|
5
5
|
require 'luca_book'
|
6
6
|
require 'luca_support'
|
7
|
-
#require 'luca_book/dict'
|
8
7
|
require 'luca_record'
|
9
8
|
|
9
|
+
begin
|
10
|
+
require "luca_book/import_#{LucaSupport::CONFIG['country']}"
|
11
|
+
rescue LoadError => e
|
12
|
+
e.message
|
13
|
+
end
|
14
|
+
|
10
15
|
module LucaBook
|
11
16
|
class Import
|
12
17
|
DEBIT_DEFAULT = '10XX'
|
@@ -18,7 +23,7 @@ module LucaBook
|
|
18
23
|
@target_file = path
|
19
24
|
# TODO: yaml need to be configurable
|
20
25
|
@dict_name = dict
|
21
|
-
@dict =
|
26
|
+
@dict = LucaBook::Dict.new("import-#{dict}.yaml")
|
22
27
|
@code_map = LucaRecord::Dict.reverse(LucaRecord::Dict.load('base.tsv'))
|
23
28
|
@config = @dict.csv_config if dict
|
24
29
|
end
|
@@ -30,13 +35,13 @@ module LucaBook
|
|
30
35
|
# "debit" : [
|
31
36
|
# {
|
32
37
|
# "label": "savings accounts",
|
33
|
-
# "
|
38
|
+
# "amount": 20000
|
34
39
|
# }
|
35
40
|
# ],
|
36
41
|
# "credit" : [
|
37
42
|
# {
|
38
43
|
# "label": "trade notes receivable",
|
39
|
-
# "
|
44
|
+
# "amount": 20000
|
40
45
|
# }
|
41
46
|
# ],
|
42
47
|
# "note": "settlement for the last month trade"
|
@@ -45,8 +50,6 @@ module LucaBook
|
|
45
50
|
#
|
46
51
|
def self.import_json(io)
|
47
52
|
JSON.parse(io).each do |d|
|
48
|
-
validate(d)
|
49
|
-
|
50
53
|
code_map = LucaRecord::Dict.reverse(LucaRecord::Dict.load('base.tsv'))
|
51
54
|
d['debit'].each { |h| h['code'] = code_map.dig(h['label']) || DEBIT_DEFAULT }
|
52
55
|
d['credit'].each { |h| h['code'] = code_map.dig(h['label']) || CREDIT_DEFAULT }
|
@@ -67,46 +70,41 @@ module LucaBook
|
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
70
|
-
def self.validate(obj)
|
71
|
-
raise 'NoDateKey' unless obj.key?('date')
|
72
|
-
raise 'NoDebitKey' unless obj.key?('debit')
|
73
|
-
raise 'NoDebitValue' if obj['debit'].empty?
|
74
|
-
raise 'NoCreditKey' unless obj.key?('credit')
|
75
|
-
raise 'NoCreditValue' if obj['credit'].empty?
|
76
|
-
end
|
77
|
-
|
78
73
|
private
|
79
74
|
|
80
|
-
#
|
81
75
|
# convert single entry data
|
82
76
|
#
|
83
77
|
def parse_single(row)
|
84
|
-
|
78
|
+
if (row.dig(@config[:credit_amount]) || []).empty?
|
79
|
+
amount = BigDecimal(row[@config[:debit_amount]])
|
80
|
+
debit = true
|
81
|
+
else
|
82
|
+
amount = BigDecimal(row[@config[:credit_amount]])
|
83
|
+
end
|
84
|
+
default_label = debit ? @config.dig(:default_debit) : @config.dig(:default_credit)
|
85
|
+
code, options = search_code(row[@config[:label]], default_label, amount)
|
86
|
+
counter_code = @code_map.dig(@config[:counter_label])
|
87
|
+
if options
|
88
|
+
x_customer = options[:'x-customer'] if options[:'x-customer']
|
89
|
+
data, data_c = tax_extension(code, counter_code, amount, options) if respond_to? :tax_extension
|
90
|
+
end
|
91
|
+
data ||= [{ 'code' => code, 'amount' => amount }]
|
92
|
+
data_c ||= [{ 'code' => counter_code, 'amount' => amount }]
|
85
93
|
{}.tap do |d|
|
86
94
|
d['date'] = parse_date(row)
|
87
|
-
if
|
88
|
-
d['debit'] =
|
89
|
-
|
90
|
-
]
|
91
|
-
d['credit'] = [
|
92
|
-
{ 'code' => @code_map.dig(@config[:counter_label]) }
|
93
|
-
]
|
95
|
+
if debit
|
96
|
+
d['debit'] = data
|
97
|
+
d['credit'] = data_c
|
94
98
|
else
|
95
|
-
d['debit'] =
|
96
|
-
|
97
|
-
]
|
98
|
-
d['credit'] = [
|
99
|
-
{ 'code' => search_code(row[@config[:label]], @config.dig(:default_credit)) || CREDIT_DEFAULT }
|
100
|
-
]
|
99
|
+
d['debit'] = data_c
|
100
|
+
d['credit'] = data
|
101
101
|
end
|
102
|
-
d['debit'][0]['value'] = value
|
103
|
-
d['credit'][0]['value'] = value
|
104
102
|
d['note'] = Array(@config[:note]).map{ |col| row[col] }.join(' ')
|
105
|
-
d['x-editor'
|
103
|
+
d['headers'] = { 'x-editor' => "LucaBook::Import/#{@dict_name}" }
|
104
|
+
d['headers']['x-customer'] = x_customer if x_customer
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
|
-
#
|
110
108
|
# convert double entry data
|
111
109
|
#
|
112
110
|
def parse_double(row)
|
@@ -114,19 +112,20 @@ module LucaBook
|
|
114
112
|
d['date'] = parse_date(row)
|
115
113
|
d['debit'] = {
|
116
114
|
'code' => search_code(row[@config[:label]], @config.dig(:default_debit)) || DEBIT_DEFAULT,
|
117
|
-
'
|
115
|
+
'amount' => row.dig(@config[:debit_amount])
|
118
116
|
}
|
119
117
|
d['credit'] = {
|
120
118
|
'code' => search_code(row[@config[:label]], @config.dig(:default_credit)) || CREDIT_DEFAULT,
|
121
|
-
'
|
119
|
+
'amount' => row.dig(@config[:credit_amount])
|
122
120
|
}
|
123
121
|
d['note'] = Array(@config[:note]).map{ |col| row[col] }.join(' ')
|
124
122
|
d['x-editor'] = "LucaBook::Import/#{@dict_name}"
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
128
|
-
def search_code(label, default_label)
|
129
|
-
@
|
126
|
+
def search_code(label, default_label, amount = nil)
|
127
|
+
label, options = @dict.search(label, default_label, amount)
|
128
|
+
[@code_map.dig(label), options]
|
130
129
|
end
|
131
130
|
|
132
131
|
def parse_date(row)
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'luca_book'
|
5
|
+
require 'luca_support'
|
6
|
+
|
7
|
+
module LucaBook
|
8
|
+
class Import
|
9
|
+
# TODO: need to be separated into pluggable l10n module.
|
10
|
+
# TODO: gensen rate >1m yen.
|
11
|
+
# TODO: gensen & consumption `round()` rules need to be confirmed.
|
12
|
+
# Profit or Loss account should be specified as code1.
|
13
|
+
#
|
14
|
+
def tax_extension(code1, code2, amount, options)
|
15
|
+
return nil if options.nil? || options[:tax_options].nil?
|
16
|
+
return nil if !options[:tax_options].include?('jp-gensen') && !options[:tax_options].include?('jp-consumption')
|
17
|
+
|
18
|
+
gensen_rate = BigDecimal('0.1021')
|
19
|
+
consumption_rate = BigDecimal('0.1')
|
20
|
+
gensen_code = @code_map.dig(options[:gensen_label]) || @code_map.dig('預り金')
|
21
|
+
gensen_idx = /^[5-8B-G]/.match(code1) ? 1 : 0
|
22
|
+
consumption_idx = /^[A-G]/.match(code1) ? 0 : 1
|
23
|
+
consumption_code = @code_map.dig(options[:consumption_label])
|
24
|
+
consumption_code ||= /^[A]/.match(code1) ? @code_map.dig('仮受消費税等') : @code_map.dig('仮払消費税等')
|
25
|
+
if options[:tax_options].include?('jp-gensen') && options[:tax_options].include?('jp-consumption')
|
26
|
+
paid_rate = BigDecimal('1') + consumption_rate - gensen_rate
|
27
|
+
gensen_amount = (amount / paid_rate * gensen_rate).round
|
28
|
+
consumption_amount = (amount / paid_rate * consumption_rate).round
|
29
|
+
[].tap do |res|
|
30
|
+
res << [].tap do |res1|
|
31
|
+
amount1 = amount
|
32
|
+
amount1 -= consumption_amount if consumption_idx == 0
|
33
|
+
amount1 += gensen_amount if gensen_idx == 1
|
34
|
+
res1 << { 'code' => code1, 'amount' => amount1 }
|
35
|
+
res1 << { 'code' => consumption_code, 'amount' => consumption_amount } if consumption_idx == 0
|
36
|
+
res1 << { 'code' => gensen_code, 'amount' => gensen_amount } if gensen_idx == 0
|
37
|
+
end
|
38
|
+
res << [].tap do |res2|
|
39
|
+
amount2 = amount
|
40
|
+
amount2 -= consumption_amount if consumption_idx == 1
|
41
|
+
amount2 += gensen_amount if gensen_idx == 0
|
42
|
+
res2 << { 'code' => code2, 'amount' => amount2 }
|
43
|
+
res2 << { 'code' => consumption_code, 'amount' => consumption_amount } if consumption_idx == 1
|
44
|
+
res2 << { 'code' => gensen_code, 'amount' => gensen_amount } if gensen_idx == 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
elsif options[:tax_options].include?('jp-gensen')
|
48
|
+
paid_rate = BigDecimal('1') - gensen_rate
|
49
|
+
gensen_amount = (amount / paid_rate * gensen_rate).round
|
50
|
+
[].tap do |res|
|
51
|
+
res << [].tap do |res1|
|
52
|
+
amount1 = amount
|
53
|
+
amount1 += gensen_amount if gensen_idx == 1
|
54
|
+
res1 << { 'code' => code, 'amount' => amount1 }
|
55
|
+
res1 << { 'code' => gensen_code, 'amount' => gensen_amount } if gensen_idx == 0
|
56
|
+
end
|
57
|
+
res << [].tap do |res2|
|
58
|
+
amount2 = amount
|
59
|
+
amount2 += gensen_amount if gensen_idx == 0
|
60
|
+
mount2 ||= amount
|
61
|
+
res2 << { 'code' => code2, 'amount' => amount2 }
|
62
|
+
res2 << { 'code' => gensen_code, 'amount' => gensen_amount } if gensen_idx == 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
elsif options[:tax_options].include?('jp-consumption')
|
66
|
+
paid_rate = BigDecimal('1') + consumption_rate - gensen_rate
|
67
|
+
consumption_amount = (amount / paid_rate * consumption_rate).round
|
68
|
+
res << [].tap do |res1|
|
69
|
+
amount1 = amount
|
70
|
+
amount1 -= consumption_amount if consumption_idx == 0
|
71
|
+
res1 << { 'code' => code1, 'amount' => amount1 }
|
72
|
+
res1 << { 'code' => consumption_code, 'amount' => consumption_amount } if consumption_idx == 0
|
73
|
+
end
|
74
|
+
res << [].tap do |res2|
|
75
|
+
amount2 = amount
|
76
|
+
amount2 -= consumption_amount if consumption_idx == 1
|
77
|
+
res2 << { 'code' => code2, 'amount' => amount2 }
|
78
|
+
res2 << { 'code' => consumption_code, 'amount' => consumption_amount } if consumption_idx == 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|