修正
This commit is contained in:
@@ -12,6 +12,7 @@ import openpyxl
|
||||
import xlrd
|
||||
from . import schemas
|
||||
from ...core.database import get_connection
|
||||
from psycopg.errors import UniqueViolation
|
||||
|
||||
|
||||
router = APIRouter(prefix="/payroll/settings", tags=["Payroll - Settings"])
|
||||
@@ -67,45 +68,51 @@ def create_salary_setting(setting: schemas.SalarySettingCreate):
|
||||
)
|
||||
has_employment_insurance_column = cur.fetchone()
|
||||
|
||||
if has_employment_insurance_column:
|
||||
# カラムが存在する場合
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO salary_settings (
|
||||
employee_id, base_salary, hourly_rate, employment_type,
|
||||
payment_type, commute_allowance, other_allowance,
|
||||
employment_insurance_eligible,
|
||||
valid_from, valid_to
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
setting.employee_id, setting.base_salary, setting.hourly_rate,
|
||||
setting.employment_type, setting.payment_type,
|
||||
setting.commute_allowance, setting.other_allowance,
|
||||
setting.employment_insurance_eligible,
|
||||
setting.valid_from, setting.valid_to
|
||||
),
|
||||
try:
|
||||
if has_employment_insurance_column:
|
||||
# カラムが存在する場合
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO salary_settings (
|
||||
employee_id, base_salary, hourly_rate, employment_type,
|
||||
payment_type, commute_allowance, other_allowance,
|
||||
employment_insurance_eligible,
|
||||
valid_from, valid_to
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
setting.employee_id, setting.base_salary, setting.hourly_rate,
|
||||
setting.employment_type, setting.payment_type,
|
||||
setting.commute_allowance, setting.other_allowance,
|
||||
setting.employment_insurance_eligible,
|
||||
setting.valid_from, setting.valid_to
|
||||
),
|
||||
)
|
||||
else:
|
||||
# カラムが存在しない場合(互換性維持)
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO salary_settings (
|
||||
employee_id, base_salary, hourly_rate, employment_type,
|
||||
payment_type, commute_allowance, other_allowance,
|
||||
valid_from, valid_to
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
setting.employee_id, setting.base_salary, setting.hourly_rate,
|
||||
setting.employment_type, setting.payment_type,
|
||||
setting.commute_allowance, setting.other_allowance,
|
||||
setting.valid_from, setting.valid_to
|
||||
),
|
||||
)
|
||||
print("[DEBUG] employment_insurance_eligible カラムがまだ存在しないため、除外しました")
|
||||
except UniqueViolation:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="この適用開始日はすでに登録されています。別の日付を指定してください。"
|
||||
)
|
||||
else:
|
||||
# カラムが存在しない場合(互換性維持)
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO salary_settings (
|
||||
employee_id, base_salary, hourly_rate, employment_type,
|
||||
payment_type, commute_allowance, other_allowance,
|
||||
valid_from, valid_to
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
setting.employee_id, setting.base_salary, setting.hourly_rate,
|
||||
setting.employment_type, setting.payment_type,
|
||||
setting.commute_allowance, setting.other_allowance,
|
||||
setting.valid_from, setting.valid_to
|
||||
),
|
||||
)
|
||||
print("[DEBUG] employment_insurance_eligible カラムがまだ存在しないため、除外しました")
|
||||
|
||||
result = cur.fetchone()
|
||||
conn.commit()
|
||||
@@ -184,10 +191,16 @@ def update_salary_setting(setting_id: int, setting: schemas.SalarySettingUpdate)
|
||||
|
||||
with get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
f"UPDATE salary_settings SET {set_clause} WHERE setting_id = %s RETURNING *",
|
||||
values,
|
||||
)
|
||||
try:
|
||||
cur.execute(
|
||||
f"UPDATE salary_settings SET {set_clause} WHERE setting_id = %s RETURNING *",
|
||||
values,
|
||||
)
|
||||
except UniqueViolation:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="この適用開始日はすでに登録されています。別の日付を指定してください。"
|
||||
)
|
||||
result = cur.fetchone()
|
||||
if not result:
|
||||
raise HTTPException(status_code=404, detail="給与設定が見つかりません")
|
||||
@@ -195,6 +208,21 @@ def update_salary_setting(setting_id: int, setting: schemas.SalarySettingUpdate)
|
||||
return result
|
||||
|
||||
|
||||
@router.delete("/salary/{setting_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
def delete_salary_setting(setting_id: int):
|
||||
"""給与設定を削除"""
|
||||
with get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"DELETE FROM salary_settings WHERE setting_id = %s RETURNING setting_id",
|
||||
(setting_id,),
|
||||
)
|
||||
result = cur.fetchone()
|
||||
if not result:
|
||||
raise HTTPException(status_code=404, detail="給与設定が見つかりません")
|
||||
conn.commit()
|
||||
|
||||
|
||||
# ========================================
|
||||
# 社会保険料率管理
|
||||
# ========================================
|
||||
|
||||
Reference in New Issue
Block a user