修正
This commit is contained in:
@@ -89,27 +89,27 @@ class BonusCalculationService:
|
||||
|
||||
@staticmethod
|
||||
def get_previous_salary_avg(employee_id: int, payment_date: date) -> Decimal:
|
||||
"""前月までの3ヶ月平均給与を取得(賞与所得税計算用)"""
|
||||
"""前月の社会保険料等控除後の給与を取得(賞与所得税計算用)
|
||||
|
||||
税法上は「前月分の社会保険料等控除後の給与」= 直前1ヶ月分のみを使用する。
|
||||
ステータス問わず最新の月次給与レコードを参照する。
|
||||
"""
|
||||
with get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
# 前月までの3ヶ月の社会保険料等控除後の給与を取得
|
||||
# 賞与支払日より前の直近1ヶ月分の給与を取得(ステータス問わず)
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT AVG(total_payment - commute_allowance - health_insurance - care_insurance - pension_insurance - employment_insurance - COALESCE(child_support, 0)) as avg_salary
|
||||
FROM (
|
||||
SELECT total_payment, commute_allowance, health_insurance, care_insurance, pension_insurance, employment_insurance, child_support
|
||||
FROM monthly_payroll
|
||||
WHERE employee_id = %s
|
||||
AND payment_date < %s
|
||||
AND status IN ('approved', 'paid')
|
||||
ORDER BY payment_date DESC
|
||||
LIMIT 3
|
||||
) as recent_payroll
|
||||
SELECT total_payment - commute_allowance - health_insurance - care_insurance - pension_insurance - employment_insurance - COALESCE(child_support, 0) as net_salary
|
||||
FROM monthly_payroll
|
||||
WHERE employee_id = %s
|
||||
AND payment_date < %s
|
||||
ORDER BY payment_date DESC
|
||||
LIMIT 1
|
||||
""",
|
||||
(employee_id, payment_date)
|
||||
)
|
||||
result = cur.fetchone()
|
||||
return Decimal(str(result["avg_salary"])) if result and result["avg_salary"] else Decimal("0")
|
||||
return Decimal(str(result["net_salary"])) if result and result["net_salary"] else Decimal("0")
|
||||
|
||||
@staticmethod
|
||||
def calculate_bonus_income_tax(
|
||||
@@ -230,11 +230,11 @@ class BonusCalculationService:
|
||||
total_bonus * Decimal(str(employment_insurance_rate["employee_rate"]))
|
||||
).quantize(Decimal("1"), rounding=ROUND_HALF_UP)
|
||||
|
||||
# 子ども・子育て支援金(令和8年4月分以降のみ適用)
|
||||
# 賞与の場合: 社会保険料率設定(insurance_rates)の料率 × 賞与総額で計算
|
||||
# 子ども・子育て支援金(令和8年5月支給分以降のみ適用)
|
||||
# 賞与は bonus_month でなく実際の支給日(payment_date)で判定する
|
||||
child_support = Decimal("0")
|
||||
is_child_support_applicable = (
|
||||
(bonus_year == 2026 and bonus_month >= 5) or bonus_year >= 2027
|
||||
(payment_date.year == 2026 and payment_date.month >= 5) or payment_date.year >= 2027
|
||||
)
|
||||
if is_child_support_applicable:
|
||||
child_support_rate = BonusCalculationService.get_insurance_rate("子ども・子育て支援金", payment_date)
|
||||
|
||||
Reference in New Issue
Block a user