This commit is contained in:
admin
2026-01-22 22:10:17 +09:00
parent 536266d70b
commit 50e534094d
9 changed files with 590 additions and 17 deletions

88
check_income_tax.py Normal file
View File

@@ -0,0 +1,88 @@
#!/usr/bin/env python3
"""
所得税表の確認スクリプト
ユーザーが提供したデータ:
- 月収(控除後): 356,600円
- 扶養人数: 3人
- 期待される所得税: 5,840円
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
from decimal import Decimal
from datetime import date
from app.core.database import get_connection
def check_income_tax():
"""所得税テーブルを確認"""
monthly_income = Decimal("356600")
dependents_count = 3
target_date = date(2025, 1, 22)
print(f"検索条件:")
print(f" 月収: {monthly_income}")
print(f" 扶養人数: {dependents_count}")
print(f" 適用日: {target_date}")
print()
with get_connection() as conn:
with conn.cursor() as cur:
# 全てのデータを確認
print("=== 3人扶養の全データ ===")
cur.execute(
"""
SELECT * FROM income_tax_table
WHERE dependents_count = %s
ORDER BY monthly_income_from
""",
(dependents_count,)
)
results = cur.fetchall()
print(f"総件数: {len(results)}")
# 月収356,600円が属する範囲を探す
for row in results:
if (row["monthly_income_from"] <= monthly_income <= row["monthly_income_to"]):
print(f"\n✓ 月収 {monthly_income} が属する範囲:")
print(f" From: {row['monthly_income_from']}")
print(f" To: {row['monthly_income_to']}")
print(f" 税額: {row['tax_amount']}")
print(f" 有効期間: {row['valid_from']} ~ {row['valid_to']}")
break
else:
print(f"\n✗ 月収 {monthly_income} が属する範囲が見つかりません")
print("\n該当の近い範囲:")
for row in results[-5:]:
print(f" {row['monthly_income_from']} ~ {row['monthly_income_to']}: {row['tax_amount']}")
# 現在の年度で検索(元の検索ロジックをシミュレート)
print("\n=== 元の検索ロジックvalid_from/toで検索===")
cur.execute(
"""
SELECT * FROM income_tax_table
WHERE valid_from <= %s
AND (valid_to IS NULL OR valid_to >= %s)
AND dependents_count = %s
AND monthly_income_from <= %s
AND monthly_income_to >= %s
ORDER BY valid_from DESC
LIMIT 1
""",
(target_date, target_date, dependents_count, monthly_income, monthly_income)
)
result = cur.fetchone()
if result:
print(f"検索結果:")
print(f" 月収範囲: {result['monthly_income_from']} ~ {result['monthly_income_to']}")
print(f" 税額: {result['tax_amount']}")
print(f" 有効期間: {result['valid_from']} ~ {result['valid_to']}")
else:
print("検索結果: なし")
if __name__ == "__main__":
check_income_tax()