修正
This commit is contained in:
@@ -11,20 +11,22 @@ class BonusCalculationService:
|
||||
"""賞与計算サービス"""
|
||||
|
||||
@staticmethod
|
||||
def get_insurance_rate(rate_type: str, target_date: date) -> Dict[str, Any]:
|
||||
"""保険料率を取得"""
|
||||
def get_insurance_rate(rate_type: str, target_date: date, calculation_target: str = '賞与') -> Dict[str, Any]:
|
||||
"""保険料率を取得(賞与用)"""
|
||||
with get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
# rate_yearで年度を判定
|
||||
target_year = target_date.year
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT * FROM insurance_rates
|
||||
WHERE rate_type = %s
|
||||
AND valid_from <= %s
|
||||
AND (valid_to IS NULL OR valid_to >= %s)
|
||||
ORDER BY valid_from DESC
|
||||
AND rate_year = %s
|
||||
AND calculation_target = %s
|
||||
ORDER BY rate_id DESC
|
||||
LIMIT 1
|
||||
""",
|
||||
(rate_type, target_date, target_date)
|
||||
(rate_type, target_year, calculation_target)
|
||||
)
|
||||
return cur.fetchone()
|
||||
|
||||
@@ -134,10 +136,15 @@ class BonusCalculationService:
|
||||
)
|
||||
employee_info = cur.fetchone()
|
||||
|
||||
# 年齢を計算
|
||||
# 年齢を計算(介護保険は40歳以上65歳未満が対象)
|
||||
age = 0
|
||||
if employee_info and employee_info["birth_date"]:
|
||||
age = (payment_date - employee_info["birth_date"]).days // 365
|
||||
birth_date = employee_info["birth_date"]
|
||||
# より正確な年齢計算
|
||||
age = payment_date.year - birth_date.year
|
||||
# 誕生日がまだ来ていない場合は-1
|
||||
if (payment_date.month, payment_date.day) < (birth_date.month, birth_date.day):
|
||||
age -= 1
|
||||
|
||||
# 健康保険(賞与額の1/1000で計算)
|
||||
health_insurance_rate = BonusCalculationService.get_insurance_rate("健康保険", payment_date)
|
||||
|
||||
Reference in New Issue
Block a user