Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YukiYamashina/c3db2102eeabfb8b2dda5f8d9a3f2af2 to your computer and use it in GitHub Desktop.
Save YukiYamashina/c3db2102eeabfb8b2dda5f8d9a3f2af2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>免税事業者向けインボイス経過措置による値引き計算</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]" />
</head>
<body style="display:grid;place-items:center;gap:1rem;min-height:auto;">
<h1>免税事業者向けインボイス経過措置による値引き計算</h1>
<label style="display:grid;width:100%;">
<span>税抜本体価格</span>
<div style="display:flex;align-items:center;gap:.5rem">
<input type="text" id="price" placeholder="価格を入力してください" />
<span>円</span>
</div>
</label>
<div style="display:grid;width:100%;">
<span>消費税率</span>
<div style="display:flex;gap:2rem;align-items:center">
<label style="border:var(--border-width) solid var(--border-color);padding:.5rem">
<span>10%</span>
<input type="radio" name="tax" value="0.1" checked />
</label>
<label style="border:var(--border-width) solid var(--border-color);padding:.5rem">
<span>8%</span>
<input type="radio" name="tax" value="0.08" />
</label>
</div>
</div>
<input type="button" value="計算する" onclick="calc()" />
<div style="width:100%">
<h2>請求元の免税事業者側</h2>
<table>
<thead>
<tr>
<th>控除率</th>
<th>値引き額</th>
<th>値引き後の本体価格</th>
<th>消費税</th>
<th>税込合計金額</th>
</tr>
</thead>
<tbody>
<tr>
<td id="r">0</td>
<td id="a">0</td>
<td id="b">0</td>
<td id="c">0</td>
<td id="d">0</td>
</tr>
</tbody>
</table>
<h2>請求先の課税事業者側</h2>
<table>
<thead>
<tr>
<th>消費税控除額</th>
<th>消費税控除後の金額</th>
</tr>
</thead>
<tbody>
<tr>
<td id="e">0</td>
<td id="f">0</td>
</tr>
</tbody>
</table>
</div>
<script>
function calc() {
const price = + document.getElementById('price').value.replace(/,/g, '');
if (isNaN(price)) {
alert('価格を正しく入力してください');
return;
}
const tax = + document.querySelector('input[name="tax"]:checked').value;
// 2026年9月30日までは経過措置控除率が80%、2026年10月1日~2029年9月30日までは50%、2029年10月1日以降は0%となる.
const now = new Date();
const reduction = now < new Date('2026-10-01') ? 0.8 : now < new Date('2029-10-01') ? 0.5 : 0;
/**
* ([本体価格] - [値引き額]) * (1 + [消費税率]) - ([本体価格] - [値引き額]) * [消費税率] * [経過措置控除率] = [本体価格]
* x = 本体価格, y = 値引き額, z = 消費税率, r = 経過措置控除率とすると
* (x - y) * (1 + z) - (x - y) * z * r = x
* x - y + z * x - z * y - z * r * x + z * r * y = x
* z * x - z * r * x = y + z * y - z * r * y
* x * (z - z * r) = y * (1 + z - z * r)
* y = x * (z - z * r) / (1 + z - z * r)
* となるように値引き額を計算する.
*/
const a = Math.floor(price * (tax - tax * reduction) / (1 + tax - tax * reduction));
const b = price - a;
const c = Math.floor(b * tax);
const d = b + c;
const e = Math.floor(c * reduction);
const f = d - e;
document.getElementById('a').textContent = a.toLocaleString() + '円';
document.getElementById('b').textContent = b.toLocaleString() + '円';
document.getElementById('c').textContent = c.toLocaleString() + '円';
document.getElementById('d').textContent = d.toLocaleString() + '円';
document.getElementById('r').textContent = (reduction * 100).toFixed(0) + '%';
document.getElementById('e').textContent = e.toLocaleString() + '円';
document.getElementById('f').textContent = f.toLocaleString() + '円';
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment