luca-jp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d226efcad9d2c52181b9fcbdd4ae8b74d9d5b754fe77394aa82461ad216fcffa
4
- data.tar.gz: 8fe33b512f972ee94b78086d5a776ca348d26293c3da4e50d6979c839f0bb4c9
3
+ metadata.gz: 5c6d1f716fed87d639d11ba925e383a2b1d338a901dd148508c39d56664b1a36
4
+ data.tar.gz: e82fd1948e7df170d163fe15f790d58b61809319d6e2f9aba62499bbabbf6be3
5
5
  SHA512:
6
- metadata.gz: 9087580538986050f9f759825a20fa3be2931814d558b555d1fcfd34d9b5469e2295f3840b6e4ee788dab53623cad0a7b1ffac1fd6764afe8faff25a753ca2d0
7
- data.tar.gz: 5817884c64afecdba20440cc3f8a346656a025604d72b8d862e841aea6b53439a992a1076d8c4230e5507406a436da50fd88b3f6644d219eff38eb96b3b6f550
6
+ metadata.gz: 3501fc606dc9955b03b8e0cde1c3ebc4b4ff1374fa88e53218b4a66d2c48028325e49709e722aea835dd8b21cb0f4224036a77366665c1e6a46131e5648a8f06
7
+ data.tar.gz: ba151aeb2da6ab8f5334067804cb7d64d23ab218878b944f2bbd099749b452d322c9695817b44296b9dfd6e2fe6bcca34bfd9f18c38fc87e38a1c43b05bc9f16
data/exe/luca-jp CHANGED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require 'luca/jp'
5
+
6
+ class LucaCmd
7
+ def self.syouhizei(args, params)
8
+ if params[:export]
9
+ Luca::Jp::Syouhizei.range(*args).export_json
10
+ else
11
+ puts Luca::Jp::Syouhizei.range(*args).kani
12
+ end
13
+ end
14
+
15
+ def self.houjinzei(args, params)
16
+ if params[:export]
17
+ Luca::Jp::Aoiro.range(*args).export_json
18
+ else
19
+ puts Luca::Jp::Aoiro.range(*args).kani
20
+ end
21
+ end
22
+
23
+ def self.chihouzei(args, params)
24
+ if params[:export]
25
+ Luca::Jp::Chihouzei.range(*args).export_json
26
+ else
27
+ puts Luca::Jp::Chihouzei.range(*args).kani
28
+ end
29
+ end
30
+ end
31
+
32
+ cmd = ARGV.shift
33
+ params = {}
34
+
35
+ case cmd
36
+ when /hou?jinzei/
37
+ OptionParser.new do |opt|
38
+ opt.banner = 'Usage: luca-jp houjinzei [options] yyyy mm yyyy mm'
39
+ opt.on('--export', 'export json') { |_v| params[:export] = true }
40
+ args = opt.parse!(ARGV)
41
+ LucaCmd.houjinzei(args, params)
42
+ end
43
+ when /s[yh]ou?hizei/
44
+ OptionParser.new do |opt|
45
+ opt.banner = 'Usage: luca-jp syouhizei [options] yyyy mm yyyy mm'
46
+ opt.on('--export', 'export json') { |_v| params[:export] = true }
47
+ args = opt.parse!(ARGV)
48
+ LucaCmd.syouhizei(args, params)
49
+ end
50
+ when /chihou?zei/
51
+ OptionParser.new do |opt|
52
+ opt.banner = 'Usage: luca-jp chihouzei [options] yyyy mm yyyy mm'
53
+ opt.on('--export', 'export json') { |_v| params[:export] = true }
54
+ args = opt.parse!(ARGV)
55
+ LucaCmd.chihouzei(args, params)
56
+ end
57
+ end
data/lib/luca/jp.rb CHANGED
@@ -5,6 +5,10 @@ require 'luca/jp/version'
5
5
  module Luca
6
6
  module Jp
7
7
  autoload :Kessan, 'luca/jp/kessan'
8
+ autoload :Aoiro, 'luca/jp/aoiro'
8
9
  autoload :Syouhizei, 'luca/jp/syouhizei'
10
+ autoload :Chihouzei, 'luca/jp/chihouzei'
11
+ autoload :Common, 'luca/jp/common'
12
+ autoload :Util, 'luca/jp/util'
9
13
  end
10
14
  end
@@ -0,0 +1,409 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'cgi/escape'
5
+ require 'luca_book'
6
+ require 'luca_support'
7
+ require 'luca_record/dict'
8
+ require 'luca_support/config'
9
+ require 'luca/jp'
10
+
11
+ module Luca
12
+ module Jp
13
+ class Aoiro < LucaBook::State
14
+ include LucaSupport::View
15
+ include LucaSupport::Code
16
+ include Luca::Jp::Common
17
+ include Luca::Jp::Util
18
+
19
+ @dirname = 'journals'
20
+ @record_type = 'raw'
21
+
22
+ def kani(export: false)
23
+ set_pl(4)
24
+ set_bs(4)
25
+ @issue_date = Date.today
26
+ @company = CGI.escapeHTML(LucaSupport::CONFIG.dig('company', 'name'))
27
+ @software = 'LucaJp'
28
+ @法人税中間納付 = prepaid_tax('1851')
29
+ @地方法人税中間納付 = prepaid_tax('1852')
30
+ @法人税額 = 中小企業の軽減税額 + 一般区分の税額
31
+ @確定法人税額 = (@法人税額 / 100).floor * 100
32
+ @地方法人税課税標準 = (@法人税額 / 1000).floor * 1000
33
+ @地方法人税額 = 地方法人税額(@地方法人税課税標準)
34
+ @確定地方法人税額 = (@地方法人税額 / 100).floor * 100
35
+
36
+ if export
37
+ {
38
+ kokuzei: {
39
+ zeigaku: @確定法人税額,
40
+ chukan: @法人税中間納付
41
+ },
42
+ chihou: {
43
+ zeigaku: @確定地方法人税額,
44
+ chukan: @地方法人税中間納付
45
+ }
46
+ }
47
+ else
48
+ @procedure_code = 'RHO0012'
49
+ @procedure_name = '内国法人の確定申告(青色)'
50
+ @version = '20.0.2'
51
+ @法人税期中増, @法人税期中減 = 未納法人税期中増減
52
+ @都道府県民税期中増, @都道府県民税期中減 = 未納都道府県民税期中増減
53
+ @市民税期中増, @市民税期中減 = 未納市民税期中増減
54
+ @事業税期中増, @事業税期中減 = 未納事業税期中増減
55
+ @納税充当金期中増, @納税充当金期中減 = 納税充当金期中増減
56
+ @概況売上 = gaikyo('A0')
57
+ @form_sec = ['HOA112', 'HOA116', 'HOA201', 'HOA420', 'HOA511', 'HOA522', 'HOE200', 'HOE990', 'HOI010', 'HOI100', 'HOI141', 'HOK010'].map{ |c| form_rdf(c) }.join('')
58
+ #@extra_form_sec = ['HOI040', 'HOI060', 'HOI090', 'HOI110']
59
+ @it = it_part
60
+ @form_data = [別表一, 別表一次葉, 別表二, 別表四簡易, 別表五一, 別表五二, 別表十五, 適用額明細, 預貯金内訳, 仮受金内訳, 役員報酬内訳, 概況説明].join("\n")
61
+ render_erb(search_template('aoiro.xtx.erb'))
62
+ end
63
+ end
64
+
65
+ def export_json
66
+ dat = kani(export: true)
67
+ [].tap do |res|
68
+ item = {}
69
+ item['date'] = @end_date
70
+ item['debit'] = []
71
+ item['credit'] = []
72
+ if dat[:kokuzei][:chukan] > 0
73
+ item['credit'] << { 'label' => '仮払法人税', 'amount' => dat[:kokuzei][:chukan] }
74
+ end
75
+ if dat[:kokuzei][:chukan] > dat[:kokuzei][:zeigaku]
76
+ item['debit'] << { 'label' => '未収法人税', 'amount' => dat[:kokuzei][:chukan] - dat[:kokuzei][:zeigaku] }
77
+ else
78
+ item['credit'] << { 'label' => '未払法人税', 'amount' => dat[:kokuzei][:zeigaku] - dat[:kokuzei][:chukan] }
79
+ end
80
+ item['debit'] << { 'label' => '法人税、住民税及び事業税', 'amount' => dat[:kokuzei][:zeigaku] }
81
+ if dat[:chihou][:chukan] > 0
82
+ item['credit'] << { 'label' => '仮払法人税(地方)', 'amount' => dat[:chihou][:chukan] }
83
+ end
84
+ if dat[:chihou][:chukan] > dat[:chihou][:zeigaku]
85
+ item['debit'] << { 'label' => '未収法人税', 'amount' => dat[:chihou][:chukan] - dat[:chihou][:zeigaku] }
86
+ else
87
+ item['credit'] << { 'label' => '未払法人税', 'amount' => dat[:chihou][:zeigaku] - dat[:chihou][:chukan] }
88
+ end
89
+ item['debit'] << { 'label' => '法人税、住民税及び事業税', 'amount' => dat[:chihou][:zeigaku] }
90
+ item['x-editor'] = 'LucaJp'
91
+ res << item
92
+ puts JSON.dump(res)
93
+ end
94
+ end
95
+
96
+ def 別表一
97
+ render_erb(search_template('beppyo1.xml.erb'))
98
+ end
99
+
100
+ def 別表一次葉
101
+ @消費税期中増, @消費税期中減 = 未納消費税期中増減
102
+ render_erb(search_template('beppyo1-next.xml.erb'))
103
+ end
104
+
105
+ def 別表二
106
+ render_erb(search_template('beppyo2.xml.erb'))
107
+ end
108
+
109
+ def 別表四簡易
110
+ @当期純損益 = readable(@pl_data.dig('HA'))
111
+ @法人税等 = readable(@pl_data.dig('H0'))
112
+ _, @納付事業税 = 未納事業税期中増減
113
+ @還付事業税 = readable(還付事業税 || 0)
114
+ @別表四調整所得 = @当期純損益 + @法人税等 + @還付事業税 - @納付事業税
115
+
116
+ render_erb(search_template('beppyo4.xml.erb'))
117
+ end
118
+
119
+ def 別表五一
120
+ render_erb(search_template('beppyo51.xml.erb'))
121
+ end
122
+
123
+ def 別表五二
124
+ @その他事業税 = 租税公課
125
+ render_erb(search_template('beppyo52.xml.erb'))
126
+ end
127
+
128
+ def 別表十五
129
+ @交際費 = readable(@pl_data.dig('C1B') || 0)
130
+ @限度額 = @交際費 < 4_000_000 ? @交際費 : 4_000_000
131
+ @不算入額 = @交際費 < 4_000_000 ? 0 : @交際費 - 4_000_000
132
+ render_erb(search_template('beppyo15.xml.erb'))
133
+ end
134
+
135
+ def 預貯金内訳
136
+ @預金 = @bs_data.each.with_object({}) do |(k, v), h|
137
+ next unless /^110[0-9A-Z]/.match(k)
138
+ next unless readable(v || 0) > 0
139
+
140
+ h[@dict.dig(k)[:label]] = readable(v)
141
+ end
142
+ render_erb(search_template('yokin-meisai.xml.erb'))
143
+ end
144
+
145
+ def 仮受金内訳
146
+ @源泉給与 = readable(@bs_data.dig('5191') || 0)
147
+ @源泉報酬 = readable(@bs_data.dig('5193') || 0)
148
+ render_erb(search_template('kariuke-meisai.xml.erb'))
149
+ end
150
+
151
+ def 役員報酬内訳
152
+ @役員報酬 = readable(@pl_data.dig('C11') || 0)
153
+ @給料 = readable(@pl_data.dig('C12') || 0)
154
+ render_erb(search_template('yakuin-meisai.xml.erb'))
155
+ end
156
+
157
+ def 適用額明細
158
+ render_erb(search_template('tekiyougaku.xml.erb'))
159
+ end
160
+
161
+ def 概況説明
162
+ @概況粗利益 = gaikyo('BA')
163
+ @概況役員報酬 = gaikyo('C11')
164
+ @概況給料 = gaikyo('C12')
165
+ @概況交際費 = gaikyo('C1B')
166
+ @概況減価償却 = gaikyo('C1P')
167
+ @概況地代租税 = gaikyo('C1E') + gaikyo('C1I')
168
+ @概況営業損益 = gaikyo('CA')
169
+ @概況特別利益 = gaikyo('F0')
170
+ @概況特別損失 = gaikyo('G0')
171
+ @概況税引前損益 = gaikyo('GA')
172
+ @概況資産計 = gaikyo('5')
173
+ @概況現預金 = gaikyo('10')
174
+ @概況受取手形 = gaikyo('120')
175
+ @概況売掛金 = gaikyo('130')
176
+ @概況棚卸資産 = gaikyo('160')
177
+ @概況貸付金 = gaikyo('140') + gaikyo('333')
178
+ @概況建物 = gaikyo('311')
179
+ @概況機械 = gaikyo('313')
180
+ @概況車船 = gaikyo('314') + gaikyo('318')
181
+ @概況土地 = gaikyo('316')
182
+ @概況負債計 = gaikyo('8ZZ')
183
+ @概況支払手形 = gaikyo('510')
184
+ @概況買掛金 = gaikyo('511')
185
+ @概況個人借入金 = gaikyo('5121')
186
+ @概況ほか借入金 = gaikyo('512') - gaikyo('5121')
187
+ @概況純資産 = gaikyo('9ZZ')
188
+ @代表者報酬 = gaikyo('C11')
189
+ @代表者借入 = gaikyo('5121')
190
+ @概況仕入 = gaikyo('B11') + gaikyo('B12')
191
+ @概況外注費 = gaikyo('C10')
192
+ @概況人件費 = gaikyo('C11') + gaikyo('C12') + gaikyo('C13')
193
+ render_erb(search_template('gaikyo.xml.erb'))
194
+ end
195
+
196
+ private
197
+
198
+ def 期首未納事業税
199
+ readable(@start_balance.dig('5152')) || 0
200
+ end
201
+
202
+ def 期末未納事業税
203
+ readable(@bs_data.dig('5152')) || 0
204
+ end
205
+
206
+ def 当期事業税納付
207
+ readable(@pl_data.dig('C1I2')) || 0
208
+ end
209
+
210
+ def 租税公課
211
+ readable(LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: 'C1I')[:debit]) || 0
212
+ end
213
+
214
+ def 別表四還付事業税
215
+ return nil if @還付事業税 == 0
216
+
217
+ "<ARC00220><ARC00230>仮払事業税消却(未収計上した還付事業税)</ARC00230>#{render_attr('ARC00240', @還付事業税)}#{render_attr('ARC00250', @還付事業税)}</ARC00220>\n"
218
+ end
219
+
220
+ def 期首繰越損益
221
+ readable(@start_balance.dig('914')) || 0
222
+ end
223
+
224
+ def 期末繰越損益
225
+ readable(@bs_data.dig('914')) || 0
226
+ end
227
+
228
+ def 期首納税充当金
229
+ readable(@start_balance.dig('515')) || 0
230
+ end
231
+
232
+ def 期末納税充当金
233
+ readable(@bs_data.dig('515')) || 0
234
+ end
235
+
236
+ def 納税充当金期中増減
237
+ r = LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '515')
238
+ [
239
+ readable(r[:credit] || 0) + @法人税期中増 + @都道府県民税期中増 + @市民税期中増 + @事業税期中増,
240
+ readable(r[:debit] || 0) + @法人税期中減 + @都道府県民税期中減 + @市民税期中減 + @事業税期中減
241
+ ]
242
+ end
243
+
244
+ def 期首未納法人税
245
+ readable(@start_balance.dig('5151')) || 0
246
+ end
247
+
248
+ def 期末未納法人税
249
+ readable(@bs_data.dig('5151')) || 0
250
+ end
251
+
252
+ def 未納法人税期中増減
253
+ r = LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '5151')
254
+ [readable(r[:credit] || 0), readable(r[:debit] || 0)]
255
+ end
256
+
257
+ def 期首未納都道府県民税
258
+ readable(@start_balance.dig('5153')) || 0
259
+ end
260
+
261
+ def 期末未納都道府県民税
262
+ readable(@bs_data.dig('5153')) || 0
263
+ end
264
+
265
+ def 未納都道府県民税期中増減
266
+ r = LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '5153')
267
+ [readable(r[:credit] || 0), readable(r[:debit] || 0)]
268
+ end
269
+
270
+ def 期首未納市民税
271
+ readable(@start_balance.dig('5154')) || 0
272
+ end
273
+
274
+ def 期末未納市民税
275
+ readable(@bs_data.dig('5154')) || 0
276
+ end
277
+
278
+ def 未納市民税期中増減
279
+ r = LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '5154')
280
+ [readable(r[:credit] || 0), readable(r[:debit] || 0)]
281
+ end
282
+
283
+ def 別表五一期首差引金額
284
+ 期首繰越損益 + 期首納税充当金 - 期首未納法人税 - 期首未納都道府県民税 - 期首未納市民税
285
+ end
286
+
287
+ def 別表五一期末差引金額
288
+ 期末繰越損益 + 期末納税充当金 - 期末未納法人税 - 期末未納都道府県民税 - 期末未納市民税
289
+ end
290
+
291
+ def 別表五一期中減差引金額
292
+ 期首繰越損益 + @納税充当金期中減 - @法人税期中減 - @都道府県民税期中減 - @市民税期中減
293
+ end
294
+
295
+ def 別表五一期中増差引金額
296
+ 期末繰越損益 + @納税充当金期中増 - @法人税期中増 - @都道府県民税期中増 - @市民税期中増
297
+ end
298
+
299
+ def 期首資本金
300
+ readable(@start_balance.dig('911')) || 0
301
+ end
302
+
303
+ def 期末資本金
304
+ readable(@bs_data.dig('911')) || 0
305
+ end
306
+
307
+ def 別表五一期首資本
308
+ 期首資本金
309
+ end
310
+
311
+ def 別表五一期末資本
312
+ 期末資本金
313
+ end
314
+
315
+ def 期首未納消費税
316
+ readable(@start_balance.dig('516')) || 0
317
+ end
318
+
319
+ def 期末未納消費税
320
+ readable(@bs_data.dig('516')) || 0
321
+ end
322
+
323
+ def 未納消費税期中増減
324
+ r = LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '516')
325
+ [readable(r[:credit] || 0), readable(r[:debit] || 0)]
326
+ end
327
+
328
+ def 中小企業の軽減税率対象所得
329
+ if 所得金額 >= 8_000_000
330
+ 8_000_000
331
+ elsif 所得金額 < 0
332
+ 0
333
+ else
334
+ (所得金額 / 1000).floor * 1000
335
+ end
336
+ end
337
+
338
+ def 中小企業の軽減税額
339
+ 中小企業の軽減税率対象所得 * 15 / 100
340
+ end
341
+
342
+ def 中小企業の軽減税率対象を超える所得
343
+ if 所得金額 <= 8_000_000
344
+ 0
345
+ else
346
+ ((所得金額 - 8_000_000) / 1000).floor * 1000
347
+ end
348
+ end
349
+
350
+ def 一般区分の税額
351
+ (中小企業の軽減税率対象を超える所得 * 23.2 / 100).to_i
352
+ end
353
+
354
+ def 地方法人税額(地方法人税課税標準)
355
+ (地方法人税課税標準 * 10.3 / 100).to_i
356
+ end
357
+
358
+ def 概況月(idx)
359
+ @start_date.next_month(idx).month
360
+ end
361
+
362
+ def 概況月売上(idx)
363
+ gaikyo_month(idx, 'A0')
364
+ end
365
+
366
+ def 概況月仕入(idx)
367
+ gaikyo_month(idx, 'B11') + gaikyo_month(idx, 'B12')
368
+ end
369
+
370
+ def 概況月人件費(idx)
371
+ gaikyo_month(idx, 'C11') + gaikyo_month(idx, 'C12') + gaikyo_month(idx, 'C13') + gaikyo_month(idx, 'C14')
372
+ end
373
+
374
+ def 概況月外注費(idx)
375
+ gaikyo_month(idx, 'C10')
376
+ end
377
+
378
+ def 概況月源泉徴収(idx)
379
+ target = @start_date.next_month(idx)
380
+ readable(LucaBook::State.gross(target.year, target.month, code: '5191')[:credit] || 0)
381
+ + readable(LucaBook::State.gross(target.year, target.month, code: '5193')[:credit] || 0)
382
+ end
383
+
384
+ def 概況源泉徴収
385
+ readable(LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '5191')[:credit] || 0)
386
+ + readable(LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '5193')[:credit] || 0)
387
+ end
388
+
389
+ def gaikyo(code)
390
+ case code
391
+ when /^[0-9]/
392
+ readable(@bs_data.dig(code) || 0)
393
+ when /^[A-H]/
394
+ readable(@pl_data.dig(code) || 0)
395
+ else
396
+ raise 'invalid code supplied'
397
+ end
398
+ end
399
+
400
+ def gaikyo_month(index, code)
401
+ readable(@monthly.dig(index, code) || 0)
402
+ end
403
+
404
+ def lib_path
405
+ __dir__
406
+ end
407
+ end
408
+ end
409
+ end