j-law-ruby 0.0.3

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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +109 -0
  4. data/Rakefile +87 -0
  5. data/ext/j_law_ruby/extconf.rb +34 -0
  6. data/lib/j_law_ruby/build_support.rb +129 -0
  7. data/lib/j_law_ruby/c_ffi.rb +662 -0
  8. data/lib/j_law_ruby.rb +532 -0
  9. data/rake_support/vendor_rust.rb +51 -0
  10. data/test/test_c_ffi_adapter.rb +46 -0
  11. data/test/test_consumption_tax.rb +66 -0
  12. data/test/test_gemspec.rb +82 -0
  13. data/test/test_income_tax.rb +77 -0
  14. data/test/test_income_tax_deductions.rb +82 -0
  15. data/test/test_real_estate.rb +98 -0
  16. data/test/test_stamp_tax.rb +68 -0
  17. data/test/test_withholding_tax.rb +65 -0
  18. data/vendor/rust/Cargo.lock +235 -0
  19. data/vendor/rust/Cargo.toml +12 -0
  20. data/vendor/rust/crates/j-law-c-ffi/Cargo.toml +20 -0
  21. data/vendor/rust/crates/j-law-c-ffi/j_law_c_ffi.h +493 -0
  22. data/vendor/rust/crates/j-law-c-ffi/src/lib.rs +1553 -0
  23. data/vendor/rust/crates/j-law-core/Cargo.toml +18 -0
  24. data/vendor/rust/crates/j-law-core/src/domains/consumption_tax/calculator.rs +216 -0
  25. data/vendor/rust/crates/j-law-core/src/domains/consumption_tax/context.rs +29 -0
  26. data/vendor/rust/crates/j-law-core/src/domains/consumption_tax/mod.rs +9 -0
  27. data/vendor/rust/crates/j-law-core/src/domains/consumption_tax/params.rs +24 -0
  28. data/vendor/rust/crates/j-law-core/src/domains/consumption_tax/policy.rs +34 -0
  29. data/vendor/rust/crates/j-law-core/src/domains/income_tax/assessment.rs +76 -0
  30. data/vendor/rust/crates/j-law-core/src/domains/income_tax/calculator.rs +222 -0
  31. data/vendor/rust/crates/j-law-core/src/domains/income_tax/context.rs +79 -0
  32. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/calculator.rs +167 -0
  33. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/context.rs +172 -0
  34. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/expense.rs +465 -0
  35. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/mod.rs +20 -0
  36. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/params.rs +205 -0
  37. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/personal.rs +324 -0
  38. data/vendor/rust/crates/j-law-core/src/domains/income_tax/deduction/types.rs +61 -0
  39. data/vendor/rust/crates/j-law-core/src/domains/income_tax/mod.rs +24 -0
  40. data/vendor/rust/crates/j-law-core/src/domains/income_tax/params.rs +109 -0
  41. data/vendor/rust/crates/j-law-core/src/domains/income_tax/policy.rs +103 -0
  42. data/vendor/rust/crates/j-law-core/src/domains/mod.rs +5 -0
  43. data/vendor/rust/crates/j-law-core/src/domains/real_estate/calculator.rs +197 -0
  44. data/vendor/rust/crates/j-law-core/src/domains/real_estate/context.rs +48 -0
  45. data/vendor/rust/crates/j-law-core/src/domains/real_estate/mod.rs +9 -0
  46. data/vendor/rust/crates/j-law-core/src/domains/real_estate/params.rs +43 -0
  47. data/vendor/rust/crates/j-law-core/src/domains/real_estate/policy.rs +40 -0
  48. data/vendor/rust/crates/j-law-core/src/domains/stamp_tax/calculator.rs +321 -0
  49. data/vendor/rust/crates/j-law-core/src/domains/stamp_tax/context.rs +408 -0
  50. data/vendor/rust/crates/j-law-core/src/domains/stamp_tax/mod.rs +12 -0
  51. data/vendor/rust/crates/j-law-core/src/domains/stamp_tax/params.rs +190 -0
  52. data/vendor/rust/crates/j-law-core/src/domains/stamp_tax/policy.rs +105 -0
  53. data/vendor/rust/crates/j-law-core/src/domains/withholding_tax/calculator.rs +247 -0
  54. data/vendor/rust/crates/j-law-core/src/domains/withholding_tax/context.rs +167 -0
  55. data/vendor/rust/crates/j-law-core/src/domains/withholding_tax/mod.rs +9 -0
  56. data/vendor/rust/crates/j-law-core/src/domains/withholding_tax/params.rs +80 -0
  57. data/vendor/rust/crates/j-law-core/src/domains/withholding_tax/policy.rs +49 -0
  58. data/vendor/rust/crates/j-law-core/src/error.rs +171 -0
  59. data/vendor/rust/crates/j-law-core/src/lib.rs +9 -0
  60. data/vendor/rust/crates/j-law-core/src/types/amount.rs +232 -0
  61. data/vendor/rust/crates/j-law-core/src/types/citation.rs +82 -0
  62. data/vendor/rust/crates/j-law-core/src/types/date.rs +280 -0
  63. data/vendor/rust/crates/j-law-core/src/types/mod.rs +11 -0
  64. data/vendor/rust/crates/j-law-core/src/types/rate.rs +219 -0
  65. data/vendor/rust/crates/j-law-core/src/types/rounding.rs +81 -0
  66. data/vendor/rust/crates/j-law-registry/Cargo.toml +15 -0
  67. data/vendor/rust/crates/j-law-registry/data/consumption_tax/consumption_tax.json +70 -0
  68. data/vendor/rust/crates/j-law-registry/data/income_tax/deductions.json +327 -0
  69. data/vendor/rust/crates/j-law-registry/data/income_tax/income_tax.json +352 -0
  70. data/vendor/rust/crates/j-law-registry/data/real_estate/brokerage_fee.json +125 -0
  71. data/vendor/rust/crates/j-law-registry/data/stamp_tax/stamp_tax.json +674 -0
  72. data/vendor/rust/crates/j-law-registry/data/withholding_tax/withholding_tax.json +70 -0
  73. data/vendor/rust/crates/j-law-registry/src/consumption_tax_loader.rs +325 -0
  74. data/vendor/rust/crates/j-law-registry/src/consumption_tax_schema.rs +49 -0
  75. data/vendor/rust/crates/j-law-registry/src/income_tax_deduction_loader.rs +636 -0
  76. data/vendor/rust/crates/j-law-registry/src/income_tax_deduction_schema.rs +111 -0
  77. data/vendor/rust/crates/j-law-registry/src/income_tax_loader.rs +445 -0
  78. data/vendor/rust/crates/j-law-registry/src/income_tax_schema.rs +44 -0
  79. data/vendor/rust/crates/j-law-registry/src/lib.rs +20 -0
  80. data/vendor/rust/crates/j-law-registry/src/loader.rs +221 -0
  81. data/vendor/rust/crates/j-law-registry/src/schema.rs +73 -0
  82. data/vendor/rust/crates/j-law-registry/src/stamp_tax_loader.rs +374 -0
  83. data/vendor/rust/crates/j-law-registry/src/stamp_tax_schema.rs +72 -0
  84. data/vendor/rust/crates/j-law-registry/src/validator.rs +204 -0
  85. data/vendor/rust/crates/j-law-registry/src/withholding_tax_loader.rs +310 -0
  86. data/vendor/rust/crates/j-law-registry/src/withholding_tax_schema.rs +61 -0
  87. metadata +148 -0
@@ -0,0 +1,493 @@
1
+ #ifndef J_LAW_C_FFI_H
2
+ #define J_LAW_C_FFI_H
3
+
4
+ #include <stdint.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ /* ─── 定数 ───────────────────────────────────────────────────────────────── */
11
+
12
+ /** ティア内訳の最大件数。現行法令では 3 ティアだが余裕を持たせている。 */
13
+ #define J_LAW_MAX_TIERS 8
14
+
15
+ /** 所得控除内訳の最大件数。 */
16
+ #define J_LAW_MAX_DEDUCTION_LINES 8
17
+
18
+ /** ティアラベルの最大バイト長(NUL 終端含む)。 */
19
+ #define J_LAW_LABEL_LEN 64
20
+
21
+ /** エラーバッファの推奨バイト長。 */
22
+ #define J_LAW_ERROR_BUF_LEN 256
23
+
24
+ /** j-law-c-ffi の FFI 互換バージョン。 */
25
+ #define J_LAW_C_FFI_VERSION 4
26
+
27
+ /** 所得控除種別定数。 */
28
+ #define J_LAW_INCOME_DEDUCTION_KIND_BASIC 1
29
+ #define J_LAW_INCOME_DEDUCTION_KIND_SPOUSE 2
30
+ #define J_LAW_INCOME_DEDUCTION_KIND_DEPENDENT 3
31
+ #define J_LAW_INCOME_DEDUCTION_KIND_SOCIAL_INSURANCE 4
32
+ #define J_LAW_INCOME_DEDUCTION_KIND_MEDICAL 5
33
+ #define J_LAW_INCOME_DEDUCTION_KIND_LIFE_INSURANCE 6
34
+ #define J_LAW_INCOME_DEDUCTION_KIND_DONATION 7
35
+
36
+ /** 源泉徴収カテゴリ定数。 */
37
+ #define J_LAW_WITHHOLDING_TAX_CATEGORY_MANUSCRIPT_AND_LECTURE 1
38
+ #define J_LAW_WITHHOLDING_TAX_CATEGORY_PROFESSIONAL_FEE 2
39
+ #define J_LAW_WITHHOLDING_TAX_CATEGORY_EXCLUSIVE_CONTRACT_FEE 3
40
+
41
+ /* ─── 構造体 ─────────────────────────────────────────────────────────────── */
42
+
43
+ /**
44
+ * 1 ティアの計算内訳。
45
+ */
46
+ typedef struct {
47
+ /** ティアラベル(NUL 終端・最大 63 文字)。 */
48
+ char label[J_LAW_LABEL_LEN];
49
+ /** ティア対象金額(円)。 */
50
+ uint64_t base_amount;
51
+ uint64_t rate_numer;
52
+ uint64_t rate_denom;
53
+ /** ティア計算結果(円・端数切捨て済み)。 */
54
+ uint64_t result;
55
+ } JLawBreakdownStep;
56
+
57
+ /**
58
+ * 媒介報酬の計算結果。
59
+ */
60
+ typedef struct {
61
+ /** 税抜合計額(円)。 */
62
+ uint64_t total_without_tax;
63
+ /** 税込合計額(円)。 */
64
+ uint64_t total_with_tax;
65
+ /** 消費税額(円)。 */
66
+ uint64_t tax_amount;
67
+ /** 低廉な空き家特例が適用されたか(0 = false, 1 = true)。 */
68
+ int low_cost_special_applied;
69
+ /** 各ティアの計算内訳(breakdown_len 件が有効)。 */
70
+ JLawBreakdownStep breakdown[J_LAW_MAX_TIERS];
71
+ /** breakdown の有効件数。 */
72
+ int breakdown_len;
73
+ } JLawBrokerageFeeResult;
74
+
75
+ /* ─── 関数 ───────────────────────────────────────────────────────────────── */
76
+
77
+ /**
78
+ * j-law-c-ffi の FFI バージョンを返す。
79
+ *
80
+ * Ruby / Go バインディングはロード時にこの値を確認し、
81
+ * 期待する C FFI と一致するかを検証する。
82
+ */
83
+ uint32_t j_law_c_ffi_version(void);
84
+
85
+ /**
86
+ * 宅建業法第46条に基づく媒介報酬を計算する。
87
+ *
88
+ * 法的根拠: 宅地建物取引業法 第46条第1項 / 国土交通省告示
89
+ *
90
+ * @param price 売買価格(円)
91
+ * @param year 基準日(年)
92
+ * @param month 基準日(月)
93
+ * @param day 基準日(日)
94
+ * @param is_low_cost_vacant_house 低廉な空き家特例フラグ(0 = false, 非0 = true)
95
+ * WARNING: 事実認定は呼び出し元の責任。
96
+ * @param is_seller 売主側フラグ(0 = false, 非0 = true)
97
+ * 2018年1月1日〜2024年6月30日の低廉特例は売主のみ適用。
98
+ * WARNING: 売主・買主の事実認定は呼び出し元の責任。
99
+ * @param out_result [OUT] 計算結果の書き込み先(呼び出し元が確保すること)
100
+ * @param error_buf [OUT] エラーメッセージの書き込み先(呼び出し元が確保すること)
101
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
102
+ * @return 成功時 0、失敗時 非0
103
+ */
104
+ int j_law_calc_brokerage_fee(
105
+ uint64_t price,
106
+ uint16_t year,
107
+ uint8_t month,
108
+ uint8_t day,
109
+ int is_low_cost_vacant_house,
110
+ int is_seller,
111
+ JLawBrokerageFeeResult *out_result,
112
+ char *error_buf,
113
+ int error_buf_len
114
+ );
115
+
116
+ /* ─── 源泉徴収 構造体 ─────────────────────────────────────────────────────── */
117
+
118
+ /**
119
+ * 源泉徴収税額の計算結果。
120
+ */
121
+ typedef struct {
122
+ /** 支払総額(円)。 */
123
+ uint64_t gross_payment_amount;
124
+ /** 源泉徴収税額の計算対象額(円)。 */
125
+ uint64_t taxable_payment_amount;
126
+ /** 源泉徴収税額(円)。 */
127
+ uint64_t tax_amount;
128
+ /** 源泉徴収後の支払額(円)。 */
129
+ uint64_t net_payment_amount;
130
+ /** カテゴリコード(J_LAW_WITHHOLDING_TAX_CATEGORY_*)。 */
131
+ uint32_t category;
132
+ /** 応募作品等の入選賞金・謝金の非課税特例を適用したか(0 = false, 1 = true)。 */
133
+ int submission_prize_exempted;
134
+ /** 計算内訳(breakdown_len 件が有効)。 */
135
+ JLawBreakdownStep breakdown[J_LAW_MAX_TIERS];
136
+ /** breakdown の有効件数。 */
137
+ int breakdown_len;
138
+ } JLawWithholdingTaxResult;
139
+
140
+ /* ─── 源泉徴収 関数 ───────────────────────────────────────────────────────── */
141
+
142
+ /**
143
+ * 所得税法第204条第1項に基づく報酬・料金等の源泉徴収税額を計算する。
144
+ *
145
+ * 法的根拠: 所得税法 第204条第1項 / 国税庁タックスアンサー No.2795 / No.2798 / No.2810
146
+ *
147
+ * @param payment_amount 支払総額(円)
148
+ * @param separated_consumption_tax_amount 区分表示された消費税額(円)
149
+ * @param year 基準日(年)
150
+ * @param month 基準日(月)
151
+ * @param day 基準日(日)
152
+ * @param category カテゴリコード(J_LAW_WITHHOLDING_TAX_CATEGORY_*)
153
+ * @param is_submission_prize 応募作品等の入選賞金・謝金として扱うか(0 = false, 非0 = true)
154
+ * WARNING: 事実認定は呼び出し元の責任。
155
+ * @param out_result [OUT] 計算結果の書き込み先
156
+ * @param error_buf [OUT] エラーメッセージの書き込み先
157
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
158
+ * @return 成功時 0、失敗時 非0
159
+ */
160
+ int j_law_calc_withholding_tax(
161
+ uint64_t payment_amount,
162
+ uint64_t separated_consumption_tax_amount,
163
+ uint16_t year,
164
+ uint8_t month,
165
+ uint8_t day,
166
+ uint32_t category,
167
+ int is_submission_prize,
168
+ JLawWithholdingTaxResult *out_result,
169
+ char *error_buf,
170
+ int error_buf_len
171
+ );
172
+
173
+ /* ─── 所得税 構造体 ───────────────────────────────────────────────────────── */
174
+
175
+ /**
176
+ * 所得税の計算内訳(速算表の適用結果)。
177
+ */
178
+ typedef struct {
179
+ /** ラベル(NUL 終端・最大 63 文字)。 */
180
+ char label[J_LAW_LABEL_LEN];
181
+ /** 課税所得金額(円)。 */
182
+ uint64_t taxable_income;
183
+ uint64_t rate_numer;
184
+ uint64_t rate_denom;
185
+ /** 速算表の控除額(円)。 */
186
+ uint64_t deduction;
187
+ /** 算出税額(円)。 */
188
+ uint64_t result;
189
+ } JLawIncomeTaxStep;
190
+
191
+ /**
192
+ * 所得税の計算結果。
193
+ */
194
+ typedef struct {
195
+ /** 基準所得税額(円)。 */
196
+ uint64_t base_tax;
197
+ /** 復興特別所得税額(円)。 */
198
+ uint64_t reconstruction_tax;
199
+ /** 申告納税額(円・100円未満切り捨て)。 */
200
+ uint64_t total_tax;
201
+ /** 復興特別所得税が適用されたか(0 = false, 1 = true)。 */
202
+ int reconstruction_tax_applied;
203
+ /** 計算内訳(breakdown_len 件が有効)。 */
204
+ JLawIncomeTaxStep breakdown[J_LAW_MAX_TIERS];
205
+ /** breakdown の有効件数。 */
206
+ int breakdown_len;
207
+ } JLawIncomeTaxResult;
208
+
209
+ /**
210
+ * 所得控除の内訳1行。
211
+ */
212
+ typedef struct {
213
+ /** 控除種別定数(J_LAW_INCOME_DEDUCTION_KIND_*)。 */
214
+ uint32_t kind;
215
+ /** ラベル(NUL 終端・最大 63 文字)。 */
216
+ char label[J_LAW_LABEL_LEN];
217
+ /** 控除額(円)。 */
218
+ uint64_t amount;
219
+ } JLawIncomeDeductionLine;
220
+
221
+ /**
222
+ * 所得控除計算の入力。
223
+ */
224
+ typedef struct {
225
+ uint64_t total_income_amount;
226
+ uint16_t year;
227
+ uint8_t month;
228
+ uint8_t day;
229
+ int has_spouse;
230
+ uint64_t spouse_total_income_amount;
231
+ int spouse_is_same_household;
232
+ int spouse_is_elderly;
233
+ uint64_t dependent_general_count;
234
+ uint64_t dependent_specific_count;
235
+ uint64_t dependent_elderly_cohabiting_count;
236
+ uint64_t dependent_elderly_other_count;
237
+ uint64_t social_insurance_premium_paid;
238
+ int has_medical;
239
+ uint64_t medical_expense_paid;
240
+ uint64_t medical_reimbursed_amount;
241
+ int has_life_insurance;
242
+ uint64_t life_new_general_paid_amount;
243
+ uint64_t life_new_individual_pension_paid_amount;
244
+ uint64_t life_new_care_medical_paid_amount;
245
+ uint64_t life_old_general_paid_amount;
246
+ uint64_t life_old_individual_pension_paid_amount;
247
+ int has_donation;
248
+ uint64_t donation_qualified_amount;
249
+ } JLawIncomeDeductionInput;
250
+
251
+ /**
252
+ * 所得控除の計算結果。
253
+ */
254
+ typedef struct {
255
+ uint64_t total_income_amount;
256
+ uint64_t total_deductions;
257
+ uint64_t taxable_income_before_truncation;
258
+ uint64_t taxable_income;
259
+ JLawIncomeDeductionLine breakdown[J_LAW_MAX_DEDUCTION_LINES];
260
+ int breakdown_len;
261
+ } JLawIncomeDeductionResult;
262
+
263
+ /**
264
+ * 所得控除から所得税額までの通し計算結果。
265
+ */
266
+ typedef struct {
267
+ uint64_t total_income_amount;
268
+ uint64_t total_deductions;
269
+ uint64_t taxable_income_before_truncation;
270
+ uint64_t taxable_income;
271
+ uint64_t base_tax;
272
+ uint64_t reconstruction_tax;
273
+ uint64_t total_tax;
274
+ int reconstruction_tax_applied;
275
+ JLawIncomeDeductionLine deduction_breakdown[J_LAW_MAX_DEDUCTION_LINES];
276
+ int deduction_breakdown_len;
277
+ JLawIncomeTaxStep tax_breakdown[J_LAW_MAX_TIERS];
278
+ int tax_breakdown_len;
279
+ } JLawIncomeTaxAssessmentResult;
280
+
281
+ /* ─── 所得税 関数 ─────────────────────────────────────────────────────────── */
282
+
283
+ /**
284
+ * 所得税法第89条に基づく所得税額を計算する。
285
+ *
286
+ * 法的根拠: 所得税法 第89条第1項 / 復興財源確保法 第13条
287
+ *
288
+ * @param taxable_income 課税所得金額(円)
289
+ * @param year 対象年度(年)
290
+ * @param month 基準日(月)
291
+ * @param day 基準日(日)
292
+ * @param apply_reconstruction_tax 復興特別所得税を適用するか(0 = false, 非0 = true)
293
+ * @param out_result [OUT] 計算結果の書き込み先(呼び出し元が確保すること)
294
+ * @param error_buf [OUT] エラーメッセージの書き込み先(呼び出し元が確保すること)
295
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
296
+ * @return 成功時 0、失敗時 非0
297
+ */
298
+ int j_law_calc_income_tax(
299
+ uint64_t taxable_income,
300
+ uint16_t year,
301
+ uint8_t month,
302
+ uint8_t day,
303
+ int apply_reconstruction_tax,
304
+ JLawIncomeTaxResult *out_result,
305
+ char *error_buf,
306
+ int error_buf_len
307
+ );
308
+
309
+ /**
310
+ * 所得控除額を計算し、課税所得金額までを返す。
311
+ *
312
+ * 法的根拠: 所得税法 第73条 / 第74条 / 第76条 / 第78条 / 第83条 / 第84条 / 第86条
313
+ *
314
+ * @param input [IN] 所得控除計算の入力
315
+ * @param out_result [OUT] 計算結果の書き込み先
316
+ * @param error_buf [OUT] エラーメッセージの書き込み先
317
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
318
+ * @return 成功時 0、失敗時 非0
319
+ */
320
+ int j_law_calc_income_deductions(
321
+ const JLawIncomeDeductionInput *input,
322
+ JLawIncomeDeductionResult *out_result,
323
+ char *error_buf,
324
+ int error_buf_len
325
+ );
326
+
327
+ /**
328
+ * 所得控除から所得税額までを通しで計算する。
329
+ *
330
+ * 法的根拠: 所得税法 第73条 / 第74条 / 第76条 / 第78条 / 第83条 / 第84条 / 第86条 /
331
+ * 第89条第1項 / 復興財源確保法 第13条
332
+ *
333
+ * @param input [IN] 所得控除計算の入力
334
+ * @param apply_reconstruction_tax 復興特別所得税を適用するか(0 = false, 非0 = true)
335
+ * @param out_result [OUT] 計算結果の書き込み先
336
+ * @param error_buf [OUT] エラーメッセージの書き込み先
337
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
338
+ * @return 成功時 0、失敗時 非0
339
+ */
340
+ int j_law_calc_income_tax_assessment(
341
+ const JLawIncomeDeductionInput *input,
342
+ int apply_reconstruction_tax,
343
+ JLawIncomeTaxAssessmentResult *out_result,
344
+ char *error_buf,
345
+ int error_buf_len
346
+ );
347
+
348
+ /* ─── 消費税 構造体 ───────────────────────────────────────────────────────── */
349
+
350
+ /**
351
+ * 消費税の計算結果。
352
+ */
353
+ typedef struct {
354
+ /** 消費税額(円)。 */
355
+ uint64_t tax_amount;
356
+ /** 税込金額(円)。 */
357
+ uint64_t amount_with_tax;
358
+ /** 税抜金額(円)。 */
359
+ uint64_t amount_without_tax;
360
+ /** 適用税率の分子。 */
361
+ uint64_t applied_rate_numer;
362
+ /** 適用税率の分母。 */
363
+ uint64_t applied_rate_denom;
364
+ /** 軽減税率が適用されたか(0 = false, 1 = true)。 */
365
+ int is_reduced_rate;
366
+ } JLawConsumptionTaxResult;
367
+
368
+ /* ─── 消費税 関数 ─────────────────────────────────────────────────────────── */
369
+
370
+ /**
371
+ * 消費税法第29条に基づく消費税額を計算する。
372
+ *
373
+ * 法的根拠: 消費税法 第29条(税率)
374
+ *
375
+ * @param amount 課税標準額(税抜き・円)
376
+ * @param year 基準日(年)
377
+ * @param month 基準日(月)
378
+ * @param day 基準日(日)
379
+ * @param is_reduced_rate 軽減税率フラグ(0 = false, 非0 = true)
380
+ * 2019-10-01以降の飲食料品・新聞等に適用される8%軽減税率。
381
+ * WARNING: 事実認定は呼び出し元の責任。
382
+ * @param out_result [OUT] 計算結果の書き込み先(呼び出し元が確保すること)
383
+ * @param error_buf [OUT] エラーメッセージの書き込み先(呼び出し元が確保すること)
384
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
385
+ * @return 成功時 0、失敗時 非0
386
+ */
387
+ int j_law_calc_consumption_tax(
388
+ uint64_t amount,
389
+ uint16_t year,
390
+ uint8_t month,
391
+ uint8_t day,
392
+ int is_reduced_rate,
393
+ JLawConsumptionTaxResult *out_result,
394
+ char *error_buf,
395
+ int error_buf_len
396
+ );
397
+
398
+ /* ─── 印紙税 構造体 ───────────────────────────────────────────────────────── */
399
+
400
+ /**
401
+ * 印紙税の計算結果。
402
+ */
403
+ typedef struct {
404
+ /** 印紙税額(円)。 */
405
+ uint64_t tax_amount;
406
+ /** 適用された税額ルールの表示名(NUL 終端・最大 63 文字)。 */
407
+ char rule_label[J_LAW_LABEL_LEN];
408
+ /** 適用された特例ルールコード(NUL 終端・最大 63 文字)。 */
409
+ char applied_special_rule[J_LAW_LABEL_LEN];
410
+ } JLawStampTaxResult;
411
+
412
+ /**
413
+ * 印紙税の文書コード。
414
+ */
415
+ typedef enum {
416
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE1_REAL_ESTATE_TRANSFER = 1,
417
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE1_OTHER_TRANSFER = 2,
418
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE1_LAND_LEASE_OR_SURFACE_RIGHT = 3,
419
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE1_CONSUMPTION_LOAN = 4,
420
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE1_TRANSPORTATION = 5,
421
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE2_CONSTRUCTION_WORK = 6,
422
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE2_GENERAL_CONTRACT = 7,
423
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE3_BILL_AMOUNT_TABLE = 8,
424
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE3_BILL_SPECIAL_FLAT_200 = 9,
425
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE4_SECURITY_CERTIFICATE = 10,
426
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE5_MERGER_OR_SPLIT = 11,
427
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE6_ARTICLES_OF_INCORPORATION = 12,
428
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE7_CONTINUING_TRANSACTION_BASIC = 13,
429
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE8_DEPOSIT_CERTIFICATE = 14,
430
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE9_TRANSPORT_CERTIFICATE = 15,
431
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE10_INSURANCE_CERTIFICATE = 16,
432
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE11_LETTER_OF_CREDIT = 17,
433
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE12_TRUST_CONTRACT = 18,
434
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE13_DEBT_GUARANTEE = 19,
435
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE14_DEPOSIT_CONTRACT = 20,
436
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE15_ASSIGNMENT_OR_ASSUMPTION = 21,
437
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE16_DIVIDEND_RECEIPT = 22,
438
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE17_SALES_RECEIPT = 23,
439
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE17_OTHER_RECEIPT = 24,
440
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE18_PASSBOOK = 25,
441
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE19_MISC_PASSBOOK = 26,
442
+ J_LAW_STAMP_TAX_DOCUMENT_ARTICLE20_SEAL_BOOK = 27
443
+ } JLawStampTaxDocumentCode;
444
+
445
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE3_COPY_OR_TRANSCRIPT_EXEMPT (1ULL << 0)
446
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE4_SPECIFIED_ISSUER_EXEMPT (1ULL << 1)
447
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE4_RESTRICTED_BENEFICIARY_CERTIFICATE_EXEMPT (1ULL << 2)
448
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE6_NOTARY_COPY_EXEMPT (1ULL << 3)
449
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE8_SMALL_DEPOSIT_EXEMPT (1ULL << 4)
450
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE13_IDENTITY_GUARANTEE_EXEMPT (1ULL << 5)
451
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE17_NON_BUSINESS_EXEMPT (1ULL << 6)
452
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE17_APPENDED_RECEIPT_EXEMPT (1ULL << 7)
453
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE18_SPECIFIED_FINANCIAL_INSTITUTION_EXEMPT (1ULL << 8)
454
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE18_INCOME_TAX_EXEMPT_PASSBOOK (1ULL << 9)
455
+ #define J_LAW_STAMP_TAX_FLAG_ARTICLE18_TAX_RESERVE_DEPOSIT_PASSBOOK (1ULL << 10)
456
+
457
+ /* ─── 印紙税 関数 ─────────────────────────────────────────────────────────── */
458
+
459
+ /**
460
+ * 印紙税法 別表第一に基づく印紙税額を計算する。
461
+ *
462
+ * 法的根拠: 印紙税法 別表第一 / 租税特別措置法 第91条
463
+ *
464
+ * @param document_code 文書コード(JLawStampTaxDocumentCode)
465
+ * @param stated_amount 記載金額、受取金額、券面金額など
466
+ * @param has_stated_amount stated_amount を使う場合は非0、未記載文書なら 0
467
+ * @param year 契約書作成日(年)
468
+ * @param month 契約書作成日(月)
469
+ * @param day 契約書作成日(日)
470
+ * @param flags_bitset 主な非課税文書フラグの bit OR
471
+ * @param out_result [OUT] 計算結果の書き込み先(呼び出し元が確保すること)
472
+ * @param error_buf [OUT] エラーメッセージの書き込み先(呼び出し元が確保すること)
473
+ * @param error_buf_len error_buf のバイト長(推奨: J_LAW_ERROR_BUF_LEN = 256)
474
+ * @return 成功時 0、失敗時 非0
475
+ */
476
+ int j_law_calc_stamp_tax(
477
+ uint32_t document_code,
478
+ uint64_t stated_amount,
479
+ int has_stated_amount,
480
+ uint16_t year,
481
+ uint8_t month,
482
+ uint8_t day,
483
+ uint64_t flags_bitset,
484
+ JLawStampTaxResult *out_result,
485
+ char *error_buf,
486
+ int error_buf_len
487
+ );
488
+
489
+ #ifdef __cplusplus
490
+ }
491
+ #endif
492
+
493
+ #endif /* J_LAW_C_FFI_H */