Commit ·
67fe076
1
Parent(s): 8e76558
refactor: 時給管理を設定画面に一元化、社員を人件費計算から除外
Browse files- 時給フィールドを従業員フォームから削除し、設定画面の「アルバイト時給管理」セクションで一括管理
- PT スタッフを一覧表示して個別に時給を設定可能(昇給対応)
- 社員(full_time)は人件費計算対象外とし、統計画面に「対象外」と表示
- save_employee_wages リポジトリ関数を追加
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- db/repositories.py +20 -3
- routes/employees.py +0 -1
- routes/settings_routes.py +20 -0
- templates/employees/form.html +0 -11
- templates/schedule/stats_multi.html +8 -3
- templates/settings/index.html +34 -0
db/repositories.py
CHANGED
|
@@ -88,6 +88,21 @@ def save_employee(emp: Employee) -> Employee:
|
|
| 88 |
return emp
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
def delete_employee(employee_id: int):
|
| 92 |
conn = get_connection()
|
| 93 |
conn.execute("UPDATE employees SET is_active=0 WHERE id=?", (employee_id,))
|
|
@@ -798,9 +813,10 @@ def get_multi_period_stats(period_ids: list[int]) -> dict:
|
|
| 798 |
else:
|
| 799 |
hour_map[(pid_r, eid_r, date_r, "dinner")] = hrs
|
| 800 |
|
| 801 |
-
# 従業員マップ(
|
| 802 |
all_emps = get_all_employees(active_only=False)
|
| 803 |
-
|
|
|
|
| 804 |
|
| 805 |
result: dict = {}
|
| 806 |
for a in asgn_rows:
|
|
@@ -815,7 +831,8 @@ def get_multi_period_stats(period_ids: list[int]) -> dict:
|
|
| 815 |
else:
|
| 816 |
hrs = _ft_hours(slot, pos)
|
| 817 |
|
| 818 |
-
|
|
|
|
| 819 |
cost = hrs * wage
|
| 820 |
|
| 821 |
if eid not in result:
|
|
|
|
| 88 |
return emp
|
| 89 |
|
| 90 |
|
| 91 |
+
def save_employee_wages(wages: dict) -> None:
|
| 92 |
+
"""PT スタッフの時給を一括更新 {employee_id: hourly_wage}"""
|
| 93 |
+
if not wages:
|
| 94 |
+
return
|
| 95 |
+
conn = get_connection()
|
| 96 |
+
for emp_id, wage in wages.items():
|
| 97 |
+
conn.execute(
|
| 98 |
+
"UPDATE employees SET hourly_wage=? WHERE id=?",
|
| 99 |
+
(max(0, int(wage)), int(emp_id))
|
| 100 |
+
)
|
| 101 |
+
conn.commit()
|
| 102 |
+
conn.close()
|
| 103 |
+
cache.delete_memoized(get_all_employees)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
def delete_employee(employee_id: int):
|
| 107 |
conn = get_connection()
|
| 108 |
conn.execute("UPDATE employees SET is_active=0 WHERE id=?", (employee_id,))
|
|
|
|
| 813 |
else:
|
| 814 |
hour_map[(pid_r, eid_r, date_r, "dinner")] = hrs
|
| 815 |
|
| 816 |
+
# 従業員マップ(PT のみ。社員は時給計算対象外)
|
| 817 |
all_emps = get_all_employees(active_only=False)
|
| 818 |
+
pt_ids = {e.id for e in all_emps if e.employment_type != EmploymentType.FULL_TIME}
|
| 819 |
+
wage_map = {e.id: e.hourly_wage for e in all_emps if e.id in pt_ids}
|
| 820 |
|
| 821 |
result: dict = {}
|
| 822 |
for a in asgn_rows:
|
|
|
|
| 831 |
else:
|
| 832 |
hrs = _ft_hours(slot, pos)
|
| 833 |
|
| 834 |
+
# 社員は時給計算対象外(コストは 0 のまま)
|
| 835 |
+
wage = wage_map.get(eid, 0) if eid in pt_ids else 0
|
| 836 |
cost = hrs * wage
|
| 837 |
|
| 838 |
if eid not in result:
|
routes/employees.py
CHANGED
|
@@ -123,7 +123,6 @@ def _form_to_employee(emp_id):
|
|
| 123 |
id=emp_id,
|
| 124 |
name=f["name"].strip(),
|
| 125 |
employment_type=EmploymentType(f["employment_type"]),
|
| 126 |
-
hourly_wage=int(f.get("hourly_wage") or 0),
|
| 127 |
hall_skill=SkillLevel(f.get("hall_skill") or "novice"),
|
| 128 |
kitchen_skill=SkillLevel(f.get("kitchen_skill") or "novice"),
|
| 129 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
|
|
|
| 123 |
id=emp_id,
|
| 124 |
name=f["name"].strip(),
|
| 125 |
employment_type=EmploymentType(f["employment_type"]),
|
|
|
|
| 126 |
hall_skill=SkillLevel(f.get("hall_skill") or "novice"),
|
| 127 |
kitchen_skill=SkillLevel(f.get("kitchen_skill") or "novice"),
|
| 128 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
routes/settings_routes.py
CHANGED
|
@@ -12,11 +12,15 @@ def index():
|
|
| 12 |
constraints = repo.get_shift_constraints()
|
| 13 |
settings = repo.get_all_app_settings()
|
| 14 |
band_constraints = repo.get_breakfast_band_constraints()
|
|
|
|
|
|
|
|
|
|
| 15 |
return render_template(
|
| 16 |
"settings/index.html",
|
| 17 |
constraints=constraints,
|
| 18 |
settings=settings,
|
| 19 |
band_constraints=band_constraints,
|
|
|
|
| 20 |
TimeSlot=TimeSlot,
|
| 21 |
Position=Position,
|
| 22 |
)
|
|
@@ -61,6 +65,22 @@ def save():
|
|
| 61 |
return redirect(url_for("settings.index"))
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
@bp.get("/backup")
|
| 65 |
def backup():
|
| 66 |
"""全データをJSONでダウンロード"""
|
|
|
|
| 12 |
constraints = repo.get_shift_constraints()
|
| 13 |
settings = repo.get_all_app_settings()
|
| 14 |
band_constraints = repo.get_breakfast_band_constraints()
|
| 15 |
+
from utils.constants import EmploymentType
|
| 16 |
+
all_employees = repo.get_all_employees(active_only=True)
|
| 17 |
+
pt_employees = [e for e in all_employees if e.employment_type != EmploymentType.FULL_TIME]
|
| 18 |
return render_template(
|
| 19 |
"settings/index.html",
|
| 20 |
constraints=constraints,
|
| 21 |
settings=settings,
|
| 22 |
band_constraints=band_constraints,
|
| 23 |
+
pt_employees=pt_employees,
|
| 24 |
TimeSlot=TimeSlot,
|
| 25 |
Position=Position,
|
| 26 |
)
|
|
|
|
| 65 |
return redirect(url_for("settings.index"))
|
| 66 |
|
| 67 |
|
| 68 |
+
@bp.post("/save-wages")
|
| 69 |
+
def save_wages():
|
| 70 |
+
"""PT スタッフの時給を一括保存"""
|
| 71 |
+
wages = {}
|
| 72 |
+
for key, val in request.form.items():
|
| 73 |
+
if key.startswith("wage_"):
|
| 74 |
+
try:
|
| 75 |
+
emp_id = int(key[5:])
|
| 76 |
+
wages[emp_id] = int(val or 0)
|
| 77 |
+
except ValueError:
|
| 78 |
+
pass
|
| 79 |
+
repo.save_employee_wages(wages)
|
| 80 |
+
flash("時給を保存しました", "success")
|
| 81 |
+
return redirect(url_for("settings.index"))
|
| 82 |
+
|
| 83 |
+
|
| 84 |
@bp.get("/backup")
|
| 85 |
def backup():
|
| 86 |
"""全データをJSONでダウンロード"""
|
templates/employees/form.html
CHANGED
|
@@ -52,17 +52,6 @@
|
|
| 52 |
</select>
|
| 53 |
</div>
|
| 54 |
|
| 55 |
-
<div class="mb-3">
|
| 56 |
-
<label class="form-label fw-semibold">時給 <span class="text-muted fw-normal small">(人件費集計に使用)</span></label>
|
| 57 |
-
<div class="input-group" style="max-width:200px">
|
| 58 |
-
<input type="number" name="hourly_wage" class="form-control"
|
| 59 |
-
min="0" max="9999" step="1"
|
| 60 |
-
value="{{ emp.hourly_wage if emp else 0 }}"
|
| 61 |
-
placeholder="0">
|
| 62 |
-
<span class="input-group-text">円/時</span>
|
| 63 |
-
</div>
|
| 64 |
-
</div>
|
| 65 |
-
|
| 66 |
<!-- 所属ポジション -->
|
| 67 |
<div class="mb-3">
|
| 68 |
<label class="form-label fw-semibold">所属ポジション</label>
|
|
|
|
| 52 |
</select>
|
| 53 |
</div>
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
<!-- 所属ポジション -->
|
| 56 |
<div class="mb-3">
|
| 57 |
<label class="form-label fw-semibold">所属ポジション</label>
|
templates/schedule/stats_multi.html
CHANGED
|
@@ -111,9 +111,14 @@
|
|
| 111 |
{% if hours > 0 %}{{ "%.1f"|format(hours) }}h{% else %}—{% endif %}
|
| 112 |
</td>
|
| 113 |
{% if any_wage %}
|
| 114 |
-
<td class="num text-center
|
| 115 |
-
{% if
|
| 116 |
-
<span class="text-muted small">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
</td>
|
| 118 |
{% endif %}
|
| 119 |
</tr>
|
|
|
|
| 111 |
{% if hours > 0 %}{{ "%.1f"|format(hours) }}h{% else %}—{% endif %}
|
| 112 |
</td>
|
| 113 |
{% if any_wage %}
|
| 114 |
+
<td class="num text-center">
|
| 115 |
+
{% if emp.employment_type.value == 'full_time' %}
|
| 116 |
+
<span class="text-muted small">対象外</span>
|
| 117 |
+
{% elif cost > 0 %}
|
| 118 |
+
<span class="cost-col">¥{{ "{:,.0f}".format(cost) }}</span>
|
| 119 |
+
{% elif emp.hourly_wage == 0 %}
|
| 120 |
+
<span class="text-muted small">時給未設定</span>
|
| 121 |
+
{% else %}—{% endif %}
|
| 122 |
</td>
|
| 123 |
{% endif %}
|
| 124 |
</tr>
|
templates/settings/index.html
CHANGED
|
@@ -121,6 +121,40 @@
|
|
| 121 |
|
| 122 |
</form>
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
<!-- バックアップ / リストア -->
|
| 125 |
<div class="card mb-3">
|
| 126 |
<div class="card-body">
|
|
|
|
| 121 |
|
| 122 |
</form>
|
| 123 |
|
| 124 |
+
<!-- アルバイト時給管理 -->
|
| 125 |
+
<form method="post" action="{{ url_for('settings.save_wages') }}">
|
| 126 |
+
<div class="card mb-3">
|
| 127 |
+
<div class="card-body">
|
| 128 |
+
<h6 class="card-title text-muted mb-3">アルバイト時給管理</h6>
|
| 129 |
+
{% if pt_employees %}
|
| 130 |
+
<div class="text-muted small mb-3">
|
| 131 |
+
勤務統計の人件費集計に使用します。社員は対象外です。
|
| 132 |
+
</div>
|
| 133 |
+
{% for emp in pt_employees %}
|
| 134 |
+
<div class="mb-2 d-flex align-items-center justify-content-between gap-2">
|
| 135 |
+
<label class="form-label mb-0 small fw-semibold flex-grow-1">{{ emp.name }}</label>
|
| 136 |
+
<div class="input-group input-group-sm" style="max-width:160px">
|
| 137 |
+
<input type="number" name="wage_{{ emp.id }}"
|
| 138 |
+
value="{{ emp.hourly_wage }}"
|
| 139 |
+
min="0" max="9999" step="1"
|
| 140 |
+
class="form-control form-control-sm text-end"
|
| 141 |
+
placeholder="0">
|
| 142 |
+
<span class="input-group-text">円/時</span>
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
{% endfor %}
|
| 146 |
+
<div class="mt-3">
|
| 147 |
+
<button type="submit" class="btn btn-primary btn-sm">
|
| 148 |
+
<i class="bi bi-floppy me-1"></i>時給を保存
|
| 149 |
+
</button>
|
| 150 |
+
</div>
|
| 151 |
+
{% else %}
|
| 152 |
+
<div class="text-muted small">アルバイトスタッフが登録されていません。</div>
|
| 153 |
+
{% endif %}
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
</form>
|
| 157 |
+
|
| 158 |
<!-- バックアップ / リストア -->
|
| 159 |
<div class="card mb-3">
|
| 160 |
<div class="card-body">
|