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.
@@ -0,0 +1,200 @@
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 Chihouzei < LucaBook::State
14
+ include LucaSupport::View
15
+ include Luca::Jp::Common
16
+ include Luca::Jp::Util
17
+
18
+ @dirname = 'journals'
19
+ @record_type = 'raw'
20
+
21
+ def kani(export: false)
22
+ set_pl(4)
23
+ set_bs(4)
24
+ @issue_date = Date.today
25
+ @company = CGI.escapeHTML(LucaSupport::CONFIG.dig('company', 'name'))
26
+ @software = 'LucaJp'
27
+ @jimusho_code = LucaSupport::CONFIG.dig('jp', 'eltax', 'jimusho_code')
28
+ @jimusho_name = '都税事務所長'
29
+
30
+ @均等割 = 70000
31
+ @法人税割課税標準 = 法人税割課税標準
32
+ @確定法人税割 = (法人税割 / 100).floor * 100
33
+ @地方特別法人事業税中間納付 = prepaid_tax('1854')
34
+ @所得割中間納付 = prepaid_tax('1855')
35
+ @法人税割中間納付 = prepaid_tax('1859')
36
+ @均等割中間納付 = prepaid_tax('185A')
37
+ @所得割 = 所得割400万以下 + 所得割800万以下 + 所得割800万超
38
+ if export
39
+ {
40
+ jigyouzei: {
41
+ shotoku: {
42
+ zeigaku: @所得割,
43
+ chukan: @所得割中間納付
44
+ },
45
+ tokubetsu: {
46
+ zeigaku: 地方法人特別税(@所得割),
47
+ chukan: @地方特別法人事業税中間納付
48
+ },
49
+ },
50
+ juminzei: {
51
+ kinto: {
52
+ zeigaku: @均等割,
53
+ chukan: @均等割中間納付
54
+ },
55
+ houjinzei: {
56
+ zeigaku: @確定法人税割,
57
+ chukan: @法人税割中間納付
58
+ }
59
+ }
60
+ }
61
+ else
62
+ @procedure_code = 'R0102100'
63
+ @procedure_name = '法人都道府県民税・事業税・特別法人事業税又は地方法人特別税 確定申告'
64
+ @form_sec = ['R0102AA190', 'R0102AG120'].map{ |c| form_attr(c) }.join('')
65
+ @user_inf = render_erb(search_template('el-userinf.xml.erb'))
66
+ @form_data = [第六号, 別表四三].join("\n")
67
+ render_erb(search_template('eltax.xml.erb'))
68
+ end
69
+ end
70
+
71
+ def export_json
72
+ records = kani(export: true)
73
+ [].tap do |res|
74
+ item = {}
75
+ item['date'] = @end_date
76
+ item['debit'] = []
77
+ item['credit'] = []
78
+ records[:jigyouzei].each do |k, dat|
79
+ if dat[:chukan] > 0
80
+ item['credit'] << { 'label' => karibarai_label(k), 'amount' => dat[:chukan] }
81
+ end
82
+ if dat[:chukan] > dat[:zeigaku]
83
+ item['debit'] << { 'label' => '未収法人税', 'amount' => dat[:chukan] - dat[:zeigaku] }
84
+ else
85
+ item['credit'] << { 'label' => '未払地方事業税', 'amount' => dat[:zeigaku] - dat[:chukan] }
86
+ end
87
+ item['debit'] << { 'label' => '法人税、住民税及び事業税', 'amount' => dat[:zeigaku] }
88
+ end
89
+ records[:juminzei].each do |k, dat|
90
+ if dat[:chukan] > 0
91
+ item['credit'] << { 'label' => karibarai_label(k), 'amount' => dat[:chukan] }
92
+ end
93
+ if dat[:chukan] > dat[:zeigaku]
94
+ item['debit'] << { 'label' => '未収法人税', 'amount' => dat[:chukan] - dat[:zeigaku] }
95
+ else
96
+ item['credit'] << { 'label' => '未払都道府県民税', 'amount' => dat[:zeigaku] - dat[:chukan] }
97
+ end
98
+ item['debit'] << { 'label' => '法人税、住民税及び事業税', 'amount' => dat[:zeigaku] }
99
+ end
100
+ item['x-editor'] = 'LucaJp'
101
+ res << item
102
+ puts JSON.dump(res)
103
+ end
104
+ end
105
+
106
+ def 第六号
107
+ render_erb(search_template('el-no6.xml.erb'))
108
+ end
109
+
110
+ def 別表四三
111
+ @office_23ku = LucaSupport::CONFIG.dig('jp', 'eltax', 'office_23ku')
112
+ render_erb(search_template('el-no6-43.xml.erb'))
113
+ end
114
+
115
+ private
116
+
117
+ def 法人税割課税標準
118
+ national_tax = Luca::Jp::Aoiro.range(@start_date.year, @start_date.month, @end_date.year, @end_date.month).kani(export: true)
119
+ (national_tax[:kokuzei][:zeigaku] / 1000).floor * 1000
120
+ end
121
+
122
+ def 法人税割
123
+ (@法人税割課税標準 * 7 / 100).floor
124
+ end
125
+
126
+ def 地方法人特別税(事業税)
127
+ ((事業税 * 37 / 100) / 100).floor * 100
128
+ end
129
+
130
+ def 所得400万以下
131
+ if 所得金額 >= 4_000_000
132
+ 4_000_000
133
+ else
134
+ (所得金額 / 1000).floor * 1000
135
+ end
136
+ end
137
+
138
+ def 所得割400万以下
139
+ ((所得400万以下 * 3.5 / 100) / 100).floor * 100
140
+ end
141
+
142
+ def 所得800万以下
143
+ if 所得金額 <= 4_000_000
144
+ 0
145
+ elsif 所得金額 >= 8_000_000
146
+ 4_000_000
147
+ else
148
+ ((所得金額 - 4_000_000) / 1000).floor * 1000
149
+ end
150
+ end
151
+
152
+ def 所得割800万以下
153
+ ((所得800万以下 * 5.3 / 100) / 100).floor * 100
154
+ end
155
+
156
+ def 所得800万超
157
+ if 所得金額 <= 8_000_000
158
+ 0
159
+ else
160
+ ((所得金額 - 8_000_000) / 1000).floor * 1000
161
+ end
162
+ end
163
+
164
+ def 所得割800万超
165
+ ((所得800万超 * 7.0 / 100) / 100).floor * 100
166
+ end
167
+
168
+ def 事業税中間納付
169
+ @所得割中間納付
170
+ end
171
+
172
+ def form_attr(code)
173
+ "<FORM_ATTR><FORM_ID>#{code}</FORM_ID><FORM_NAME></FORM_NAME><FORM_FILE_NAME></FORM_FILE_NAME><FORM_XSL_NAME></FORM_XSL_NAME></FORM_ATTR>"
174
+ end
175
+
176
+ def karibarai_label(key)
177
+ case key
178
+ when :tokubetsu
179
+ '仮払地方税特別法人事業税'
180
+ when :shotoku
181
+ '仮払地方税所得割'
182
+ when :syunyu
183
+ '仮払地方税収入割'
184
+ when :shihon
185
+ '仮払地方税資本割'
186
+ when :fukakachi
187
+ '仮払地方税付加価値割'
188
+ when :hojinzei
189
+ '仮払地方税法人税割'
190
+ when :kinto
191
+ '仮払地方税均等割'
192
+ end
193
+ end
194
+
195
+ def lib_path
196
+ __dir__
197
+ end
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'luca_support'
4
+
5
+ module Luca
6
+ module Jp
7
+ module Common
8
+ module_function
9
+
10
+ # 税引前当期利益をもとに計算
11
+ # 消費税を租税公課に計上している場合、控除済みの金額
12
+ # 未払/未収事業税は精算時に認識
13
+ #
14
+ def 所得金額
15
+ _, 納付事業税 = 未納事業税期中増減
16
+ LucaSupport::Code.readable(@pl_data.dig('GA') - 納付事業税 + 還付事業税)
17
+ end
18
+
19
+ def 消費税課税売上高(税率 = 10)
20
+ LucaSupport::Code.readable(@pl_data.dig('A0') * 100 / (100 + 税率).floor || 0)
21
+ end
22
+
23
+ def 納付税額(税額, 中間納付額)
24
+ if 税額 > 中間納付額
25
+ 税額 - 中間納付額
26
+ else
27
+ 0
28
+ end
29
+ end
30
+
31
+ def 中間還付税額(税額, 中間納付額)
32
+ if 税額 < 中間納付額
33
+ 中間納付額 - 税額
34
+ else
35
+ 0
36
+ end
37
+ end
38
+
39
+ def 還付事業税
40
+ LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '1504')[:credit]
41
+ end
42
+
43
+ def 未納事業税期中増減
44
+ r = LucaBook::State.gross(@start_date.year, @start_date.month, @end_date.year, @end_date.month, code: '5152')
45
+ [LucaSupport::Code.readable(r[:credit] || 0), LucaSupport::Code.readable(r[:debit] || 0)]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,31 +1,112 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+ require 'cgi/escape'
3
5
  require 'luca_book'
4
6
  require 'luca_support'
5
7
  require 'luca_record/dict'
6
8
  require 'luca_support/config'
9
+ require 'luca/jp/util'
7
10
 
8
11
  module Luca
9
12
  module Jp
10
- class Syouhizei
11
- def initialize(from_year, from_month, to_year = from_year, to_month = from_month)
12
- @dict = LucaRecord::Dict.load('base.tsv')
13
- @state = LucaBook::State.range(from_year, from_month, to_year, to_month)
14
- end
13
+ class Syouhizei < LucaBook::State
14
+ include LucaSupport::View
15
+ include Luca::Jp::Util
16
+
17
+ @dirname = 'journals'
18
+ @record_type = 'raw'
15
19
 
16
20
  # TODO: 軽減税率売上の識別
17
21
  #
18
- def kani
19
- 税率 = 10 # percent
20
- @state.pl
21
- sales = @state.pl_data.dig('A0')
22
- tax_amount = sales * 10 / 100
23
- みなし仕入額 = tax_amount * みなし仕入率(LucaSupport::CONFIG.dig('jp', 'syouhizei_kubun')) / 100
24
- 税額 = LucaSupport::Code.readable(tax_amount - みなし仕入額)
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
+ 税率 = BigDecimal('7.8') # percent
29
+ 地方税率 = BigDecimal('2.2')
30
+
31
+ @sales = @pl_data.dig('A0') * 100 / (100 + 税率 + 地方税率).floor
32
+ @tax_amount = (課税標準額(@sales) * 税率 / 100).floor
33
+ @みなし仕入税額 = (@tax_amount * みなし仕入率(LucaSupport::CONFIG.dig('jp', 'syouhizei_kubun')) / 100).floor
34
+ @税額 = LucaSupport::Code.readable(((@tax_amount - @みなし仕入税額) / 100).floor * 100)
35
+ @譲渡割額 = (@税額 * 地方税率 / (税率*100)).floor * 100
36
+ @中間納付額 = prepaid_tax('185B')
37
+ @地方税中間納付額 = prepaid_tax('185C')
38
+
39
+ if export
40
+ {
41
+ kokuzei: {
42
+ zeigaku: @税額,
43
+ chukan: @中間納付額
44
+ },
45
+ chihou: {
46
+ zeigaku: @譲渡割額,
47
+ chukan: @地方税中間納付額
48
+ }
49
+ }
50
+ else
51
+ @procedure_code = 'RSH0040'
52
+ @procedure_name = '消費税及び地方消費税申告(簡易課税・法人)'
53
+ @version = '20.0.0'
54
+ @form_sec = ['SHA020', 'SHB047', 'SHB067'].map{ |c| form_rdf(c) }.join('')
55
+ @it = it_part
56
+ @form_data = [申告書簡易課税, 付表四の三, 付表五の三].join("\n")
57
+ render_erb(search_template('consumption.xtx.erb'))
58
+ end
59
+ end
60
+
61
+ def 申告書簡易課税
62
+ render_erb(search_template('syouhizei-shinkoku-kanni.xml.erb'))
63
+ end
64
+
65
+ def 付表四の三
66
+ render_erb(search_template('fuhyo43.xml.erb'))
67
+ end
68
+
69
+ def 付表五の三
70
+ render_erb(search_template('fuhyo53.xml.erb'))
71
+ end
72
+
73
+ def export_json
74
+ dat = kani(export: true)
75
+ [].tap do |res|
76
+ item = {}
77
+ item['date'] = @end_date
78
+ item['debit'] = []
79
+ item['credit'] = []
80
+ if dat[:kokuzei][:chukan] > 0
81
+ item['credit'] << { 'label' => '仮払消費税', 'amount' => dat[:kokuzei][:chukan] }
82
+ end
83
+ if dat[:kokuzei][:chukan] > dat[:kokuzei][:zeigaku]
84
+ item['debit'] << { 'label' => '未収消費税等', 'amount' => dat[:kokuzei][:chukan] - dat[:kokuzei][:zeigaku] }
85
+ else
86
+ item['credit'] << { 'label' => '未払消費税等', 'amount' => dat[:kokuzei][:zeigaku] - dat[:kokuzei][:chukan] }
87
+ end
88
+ item['debit'] << { 'label' => '消費税', 'amount' => dat[:kokuzei][:zeigaku] }
89
+ if dat[:chihou][:chukan] > 0
90
+ item['credit'] << { 'label' => '仮払地方消費税', 'amount' => dat[:chihou][:chukan] }
91
+ end
92
+ if dat[:chihou][:chukan] > dat[:chihou][:zeigaku]
93
+ item['debit'] << { 'label' => '未収消費税等', 'amount' => dat[:chihou][:chukan] - dat[:chihou][:zeigaku] }
94
+ else
95
+ item['credit'] << { 'label' => '未払消費税等', 'amount' => dat[:chihou][:zeigaku] - dat[:chihou][:chukan] }
96
+ end
97
+ item['debit'] << { 'label' => '消費税', 'amount' => dat[:chihou][:zeigaku] }
98
+ item['x-editor'] = 'LucaJp'
99
+ res << item
100
+ puts JSON.dump(res)
101
+ end
25
102
  end
26
103
 
27
104
  private
28
105
 
106
+ def 課税標準額(課税資産の譲渡等の対価の額)
107
+ (課税資産の譲渡等の対価の額 / 1000).floor * 1000
108
+ end
109
+
29
110
  def みなし仕入率(事業区分)
30
111
  {
31
112
  1 => 90,
@@ -36,6 +117,32 @@ module Luca
36
117
  6 => 40
37
118
  }[事業区分]
38
119
  end
120
+
121
+ def 事業区分
122
+ tags = case LucaSupport::CONFIG.dig('jp', 'syouhizei_kubun')
123
+ when 1
124
+ ['ABL00030', 'ABL00040', 'ABL00050']
125
+ when 2
126
+ ['ABL00060', 'ABL00070', 'ABL00080']
127
+ when 3
128
+ ['ABL00090', 'ABL00100', 'ABL00110']
129
+ when 4
130
+ ['ABL00120', 'ABL00130', 'ABL00140']
131
+ when 5
132
+ ['ABL00150', 'ABL00160', 'ABL00170']
133
+ when 6
134
+ ['ABL00180', 'ABL00190', 'ABL00200']
135
+ else
136
+ return nil
137
+ end
138
+ amount = render_attr(tags[1], LucaSupport::Code.readable(@sales))
139
+ share = render_attr(tags[2], '100.0')
140
+ render_attr(tags[0], [amount, share].join(''))
141
+ end
142
+
143
+ def lib_path
144
+ __dir__
145
+ end
39
146
  end
40
147
  end
41
148
  end
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2
+ <DATA id="DATA" xmlns="http://xml.e-tax.nta.go.jp/XSD/hojin" xmlns:gen="http://xml.e-tax.nta.go.jp/XSD/general" xmlns:kyo="http://xml.e-tax.nta.go.jp/XSD/kyotsu" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <<%= @procedure_code %> VR="<%= @version %>" id="<%= @procedure_code %>">
4
+ <CATALOG id="CATALOG">
5
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
6
+ <rdf:description id="REPORT">
7
+ <SEND_DATA/>
8
+ <FORM_SEC><rdf:Seq><%= @form_sec %></rdf:Seq></FORM_SEC>
9
+ <IT_SEC><rdf:description about="#IT"/></IT_SEC>
10
+ <TENPU_SEC/><XBRL_SEC/><XBRL_2_1_SEC/>
11
+ <SOFUSHO_SEC/><ATTACH_SEC/><CSV_SEC/>
12
+ </rdf:description>
13
+ </rdf:RDF>
14
+ </CATALOG>
15
+ <CONTENTS id="CONTENTS">
16
+
17
+ <%= @it %>
18
+ <%= @form_data %>
19
+ </CONTENTS>
20
+ </<%= @procedure_code %>>
21
+ </DATA>
@@ -0,0 +1,31 @@
1
+ <HOA116 page="1" VR="1.0" id="HOA116" sakuseiNM="<%= @company %>" softNM="<%= @software %> <%= @company %>" sakuseiDay="<%= @issue_date %>">
2
+
3
+ <QHA00000><QHA00010>
4
+ <QHA00020 IDREF="JIGYO_NENDO_FROM"/>
5
+ <QHA00030 IDREF="JIGYO_NENDO_TO"/>
6
+ </QHA00010>
7
+ <QHA00040 IDREF="NOZEISHA_NM"/>
8
+ </QHA00000>
9
+ <QHB00000>
10
+ <QHB00010>
11
+ <%= render_attr('QHB00020', '12') %>
12
+ <%= render_attr('QHB00030', 中小企業の軽減税率対象所得) %>
13
+ </QHB00010>
14
+ <%= render_attr('QHB00070', 中小企業の軽減税率対象を超える所得) %>
15
+ <QHB00080>
16
+ <QHB00090><kubun_CD>1</kubun_CD></QHB00090><%# 15% %>
17
+ <%= render_attr('QHB00100', 中小企業の軽減税額) %>
18
+ </QHB00080>
19
+ <QHB00120>
20
+ <QHB00130><kubun_CD>2</kubun_CD></QHB00130><%# 23.2% %>
21
+ <%= render_attr('QHB00140', 一般区分の税額) %>
22
+ </QHB00120>
23
+ </QHB00000>
24
+ <QHC00000>
25
+ <%= render_attr('QHC00010', @地方法人税課税標準) %>
26
+ <QHC00030>
27
+ <QHC00040><kubun_CD>2</kubun_CD></QHC00040><%# 10.3% %>
28
+ <%= render_attr('QHC00050', 地方法人税額(@地方法人税課税標準)) %>
29
+ </QHC00030>
30
+ </QHC00000>
31
+ </HOA116>