This commit is contained in:
admin
2026-03-04 23:20:42 +09:00
parent 99d16d8219
commit 31a64d5b59
11 changed files with 674 additions and 201 deletions

View File

@@ -51,7 +51,9 @@ def calculate_payroll(request: schemas.PayrollCalculationRequest):
payment_date=request.payment_date,
other_allowance=request.other_allowance,
resident_tax=request.resident_tax,
other_deduction=request.other_deduction
other_deduction=request.other_deduction,
calc_income_tax=request.calc_income_tax,
calc_social_insurance=request.calc_social_insurance
)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))
@@ -174,8 +176,10 @@ def update_payroll(payroll_id: int, request: schemas.MonthlyPayrollUpdate):
@router.post("/{payroll_id}/recalculate", response_model=schemas.MonthlyPayroll)
def recalculate_payroll(payroll_id: int):
def recalculate_payroll(payroll_id: int, request: schemas.RecalculateRequest = None):
"""給与を再計算"""
if request is None:
request = schemas.RecalculateRequest()
with get_connection() as conn:
with conn.cursor() as cur:
# 既存データを取得
@@ -204,7 +208,9 @@ def recalculate_payroll(payroll_id: int):
other_allowance=existing["other_allowance"],
resident_tax=existing["resident_tax"],
other_deduction=existing["other_deduction"],
calculated_by="recalculated"
calculated_by="recalculated",
calc_income_tax=request.calc_income_tax,
calc_social_insurance=request.calc_social_insurance
)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))

View File

@@ -123,6 +123,14 @@ class PayrollCalculationRequest(BaseModel):
other_allowance: Decimal = Decimal("0")
resident_tax: Decimal = Decimal("0")
other_deduction: Decimal = Decimal("0")
calc_income_tax: bool = True
calc_social_insurance: bool = True
class RecalculateRequest(BaseModel):
"""再計算リクエスト"""
calc_income_tax: bool = True
calc_social_insurance: bool = True
class PayrollApprovalRequest(BaseModel):

View File

@@ -231,7 +231,9 @@ class PayrollCalculationService:
other_allowance: Decimal = Decimal("0"),
resident_tax: Decimal = Decimal("0"),
other_deduction: Decimal = Decimal("0"),
calculated_by: str = "system"
calculated_by: str = "system",
calc_income_tax: bool = True,
calc_social_insurance: bool = True
) -> Dict[str, Any]:
"""給与を計算"""
@@ -378,7 +380,7 @@ class PayrollCalculationService:
health_insurance = (
health_standard_salary * Decimal(str(health_insurance_rate["employee_rate"]))
).quantize(Decimal("0.01"))
else:
elif calc_social_insurance:
errors.append(f"健康保険料率が見つかりません(年度: {payment_date.year}")
# 介護保険40歳以上65歳未満が対象、標準報酬月額表から検索した月額で計算
@@ -391,7 +393,7 @@ class PayrollCalculationService:
).quantize(Decimal("0.01"))
print(f"[DEBUG] 介護保険計算: {health_standard_salary} × {care_insurance_rate['employee_rate']}% = {care_insurance}")
else:
errors.append(f"介護保険料率が見つかりません(年度: {payment_date.year}")
errors.append(f"介護保険料率が見つかりません(年度: {payment_date.year}") if calc_social_insurance else None
# 厚生年金(上限適用後の標準報酬月額で計算)
pension_insurance_rate = PayrollCalculationService.get_insurance_rate("厚生年金", payment_date)
@@ -401,7 +403,7 @@ class PayrollCalculationService:
pension_standard_salary * Decimal(str(pension_insurance_rate["employee_rate"]))
).quantize(Decimal("0.01"))
print(f"[DEBUG] 厚生年金計算: {pension_standard_salary} × {pension_insurance_rate['employee_rate']}% = {pension_insurance}")
else:
elif calc_social_insurance:
errors.append(f"厚生年金保険料率が見つかりません(年度: {payment_date.year}")
# 雇用保険
@@ -417,9 +419,16 @@ class PayrollCalculationService:
).quantize(Decimal("0.01"))
elif not is_employment_insurance_eligible:
print(f"[DEBUG] この従業員は雇用保険非対象です")
elif not employment_insurance_rate:
elif not employment_insurance_rate and calc_social_insurance:
errors.append(f"雇用保険料率が見つかりません(年度: {payment_date.year}")
# 社会保険計算スキップ時は全て。0にする
if not calc_social_insurance:
health_insurance = Decimal("0")
care_insurance = Decimal("0")
pension_insurance = Decimal("0")
employment_insurance = Decimal("0")
# エラーがある場合は、エラーメッセージを返す
if errors:
raise ValueError(f"給与計算に必要なデータが不足しています:\n" + "\n".join(errors))
@@ -441,11 +450,14 @@ class PayrollCalculationService:
employment_insurance
)
income_tax = PayrollCalculationService.calculate_income_tax(
taxable_income,
dependents_count,
payment_date
)
if calc_income_tax:
income_tax = PayrollCalculationService.calculate_income_tax(
taxable_income,
dependents_count,
payment_date
)
else:
income_tax = Decimal("0")
# 総控除額
total_deduction = (