@first-ch/tools-mcp 0.45.0 → 0.47.1
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.
- package/README.md +2 -0
- package/invoice-nebiki.mjs +426 -0
- package/package.json +2 -1
- package/server.mjs +35 -0
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@ This server is also registered in the [MCP Registry](https://registry.modelconte
|
|
|
90
90
|
| `css_layout_generate` | Builds copy-ready CSS and HTML for a Flexbox or CSS Grid layout (same logic as tools.first-ch.com/css-layout/). Only non-default declarations are written, repeated tracks fold into `repeat()`. Validates `grid-template-areas` (equal cell counts per row, rectangular names, valid names, track-count mismatch) and emits `grid-area` rules. Notes flag combinations that do nothing (flex-grow vs justify-content, align-content with nowrap, 1fr tracks leaving no free space) and common pitfalls (min-width: auto overflow, 1fr minimum, reverse/dense reading order). Eight presets (holy grail, auto-fit grid, sidebar, header…) | `mode?` (`flex` / `grid` / `presets`), `preset?`, flex: `direction?`, `wrap?`, `justifyContent?`, `alignItems?`…; grid: `columns?`, `rows?`, `areas?`, `autoFit?`, `flow?`…; `gap?`, `count?`, `items?`, `lang?` |
|
|
91
91
|
| `wiki_doc_lint` | Audits an exported internal wiki — Markdown, HTML or text exported from Notion, Backlog Wiki, Confluence and the like (same logic as tools.first-ch.com/wiki-doc-lint/). Returns **near-duplicate page pairs** (`duplicates`: Jaccard index of four-character fragments of the text with symbols and spaces removed, at or above `threshold`, with the lines only one side has and a fix that keeps the page with more incoming links, or the longer one on a tie), **orphan pages that no other page links to** (`orphans`, with `addLine` — the link line to add to a Notion-style parent or a contents page; index/README/home pages are not counted unless `entryPages=false`), **inconsistent and outdated terms** (`terms`: a "preferred ← variant" dictionary — your `dictionary` is added to the default one — plus Japanese katakana words found both with and without a final long-vowel mark, suggesting the majority form; every hit has its line and the line before/after the fix), **broken links** (`broken`: relative links with a document extension and `[[Page name]]` links whose target is not among the files) and a Markdown `report` of suggested fixes. Links are read from `[text](path)`, `[[Page name]]` and `<a href>`, matched by relative path, title, Notion file names with their IDs and the page name at the end of Notion/Confluence URLs. Code blocks, inline code, URLs and tags are skipped for terms, and matches inside a longer word (ユーザ in ユーザビリティ, Javascript in Javascripts) are ignored. Pass `paths` (absolute files or folders, read recursively; hidden folders and node_modules are skipped) or `files`. UTF-8, Shift_JIS and UTF-16 (BOM) are detected; up to 3,000 files / 60 MB. Read-only — it never edits the files | `paths?` or `files?` (`[{ path, text }]`), `threshold?` (0.5–1, default 0.8), `dictionary?`, `useDefaultDictionary?`, `autoChoon?`, `entryPages?`, `format?` (`both` default / `json` / `markdown`), `lang?` (`ja` default / `en`) |
|
|
92
92
|
| `fit_to_box` | Character size and line breaks for writing a string by hand into a printed box — e.g. the address, amount and name boxes on the inner envelope (nakabukuro) of a Japanese wedding or condolence money envelope (same logic as tools.first-ch.com/en/nakabukuro-ran/). From the box width and height (mm) and direction, returns the character size that fits (mm, rounded down to 0.1 mm), the line count and each line. Size uses a 1.5 mm margin inside each side and a 0.3× line gap, limited by both line length and line count (half-width letters/digits count as 0.6 in horizontal boxes; caps of 9 mm for addresses, 14 mm for amount/name). `kind: "address"` breaks between the street number and the building/room first, and only when that cannot reach 4 mm also after the prefecture/city or before the street number (runs like 12番地の18 or 1203号室 are never split; a line break in `text` marks the building; up to 4 lines); `postalCode` adds a 〒 line; vertical boxes get kanji street numbers (`numerals`: `digits` = 一〇, `tens` = 十). Below 4 mm, `alternatives` gives the size and lines with the prefecture dropped and with the building on two lines (it does not decide what may be dropped); `asIs` is how many characters spill out when written unbroken at 5 mm. `kind: "amount"` writes 30000 / 3万 / 30,000円 in formal numerals (daiji) as 金参萬円 (1–99,999,999; 圓, 也 and pre-printed 金/円 supported); `name` breaks only at spaces; `plain` takes any text | `text`, `width`, `height` (mm), `orientation?` (`vertical` default / `horizontal`), `kind?` (`address` default / `name` / `amount` / `plain`), `postalCode?`, `numerals?`, `thousandChar?` (阡 default / 千 / 仟), `yenChar?` (円 / 圓), `nari?`, `kinEnPrinted?`, `lang?` |
|
|
93
|
+
| `invoice_nebiki_check` | For a freelancer in Japan who is **not a registered invoice issuer** and is asked for a price cut (same logic as tools.first-ch.com/invoice-nebiki/). From three answers — the client's consumption tax `method` (`general` / `simplified` / `niwari` 20% rule / `sanwari` 30% rule / `exempt` / `unknown`), `party` (`individual` / `corporation`, required for the special rules) and `small` (is one invoice under ¥10,000 incl. tax) — returns `rows` per period from `today`: `diff` (monthly difference = amount × 10/110 × 20/30/50/70/100%, rounded down), `none` or `check`. The 20% rule gives no difference to 2026 for sole proprietors and to the tax period including Sep 30, 2026 for corporations; the 30% rule covers sole proprietors' 2027–2028 only; after that `recheck: true` (no assumption of simplified taxation). Purchases that may fall under the small-amount rule (to Sep 30, 2029) are `check`. Optional `monthly`, `cutRate` / `cutAmount` add a comparison; `message` asks only the open points (`format: "md"` for Markdown) and always carries the four assumptions; `showAmount: false` hides yen amounts. |
|
|
93
94
|
|
|
94
95
|
### App tools (`app_*`, sent to apps.first-ch.com)
|
|
95
96
|
|
|
@@ -278,6 +279,7 @@ claude mcp add firstch-tools -- npx -y @first-ch/tools-mcp
|
|
|
278
279
|
| `css_layout_generate` | Flexbox / CSS Grid の指定から、コピーして使える CSS と HTML を作る(tools.first-ch.com/css-layout/ と同一ロジック)。既定値と同じ宣言は書かず、同じトラックは repeat() に畳む。grid-template-areas を検証し(行ごとのマス数・名前が長方形か・使えない名前・列トラック数との食い違い)、名前ごとの grid-area を出す。効かない組み合わせ(flex-grow と justify-content・nowrap の align-content・1fr で余白が無い)と落とし穴(min-width: auto のあふれ・1fr の最小値・reverse/dense の読む順)を notes で指摘。定番8種のプリセット | `mode?`(`flex` / `grid` / `presets`), `preset?`, flex: `direction?`・`wrap?`・`justifyContent?`・`alignItems?` ほか、grid: `columns?`・`rows?`・`areas?`・`autoFit?`・`flow?` ほか、`gap?`, `count?`, `items?`, `lang?` |
|
|
279
280
|
| `wiki_doc_lint` | Notion・Backlog Wiki・Confluence などから書き出した社内文書(Markdown / HTML / テキスト)を点検する(tools.first-ch.com/wiki-doc-lint/ と同一ロジック)。**内容がほぼ同じページの組**(`duplicates`: 記号と空白を除いた本文の4文字単位の断片の Jaccard 係数が `threshold` 以上の組・それぞれにしかない行・被リンクの多い方〔同数なら本文が長い方〕を残す修正案)、**ほかのどのページからもリンクされていない孤立ページ**(`orphans`: Notion 型の親ページか目次ページに足すリンクの1行 `addLine` つき。index・README・home などの目次ページは `entryPages=false` にしない限り数えない)、**表記ゆれ・旧称**(`terms`: 「揃える表記 ← ゆれ」の辞書〔`dictionary` は既定の辞書に足す〕と、辞書に無いカタカナ語の語末の長音ゆれ〔多い方に揃える案〕。各箇所の行番号と修正前後の文)、**リンク切れ**(`broken`: 文書の拡張子を持つ相対リンクと `[[ページ名]]` のうち行き先が無いもの)、修正案をまとめた Markdown の `report` を返す。リンクは `[文字](パス)`・`[[ページ名]]`・a タグを読み、相対パス・ページ名・Notion のIDつきファイル名・Notion/Confluence のURL末尾のページ名で照合する。コードブロック・インラインコード・URL・タグは表記ゆれの対象外で、語の途中(ユーザビリティの中のユーザ)は拾わない。`paths`(ファイル・フォルダーの絶対パス。サブフォルダーまで読み、隠しフォルダーと node_modules は飛ばす)か `files` を渡す。UTF-8・Shift_JIS・UTF-16(BOM)を自動判別し、3,000ファイル・合計60MBまで。ファイルは読むだけで書き換えない | `paths?` または `files?`(`[{ path, text }]`)、`threshold?`(0.5〜1・既定 0.8)、`dictionary?`、`useDefaultDictionary?`、`autoChoon?`、`entryPages?`、`format?`(既定 `both` / `json` / `markdown`)、`lang?`(既定 `ja` / `en`) |
|
|
280
281
|
| `fit_to_box` | 印刷済みの記入欄(市販の中袋〔ご祝儀袋・香典袋〕の「住所」「金額」「氏名」の欄など)に手で書くとき、欄の幅・高さ(mm)と向きから、収まる1字の大きさ(mm・0.1mm単位で切り捨て)・行数・改行した後の各行を返す(tools.first-ch.com/nakabukuro-ran/ と同一ロジック)。欄の線から内側へ1.5mmずつ余白を取り、行間を字の0.3倍として、行の長さと行数の両方から決める(横書きの半角英数は0.6字分・上限は住所9mm・金額と氏名14mm)。`kind: "address"` は「〜番地」と「建物名・部屋番号」の境目で改行し、そこで4mmに届かないときだけ都道府県・市区町村の後や番地の前でも区切る(「12番地の18」「1203号室」など数字の並びの途中では切らない・`text` の改行は建物名の前として扱う・最大4行)。`postalCode` で「〒」の行を先頭に足し、縦書きの欄では番地を漢数字にする(`numerals`: `digits`=一〇型 / `tens`=十型)。1字が4mm未満なら `alternatives` に「都道府県を省いた場合」「建物名を2行にした場合」の大きさと行を返す(省いてよいかは判断しない)。`asIs` は改行せずに1字5mmで書いたときにはみ出す字数。`kind: "amount"` は 30000・3万・30,000円 を大字の「金参萬円」にして欄に合わせる(1〜99,999,999円・圓/也/「金」「円」が印刷済みに対応)。`name` は空白でだけ改行し、`plain` は任意の文字列 | `text`、`width`・`height`(mm)、`orientation?`(既定 `vertical` / `horizontal`)、`kind?`(既定 `address` / `name` / `amount` / `plain`)、`postalCode?`、`numerals?`、`thousandChar?`(既定 阡 / 千 / 仟)、`yenChar?`(円 / 圓)、`nari?`、`kinEnPrinted?`、`lang?` |
|
|
282
|
+
| `invoice_nebiki_check` | インボイス未登録のまま取引先から値下げを求められた個人の制作者向け(tools.first-ch.com/invoice-nebiki/ と同一ロジック)。取引先の申告方式 `method`(`general` 一般課税・`simplified` 簡易課税・`niwari` 2割特例・`sanwari` 3割特例・`exempt` 免税・`unknown`)、`party`(個人・法人。特例では必須)、`small`(1回の請求が税込1万円未満か)の3問から、`today` を含む時期以降を `diff`(差あり・月額=税込×10/110×20/30/50/70/100% の1円未満切り捨て)・`none`(差なし)・`check`(要確認)で返す。2割特例は個人2026年分・法人は2026年9月30日を含む課税期間まで、3割特例は個人の2027・2028年分だけで、期限後は `recheck: true`(簡易課税へ移ったとは仮定しない)。少額特例(2029年9月30日まで)が効きうる取引は要確認。任意の `monthly`・`cutRate`/`cutAmount` で値下げと比べ、`message` は要確認の点だけを尋ねる確認文(前提4点つき・`format: "md"` で Markdown)。`showAmount: false` で金額を出さない。 |
|
|
281
283
|
|
|
282
284
|
#### apps のツール(`app_*`・apps.first-ch.com へ送信)
|
|
283
285
|
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/* インボイス値下げ、応じる前に相手へ聞く3問チェック(invoice_nebiki_check)
|
|
2
|
+
* 判定と文面のコアは FirstCHTools の site/invoice-nebiki/lib.mjs と同一
|
|
3
|
+
* (2箇所ルール: site側が正本・片方を直したらもう片方も同じ内容で反映する)。
|
|
4
|
+
* 両ファイルの「ここからコア」〜「ここまでコア」はバイト一致する(どちらも ES module):
|
|
5
|
+
* diff <(sed -n '/^\/\/ ===== ここから/,/^\/\/ ===== ここまで/p' site/invoice-nebiki/lib.mjs) <(sed -n '/^\/\/ ===== ここから/,/^\/\/ ===== ここまで/p' invoice-nebiki.mjs)
|
|
6
|
+
*
|
|
7
|
+
* インボイス発行事業者でない側(個人の制作者など)が取引先から値下げを求められたとき、取引先の申告方式・個人か法人か・
|
|
8
|
+
* 1回の請求が税込1万円未満かの3問から、時期別に「差あり(月額)・差なし・要確認」を返し、要確認の点だけを尋ねる確認文を作る。
|
|
9
|
+
* 制度の数字(2026-11-05 確認): 国税庁「インボイス制度に関する令和8年度税制改正について」・「少額特例の概要」。
|
|
10
|
+
* 自分の納税額・登録の要否・違法かどうか・相手の方式や規模の推定・法人税等は扱わない。完全ローカル処理・ネットワーク送信なし。 */
|
|
11
|
+
|
|
12
|
+
// ===== ここからコア =====
|
|
13
|
+
export const METHODS = ['general', 'simplified', 'niwari', 'sanwari', 'exempt', 'unknown'];
|
|
14
|
+
export const PARTIES = ['individual', 'corporation'];
|
|
15
|
+
export const SMALLS = ['yes', 'no', 'unknown'];
|
|
16
|
+
|
|
17
|
+
// 時期の区切り(この日から)。pct は、登録事業者からの仕入れなら控除できた税額のうち、相手が控除できなくなる割合
|
|
18
|
+
// (経過措置で控除できる割合 80→70→50→30→0% の残り)。同じ pct が続く区切りは、特例の終わりで行を分けるためのもの
|
|
19
|
+
export const SEGMENTS = [
|
|
20
|
+
{ from: '2023-10-01', pct: 20 },
|
|
21
|
+
{ from: '2026-10-01', pct: 30 },
|
|
22
|
+
{ from: '2027-01-01', pct: 30 }, // 個人の2割特例は2026年分まで
|
|
23
|
+
{ from: '2027-10-01', pct: 30 }, // 法人の「2026年9月30日を含む課税期間」は遅くともこの前日までに終わる
|
|
24
|
+
{ from: '2028-10-01', pct: 50 },
|
|
25
|
+
{ from: '2029-01-01', pct: 50 }, // 個人の3割特例は2028年分まで
|
|
26
|
+
{ from: '2029-10-01', pct: 50 }, // 少額特例は2029年9月30日までの仕入れ
|
|
27
|
+
{ from: '2030-10-01', pct: 70 },
|
|
28
|
+
{ from: '2031-10-01', pct: 100 },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export class InvoiceNebikiError extends Error {
|
|
32
|
+
constructor(code, message) { super(message); this.code = code; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const T = {
|
|
36
|
+
ja: {
|
|
37
|
+
method: { general: '一般課税', simplified: '簡易課税', niwari: '2割特例', sanwari: '3割特例', exempt: '免税事業者・消費者', unknown: 'わからない' },
|
|
38
|
+
party: { individual: '個人', corporation: '法人' },
|
|
39
|
+
small: { yes: '税込1万円未満', no: '税込1万円以上', unknown: 'わからない' },
|
|
40
|
+
status: { diff: '差あり', none: '差なし', check: '要確認' },
|
|
41
|
+
recheck: '方式の再確認が必要',
|
|
42
|
+
month: function (ym) { return Number(ym.slice(0, 4)) + '年' + Number(ym.slice(5, 7)) + '月'; },
|
|
43
|
+
range: function (a, b) { return a + '〜' + (b || ''); },
|
|
44
|
+
yen: function (n) { return '月' + n.toLocaleString('ja-JP') + '円'; },
|
|
45
|
+
pctOf: function (p) { return '税込額の約' + p + '%'; },
|
|
46
|
+
note: {
|
|
47
|
+
exempt: '相手は仕入税額控除をしないため、登録の有無で差は出ません(相手が課税事業者になれば変わります)。',
|
|
48
|
+
simplified: '簡易課税は売上の税額から控除額を計算するため、登録の有無で差は出ません(相手が簡易課税を続ける間)。',
|
|
49
|
+
niwari: '2割特例は売上の税額から納税額を計算するため、差は出ません。',
|
|
50
|
+
niwari_end_ind: '2割特例は個人の2026年分まで。2027年分からの方式は相手への確認が必要です(簡易課税へ移ったとは仮定しません)。',
|
|
51
|
+
niwari_corp_fy: '法人の2割特例は2026年9月30日を含む課税期間まで。その課税期間の末日までは差なし、その後は方式の再確認が必要です。',
|
|
52
|
+
niwari_end_corp: '2026年9月30日を含む課税期間は終わっています。今の方式は相手への確認が必要です(簡易課税へ移ったとは仮定しません)。',
|
|
53
|
+
sanwari_before: '3割特例は個人の2027年分からです。2026年分の方式は相手への確認が必要です。',
|
|
54
|
+
sanwari: '3割特例は売上の税額から納税額を計算するため、差は出ません。',
|
|
55
|
+
sanwari_end: '3割特例は2028年分まで。2029年分からの方式は相手への確認が必要です(簡易課税へ移ったとは仮定しません)。',
|
|
56
|
+
sanwari_corp: '3割特例は個人事業者だけの特例です。法人である相手の方式は確認が必要です。',
|
|
57
|
+
general: function (pct) { return (pct >= 100 ? '相手は税額を控除できず、全額が差になります' : '相手は税額の' + (100 - pct) + '%しか控除できず、' + pct + '%分の控除が減ります') + '(少額特例など全額控除できる取引を除いた概算)。'; },
|
|
58
|
+
generalShort: function (pct) { return pct >= 100 ? '控除なし(経過措置の終了)' : '控除できるのは' + (100 - pct) + '%(経過措置)'; },
|
|
59
|
+
small_yes: '1回が税込1万円未満の取引は、相手が少額特例(2029年9月30日まで)の対象なら全額控除でき差なし。対象かは相手の売上規模で決まるため確認が必要です。',
|
|
60
|
+
small_unknown: '1回の請求が税込1万円未満かで変わります。1万円未満で、相手が少額特例の対象なら差なし。',
|
|
61
|
+
method_unknown: '相手の方式で変わります。一般課税なら差あり、簡易課税・2割特例・3割特例・免税なら差なし。',
|
|
62
|
+
},
|
|
63
|
+
paren: function (s) { return '(' + s + ')'; },
|
|
64
|
+
hint: function (amt, pctText) { return '一般課税で全額控除できない取引なら ' + (amt != null ? amt + '(' + pctText + ')' : pctText); },
|
|
65
|
+
premises: [
|
|
66
|
+
'概算です(税込10%の請求額から計算し、1円未満は切り捨て)。',
|
|
67
|
+
'相手が登録事業者からの仕入れなら全額を控除でき、帳簿と請求書の保存要件を満たしている場合に限ります。',
|
|
68
|
+
'法人税・所得税などへの影響は含めていません。',
|
|
69
|
+
'特例(2割特例・3割特例・少額特例・簡易課税)を使えるかどうかは、相手が判断します。',
|
|
70
|
+
],
|
|
71
|
+
premisesTitle: '前提',
|
|
72
|
+
cut: {
|
|
73
|
+
none: '言われた値下げを入れると、相手側の差と比べます。',
|
|
74
|
+
needMonthly: '値下げを金額で比べるには、月の請求額を入れてください。',
|
|
75
|
+
noDiff: function (cut) { return '言われた値下げは' + cut + '。今の時期、前提のもとで相手側の差は出ない見込みです。'; },
|
|
76
|
+
check: function (cut) { return '言われた値下げは' + cut + '。要確認の点が分かるまで、相手側の差は確定しません。'; },
|
|
77
|
+
ratio: function (cut, diff, r) { return '言われた値下げ(' + cut + ')は、相手側の差(' + diff + ')の約' + r + '倍です。'; },
|
|
78
|
+
below: function (cut, diff) { return '言われた値下げ(' + cut + ')は、相手側の差(' + diff + ')より小さい額です。'; },
|
|
79
|
+
same: function (cut, diff) { return '言われた値下げ(' + cut + ')は、相手側の差(' + diff + ')とほぼ同じです。'; },
|
|
80
|
+
rate: function (r) { return '請求額の' + r + '%'; },
|
|
81
|
+
},
|
|
82
|
+
msg: {
|
|
83
|
+
to: '(取引先名)様',
|
|
84
|
+
hello: 'いつもお世話になっております。',
|
|
85
|
+
askLead: '先日ご相談いただいたお支払い額の見直しについて、こちらでも影響を正しく把握したく、次の点を教えていただけますでしょうか。',
|
|
86
|
+
askEnd: 'お答えいただいた内容をもとに、条件をあらためてご相談させてください。',
|
|
87
|
+
tellLead: function (facts) { return '先日ご相談いただいたお支払い額の見直しについて、伺った内容(' + facts + ')をもとに整理しました。'; },
|
|
88
|
+
tellEnd: '上の見込みを踏まえて、条件をご相談させてください。',
|
|
89
|
+
rowDiff: function (label, v) { return label + ':差は' + v + 'の見込み'; },
|
|
90
|
+
rowNone: function (label) { return label + ':差は出ない見込み'; },
|
|
91
|
+
premiseHead: '当方の試算の前提',
|
|
92
|
+
premises: [
|
|
93
|
+
'概算です(税込10%の請求額から計算し、1円未満は切り捨て)。',
|
|
94
|
+
'貴社が登録事業者からの仕入れなら全額を控除でき、帳簿と請求書の保存要件を満たしている場合に限ります。',
|
|
95
|
+
'法人税・所得税などへの影響は含めていません。',
|
|
96
|
+
'特例(2割特例・3割特例・少額特例・簡易課税)を使えるかどうかは、貴社のご判断によります。',
|
|
97
|
+
],
|
|
98
|
+
q: {
|
|
99
|
+
method_unknown: '貴社の消費税の申告方式は、一般課税・簡易課税・2割特例・3割特例のどれでしょうか(免税事業者の場合もお知らせください)。',
|
|
100
|
+
small: '当方への1回のお支払いが税込1万円未満となる取引について、少額特例(インボイスがなくても帳簿の保存だけで全額控除できる、2029年9月30日までの特例)をお使いでしょうか。',
|
|
101
|
+
niwari_ind: '2割特例は2026年分までと承知しています。2027年分以降の申告方式(3割特例・簡易課税・一般課税など)のご予定を教えてください。',
|
|
102
|
+
niwari_corp: '2割特例は2026年9月30日を含む課税期間までと承知しています。その課税期間の末日と、その後の申告方式のご予定を教えてください。',
|
|
103
|
+
sanwari_2026: '3割特例は2027年分・2028年分が対象と承知しています。2026年分の申告方式を教えてください。',
|
|
104
|
+
sanwari_after: '3割特例は2028年分までと承知しています。2029年分以降の申告方式のご予定を教えてください。',
|
|
105
|
+
sanwari_corp: '3割特例は個人事業者向けの特例と承知しています。貴社の申告方式をあらためて教えてください。',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
en: {
|
|
110
|
+
method: { general: 'Standard taxation', simplified: 'Simplified taxation', niwari: '20% special rule', sanwari: '30% special rule', exempt: 'Tax-exempt business / consumer', unknown: 'Not sure' },
|
|
111
|
+
party: { individual: 'Sole proprietor', corporation: 'Corporation' },
|
|
112
|
+
small: { yes: 'Under ¥10,000 incl. tax', no: '¥10,000 or more', unknown: 'Not sure' },
|
|
113
|
+
status: { diff: 'Difference', none: 'No difference', check: 'To confirm' },
|
|
114
|
+
recheck: 'Method must be reconfirmed',
|
|
115
|
+
month: function (ym) { return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][Number(ym.slice(5, 7)) - 1] + ' ' + ym.slice(0, 4); },
|
|
116
|
+
range: function (a, b) { return b ? a + ' – ' + b : 'From ' + a; },
|
|
117
|
+
yen: function (n) { return '¥' + n.toLocaleString('en-US') + '/month'; },
|
|
118
|
+
pctOf: function (p) { return 'about ' + p + '% of the tax-inclusive amount'; },
|
|
119
|
+
note: {
|
|
120
|
+
exempt: 'They do not claim input tax credits, so your registration status makes no difference (this changes if they become a taxable business).',
|
|
121
|
+
simplified: 'Simplified taxation computes the credit from their sales, so your registration status makes no difference (while they stay on it).',
|
|
122
|
+
niwari: 'The 20% special rule computes tax from their sales, so there is no difference.',
|
|
123
|
+
niwari_end_ind: 'The 20% special rule ends with tax year 2026 for sole proprietors. Ask which method they use from 2027 (we do not assume they moved to simplified taxation).',
|
|
124
|
+
niwari_corp_fy: 'For corporations, the 20% special rule covers the tax period that includes Sep 30, 2026. No difference until that period ends; after that the method must be reconfirmed.',
|
|
125
|
+
niwari_end_corp: 'The tax period that includes Sep 30, 2026 has ended. Ask which method they use now (we do not assume simplified taxation).',
|
|
126
|
+
sanwari_before: 'The 30% special rule starts with tax year 2027 for sole proprietors. Ask which method they use for 2026.',
|
|
127
|
+
sanwari: 'The 30% special rule computes tax from their sales, so there is no difference.',
|
|
128
|
+
sanwari_end: 'The 30% special rule ends with tax year 2028. Ask which method they use from 2029 (we do not assume simplified taxation).',
|
|
129
|
+
sanwari_corp: 'The 30% special rule is for sole proprietors only. Ask the corporation which method it uses.',
|
|
130
|
+
general: function (pct) { return (pct >= 100 ? 'They can no longer credit the tax at all' : 'They can credit only ' + (100 - pct) + '% of the tax, losing ' + pct + '%') + ' (an estimate that excludes fully creditable purchases such as the small-amount rule).'; },
|
|
131
|
+
generalShort: function (pct) { return pct >= 100 ? 'No credit (transitional measure ended)' : (100 - pct) + '% creditable (transitional measure)'; },
|
|
132
|
+
small_yes: 'Purchases under ¥10,000 per transaction are fully creditable if they qualify for the small-amount rule (until Sep 30, 2029). Whether they qualify depends on their sales size, so ask.',
|
|
133
|
+
small_unknown: 'It depends on whether one invoice is under ¥10,000 incl. tax. If it is and they qualify for the small-amount rule, there is no difference.',
|
|
134
|
+
method_unknown: 'It depends on their method: a difference under standard taxation, none under simplified taxation, the 20%/30% rules or if exempt.',
|
|
135
|
+
},
|
|
136
|
+
paren: function (s) { return ' (' + s + ')'; },
|
|
137
|
+
hint: function (amt, pctText) { return 'If standard taxation without full credit: ' + (amt != null ? amt + ' (' + pctText + ')' : pctText); },
|
|
138
|
+
premises: [
|
|
139
|
+
'This is an estimate (from tax-inclusive amounts at 10%, fractions of a yen cut off).',
|
|
140
|
+
'It assumes they could fully credit purchases from a registered business and meet the bookkeeping and invoice requirements.',
|
|
141
|
+
'Corporate and income tax effects are not included.',
|
|
142
|
+
'Whether they can use a special rule (20%, 30%, small-amount, simplified) is their call.',
|
|
143
|
+
],
|
|
144
|
+
premisesTitle: 'Assumptions',
|
|
145
|
+
cut: {
|
|
146
|
+
none: 'Enter the requested cut to compare it with their difference.',
|
|
147
|
+
needMonthly: 'Enter the monthly invoice amount to compare a cut given in yen.',
|
|
148
|
+
noDiff: function (cut) { return 'The requested cut is ' + cut + '. For now, under these assumptions, they see no difference.'; },
|
|
149
|
+
check: function (cut) { return 'The requested cut is ' + cut + '. Their difference is not fixed until the open points are confirmed.'; },
|
|
150
|
+
ratio: function (cut, diff, r) { return 'The requested cut of ' + cut + ' is about ' + r + '× their difference of ' + diff + '.'; },
|
|
151
|
+
below: function (cut, diff) { return 'The requested cut of ' + cut + ' is smaller than their difference of ' + diff + '.'; },
|
|
152
|
+
same: function (cut, diff) { return 'The requested cut of ' + cut + ' is about the same as their difference of ' + diff + '.'; },
|
|
153
|
+
rate: function (r) { return r + '% of the invoice'; },
|
|
154
|
+
},
|
|
155
|
+
msg: {
|
|
156
|
+
to: 'Dear (client name),',
|
|
157
|
+
hello: 'Thank you for your continued business.',
|
|
158
|
+
askLead: 'Regarding the price adjustment you mentioned, could you tell me the following so that I can understand the impact correctly?',
|
|
159
|
+
askEnd: 'Based on your answers, I would like to discuss the terms again.',
|
|
160
|
+
tellLead: function (facts) { return 'Regarding the price adjustment you mentioned, here is my estimate based on what you told me (' + facts + ').'; },
|
|
161
|
+
tellEnd: 'I would like to discuss the terms with these figures in mind.',
|
|
162
|
+
rowDiff: function (label, v) { return label + ': an estimated difference of ' + v; },
|
|
163
|
+
rowNone: function (label) { return label + ': no difference expected'; },
|
|
164
|
+
premiseHead: 'Assumptions behind my estimate',
|
|
165
|
+
premises: [
|
|
166
|
+
'This is an estimate (from tax-inclusive amounts at 10%, fractions of a yen cut off).',
|
|
167
|
+
'It assumes you could fully credit purchases from a registered business and meet the bookkeeping and invoice requirements.',
|
|
168
|
+
'Corporate and income tax effects are not included.',
|
|
169
|
+
'Whether you can use a special rule (20%, 30%, small-amount, simplified) is your call.',
|
|
170
|
+
],
|
|
171
|
+
q: {
|
|
172
|
+
method_unknown: 'Which consumption tax method do you use: standard taxation, simplified taxation, the 20% special rule or the 30% special rule (or are you tax-exempt)?',
|
|
173
|
+
small: 'For payments to me under ¥10,000 (tax included) per transaction, do you use the small-amount rule (full credit with books only, until Sep 30, 2029)?',
|
|
174
|
+
niwari_ind: 'I understand the 20% special rule ends with tax year 2026. Which method do you plan to use from 2027 (30% rule, simplified, standard, etc.)?',
|
|
175
|
+
niwari_corp: 'I understand the 20% special rule covers the tax period that includes Sep 30, 2026. When does that period end, and which method do you plan to use after it?',
|
|
176
|
+
sanwari_2026: 'I understand the 30% special rule covers tax years 2027 and 2028. Which method do you use for 2026?',
|
|
177
|
+
sanwari_after: 'I understand the 30% special rule ends with tax year 2028. Which method do you plan to use from 2029?',
|
|
178
|
+
sanwari_corp: 'I understand the 30% special rule is for sole proprietors. Could you confirm which method your company uses?',
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// 問いの番号(同じ問いを2度聞かない)
|
|
185
|
+
var Q_OF = { method_unknown: 'method_unknown', small_yes: 'small', small_unknown: 'small', niwari_end_ind: 'niwari_ind', niwari_corp_fy: 'niwari_corp',
|
|
186
|
+
niwari_end_corp: 'niwari_corp', sanwari_before: 'sanwari_2026', sanwari_end: 'sanwari_after', sanwari_corp: 'sanwari_corp' };
|
|
187
|
+
|
|
188
|
+
function pick(v, list, name) {
|
|
189
|
+
if (v == null || v === '') return null;
|
|
190
|
+
if (list.indexOf(v) < 0) throw new InvoiceNebikiError('INVALID_' + name.toUpperCase(), name + ' must be one of ' + list.join(', '));
|
|
191
|
+
return v;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function isoDay(d) {
|
|
195
|
+
if (d == null || d === '') { var n = new Date(); return n.getFullYear() + '-' + String(n.getMonth() + 1).padStart(2, '0') + '-' + String(n.getDate()).padStart(2, '0'); }
|
|
196
|
+
var m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(d));
|
|
197
|
+
var t = m && new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
|
|
198
|
+
// 形式だけでなく実在する日付か(2026-13-45 や 2026-02-29 を時期の判定に通さない)
|
|
199
|
+
if (!t || t.getUTCFullYear() !== +m[1] || t.getUTCMonth() !== +m[2] - 1 || t.getUTCDate() !== +m[3]) throw new InvoiceNebikiError('INVALID_TODAY', 'today must be an existing date in YYYY-MM-DD');
|
|
200
|
+
return String(d);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function money(v, name) {
|
|
204
|
+
if (v == null || v === '') return null;
|
|
205
|
+
var n = typeof v === 'number' ? v : Number(String(v).replace(/[,,\s円¥¥]/g, ''));
|
|
206
|
+
if (!isFinite(n) || n < 0 || n > 1e10) throw new InvoiceNebikiError('INVALID_' + name.toUpperCase(), name + ' must be a yen amount between 0 and 10,000,000,000');
|
|
207
|
+
n = Math.floor(n);
|
|
208
|
+
return n > 0 ? n : null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 入力をそろえる(未入力は null。範囲外は InvoiceNebikiError)
|
|
212
|
+
export function normalizeInput(input) {
|
|
213
|
+
var x = input || {};
|
|
214
|
+
var cut = null;
|
|
215
|
+
if (x.cut && x.cut.value != null && x.cut.value !== '') {
|
|
216
|
+
var type = x.cut.type === 'amount' ? 'amount' : 'rate';
|
|
217
|
+
if (type === 'rate') {
|
|
218
|
+
var r = Number(String(x.cut.value).replace(/[%%\s]/g, ''));
|
|
219
|
+
if (!isFinite(r) || r < 0 || r > 100) throw new InvoiceNebikiError('INVALID_CUT', 'cut rate must be between 0 and 100');
|
|
220
|
+
if (r > 0) cut = { type: 'rate', value: Math.round(r * 100) / 100 };
|
|
221
|
+
} else {
|
|
222
|
+
var a = money(x.cut.value, 'cut');
|
|
223
|
+
if (a) cut = { type: 'amount', value: a };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
var method = pick(x.method, METHODS, 'method') || 'unknown', party = pick(x.party, PARTIES, 'party');
|
|
227
|
+
// 2割特例・3割特例は個人と法人で期限が違うので、どちらかが要る
|
|
228
|
+
if (!party && (method === 'niwari' || method === 'sanwari')) throw new InvoiceNebikiError('PARTY_REQUIRED', 'party (individual or corporation) is required for the 20%/30% special rules');
|
|
229
|
+
return {
|
|
230
|
+
method: method,
|
|
231
|
+
party: party,
|
|
232
|
+
small: pick(x.small, SMALLS, 'small') || 'unknown',
|
|
233
|
+
monthly: money(x.monthly, 'monthly'),
|
|
234
|
+
cut: cut,
|
|
235
|
+
today: isoDay(x.today),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 1つの区切りでの判定。status: diff(差あり)・none(差なし)・check(要確認)
|
|
240
|
+
export function judgeSegment(seg, x) {
|
|
241
|
+
var d = seg.from;
|
|
242
|
+
var none = function (code) { return { status: 'none', code: code }; };
|
|
243
|
+
var check = function (code, recheck) { return { status: 'check', code: code, recheck: !!recheck }; };
|
|
244
|
+
switch (x.method) {
|
|
245
|
+
case 'exempt': return none('exempt');
|
|
246
|
+
case 'simplified': return none('simplified');
|
|
247
|
+
case 'niwari':
|
|
248
|
+
if (d < '2026-10-01') return none('niwari');
|
|
249
|
+
if (x.party === 'individual') return d < '2027-01-01' ? none('niwari') : check('niwari_end_ind', true);
|
|
250
|
+
return d < '2027-10-01' ? check('niwari_corp_fy') : check('niwari_end_corp', true);
|
|
251
|
+
case 'sanwari':
|
|
252
|
+
if (x.party === 'corporation') return check('sanwari_corp', true);
|
|
253
|
+
if (d < '2027-01-01') return check('sanwari_before');
|
|
254
|
+
if (d < '2029-01-01') return none('sanwari');
|
|
255
|
+
return check('sanwari_end', true);
|
|
256
|
+
case 'general':
|
|
257
|
+
if (x.small !== 'no' && d < '2029-10-01') return check(x.small === 'yes' ? 'small_yes' : 'small_unknown');
|
|
258
|
+
return { status: 'diff', code: 'general' };
|
|
259
|
+
default: return check('method_unknown');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 月額の差(1円未満切り捨て)。税込 × 10/110 × pct% を整数のまま計算する
|
|
264
|
+
export function diffAmount(monthly, pct) { return monthly ? Math.floor(monthly * pct / 1100) : null; }
|
|
265
|
+
// 税込額に対する割合(小数1桁)
|
|
266
|
+
export function diffPctOfTotal(pct) { return Math.round(pct / 11 * 10) / 10; }
|
|
267
|
+
|
|
268
|
+
function ym(iso) { return iso.slice(0, 7); }
|
|
269
|
+
function prevMonth(iso) { var y = Number(iso.slice(0, 4)), m = Number(iso.slice(5, 7)) - 1; if (m === 0) { y--; m = 12; } return y + '-' + String(m).padStart(2, '0'); }
|
|
270
|
+
|
|
271
|
+
// 時期別の表。今日を含む区切りから、判定が同じ区切りをまとめて返す
|
|
272
|
+
export function judge(input) {
|
|
273
|
+
var x = normalizeInput(input);
|
|
274
|
+
var start = 0;
|
|
275
|
+
for (var i = 0; i < SEGMENTS.length; i++) if (SEGMENTS[i].from <= x.today) start = i;
|
|
276
|
+
var rows = [];
|
|
277
|
+
for (var j = start; j < SEGMENTS.length; j++) {
|
|
278
|
+
var seg = SEGMENTS[j], r = judgeSegment(seg, x);
|
|
279
|
+
var row = { from: ym(seg.from), to: null, status: r.status, code: r.code, recheck: !!r.recheck, pct: seg.pct, amount: null, now: j === start };
|
|
280
|
+
if (r.status === 'diff') row.amount = diffAmount(x.monthly, seg.pct);
|
|
281
|
+
if (r.status === 'check') row.hintAmount = diffAmount(x.monthly, seg.pct);
|
|
282
|
+
if (r.status === 'none') row.pct = null;
|
|
283
|
+
var last = rows[rows.length - 1];
|
|
284
|
+
if (last && last.status === row.status && last.code === row.code && last.pct === row.pct) continue;
|
|
285
|
+
if (last) last.to = prevMonth(seg.from + '');
|
|
286
|
+
rows.push(row);
|
|
287
|
+
}
|
|
288
|
+
var questions = [];
|
|
289
|
+
rows.forEach(function (row) { var q = row.status === 'check' && Q_OF[row.code]; if (q && questions.indexOf(q) < 0) questions.push(q); });
|
|
290
|
+
return { input: x, rows: rows, current: rows[0], questions: questions, compare: compareCut(x, rows[0]) };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// 言われた値下げと、今の時期の相手側の差を比べる
|
|
294
|
+
export function compareCut(x, row) {
|
|
295
|
+
if (!x.cut) return { kind: 'none' };
|
|
296
|
+
var cutPct = null, cutAmount = null;
|
|
297
|
+
if (x.cut.type === 'rate') { cutPct = x.cut.value; if (x.monthly) cutAmount = Math.floor(x.monthly * x.cut.value / 100); }
|
|
298
|
+
else { cutAmount = x.cut.value; if (x.monthly) cutPct = Math.round(cutAmount / x.monthly * 10000) / 100; }
|
|
299
|
+
var out = { cutPct: cutPct, cutAmount: cutAmount, kind: row.status === 'none' ? 'noDiff' : row.status === 'check' ? 'check' : '' };
|
|
300
|
+
if (out.kind) return out;
|
|
301
|
+
if (cutPct == null) { out.kind = 'needMonthly'; return out; }
|
|
302
|
+
out.diffPct = diffPctOfTotal(row.pct);
|
|
303
|
+
out.diffAmount = row.amount;
|
|
304
|
+
var ratio = cutPct / (row.pct / 11);
|
|
305
|
+
out.ratio = Math.round(ratio * 10) / 10;
|
|
306
|
+
out.kind = ratio >= 1.1 ? 'ratio' : ratio <= 0.9 ? 'below' : 'same';
|
|
307
|
+
return out;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function rowLabel(row, lang) {
|
|
311
|
+
var L = T[lang] || T.ja;
|
|
312
|
+
return L.range(L.month(row.from), row.to ? L.month(row.to) : '');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 行の中身(状態・額・説明)を文字にする。showAmount=false なら金額を出さず割合だけにする
|
|
316
|
+
export function rowText(row, lang, showAmount) {
|
|
317
|
+
var L = T[lang] || T.ja;
|
|
318
|
+
var note = row.code === 'general' ? L.note.general(row.pct) : L.note[row.code];
|
|
319
|
+
var value = '';
|
|
320
|
+
if (row.status === 'diff') value = showAmount !== false && row.amount != null ? L.yen(row.amount) + L.paren(L.pctOf(diffPctOfTotal(row.pct))) : L.pctOf(diffPctOfTotal(row.pct));
|
|
321
|
+
var hint = row.status === 'check' ? L.hint(showAmount !== false && row.hintAmount != null ? L.yen(row.hintAmount) : null, L.pctOf(diffPctOfTotal(row.pct))) : '';
|
|
322
|
+
return { label: rowLabel(row, lang), status: L.status[row.status], recheck: row.recheck ? L.recheck : '', value: value, note: note, hint: hint,
|
|
323
|
+
short: row.code === 'general' ? L.note.generalShort(row.pct) : note,
|
|
324
|
+
amountText: row.amount != null && showAmount !== false ? L.yen(row.amount) : '', pctText: L.pctOf(diffPctOfTotal(row.pct)) };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export function cutText(result, lang) {
|
|
328
|
+
var L = T[lang] || T.ja, c = result.compare;
|
|
329
|
+
if (c.kind === 'none') return L.cut.none;
|
|
330
|
+
if (c.kind === 'needMonthly') return L.cut.needMonthly;
|
|
331
|
+
var cut = c.cutAmount != null ? L.yen(c.cutAmount) + (c.cutPct != null ? L.paren(L.cut.rate(c.cutPct)) : '') : L.cut.rate(c.cutPct);
|
|
332
|
+
if (c.kind === 'noDiff') return L.cut.noDiff(cut);
|
|
333
|
+
if (c.kind === 'check') return L.cut.check(cut);
|
|
334
|
+
var diff = c.diffAmount != null ? L.yen(c.diffAmount) : L.pctOf(c.diffPct);
|
|
335
|
+
if (c.kind === 'ratio') return L.cut.ratio(cut, diff, c.ratio);
|
|
336
|
+
if (c.kind === 'below') return L.cut.below(cut, diff);
|
|
337
|
+
return L.cut.same(cut, diff);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 相手へ送る確認文。要確認の項目だけを尋ねる。要確認が無ければ、見込みを伝える文にする。
|
|
341
|
+
// format: 'text'(メールに貼る)・'md'(/md-pdf/ で PDF にする)
|
|
342
|
+
export function buildMessage(result, opts) {
|
|
343
|
+
var o = opts || {}, lang = o.lang === 'en' ? 'en' : 'ja', md = o.format === 'md', L = T[lang], M = L.msg, x = result.input;
|
|
344
|
+
var bullet = md || lang === 'en' ? '- ' : '・', out = [];
|
|
345
|
+
out.push(M.to, '', M.hello);
|
|
346
|
+
if (result.questions.length) {
|
|
347
|
+
out.push(M.askLead, '');
|
|
348
|
+
result.questions.forEach(function (q, i) { out.push((i + 1) + '. ' + M.q[q]); });
|
|
349
|
+
out.push('', M.askEnd);
|
|
350
|
+
} else {
|
|
351
|
+
var facts = [L.method[x.method]];
|
|
352
|
+
if (x.method === 'general') facts.push(L.small[x.small]);
|
|
353
|
+
if ((x.method === 'niwari' || x.method === 'sanwari') && x.party) facts.push(L.party[x.party]);
|
|
354
|
+
out.push(M.tellLead(facts.join(lang === 'en' ? ', ' : '・')), '');
|
|
355
|
+
result.rows.forEach(function (row) {
|
|
356
|
+
var t = rowText(row, lang, o.showAmount);
|
|
357
|
+
out.push(bullet + (row.status === 'diff' ? M.rowDiff(t.label, t.value) : M.rowNone(t.label)));
|
|
358
|
+
});
|
|
359
|
+
out.push('', M.tellEnd);
|
|
360
|
+
}
|
|
361
|
+
out.push('', md || lang === 'en' ? '---' : '――', '', (md ? '**' + M.premiseHead + '**' : M.premiseHead), '');
|
|
362
|
+
M.premises.forEach(function (p) { out.push(bullet + p); });
|
|
363
|
+
return out.join('\n') + '\n';
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// URL のフラグメント(# の後ろ)に入れる条件。サーバーへは送られない
|
|
367
|
+
export function encodeState(input) {
|
|
368
|
+
var x = normalizeInput(input), p = ['m=' + x.method, 's=' + x.small];
|
|
369
|
+
if (x.party) p.push('p=' + (x.party === 'individual' ? 'i' : 'c'));
|
|
370
|
+
if (x.monthly) p.push('a=' + x.monthly);
|
|
371
|
+
if (x.cut) p.push('c=' + (x.cut.type === 'rate' ? 'r' : 'y') + x.cut.value);
|
|
372
|
+
return p.join('&');
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function decodeState(hash) {
|
|
376
|
+
var out = {};
|
|
377
|
+
String(hash || '').replace(/^#/, '').split('&').forEach(function (kv) {
|
|
378
|
+
var i = kv.indexOf('='); if (i < 0) return;
|
|
379
|
+
var k = kv.slice(0, i), v;
|
|
380
|
+
try { v = decodeURIComponent(kv.slice(i + 1)); } catch (e) { return; } // 壊れた % はその項目だけ読まない
|
|
381
|
+
if (k === 'm' && METHODS.indexOf(v) >= 0) out.method = v;
|
|
382
|
+
if (k === 's' && SMALLS.indexOf(v) >= 0) out.small = v;
|
|
383
|
+
if (k === 'p' && (v === 'i' || v === 'c')) out.party = v === 'i' ? 'individual' : 'corporation';
|
|
384
|
+
if (k === 'a' && /^\d{1,10}$/.test(v)) out.monthly = Number(v);
|
|
385
|
+
if (k === 'c' && /^[ry]\d+(\.\d+)?$/.test(v)) out.cut = { type: v[0] === 'r' ? 'rate' : 'amount', value: Number(v.slice(1)) };
|
|
386
|
+
});
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
// ===== ここまでコア =====
|
|
390
|
+
|
|
391
|
+
// ---- MCP の入口 ----
|
|
392
|
+
// showAmount:false で、額の値下げを月額なしで渡したとき(率が出せない)の比較の文。額を伏せたまま状況だけを伝える
|
|
393
|
+
const HIDDEN_CUT = {
|
|
394
|
+
ja: { noDiff: '今の時期、前提のもとで相手側の差は出ない見込みです(値下げの額は伏せています)。', check: '要確認の点が分かるまで、相手側の差は確定しません(値下げの額は伏せています)。' },
|
|
395
|
+
en: { noDiff: 'For now, under these assumptions, they see no difference (the cut amount is hidden).', check: 'Their difference is not fixed until the open points are confirmed (the cut amount is hidden).' },
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
export function invoiceNebikiTool(opts = {}) {
|
|
399
|
+
const lang = opts.lang === 'en' ? 'en' : 'ja';
|
|
400
|
+
const showAmount = opts.showAmount !== false;
|
|
401
|
+
const cut = opts.cutRate != null ? { type: 'rate', value: opts.cutRate } : opts.cutAmount != null ? { type: 'amount', value: opts.cutAmount } : null;
|
|
402
|
+
if (opts.cutRate != null && opts.cutAmount != null) throw new InvoiceNebikiError('INVALID_CUT', 'pass either cutRate or cutAmount, not both');
|
|
403
|
+
const r = judge({ method: opts.method, party: opts.party, small: opts.small, monthly: opts.monthly, cut, today: opts.today });
|
|
404
|
+
const L = T[lang];
|
|
405
|
+
const cmp = showAmount ? r.compare : { ...r.compare, cutAmount: null, diffAmount: null };
|
|
406
|
+
// 金額を出さない指定では、返り値の input と fragment からも額(月額・額の値下げ)を外す。率の値下げは額ではないので残す
|
|
407
|
+
const cutOut = showAmount || !r.input.cut || r.input.cut.type === 'rate' ? r.input.cut : { type: 'amount', value: null };
|
|
408
|
+
const shown = { ...r.input, monthly: showAmount ? r.input.monthly : null, cut: cutOut };
|
|
409
|
+
const hiddenCut = !showAmount && cmp.cutPct == null && (cmp.kind === 'noDiff' || cmp.kind === 'check');
|
|
410
|
+
return {
|
|
411
|
+
ok: true,
|
|
412
|
+
input: { ...shown, methodLabel: L.method[r.input.method] },
|
|
413
|
+
rows: r.rows.map((row) => {
|
|
414
|
+
const t = rowText(row, lang, showAmount);
|
|
415
|
+
return { from: row.from, to: row.to, status: row.status, statusLabel: t.status, recheck: row.recheck, current: row.now,
|
|
416
|
+
pct: row.pct, pctOfTotal: row.pct == null ? null : diffPctOfTotal(row.pct),
|
|
417
|
+
monthlyDiff: showAmount ? row.amount : null, ifStandardMonthlyDiff: showAmount && row.status === 'check' ? row.hintAmount : null,
|
|
418
|
+
label: t.label, text: row.status === 'diff' ? t.value : row.status === 'check' ? t.hint : '', note: t.note };
|
|
419
|
+
}),
|
|
420
|
+
comparison: { ...cmp, text: hiddenCut ? HIDDEN_CUT[lang][cmp.kind] : cutText({ ...r, compare: cmp }, lang) },
|
|
421
|
+
questions: r.questions.map((q) => ({ id: q, text: L.msg.q[q] })),
|
|
422
|
+
message: buildMessage(r, { lang, format: opts.format === 'md' ? 'md' : 'text', showAmount }),
|
|
423
|
+
premises: L.premises,
|
|
424
|
+
fragment: encodeState({ method: r.input.method, party: r.input.party, small: r.input.small, monthly: shown.monthly, cut: cutOut && cutOut.value != null ? cutOut : null }),
|
|
425
|
+
};
|
|
426
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@first-ch/tools-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "First CH Tools の計算ロジック(WCAGコントラスト比・文字数/Xウェイト・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4/ULIDの一括生成・アスペクト比の計算とレスポンシブサイズの算出・TSV/CSVからMarkdownテーブルへの整形と相互変換・SQLクエリの整形と予約語の大文字化・URL/テキストからのQRコード生成・UNIXタイムスタンプと日時表記の相互変換・robots.txtの生成(AIクローラーの許可プリセット付き)・文字列のケース変換(camelCase/snake_case/kebab-case など11形式)・CSV/TSVとJSON配列の相互変換(区切りの自動判定・a.b 列と入れ子の相互展開)・全角⇄半角の変換とテキストの掃除(文字種ごとの向き指定・半角カナの合成/分解・空白と空行の整理)・IPアドレス/CIDRの計算(ネットワーク・ブロードキャスト・ホスト範囲とホスト数・IPv4/IPv6・サブネット分割・包含判定・IP範囲→最小CIDR集合の逆算)・日数/営業日の計算(2日付間の日数と営業日数・起点日+N日/N営業日の期日・締め日と支払サイトからの支払日・土日と日本の祝日を内蔵)・HTML→Markdownの変換(見出し/リスト/表/リンク/画像/コード・script/styleや装飾タグの除去・本文だけの抽出・相対URLの絶対化)・和暦⇄西暦の変換(令和〜明治・自動判定・曜日と干支・存在しない和暦の指摘・満年齢と入学/卒業の年・元号一覧と早見表)・日本語タイトルからのURLスラッグ生成(かな→ヘボン式ローマ字・記号除去・ハイフン/アンダースコア連結・小文字化・長音の省略/表記)・Basic認証用 htpasswd の生成と照合(bcrypt / apr1-md5・パスワードの自動生成・Apache / nginx の設定スニペット)・OpenAPI/Swagger仕様書から日本語のMarkdownドキュメントとTypeScript型定義の生成(OpenAPI 3.x / Swagger 2.0・YAML/JSON・$ref/allOf/oneOf 対応・エンドポイントごとの引数/レスポンス型・外部 $ref は読みに行かない)・FAQ構造化データ(FAQPage の JSON-LD・Markdown・details/summary の HTML を同時生成・回答のリンク/箇条書きを HTML 化・「Q: / A:」形式の一括貼り付けの解析)・テキストの行操作(重複行の削除・数値を認識する並べ替え・シード付きシャッフル・行番号・空行除去・前後トリム・接頭辞/接尾辞)・印刷サイズとDPIの計算(用紙×解像度×塗り足しから必要なピクセル数・手持ちの画像の実効dpiと判定・早見表・mm/inch/px/pt/級の換算)・SERPのメタタグ文字数チェック(title / description が検索結果に収まるかをピクセル幅で判定・切り詰め位置と表示行・パンくず表示・https や階層の指摘)・Flexbox / CSS GridのCSS生成(既定値を省いた宣言・repeat()への畳み込み・grid-template-areasの検証・効かない組み合わせの指摘・定番プリセット)・社内文書の点検(Notion・Confluence などから書き出した Markdown/HTML の重複ページ・孤立ページ・表記ゆれや旧称・リンク切れの検出と修正案)・記入欄に収める字の大きさと改行位置(中袋〔ご祝儀袋・香典袋〕の住所欄などの幅・高さmmから1字の大きさ・行数・改行位置・縦書きの漢数字・金額の大字))をMCPツールとして提供するサーバー。あわせて apps.first-ch.com のWebアプリ38本(GEO・メタタグ・セキュリティヘッダー・SSL・DNS・リダイレクト・リンク切れ・構造化データ・AIクローラー許可・和文可読性・ビジネス文面チェック等)の JSON API を呼ぶ app_* ツールも提供する(こちらは入力を apps.first-ch.com へ送るため既定では無効・FIRSTCH_ENABLE_APPS=1 で有効)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -280,6 +280,7 @@
|
|
|
280
280
|
"lib.mjs",
|
|
281
281
|
"fs-safe.mjs",
|
|
282
282
|
"fit-to-box.mjs",
|
|
283
|
+
"invoice-nebiki.mjs",
|
|
283
284
|
"webp.mjs",
|
|
284
285
|
"marp.mjs",
|
|
285
286
|
"marp-theme.css",
|
package/server.mjs
CHANGED
|
@@ -47,6 +47,7 @@ import { serpCheckTool } from './serp.mjs';
|
|
|
47
47
|
import { cssLayoutGenerateTool } from './css-layout.mjs';
|
|
48
48
|
import { wikiDocLintTool } from './wiki-doc-lint.mjs';
|
|
49
49
|
import { fitToBoxTool } from './fit-to-box.mjs';
|
|
50
|
+
import { invoiceNebikiTool } from './invoice-nebiki.mjs';
|
|
50
51
|
|
|
51
52
|
const { version } = createRequire(import.meta.url)('./package.json');
|
|
52
53
|
// SDK v2 の serveStdio は接続ごとに factory から McpServer を1つ作る(旧仕様の initialize と
|
|
@@ -2001,4 +2002,38 @@ registerTool(
|
|
|
2001
2002
|
},
|
|
2002
2003
|
);
|
|
2003
2004
|
|
|
2005
|
+
registerTool(
|
|
2006
|
+
'invoice_nebiki_check',
|
|
2007
|
+
{
|
|
2008
|
+
title: 'インボイス値下げ、応じる前に相手へ聞く3問チェック',
|
|
2009
|
+
description:
|
|
2010
|
+
'インボイス発行事業者でない側(個人のデザイナー・ライターなど)が取引先から値下げを求められたとき、取引先に控除の減り(差)が本当に出るかを時期別に返す' +
|
|
2011
|
+
'(tools.first-ch.com/invoice-nebiki/ と同一ロジック)。' +
|
|
2012
|
+
'入力は3問: method(取引先の申告方式 general=一般課税 / simplified=簡易課税 / niwari=2割特例 / sanwari=3割特例 / exempt=免税事業者・消費者 / unknown)、' +
|
|
2013
|
+
'party(individual / corporation・2割特例と3割特例では必須)、small(1回の請求が税込1万円未満か yes / no / unknown)。monthly(月の請求額・税込10%)と cutRate(%)か cutAmount(円/月)は任意。' +
|
|
2014
|
+
'rows は today を含む時期から、判定が同じ時期をまとめて status=diff(差あり・monthlyDiff=税込×10/110×pct% の1円未満切り捨て)/ none(差なし)/ check(要確認)を返す。' +
|
|
2015
|
+
'pct は経過措置で控除できなくなる割合(2026年9月まで20%・2026年10月から30%・2028年10月から50%・2030年10月から70%・2031年10月から100%)。' +
|
|
2016
|
+
'2割特例の差なしは個人2026年分まで・法人は2026年9月30日を含む課税期間まで、3割特例は個人の2027・2028年分だけで、期限後は recheck:true(方式の再確認が必要・簡易課税へ移ったとは仮定しない)。' +
|
|
2017
|
+
'一般課税で small が yes/unknown なら、少額特例(2029年9月30日までの仕入れ)があるため2029年9月までは要確認。' +
|
|
2018
|
+
'questions と message は要確認の項目だけを尋ねる確認文(要確認が無ければ見込みを伝える文。format="md" で Markdown)。前提(概算・全額控除と保存要件・法人税等を含めない・特例の可否は相手が判断)は premises と message に必ず付く。' +
|
|
2019
|
+
'showAmount:false で金額を出さない。自分の納税額・登録の要否・違法かどうか・相手の方式や規模の推定は扱わない。入力の誤りは InvoiceNebikiError(code 付き)。完全ローカル処理・ネットワーク送信なし。',
|
|
2020
|
+
inputSchema: {
|
|
2021
|
+
method: z.enum(['general', 'simplified', 'niwari', 'sanwari', 'exempt', 'unknown']).optional().describe("取引先の消費税の申告方式(既定 'unknown')"),
|
|
2022
|
+
party: z.enum(['individual', 'corporation']).optional().describe('取引先が個人事業者か法人か(niwari / sanwari では必須)'),
|
|
2023
|
+
small: z.enum(['yes', 'no', 'unknown']).optional().describe("1回の請求が税込1万円未満か(既定 'unknown')"),
|
|
2024
|
+
monthly: z.number().optional().describe('月の請求額(円・税込10%。任意)'),
|
|
2025
|
+
cutRate: z.number().optional().describe('言われた値下げの率(%・0〜100。cutAmount とどちらか)'),
|
|
2026
|
+
cutAmount: z.number().optional().describe('言われた値下げの額(円/月。cutRate とどちらか)'),
|
|
2027
|
+
today: z.string().optional().describe('基準日 YYYY-MM-DD(省略時はサーバーの今日)'),
|
|
2028
|
+
format: z.enum(['text', 'md']).optional().describe("message の形式(既定 'text')"),
|
|
2029
|
+
showAmount: z.boolean().optional().describe('金額を返すか(既定 true。false なら割合だけで、返り値の input・fragment からも月額と額の値下げを外す)'),
|
|
2030
|
+
lang: z.enum(['ja', 'en']).optional().describe("文言の言語(既定 'ja')"),
|
|
2031
|
+
},
|
|
2032
|
+
},
|
|
2033
|
+
async (opts) => {
|
|
2034
|
+
await logUsage('invoice_nebiki_check');
|
|
2035
|
+
return asText(invoiceNebikiTool(opts));
|
|
2036
|
+
},
|
|
2037
|
+
);
|
|
2038
|
+
|
|
2004
2039
|
serveStdio(buildServer);
|