0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

インボイス制度の消費税端数処理、明細行ごとに丸めていませんか?(npmパッケージ公開しました)

0
Posted at

この記事で言いたいこと

インボイス制度(適格請求書等保存方式)では、消費税の端数処理について次のルールがあります。

1つの適格請求書につき、税率ごとに1回の端数処理を行う

これを知らずに「明細行ごとに消費税を計算して端数処理し、それを合計する」実装をしてしまうと、正しい合計額と1円単位でずれることがあります。これが現場でよく報告される「消費税の1円のずれ」の正体です。

このルールに準拠した計算をしてくれるnpmパッケージ jp-invoice-tax を作って公開したので、その内容を紹介します。

具体例で見る「1円のずれ」

333円の商品を3つ、税率10%で購入したケースを考えます。

正しい方法(割戻し計算): 明細を合計してから1回だけ端数処理

999円 × 10% = 99.9円 → 四捨五入 → 100円

ありがちな間違い(積上げ計算): 明細行ごとに端数処理してから合計

333円 × 10% = 33.3円 → 33円(四捨五入)
33円 × 3行 = 99円

同じ入力なのに、消費税額が100円と99円で1円変わってしまいます。どちらも計算方法として間違ってはいませんが、請求書に記載する消費税額としてはどちらか一方に統一する必要があり、実装によって結果が食い違うことが問題になります。

jp-invoice-tax

依存パッケージなし、TypeScript製、MITライセンスのライブラリです。

インストール

npm install jp-invoice-tax

使い方

import { calculateInvoiceTax } from "jp-invoice-tax";

const result = calculateInvoiceTax(
  [
    { name: "商品A", unitPrice: 333, quantity: 1, taxRate: 0.10 },
    { name: "商品B", unitPrice: 333, quantity: 1, taxRate: 0.10 },
    { name: "商品C", unitPrice: 333, quantity: 1, taxRate: 0.10 },
  ],
  { method: "total", roundingMode: "round" }
);

console.log(result.taxTotal); // 100

method オプションを "per-line" にすると積上げ計算に切り替わり、taxTotal が 99 になります。どちらの方式を使うかをコードで明示的に選べるようにすることで、「知らないうちに間違った方式で実装していた」という事故を防げます。

軽減税率(8%)と標準税率(10%)が混在する請求書も、税率ごとに自動で区分して計算します。

const result = calculateInvoiceTax([
  { name: "食料品", unitPrice: 1000, quantity: 1, taxRate: 0.08 },
  { name: "備品",   unitPrice: 1000, quantity: 1, taxRate: 0.10 },
]);
// taxRate: 0.08 と 0.10 の2グループに分かれる

税込単価から計算したい場合は priceType: "inclusive" を指定します。

calculateInvoiceTax([{ unitPrice: 1100, quantity: 1, taxRate: 0.10 }], {
  priceType: "inclusive",
});
// => subtotal: 1000, taxTotal: 100, total: 1100

既存の実装が積上げ計算になっていないか監査したい場合は、compareCalculationMethods で両方式を同時に計算し、差額を確認できます。

import { compareCalculationMethods } from "jp-invoice-tax";

const comparison = compareCalculationMethods(items);
comparison.matches;      // 両方式で一致するか
comparison.taxTotalDiff; // 差額(円)

テストについて

Node.js標準の node:test でテストを書いており、GitHub ActionsでNode.js 18/20/22に対して自動実行しています。現時点で9件のテストがすべてパスしています。

免責事項

このライブラリは国税庁が公表している端数処理ルールに沿った計算ロジックを提供するものであり、税務・法務上の助言ではありません。返品・値引きなど個別の税務判断が必要なケースは税理士等の専門家にご確認ください。

リンク

同じ課題を感じたことがある方の参考になれば幸いです。フィードバックやIssue、PR、お待ちしています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?