修正
This commit is contained in:
@@ -131,6 +131,40 @@ def approve_bonus(bonus_id: int, approved_by: str):
|
||||
return result
|
||||
|
||||
|
||||
@router.put("/{bonus_id}", response_model=schemas.BonusPayment)
|
||||
def update_bonus(bonus_id: int, request: schemas.BonusUpdateRequest):
|
||||
"""賞与の支給項目を更新(再計算は別途実行)"""
|
||||
with get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("SELECT status FROM bonus_payments WHERE bonus_id = %s", (bonus_id,))
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="賞与が見つかりません")
|
||||
if row["status"] == "approved":
|
||||
raise HTTPException(status_code=400, detail="承認済みの賞与は編集できません")
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE bonus_payments SET
|
||||
base_bonus = %s, performance_bonus = %s, other_bonus = %s,
|
||||
other_deduction = %s,
|
||||
payment_date = COALESCE(%s, payment_date),
|
||||
bonus_type = COALESCE(%s, bonus_type)
|
||||
WHERE bonus_id = %s
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
request.base_bonus, request.performance_bonus, request.other_bonus,
|
||||
request.other_deduction,
|
||||
request.payment_date, request.bonus_type,
|
||||
bonus_id
|
||||
)
|
||||
)
|
||||
result = cur.fetchone()
|
||||
conn.commit()
|
||||
return result
|
||||
|
||||
|
||||
@router.post("/{bonus_id}/recalculate", response_model=schemas.BonusPayment)
|
||||
def recalculate_bonus(bonus_id: int):
|
||||
"""賞与を再計算"""
|
||||
@@ -170,7 +204,8 @@ def recalculate_bonus(bonus_id: int):
|
||||
base_bonus = %s, performance_bonus = %s, other_bonus = %s,
|
||||
total_bonus = %s,
|
||||
health_insurance = %s, care_insurance = %s, pension_insurance = %s,
|
||||
employment_insurance = %s, income_tax = %s, other_deduction = %s,
|
||||
employment_insurance = %s, child_support = %s,
|
||||
income_tax = %s, other_deduction = %s,
|
||||
total_deduction = %s, net_bonus = %s,
|
||||
calculated_at = %s, calculated_by = %s
|
||||
WHERE bonus_id = %s
|
||||
@@ -181,6 +216,7 @@ def recalculate_bonus(bonus_id: int):
|
||||
calc_result["other_bonus"], calc_result["total_bonus"],
|
||||
calc_result["health_insurance"], calc_result["care_insurance"],
|
||||
calc_result["pension_insurance"], calc_result["employment_insurance"],
|
||||
calc_result["child_support"],
|
||||
calc_result["income_tax"], calc_result["other_deduction"],
|
||||
calc_result["total_deduction"], calc_result["net_bonus"],
|
||||
datetime.now(), "recalculated",
|
||||
|
||||
Reference in New Issue
Block a user