tstt建議的資料庫調整-20251015
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/1289
程式對 base_exemption
的處理
-
只要畫面年度在 2025 年(令和7年)以後,程式會先檢查主檔欄位是不是「空值、0/負數,或仍然是舊制複製下來的 480,000 円」。只有在偵測到這些「尚未換成新制度」的情況時,才會用程式內建的分段表重算基礎控除額並覆寫主檔值。
-
換句話說:不用刻意把主檔改成
NULL
。如果年度資料仍維持 480,000 円,程式會把它視為舊制並自動套用新制度金額;如果未來你在主檔直接寫入新的正式金額(例如稅制再調整),那個正值也會被原封不動地採用。
程式對 dependent_base_exemption
的處理
-
扶養控除(一般)的金額會先尊重主檔,只要欄位裡有正值(像 380,000 円),程式就照讀;只有在欄位為
NULL
、0、負數等空缺時,才會落回 2025 年以後的法定 38 萬円預設值。 -
因此可以依照慣例「複製 2025 年那筆記錄」來建立 2026、2027 年資料列──主檔欄位本身填 380,000 也可以,程式會直接沿用,不會強迫你清成
NULL
。
建議的資料庫操作
-
為了避免其他功能在讀取扶養控除基礎額時遇到
NULL
,建議仍把 2025 年(含以後)的dependent_base_exemption
明確填成 380,000 円,再將該列複製出後續年度。這麼做既維持既有的年度主檔運用方式,也與程式的預設邏輯相容;若日後要改數額,只要更新主檔即可。
Summary
-
基礎控除額は2025年以降、マスタの値が未設定・0・旧制度額(48万円)の場合のみ法定テーブルで再計算するようにしてあるため、テーブルを年度コピーしたままでも自動的に新制度へ切り替わります。
-
一般扶養親族の控除額が
NULL
/ 0 のときは 38 万円をフォールバックし、マスタで明示的に値を入れた年度はそのまま利用できるようにしています。 -
基礎控除額の分岐テーブルは 2025~2026 年と 2027 年以降で切り替えるヘルパーにまとめ、将来の税制改正時にも 1 箇所の更新で済むよう整理しました。
推奨する SQL 更新
上記コードは「基礎控除額が未設定または旧制度値なら自動計算」「一般扶養控除が未設定なら 38 万円フォールバック」という前提で動作します。年度管理の慣例を維持しつつ安全に運用するには、次のように 2025 年のレコードを整備し、それを複製して 2026・2027 年を追加してください。
-- 1) 2025 年分:基礎控除はプログラム計算へ委ねるため NULL、扶養基礎控除は現行額を明示
UPDATE m_dependents_deduct
SET base_exemption = NULL,
dependent_base_exemption = 380000,
update_date = CURRENT_TIMESTAMP,
user_id = 'toukeisys2'
WHERE dependents_exemption_year = 2025;
-- 2) 2025 年をテンプレートに 2026 年を追加
INSERT INTO m_dependents_deduct (
dependents_exemption_year,
base_exemption,
older_people,
special_widow,
general_disabilities,
general_widow,
widower,
working_student,
living_special_disabilities,
non_living_sp_disabilities,
older_spouse,
specific_dependents_rel,
living_old_family_etc,
living_old_not_family,
user_id,
create_date,
update_date,
special_disabilities,
dependent_base_exemption
)
SELECT 2026,
base_exemption,
older_people,
special_widow,
general_disabilities,
general_widow,
widower,
working_student,
living_special_disabilities,
non_living_sp_disabilities,
older_spouse,
specific_dependents_rel,
living_old_family_etc,
living_old_not_family,
'toukeisys2',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
special_disabilities,
dependent_base_exemption
FROM m_dependents_deduct
WHERE dependents_exemption_year = 2025;
-- 3) 同様に 2027 年を追加
INSERT INTO m_dependents_deduct (
dependents_exemption_year,
base_exemption,
older_people,
special_widow,
general_disabilities,
general_widow,
widower,
working_student,
living_special_disabilities,
non_living_sp_disabilities,
older_spouse,
specific_dependents_rel,
living_old_family_etc,
living_old_not_family,
user_id,
create_date,
update_date,
special_disabilities,
dependent_base_exemption
)
SELECT 2027,
base_exemption,
older_people,
special_widow,
general_disabilities,
general_widow,
widower,
working_student,
living_special_disabilities,
non_living_sp_disabilities,
older_spouse,
specific_dependents_rel,
living_old_family_etc,
living_old_not_family,
'toukeisys2',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
special_disabilities,
dependent_base_exemption
FROM m_dependents_deduct
WHERE dependents_exemption_year = 2025;
この構成なら、マスタに新制度の具体的な金額がまだ決まっていない場合は NULL
のままでよく、決まったタイミングで任意の値を入力すればコード側の判定に引っかからずそのまま反映されます。扶養控除の基礎額は他機能でも参照される可能性が高いため、念のため 380,000 円を登録しておく運用を推奨します。
This article was last edited at