Commit ·
9119b9e
1
Parent(s): ad53d90
feat: 9項目の改善を実装
Browse files1. 未保存離脱の警告(希望シフト入力)
- スナップショット比較による変更検知
- 従業員切り替え時に未保存確認ダイアログを表示
2. 期間の削除機能
- 希望シフト入力画面に「期間削除」ボタンを追加
- 確認ダイアログ後にCASCADE削除
3. 固定不可日のUI(従業員編集ダイアログ)
- QDateEdit + QListWidget で不可日を追加・削除
4. 前の期間のシフト希望コピー機能
- コピー元期間選択コンボ + コピーボタンを追加
5. シフト制約の画面設定(設定画面に移す)
- shift_constraints テーブルにデフォルト値を投入
- repo.get/save_shift_constraints() を追加
- solver.py を DB 制約使用に変更
- 設定画面に QSpinBox による人員設定UIを追加
6. 月間勤務集計タブ
- シフト表に「📊 月間集計」タブを追加
- 従業員ごとの朝食/ディナー/合計/応援シフト数を表示
7. シフト表の確定ロック
- 「✅ 確定する」ボタンで期間ステータスをtoggle
- 確定済みはセル編集を無効化し 🔒 表示
8. 従業員アーカイブ表示・復元
- 「アーカイブを表示」トグルで非アクティブ従業員を一覧表示
- 「復元」ボタンで is_active=1 に戻す
9. 出力ファイル名の自動設定
- デフォルトファイル名を「シフト表_YYYY年M月D日-M月D日.pdf」形式に変更
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- db/database.py +22 -0
- db/repositories.py +51 -0
- optimizer/solver.py +19 -8
- ui/employee_view.py +126 -25
- ui/output_view.py +7 -1
- ui/schedule_view.py +128 -3
- ui/settings_view.py +82 -1
- ui/shift_input_view.py +158 -0
db/database.py
CHANGED
|
@@ -89,6 +89,15 @@ def initialize_db():
|
|
| 89 |
position TEXT NOT NULL CHECK(position IN ('hall','kitchen')),
|
| 90 |
UNIQUE(period_id, employee_id, date, time_slot)
|
| 91 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
""")
|
| 93 |
|
| 94 |
# マイグレーション: 新カラムを既存テーブルへ追加
|
|
@@ -106,5 +115,18 @@ def initialize_db():
|
|
| 106 |
except Exception:
|
| 107 |
pass # 既に存在する場合は無視
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
conn.commit()
|
| 110 |
conn.close()
|
|
|
|
| 89 |
position TEXT NOT NULL CHECK(position IN ('hall','kitchen')),
|
| 90 |
UNIQUE(period_id, employee_id, date, time_slot)
|
| 91 |
);
|
| 92 |
+
|
| 93 |
+
CREATE TABLE IF NOT EXISTS shift_constraints (
|
| 94 |
+
slot TEXT NOT NULL,
|
| 95 |
+
position TEXT NOT NULL,
|
| 96 |
+
min_staff INTEGER NOT NULL DEFAULT 2,
|
| 97 |
+
max_staff INTEGER NOT NULL DEFAULT 4,
|
| 98 |
+
min_leader INTEGER NOT NULL DEFAULT 1,
|
| 99 |
+
PRIMARY KEY (slot, position)
|
| 100 |
+
);
|
| 101 |
""")
|
| 102 |
|
| 103 |
# マイグレーション: 新カラムを既存テーブルへ追加
|
|
|
|
| 115 |
except Exception:
|
| 116 |
pass # 既に存在する場合は無視
|
| 117 |
|
| 118 |
+
# シフト制約のデフォルト値を投入(既に存在する場合は無視)
|
| 119 |
+
default_constraints = [
|
| 120 |
+
("breakfast", "hall", 3, 4, 1),
|
| 121 |
+
("breakfast", "kitchen", 3, 3, 1),
|
| 122 |
+
("dinner", "hall", 2, 3, 1),
|
| 123 |
+
("dinner", "kitchen", 3, 3, 2),
|
| 124 |
+
]
|
| 125 |
+
for slot, pos, mn, mx, ml in default_constraints:
|
| 126 |
+
cur.execute(
|
| 127 |
+
"INSERT OR IGNORE INTO shift_constraints (slot, position, min_staff, max_staff, min_leader) VALUES (?,?,?,?,?)",
|
| 128 |
+
(slot, pos, mn, mx, ml)
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
conn.commit()
|
| 132 |
conn.close()
|
db/repositories.py
CHANGED
|
@@ -59,6 +59,13 @@ def delete_employee(employee_id: int):
|
|
| 59 |
conn.close()
|
| 60 |
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def _row_to_employee(row, conn) -> Employee:
|
| 63 |
patterns = conn.execute(
|
| 64 |
"SELECT * FROM fixed_patterns WHERE employee_id=? ORDER BY day_of_week",
|
|
@@ -270,3 +277,47 @@ def remove_assignment(period_id: int, employee_id: int, date: str, time_slot: Ti
|
|
| 270 |
)
|
| 271 |
conn.commit()
|
| 272 |
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
conn.close()
|
| 60 |
|
| 61 |
|
| 62 |
+
def restore_employee(employee_id: int):
|
| 63 |
+
conn = get_connection()
|
| 64 |
+
conn.execute("UPDATE employees SET is_active=1 WHERE id=?", (employee_id,))
|
| 65 |
+
conn.commit()
|
| 66 |
+
conn.close()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
def _row_to_employee(row, conn) -> Employee:
|
| 70 |
patterns = conn.execute(
|
| 71 |
"SELECT * FROM fixed_patterns WHERE employee_id=? ORDER BY day_of_week",
|
|
|
|
| 277 |
)
|
| 278 |
conn.commit()
|
| 279 |
conn.close()
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
# ── シフト制約 ──────────────────────────────────────────────────────────
|
| 283 |
+
|
| 284 |
+
def get_shift_constraints() -> dict:
|
| 285 |
+
"""
|
| 286 |
+
DB から制約を読み込んで {(TimeSlot, Position): {"min": int, "max": int, "min_leader": int}} を返す。
|
| 287 |
+
テーブルが空の場合は定数フォールバック。
|
| 288 |
+
"""
|
| 289 |
+
from utils.constants import SHIFT_CONSTRAINTS as _FALLBACK
|
| 290 |
+
conn = get_connection()
|
| 291 |
+
rows = conn.execute("SELECT * FROM shift_constraints").fetchall()
|
| 292 |
+
conn.close()
|
| 293 |
+
if not rows:
|
| 294 |
+
return _FALLBACK
|
| 295 |
+
result = {}
|
| 296 |
+
for r in rows:
|
| 297 |
+
slot = TimeSlot(r["slot"])
|
| 298 |
+
pos = Position(r["position"])
|
| 299 |
+
result[(slot, pos)] = {
|
| 300 |
+
"min": r["min_staff"],
|
| 301 |
+
"max": r["max_staff"],
|
| 302 |
+
"min_leader": r["min_leader"],
|
| 303 |
+
}
|
| 304 |
+
return result
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def save_shift_constraints(constraints: dict):
|
| 308 |
+
"""
|
| 309 |
+
{(TimeSlot, Position): {"min": int, "max": int, "min_leader": int}} を DB に保存。
|
| 310 |
+
"""
|
| 311 |
+
conn = get_connection()
|
| 312 |
+
for (slot, pos), vals in constraints.items():
|
| 313 |
+
conn.execute(
|
| 314 |
+
"""INSERT INTO shift_constraints (slot, position, min_staff, max_staff, min_leader)
|
| 315 |
+
VALUES (?,?,?,?,?)
|
| 316 |
+
ON CONFLICT(slot, position) DO UPDATE SET
|
| 317 |
+
min_staff=excluded.min_staff,
|
| 318 |
+
max_staff=excluded.max_staff,
|
| 319 |
+
min_leader=excluded.min_leader""",
|
| 320 |
+
(slot.value, pos.value, vals["min"], vals["max"], vals["min_leader"])
|
| 321 |
+
)
|
| 322 |
+
conn.commit()
|
| 323 |
+
conn.close()
|
optimizer/solver.py
CHANGED
|
@@ -7,7 +7,7 @@ from models.employee import Employee
|
|
| 7 |
from models.schedule import ShiftRequest, ShiftAssignment, SchedulePeriod
|
| 8 |
from utils.constants import (
|
| 9 |
TimeSlot, Position, SkillLevel, EmploymentType, PrimaryPosition,
|
| 10 |
-
|
| 11 |
)
|
| 12 |
|
| 13 |
|
|
@@ -76,6 +76,10 @@ def solve(
|
|
| 76 |
|
| 77 |
active_employees = [e for e in employees if e.is_active]
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
# ── 決定変数 ────────────────────────────────────────────────────────
|
| 80 |
# assign[e_id][date_str][slot][pos] = BoolVar
|
| 81 |
assign: dict = {}
|
|
@@ -136,7 +140,7 @@ def solve(
|
|
| 136 |
for slot in slots:
|
| 137 |
for pos in positions:
|
| 138 |
key = (slot, pos)
|
| 139 |
-
constraint =
|
| 140 |
if not constraint:
|
| 141 |
continue
|
| 142 |
staff_vars = [
|
|
@@ -151,7 +155,7 @@ def solve(
|
|
| 151 |
for slot in slots:
|
| 152 |
for pos in positions:
|
| 153 |
key = (slot, pos)
|
| 154 |
-
constraint =
|
| 155 |
if not constraint:
|
| 156 |
continue
|
| 157 |
min_leader = constraint.get("min_leader", 0)
|
|
@@ -289,7 +293,7 @@ def solve(
|
|
| 289 |
# ベストエフォート生成: 人数・リーダー制約をソフト化して再実行
|
| 290 |
best_assignments, best_warnings = _solve_best_effort(
|
| 291 |
active_employees, date_strs, slots, positions,
|
| 292 |
-
req_map, req_hours, config
|
| 293 |
)
|
| 294 |
_check_warnings(best_assignments, date_strs, best_warnings)
|
| 295 |
|
|
@@ -319,11 +323,15 @@ def _extract_assignments(solver, assign, active_employees, date_strs, slots, pos
|
|
| 319 |
def _solve_best_effort(
|
| 320 |
active_employees, date_strs, slots, positions,
|
| 321 |
req_map, req_hours, config: SolverConfig | None = None,
|
|
|
|
| 322 |
) -> tuple[list[ShiftAssignment], list[str]]:
|
| 323 |
"""人数・リーダー制約をソフト化してベストエフォートのシフトを生成する"""
|
| 324 |
import time
|
| 325 |
if config is None:
|
| 326 |
config = SolverConfig()
|
|
|
|
|
|
|
|
|
|
| 327 |
model = cp_model.CpModel()
|
| 328 |
|
| 329 |
assign: dict = {}
|
|
@@ -378,7 +386,7 @@ def _solve_best_effort(
|
|
| 378 |
for ds in date_strs:
|
| 379 |
for slot in slots:
|
| 380 |
for pos in positions:
|
| 381 |
-
constraint =
|
| 382 |
if not constraint:
|
| 383 |
continue
|
| 384 |
min_req = constraint["min"]
|
|
@@ -444,6 +452,8 @@ def _solve_best_effort(
|
|
| 444 |
|
| 445 |
def _check_warnings(assignments: list[ShiftAssignment], date_strs: list[str], warnings: list[str]):
|
| 446 |
from collections import defaultdict
|
|
|
|
|
|
|
| 447 |
count = defaultdict(int)
|
| 448 |
for a in assignments:
|
| 449 |
count[(a.date, a.time_slot.value, a.position.value)] += 1
|
|
@@ -455,7 +465,7 @@ def _check_warnings(assignments: list[ShiftAssignment], date_strs: list[str], wa
|
|
| 455 |
for slot in TimeSlot:
|
| 456 |
for pos in Position:
|
| 457 |
c = count[(ds, slot.value, pos.value)]
|
| 458 |
-
constraint =
|
| 459 |
if c == constraint.get("min", 0):
|
| 460 |
warnings.append(
|
| 461 |
f"{label} {slot.short_label()} {pos.label()}: "
|
|
@@ -471,7 +481,8 @@ def _diagnose_infeasible(
|
|
| 471 |
"""実行不可能の原因を診断してエラーメッセージを返す"""
|
| 472 |
errors = []
|
| 473 |
from collections import defaultdict
|
| 474 |
-
from
|
|
|
|
| 475 |
|
| 476 |
for ds in date_strs:
|
| 477 |
d = date.fromisoformat(ds)
|
|
@@ -481,7 +492,7 @@ def _diagnose_infeasible(
|
|
| 481 |
for slot in TimeSlot:
|
| 482 |
for pos in Position:
|
| 483 |
key = (slot, pos)
|
| 484 |
-
constraint =
|
| 485 |
if not constraint:
|
| 486 |
continue
|
| 487 |
|
|
|
|
| 7 |
from models.schedule import ShiftRequest, ShiftAssignment, SchedulePeriod
|
| 8 |
from utils.constants import (
|
| 9 |
TimeSlot, Position, SkillLevel, EmploymentType, PrimaryPosition,
|
| 10 |
+
LATE_NIGHT_START
|
| 11 |
)
|
| 12 |
|
| 13 |
|
|
|
|
| 76 |
|
| 77 |
active_employees = [e for e in employees if e.is_active]
|
| 78 |
|
| 79 |
+
# DB から制約を読み込む
|
| 80 |
+
from db import repositories as repo
|
| 81 |
+
shift_constraints = repo.get_shift_constraints()
|
| 82 |
+
|
| 83 |
# ── 決定変数 ────────────────────────────────────────────────────────
|
| 84 |
# assign[e_id][date_str][slot][pos] = BoolVar
|
| 85 |
assign: dict = {}
|
|
|
|
| 140 |
for slot in slots:
|
| 141 |
for pos in positions:
|
| 142 |
key = (slot, pos)
|
| 143 |
+
constraint = shift_constraints.get(key)
|
| 144 |
if not constraint:
|
| 145 |
continue
|
| 146 |
staff_vars = [
|
|
|
|
| 155 |
for slot in slots:
|
| 156 |
for pos in positions:
|
| 157 |
key = (slot, pos)
|
| 158 |
+
constraint = shift_constraints.get(key)
|
| 159 |
if not constraint:
|
| 160 |
continue
|
| 161 |
min_leader = constraint.get("min_leader", 0)
|
|
|
|
| 293 |
# ベストエフォート生成: 人数・リーダー制約をソフト化して再実行
|
| 294 |
best_assignments, best_warnings = _solve_best_effort(
|
| 295 |
active_employees, date_strs, slots, positions,
|
| 296 |
+
req_map, req_hours, config, shift_constraints
|
| 297 |
)
|
| 298 |
_check_warnings(best_assignments, date_strs, best_warnings)
|
| 299 |
|
|
|
|
| 323 |
def _solve_best_effort(
|
| 324 |
active_employees, date_strs, slots, positions,
|
| 325 |
req_map, req_hours, config: SolverConfig | None = None,
|
| 326 |
+
shift_constraints: dict | None = None,
|
| 327 |
) -> tuple[list[ShiftAssignment], list[str]]:
|
| 328 |
"""人数・リーダー制約をソフト化してベストエフォートのシフトを生成する"""
|
| 329 |
import time
|
| 330 |
if config is None:
|
| 331 |
config = SolverConfig()
|
| 332 |
+
if shift_constraints is None:
|
| 333 |
+
from db import repositories as repo
|
| 334 |
+
shift_constraints = repo.get_shift_constraints()
|
| 335 |
model = cp_model.CpModel()
|
| 336 |
|
| 337 |
assign: dict = {}
|
|
|
|
| 386 |
for ds in date_strs:
|
| 387 |
for slot in slots:
|
| 388 |
for pos in positions:
|
| 389 |
+
constraint = shift_constraints.get((slot, pos))
|
| 390 |
if not constraint:
|
| 391 |
continue
|
| 392 |
min_req = constraint["min"]
|
|
|
|
| 452 |
|
| 453 |
def _check_warnings(assignments: list[ShiftAssignment], date_strs: list[str], warnings: list[str]):
|
| 454 |
from collections import defaultdict
|
| 455 |
+
from db import repositories as repo
|
| 456 |
+
shift_constraints = repo.get_shift_constraints()
|
| 457 |
count = defaultdict(int)
|
| 458 |
for a in assignments:
|
| 459 |
count[(a.date, a.time_slot.value, a.position.value)] += 1
|
|
|
|
| 465 |
for slot in TimeSlot:
|
| 466 |
for pos in Position:
|
| 467 |
c = count[(ds, slot.value, pos.value)]
|
| 468 |
+
constraint = shift_constraints.get((slot, pos), {})
|
| 469 |
if c == constraint.get("min", 0):
|
| 470 |
warnings.append(
|
| 471 |
f"{label} {slot.short_label()} {pos.label()}: "
|
|
|
|
| 481 |
"""実行不可能の原因を診断してエラーメッセージを返す"""
|
| 482 |
errors = []
|
| 483 |
from collections import defaultdict
|
| 484 |
+
from db import repositories as repo
|
| 485 |
+
shift_constraints = repo.get_shift_constraints()
|
| 486 |
|
| 487 |
for ds in date_strs:
|
| 488 |
d = date.fromisoformat(ds)
|
|
|
|
| 492 |
for slot in TimeSlot:
|
| 493 |
for pos in Position:
|
| 494 |
key = (slot, pos)
|
| 495 |
+
constraint = shift_constraints.get(key)
|
| 496 |
if not constraint:
|
| 497 |
continue
|
| 498 |
|
ui/employee_view.py
CHANGED
|
@@ -5,7 +5,7 @@ from PyQt6.QtWidgets import (
|
|
| 5 |
QTableWidgetItem, QHeaderView, QDialog, QFormLayout, QLineEdit,
|
| 6 |
QComboBox, QGroupBox, QCheckBox, QLabel, QMessageBox,
|
| 7 |
QCalendarWidget, QDialogButtonBox, QSizePolicy, QFrame,
|
| 8 |
-
QScrollArea, QGridLayout
|
| 9 |
)
|
| 10 |
from PyQt6.QtCore import Qt, QDate
|
| 11 |
from PyQt6.QtGui import QFont, QColor
|
|
@@ -32,6 +32,11 @@ class EmployeeView(QWidget):
|
|
| 32 |
title.setFont(QFont("", 16, QFont.Weight.Bold))
|
| 33 |
header.addWidget(title)
|
| 34 |
header.addStretch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
self._btn_new = QPushButton("+ 新規登録")
|
| 36 |
self._btn_new.setFixedHeight(36)
|
| 37 |
self._btn_new.clicked.connect(self._on_new)
|
|
@@ -39,6 +44,8 @@ class EmployeeView(QWidget):
|
|
| 39 |
self._apply_btn_style()
|
| 40 |
layout.addLayout(header)
|
| 41 |
|
|
|
|
|
|
|
| 42 |
# テーブル
|
| 43 |
self.table = QTableWidget()
|
| 44 |
self.table.setColumnCount(7)
|
|
@@ -59,6 +66,12 @@ class EmployeeView(QWidget):
|
|
| 59 |
|
| 60 |
def _apply_btn_style(self):
|
| 61 |
c = theme.c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
self._btn_new.setStyleSheet(
|
| 63 |
f"QPushButton {{ background:{c['primary']}; color:white; border-radius:6px; "
|
| 64 |
f"padding:0 16px; font-weight:bold; }} "
|
|
@@ -69,19 +82,33 @@ class EmployeeView(QWidget):
|
|
| 69 |
self._apply_btn_style()
|
| 70 |
self.refresh()
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def refresh(self):
|
| 73 |
-
self.employees = repo.get_all_employees()
|
| 74 |
self.table.setRowCount(len(self.employees))
|
| 75 |
for row, emp in enumerate(self.employees):
|
| 76 |
pp_text = emp.primary_position.label() if emp.primary_position else "どちらでも"
|
| 77 |
pt_text = emp.primary_timeslot.short_label() + "専任" if emp.primary_timeslot else "どちらでも"
|
| 78 |
skill_text = f"H:{emp.hall_skill.label()} / K:{emp.kitchen_skill.label()}"
|
|
|
|
| 79 |
self.table.setItem(row, 0, QTableWidgetItem(str(emp.id)))
|
| 80 |
-
self.table.setItem(row, 1, QTableWidgetItem(
|
| 81 |
self.table.setItem(row, 2, QTableWidgetItem(pp_text))
|
| 82 |
self.table.setItem(row, 3, QTableWidgetItem(pt_text))
|
| 83 |
self.table.setItem(row, 4, QTableWidgetItem(skill_text))
|
| 84 |
self.table.setItem(row, 5, QTableWidgetItem(emp.employment_type.label()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# 操作ボタン
|
| 87 |
btn_widget = QWidget()
|
|
@@ -89,27 +116,38 @@ class EmployeeView(QWidget):
|
|
| 89 |
btn_layout.setContentsMargins(4, 2, 4, 2)
|
| 90 |
btn_layout.setSpacing(6)
|
| 91 |
|
| 92 |
-
btn_edit = QPushButton("編集")
|
| 93 |
-
btn_edit.setFixedSize(56, 28)
|
| 94 |
c = theme.c
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
self.table.setCellWidget(row, 6, btn_widget)
|
| 114 |
self.table.setRowHeight(row, 40)
|
| 115 |
|
|
@@ -125,6 +163,16 @@ class EmployeeView(QWidget):
|
|
| 125 |
repo.save_employee(dlg.employee)
|
| 126 |
self.refresh()
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
def _on_delete(self, emp: Employee):
|
| 129 |
reply = QMessageBox.question(
|
| 130 |
self, "削除確認",
|
|
@@ -228,6 +276,40 @@ class EmployeeDialog(QDialog):
|
|
| 228 |
|
| 229 |
layout.addWidget(self.parttime_group)
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
# ボタン
|
| 232 |
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
| 233 |
buttons.button(QDialogButtonBox.StandardButton.Save).setText("保存")
|
|
@@ -243,6 +325,18 @@ class EmployeeDialog(QDialog):
|
|
| 243 |
self.parttime_group.setVisible(is_part)
|
| 244 |
self.adjustSize()
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
def _load_employee(self, emp: Employee):
|
| 247 |
self.name_edit.setText(emp.name)
|
| 248 |
idx = self.emp_type_combo.findData(emp.employment_type)
|
|
@@ -262,6 +356,10 @@ class EmployeeDialog(QDialog):
|
|
| 262 |
cb_b.setChecked(p.breakfast if p else False)
|
| 263 |
cb_d.setChecked(p.dinner if p else False)
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
def _on_save(self):
|
| 266 |
name = self.name_edit.text().strip()
|
| 267 |
if not name:
|
|
@@ -281,7 +379,10 @@ class EmployeeDialog(QDialog):
|
|
| 281 |
patterns.append(FixedPattern(i, cb_b.isChecked(), cb_d.isChecked()))
|
| 282 |
|
| 283 |
existing_id = self.employee.id if self.employee else None
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
| 285 |
|
| 286 |
self.employee = Employee(
|
| 287 |
id=existing_id,
|
|
@@ -292,6 +393,6 @@ class EmployeeDialog(QDialog):
|
|
| 292 |
primary_position=primary_position,
|
| 293 |
primary_timeslot=primary_timeslot,
|
| 294 |
fixed_patterns=patterns,
|
| 295 |
-
fixed_unavailable_dates=
|
| 296 |
)
|
| 297 |
self.accept()
|
|
|
|
| 5 |
QTableWidgetItem, QHeaderView, QDialog, QFormLayout, QLineEdit,
|
| 6 |
QComboBox, QGroupBox, QCheckBox, QLabel, QMessageBox,
|
| 7 |
QCalendarWidget, QDialogButtonBox, QSizePolicy, QFrame,
|
| 8 |
+
QScrollArea, QGridLayout, QListWidget, QDateEdit
|
| 9 |
)
|
| 10 |
from PyQt6.QtCore import Qt, QDate
|
| 11 |
from PyQt6.QtGui import QFont, QColor
|
|
|
|
| 32 |
title.setFont(QFont("", 16, QFont.Weight.Bold))
|
| 33 |
header.addWidget(title)
|
| 34 |
header.addStretch()
|
| 35 |
+
self._btn_show_archive = QPushButton("アーカイブを表示")
|
| 36 |
+
self._btn_show_archive.setFixedHeight(36)
|
| 37 |
+
self._btn_show_archive.setCheckable(True)
|
| 38 |
+
self._btn_show_archive.toggled.connect(self._on_toggle_archive)
|
| 39 |
+
header.addWidget(self._btn_show_archive)
|
| 40 |
self._btn_new = QPushButton("+ 新規登録")
|
| 41 |
self._btn_new.setFixedHeight(36)
|
| 42 |
self._btn_new.clicked.connect(self._on_new)
|
|
|
|
| 44 |
self._apply_btn_style()
|
| 45 |
layout.addLayout(header)
|
| 46 |
|
| 47 |
+
self._show_archive = False
|
| 48 |
+
|
| 49 |
# テーブル
|
| 50 |
self.table = QTableWidget()
|
| 51 |
self.table.setColumnCount(7)
|
|
|
|
| 66 |
|
| 67 |
def _apply_btn_style(self):
|
| 68 |
c = theme.c
|
| 69 |
+
self._btn_show_archive.setStyleSheet(
|
| 70 |
+
f"QPushButton {{ background:{c['surface']}; border:1px solid {c['border2']}; "
|
| 71 |
+
f"border-radius:6px; padding:0 16px; color:{c['text']}; }} "
|
| 72 |
+
f"QPushButton:checked {{ background:{c['surface2']}; color:{c['text2']}; }} "
|
| 73 |
+
f"QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 74 |
+
)
|
| 75 |
self._btn_new.setStyleSheet(
|
| 76 |
f"QPushButton {{ background:{c['primary']}; color:white; border-radius:6px; "
|
| 77 |
f"padding:0 16px; font-weight:bold; }} "
|
|
|
|
| 82 |
self._apply_btn_style()
|
| 83 |
self.refresh()
|
| 84 |
|
| 85 |
+
def _on_toggle_archive(self, checked: bool):
|
| 86 |
+
self._show_archive = checked
|
| 87 |
+
self._btn_show_archive.setText(
|
| 88 |
+
"アクティブを表示" if checked else "アーカイブを表示"
|
| 89 |
+
)
|
| 90 |
+
self.refresh()
|
| 91 |
+
|
| 92 |
def refresh(self):
|
| 93 |
+
self.employees = repo.get_all_employees(active_only=not self._show_archive)
|
| 94 |
self.table.setRowCount(len(self.employees))
|
| 95 |
for row, emp in enumerate(self.employees):
|
| 96 |
pp_text = emp.primary_position.label() if emp.primary_position else "どちらでも"
|
| 97 |
pt_text = emp.primary_timeslot.short_label() + "専任" if emp.primary_timeslot else "どちらでも"
|
| 98 |
skill_text = f"H:{emp.hall_skill.label()} / K:{emp.kitchen_skill.label()}"
|
| 99 |
+
name_text = emp.name if emp.is_active else f"{emp.name}(アーカイブ)"
|
| 100 |
self.table.setItem(row, 0, QTableWidgetItem(str(emp.id)))
|
| 101 |
+
self.table.setItem(row, 1, QTableWidgetItem(name_text))
|
| 102 |
self.table.setItem(row, 2, QTableWidgetItem(pp_text))
|
| 103 |
self.table.setItem(row, 3, QTableWidgetItem(pt_text))
|
| 104 |
self.table.setItem(row, 4, QTableWidgetItem(skill_text))
|
| 105 |
self.table.setItem(row, 5, QTableWidgetItem(emp.employment_type.label()))
|
| 106 |
+
if not emp.is_active:
|
| 107 |
+
from PyQt6.QtGui import QColor, QBrush
|
| 108 |
+
for col in range(6):
|
| 109 |
+
item = self.table.item(row, col)
|
| 110 |
+
if item:
|
| 111 |
+
item.setForeground(QBrush(QColor("#9ca3af")))
|
| 112 |
|
| 113 |
# 操作ボタン
|
| 114 |
btn_widget = QWidget()
|
|
|
|
| 116 |
btn_layout.setContentsMargins(4, 2, 4, 2)
|
| 117 |
btn_layout.setSpacing(6)
|
| 118 |
|
|
|
|
|
|
|
| 119 |
c = theme.c
|
| 120 |
+
if emp.is_active:
|
| 121 |
+
btn_edit = QPushButton("編集")
|
| 122 |
+
btn_edit.setFixedSize(56, 28)
|
| 123 |
+
btn_edit.setStyleSheet(
|
| 124 |
+
f"QPushButton {{ background:{c['surface']}; border:1px solid {c['border2']}; "
|
| 125 |
+
f"border-radius:4px; color:{c['text']}; }} "
|
| 126 |
+
f"QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 127 |
+
)
|
| 128 |
+
btn_edit.clicked.connect(lambda _, e=emp: self._on_edit(e))
|
| 129 |
+
btn_layout.addWidget(btn_edit)
|
| 130 |
+
|
| 131 |
+
btn_del = QPushButton("削除")
|
| 132 |
+
btn_del.setFixedSize(56, 28)
|
| 133 |
+
btn_del.setStyleSheet(
|
| 134 |
+
f"QPushButton {{ background:{c['danger_bg']}; border:1px solid {c['danger_border']}; "
|
| 135 |
+
f"border-radius:4px; color:{c['danger_text']}; }} "
|
| 136 |
+
f"QPushButton:hover {{ background:{c['danger_bg']}; }}"
|
| 137 |
+
)
|
| 138 |
+
btn_del.clicked.connect(lambda _, e=emp: self._on_delete(e))
|
| 139 |
+
btn_layout.addWidget(btn_del)
|
| 140 |
+
else:
|
| 141 |
+
btn_restore = QPushButton("復元")
|
| 142 |
+
btn_restore.setFixedSize(56, 28)
|
| 143 |
+
btn_restore.setStyleSheet(
|
| 144 |
+
f"QPushButton {{ background:{c['primary']}; border:none; "
|
| 145 |
+
f"border-radius:4px; color:white; }} "
|
| 146 |
+
f"QPushButton:hover {{ background:{c['primary_hover']}; }}"
|
| 147 |
+
)
|
| 148 |
+
btn_restore.clicked.connect(lambda _, e=emp: self._on_restore(e))
|
| 149 |
+
btn_layout.addWidget(btn_restore)
|
| 150 |
+
|
| 151 |
self.table.setCellWidget(row, 6, btn_widget)
|
| 152 |
self.table.setRowHeight(row, 40)
|
| 153 |
|
|
|
|
| 163 |
repo.save_employee(dlg.employee)
|
| 164 |
self.refresh()
|
| 165 |
|
| 166 |
+
def _on_restore(self, emp: Employee):
|
| 167 |
+
reply = QMessageBox.question(
|
| 168 |
+
self, "復元確認",
|
| 169 |
+
f"「{emp.name}さん」を復元しますか?\n(アクティブな従業員として再登録されます)",
|
| 170 |
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
| 171 |
+
)
|
| 172 |
+
if reply == QMessageBox.StandardButton.Yes:
|
| 173 |
+
repo.restore_employee(emp.id)
|
| 174 |
+
self.refresh()
|
| 175 |
+
|
| 176 |
def _on_delete(self, emp: Employee):
|
| 177 |
reply = QMessageBox.question(
|
| 178 |
self, "削除確認",
|
|
|
|
| 276 |
|
| 277 |
layout.addWidget(self.parttime_group)
|
| 278 |
|
| 279 |
+
# 固定不可日
|
| 280 |
+
unavail_group = QGroupBox("固定不可日(出勤不可の日を登録)")
|
| 281 |
+
unavail_vl = QVBoxLayout(unavail_group)
|
| 282 |
+
unavail_vl.setSpacing(6)
|
| 283 |
+
|
| 284 |
+
add_row = QHBoxLayout()
|
| 285 |
+
self._unavail_date_edit = QDateEdit()
|
| 286 |
+
self._unavail_date_edit.setCalendarPopup(True)
|
| 287 |
+
self._unavail_date_edit.setDate(QDate.currentDate())
|
| 288 |
+
self._unavail_date_edit.setDisplayFormat("yyyy/MM/dd")
|
| 289 |
+
btn_add_unavail = QPushButton("追加")
|
| 290 |
+
btn_add_unavail.setFixedWidth(56)
|
| 291 |
+
btn_add_unavail.clicked.connect(self._add_unavail_date)
|
| 292 |
+
add_row.addWidget(QLabel("日付:"))
|
| 293 |
+
add_row.addWidget(self._unavail_date_edit)
|
| 294 |
+
add_row.addWidget(btn_add_unavail)
|
| 295 |
+
add_row.addStretch()
|
| 296 |
+
unavail_vl.addLayout(add_row)
|
| 297 |
+
|
| 298 |
+
self._unavail_list = QListWidget()
|
| 299 |
+
self._unavail_list.setMaximumHeight(90)
|
| 300 |
+
self._unavail_list.setSelectionMode(QListWidget.SelectionMode.MultiSelection)
|
| 301 |
+
unavail_vl.addWidget(self._unavail_list)
|
| 302 |
+
|
| 303 |
+
btn_remove_row = QHBoxLayout()
|
| 304 |
+
btn_remove_row.addStretch()
|
| 305 |
+
btn_remove_unavail = QPushButton("選択した日を削除")
|
| 306 |
+
btn_remove_unavail.setFixedHeight(28)
|
| 307 |
+
btn_remove_unavail.clicked.connect(self._remove_unavail_dates)
|
| 308 |
+
btn_remove_row.addWidget(btn_remove_unavail)
|
| 309 |
+
unavail_vl.addLayout(btn_remove_row)
|
| 310 |
+
|
| 311 |
+
layout.addWidget(unavail_group)
|
| 312 |
+
|
| 313 |
# ボタン
|
| 314 |
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
| 315 |
buttons.button(QDialogButtonBox.StandardButton.Save).setText("保存")
|
|
|
|
| 325 |
self.parttime_group.setVisible(is_part)
|
| 326 |
self.adjustSize()
|
| 327 |
|
| 328 |
+
def _add_unavail_date(self):
|
| 329 |
+
ds = self._unavail_date_edit.date().toString("yyyy-MM-dd")
|
| 330 |
+
# 重複チェック
|
| 331 |
+
existing = [self._unavail_list.item(i).text() for i in range(self._unavail_list.count())]
|
| 332 |
+
if ds not in existing:
|
| 333 |
+
self._unavail_list.addItem(ds)
|
| 334 |
+
self._unavail_list.sortItems()
|
| 335 |
+
|
| 336 |
+
def _remove_unavail_dates(self):
|
| 337 |
+
for item in self._unavail_list.selectedItems():
|
| 338 |
+
self._unavail_list.takeItem(self._unavail_list.row(item))
|
| 339 |
+
|
| 340 |
def _load_employee(self, emp: Employee):
|
| 341 |
self.name_edit.setText(emp.name)
|
| 342 |
idx = self.emp_type_combo.findData(emp.employment_type)
|
|
|
|
| 356 |
cb_b.setChecked(p.breakfast if p else False)
|
| 357 |
cb_d.setChecked(p.dinner if p else False)
|
| 358 |
|
| 359 |
+
self._unavail_list.clear()
|
| 360 |
+
for ds in sorted(emp.fixed_unavailable_dates):
|
| 361 |
+
self._unavail_list.addItem(ds)
|
| 362 |
+
|
| 363 |
def _on_save(self):
|
| 364 |
name = self.name_edit.text().strip()
|
| 365 |
if not name:
|
|
|
|
| 379 |
patterns.append(FixedPattern(i, cb_b.isChecked(), cb_d.isChecked()))
|
| 380 |
|
| 381 |
existing_id = self.employee.id if self.employee else None
|
| 382 |
+
unavail_dates = [
|
| 383 |
+
self._unavail_list.item(i).text()
|
| 384 |
+
for i in range(self._unavail_list.count())
|
| 385 |
+
]
|
| 386 |
|
| 387 |
self.employee = Employee(
|
| 388 |
id=existing_id,
|
|
|
|
| 393 |
primary_position=primary_position,
|
| 394 |
primary_timeslot=primary_timeslot,
|
| 395 |
fixed_patterns=patterns,
|
| 396 |
+
fixed_unavailable_dates=unavail_dates,
|
| 397 |
)
|
| 398 |
self.accept()
|
ui/output_view.py
CHANGED
|
@@ -51,7 +51,13 @@ class OutputDialog(QDialog):
|
|
| 51 |
path_group = QGroupBox("保存先")
|
| 52 |
pl = QHBoxLayout(path_group)
|
| 53 |
self.path_edit = QLineEdit()
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
default_dir = os.path.expanduser("~/Desktop")
|
| 56 |
self.path_edit.setText(os.path.join(default_dir, default_name))
|
| 57 |
btn_browse = QPushButton("参照...")
|
|
|
|
| 51 |
path_group = QGroupBox("保存先")
|
| 52 |
pl = QHBoxLayout(path_group)
|
| 53 |
self.path_edit = QLineEdit()
|
| 54 |
+
# 自動ファイル名: シフト表_YYYY年M月D日-M月D日
|
| 55 |
+
from datetime import date as _date
|
| 56 |
+
sd = _date.fromisoformat(self.period.start_date)
|
| 57 |
+
ed = _date.fromisoformat(self.period.end_date)
|
| 58 |
+
default_name = (
|
| 59 |
+
f"シフト表_{sd.year}年{sd.month}月{sd.day}日-{ed.month}月{ed.day}日.pdf"
|
| 60 |
+
)
|
| 61 |
default_dir = os.path.expanduser("~/Desktop")
|
| 62 |
self.path_edit.setText(os.path.join(default_dir, default_name))
|
| 63 |
btn_browse = QPushButton("参照...")
|
ui/schedule_view.py
CHANGED
|
@@ -15,7 +15,7 @@ from models.employee import Employee
|
|
| 15 |
from models.schedule import ShiftAssignment, ShiftRequest
|
| 16 |
from utils.constants import (
|
| 17 |
TimeSlot, Position, PrimaryPosition, SkillLevel,
|
| 18 |
-
DAY_OF_WEEK_LABELS
|
| 19 |
)
|
| 20 |
from utils.theme import theme
|
| 21 |
|
|
@@ -61,6 +61,12 @@ class ScheduleView(QWidget):
|
|
| 61 |
header.addWidget(QLabel("期間:"))
|
| 62 |
header.addWidget(self.period_combo)
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
self._btn_output = QPushButton("出力 →")
|
| 65 |
self._btn_output.setFixedHeight(32)
|
| 66 |
self._btn_output.clicked.connect(self._on_output)
|
|
@@ -99,6 +105,20 @@ class ScheduleView(QWidget):
|
|
| 99 |
|
| 100 |
self.tab_widget.addTab(tab_b, "🌅 朝食")
|
| 101 |
self.tab_widget.addTab(tab_d, "🌆 ディナー")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
layout.addWidget(self.tab_widget)
|
| 103 |
|
| 104 |
self.status_label = QLabel("")
|
|
@@ -209,6 +229,7 @@ class ScheduleView(QWidget):
|
|
| 209 |
|
| 210 |
def apply_theme(self):
|
| 211 |
self._apply_styles()
|
|
|
|
| 212 |
self._render_table()
|
| 213 |
|
| 214 |
# ── データ読み込み ─────────────────────────────────────────────────────
|
|
@@ -239,9 +260,11 @@ class ScheduleView(QWidget):
|
|
| 239 |
self.sum_table_b, self.sum_table_d):
|
| 240 |
t.setRowCount(0)
|
| 241 |
t.setColumnCount(0)
|
|
|
|
| 242 |
return
|
| 243 |
self._load_data()
|
| 244 |
self._render_table()
|
|
|
|
| 245 |
|
| 246 |
def _load_data(self):
|
| 247 |
self._employees = repo.get_all_employees()
|
|
@@ -269,6 +292,57 @@ class ScheduleView(QWidget):
|
|
| 269 |
self.emp_table_b, self.sum_table_b, TimeSlot.BREAKFAST, self._warn_label_b)
|
| 270 |
self._render_slot_table(
|
| 271 |
self.emp_table_d, self.sum_table_d, TimeSlot.DINNER, self._warn_label_d)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
def _render_slot_table(self, emp_table: QTableWidget, sum_table: QTableWidget,
|
| 274 |
slot: TimeSlot, warn_label: QLabel):
|
|
@@ -439,7 +513,8 @@ class ScheduleView(QWidget):
|
|
| 439 |
label_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 440 |
table.setItem(row, 0, label_item)
|
| 441 |
|
| 442 |
-
|
|
|
|
| 443 |
min_req = constraint.get("min", 0)
|
| 444 |
min_leader = constraint.get("min_leader", 0)
|
| 445 |
|
|
@@ -465,6 +540,7 @@ class ScheduleView(QWidget):
|
|
| 465 |
|
| 466 |
def _update_constraint_warnings(self, warn_label: QLabel, slot: TimeSlot,
|
| 467 |
dates: list, count_map: dict, leader_map: dict):
|
|
|
|
| 468 |
violations = []
|
| 469 |
for d in dates:
|
| 470 |
ds = d.isoformat()
|
|
@@ -472,7 +548,7 @@ class ScheduleView(QWidget):
|
|
| 472 |
for pos in Position:
|
| 473 |
cnt = count_map[(ds, pos.value)]
|
| 474 |
ld = leader_map[(ds, pos.value)]
|
| 475 |
-
constraint =
|
| 476 |
min_req = constraint.get("min", 0)
|
| 477 |
min_leader = constraint.get("min_leader", 0)
|
| 478 |
if cnt < min_req:
|
|
@@ -500,6 +576,8 @@ class ScheduleView(QWidget):
|
|
| 500 |
dlg.exec()
|
| 501 |
|
| 502 |
def _on_cell_clicked(self, row: int, col: int, table: QTableWidget, slot: TimeSlot):
|
|
|
|
|
|
|
| 503 |
item = table.item(row, col)
|
| 504 |
if not item:
|
| 505 |
return
|
|
@@ -564,6 +642,53 @@ class ScheduleView(QWidget):
|
|
| 564 |
self._assignments[(emp_id, ds, slot_v)] = (dlg.selected_position.value, True)
|
| 565 |
self._render_table()
|
| 566 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
def _on_output(self):
|
| 568 |
if not self._period:
|
| 569 |
return
|
|
|
|
| 15 |
from models.schedule import ShiftAssignment, ShiftRequest
|
| 16 |
from utils.constants import (
|
| 17 |
TimeSlot, Position, PrimaryPosition, SkillLevel,
|
| 18 |
+
DAY_OF_WEEK_LABELS
|
| 19 |
)
|
| 20 |
from utils.theme import theme
|
| 21 |
|
|
|
|
| 61 |
header.addWidget(QLabel("期間:"))
|
| 62 |
header.addWidget(self.period_combo)
|
| 63 |
|
| 64 |
+
self._btn_confirm = QPushButton("✅ 確定する")
|
| 65 |
+
self._btn_confirm.setFixedHeight(32)
|
| 66 |
+
self._btn_confirm.setEnabled(False)
|
| 67 |
+
self._btn_confirm.clicked.connect(self._on_toggle_confirm)
|
| 68 |
+
header.addWidget(self._btn_confirm)
|
| 69 |
+
|
| 70 |
self._btn_output = QPushButton("出力 →")
|
| 71 |
self._btn_output.setFixedHeight(32)
|
| 72 |
self._btn_output.clicked.connect(self._on_output)
|
|
|
|
| 105 |
|
| 106 |
self.tab_widget.addTab(tab_b, "🌅 朝食")
|
| 107 |
self.tab_widget.addTab(tab_d, "🌆 ディナー")
|
| 108 |
+
|
| 109 |
+
# 月間勤務集計タブ
|
| 110 |
+
self._monthly_table = QTableWidget()
|
| 111 |
+
self._monthly_table.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
| 112 |
+
self._monthly_table.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection)
|
| 113 |
+
self._monthly_table.verticalHeader().setVisible(False)
|
| 114 |
+
self._monthly_table.setAlternatingRowColors(True)
|
| 115 |
+
self._monthly_table.setShowGrid(True)
|
| 116 |
+
monthly_tab = QWidget()
|
| 117 |
+
monthly_layout = QVBoxLayout(monthly_tab)
|
| 118 |
+
monthly_layout.setContentsMargins(0, 6, 0, 0)
|
| 119 |
+
monthly_layout.addWidget(self._monthly_table)
|
| 120 |
+
self.tab_widget.addTab(monthly_tab, "📊 月間集計")
|
| 121 |
+
|
| 122 |
layout.addWidget(self.tab_widget)
|
| 123 |
|
| 124 |
self.status_label = QLabel("")
|
|
|
|
| 229 |
|
| 230 |
def apply_theme(self):
|
| 231 |
self._apply_styles()
|
| 232 |
+
self._update_confirm_button()
|
| 233 |
self._render_table()
|
| 234 |
|
| 235 |
# ── データ読み込み ─────────────────────────────────────────────────────
|
|
|
|
| 260 |
self.sum_table_b, self.sum_table_d):
|
| 261 |
t.setRowCount(0)
|
| 262 |
t.setColumnCount(0)
|
| 263 |
+
self._btn_confirm.setEnabled(False)
|
| 264 |
return
|
| 265 |
self._load_data()
|
| 266 |
self._render_table()
|
| 267 |
+
self._update_confirm_button()
|
| 268 |
|
| 269 |
def _load_data(self):
|
| 270 |
self._employees = repo.get_all_employees()
|
|
|
|
| 292 |
self.emp_table_b, self.sum_table_b, TimeSlot.BREAKFAST, self._warn_label_b)
|
| 293 |
self._render_slot_table(
|
| 294 |
self.emp_table_d, self.sum_table_d, TimeSlot.DINNER, self._warn_label_d)
|
| 295 |
+
self._render_monthly_tab()
|
| 296 |
+
|
| 297 |
+
def _render_monthly_tab(self):
|
| 298 |
+
if not self._period or not self._employees:
|
| 299 |
+
self._monthly_table.setRowCount(0)
|
| 300 |
+
return
|
| 301 |
+
|
| 302 |
+
headers = ["氏名", "朝食(H)", "朝食(K)", "ディナー(H)", "ディナー(K)", "朝食計", "ディナー計", "合計", "応援"]
|
| 303 |
+
self._monthly_table.setColumnCount(len(headers))
|
| 304 |
+
self._monthly_table.setHorizontalHeaderLabels(headers)
|
| 305 |
+
self._monthly_table.horizontalHeader().setSectionResizeMode(
|
| 306 |
+
0, QHeaderView.ResizeMode.ResizeToContents)
|
| 307 |
+
for ci in range(1, len(headers)):
|
| 308 |
+
self._monthly_table.setColumnWidth(ci, 72)
|
| 309 |
+
|
| 310 |
+
# emp_id -> {bh, bk, dh, dk, reinforcement}
|
| 311 |
+
counts: dict[int, dict] = {
|
| 312 |
+
e.id: {"bh": 0, "bk": 0, "dh": 0, "dk": 0, "reinf": 0}
|
| 313 |
+
for e in self._employees
|
| 314 |
+
}
|
| 315 |
+
for (emp_id, ds, slot_v), (pos_v, is_reinf) in self._assignments.items():
|
| 316 |
+
if emp_id not in counts:
|
| 317 |
+
continue
|
| 318 |
+
key = ("b" if slot_v == "breakfast" else "d") + ("h" if pos_v == "hall" else "k")
|
| 319 |
+
counts[emp_id][key] += 1
|
| 320 |
+
if is_reinf:
|
| 321 |
+
counts[emp_id]["reinf"] += 1
|
| 322 |
+
|
| 323 |
+
self._monthly_table.setRowCount(len(self._employees))
|
| 324 |
+
c = theme.c
|
| 325 |
+
for row, emp in enumerate(self._employees):
|
| 326 |
+
d = counts[emp.id]
|
| 327 |
+
bh, bk = d["bh"], d["bk"]
|
| 328 |
+
dh, dk = d["dh"], d["dk"]
|
| 329 |
+
b_total = bh + bk
|
| 330 |
+
d_total = dh + dk
|
| 331 |
+
total = b_total + d_total
|
| 332 |
+
reinf = d["reinf"]
|
| 333 |
+
|
| 334 |
+
vals = [emp.name, bh, bk, dh, dk, b_total, d_total, total, reinf]
|
| 335 |
+
for ci, val in enumerate(vals):
|
| 336 |
+
item = QTableWidgetItem(str(val))
|
| 337 |
+
if ci > 0:
|
| 338 |
+
item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 339 |
+
if ci == 7 and total > 0:
|
| 340 |
+
item.setBackground(QBrush(QColor(c["cell_assigned"])))
|
| 341 |
+
if ci == 8 and reinf > 0:
|
| 342 |
+
item.setBackground(QBrush(QColor(c["cell_reinforcement"])))
|
| 343 |
+
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 344 |
+
self._monthly_table.setItem(row, ci, item)
|
| 345 |
+
self._monthly_table.setRowHeight(row, 28)
|
| 346 |
|
| 347 |
def _render_slot_table(self, emp_table: QTableWidget, sum_table: QTableWidget,
|
| 348 |
slot: TimeSlot, warn_label: QLabel):
|
|
|
|
| 513 |
label_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 514 |
table.setItem(row, 0, label_item)
|
| 515 |
|
| 516 |
+
shift_constraints = repo.get_shift_constraints()
|
| 517 |
+
constraint = shift_constraints.get((slot, pos), {})
|
| 518 |
min_req = constraint.get("min", 0)
|
| 519 |
min_leader = constraint.get("min_leader", 0)
|
| 520 |
|
|
|
|
| 540 |
|
| 541 |
def _update_constraint_warnings(self, warn_label: QLabel, slot: TimeSlot,
|
| 542 |
dates: list, count_map: dict, leader_map: dict):
|
| 543 |
+
shift_constraints = repo.get_shift_constraints()
|
| 544 |
violations = []
|
| 545 |
for d in dates:
|
| 546 |
ds = d.isoformat()
|
|
|
|
| 548 |
for pos in Position:
|
| 549 |
cnt = count_map[(ds, pos.value)]
|
| 550 |
ld = leader_map[(ds, pos.value)]
|
| 551 |
+
constraint = shift_constraints.get((slot, pos), {})
|
| 552 |
min_req = constraint.get("min", 0)
|
| 553 |
min_leader = constraint.get("min_leader", 0)
|
| 554 |
if cnt < min_req:
|
|
|
|
| 576 |
dlg.exec()
|
| 577 |
|
| 578 |
def _on_cell_clicked(self, row: int, col: int, table: QTableWidget, slot: TimeSlot):
|
| 579 |
+
if self._period and self._period.status == "confirmed":
|
| 580 |
+
return # 確定済みは編集不可
|
| 581 |
item = table.item(row, col)
|
| 582 |
if not item:
|
| 583 |
return
|
|
|
|
| 642 |
self._assignments[(emp_id, ds, slot_v)] = (dlg.selected_position.value, True)
|
| 643 |
self._render_table()
|
| 644 |
|
| 645 |
+
def _update_confirm_button(self):
|
| 646 |
+
if not self._period:
|
| 647 |
+
self._btn_confirm.setEnabled(False)
|
| 648 |
+
return
|
| 649 |
+
self._btn_confirm.setEnabled(True)
|
| 650 |
+
is_confirmed = (self._period.status == "confirmed")
|
| 651 |
+
c = theme.c
|
| 652 |
+
if is_confirmed:
|
| 653 |
+
self._btn_confirm.setText("🔒 確定済み(解除する)")
|
| 654 |
+
self._btn_confirm.setStyleSheet(
|
| 655 |
+
f"QPushButton {{ background:{c['surface2']}; border:1px solid {c['border2']}; "
|
| 656 |
+
f"border-radius:5px; padding:0 14px; color:{c['text2']}; }}"
|
| 657 |
+
f" QPushButton:hover {{ background:{c['danger_bg']}; color:{c['danger_text']}; }}"
|
| 658 |
+
)
|
| 659 |
+
else:
|
| 660 |
+
self._btn_confirm.setText("✅ 確定する")
|
| 661 |
+
self._btn_confirm.setStyleSheet(
|
| 662 |
+
f"QPushButton {{ background:#16a34a; color:white; border-radius:5px; padding:0 14px; }}"
|
| 663 |
+
f" QPushButton:hover {{ background:#15803d; }}"
|
| 664 |
+
)
|
| 665 |
+
|
| 666 |
+
def _on_toggle_confirm(self):
|
| 667 |
+
if not self._period:
|
| 668 |
+
return
|
| 669 |
+
is_confirmed = (self._period.status == "confirmed")
|
| 670 |
+
if is_confirmed:
|
| 671 |
+
reply = QMessageBox.question(
|
| 672 |
+
self, "確定解除",
|
| 673 |
+
"このシフト表の確定を解除しますか?\n解除後は再び編集可能になります。",
|
| 674 |
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
| 675 |
+
)
|
| 676 |
+
if reply != QMessageBox.StandardButton.Yes:
|
| 677 |
+
return
|
| 678 |
+
self._period.status = "draft"
|
| 679 |
+
else:
|
| 680 |
+
reply = QMessageBox.question(
|
| 681 |
+
self, "シフト確定",
|
| 682 |
+
"このシフト表を確定しますか?\n確定後は編集がロックされます。",
|
| 683 |
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
| 684 |
+
)
|
| 685 |
+
if reply != QMessageBox.StandardButton.Yes:
|
| 686 |
+
return
|
| 687 |
+
self._period.status = "confirmed"
|
| 688 |
+
repo.save_period(self._period)
|
| 689 |
+
self._update_confirm_button()
|
| 690 |
+
self._render_table()
|
| 691 |
+
|
| 692 |
def _on_output(self):
|
| 693 |
if not self._period:
|
| 694 |
return
|
ui/settings_view.py
CHANGED
|
@@ -5,12 +5,14 @@ from datetime import datetime
|
|
| 5 |
from pathlib import Path
|
| 6 |
from PyQt6.QtWidgets import (
|
| 7 |
QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
| 8 |
-
QGroupBox, QFileDialog, QMessageBox
|
|
|
|
| 9 |
)
|
| 10 |
from PyQt6.QtCore import Qt, pyqtSignal
|
| 11 |
from PyQt6.QtGui import QFont
|
| 12 |
from db.database import DB_PATH
|
| 13 |
from utils.theme import theme
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class SettingsView(QWidget):
|
|
@@ -57,6 +59,59 @@ class SettingsView(QWidget):
|
|
| 57 |
backup_layout.addWidget(self._btn_backup)
|
| 58 |
layout.addWidget(backup_group)
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# ── インポート(復元)────────────────────────────────────────
|
| 61 |
import_group = QGroupBox("インポート(復元)")
|
| 62 |
import_layout = QVBoxLayout(import_group)
|
|
@@ -75,8 +130,34 @@ class SettingsView(QWidget):
|
|
| 75 |
|
| 76 |
self._apply_styles()
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def _apply_styles(self):
|
| 79 |
c = theme.c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
self._btn_backup.setStyleSheet(
|
| 81 |
f"QPushButton {{ background:{c['primary']}; color:white; border-radius:6px; padding:0 16px; font-weight:bold; }}"
|
| 82 |
f" QPushButton:hover {{ background:{c['primary_hover']}; }}"
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from PyQt6.QtWidgets import (
|
| 7 |
QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
| 8 |
+
QGroupBox, QFileDialog, QMessageBox, QFormLayout, QSpinBox,
|
| 9 |
+
QScrollArea
|
| 10 |
)
|
| 11 |
from PyQt6.QtCore import Qt, pyqtSignal
|
| 12 |
from PyQt6.QtGui import QFont
|
| 13 |
from db.database import DB_PATH
|
| 14 |
from utils.theme import theme
|
| 15 |
+
from utils.constants import TimeSlot, Position
|
| 16 |
|
| 17 |
|
| 18 |
class SettingsView(QWidget):
|
|
|
|
| 59 |
backup_layout.addWidget(self._btn_backup)
|
| 60 |
layout.addWidget(backup_group)
|
| 61 |
|
| 62 |
+
# ── シフト人員制約 ────────────────────────────────────────────
|
| 63 |
+
constraint_group = QGroupBox("シフト人員設定")
|
| 64 |
+
constraint_layout = QVBoxLayout(constraint_group)
|
| 65 |
+
constraint_layout.setSpacing(8)
|
| 66 |
+
|
| 67 |
+
note_c = QLabel("各時間帯・ポジションの最低/最大人数とリーダー最低人数を設定します。")
|
| 68 |
+
note_c.setWordWrap(True)
|
| 69 |
+
constraint_layout.addWidget(note_c)
|
| 70 |
+
|
| 71 |
+
grid_widget = QWidget()
|
| 72 |
+
grid_layout = QFormLayout(grid_widget)
|
| 73 |
+
grid_layout.setSpacing(6)
|
| 74 |
+
|
| 75 |
+
# (TimeSlot, Position) -> (min_spin, max_spin, leader_spin)
|
| 76 |
+
self._constraint_spins: dict[tuple, tuple] = {}
|
| 77 |
+
|
| 78 |
+
_LABELS = {
|
| 79 |
+
(TimeSlot.BREAKFAST, Position.HALL): "朝食 ホール",
|
| 80 |
+
(TimeSlot.BREAKFAST, Position.KITCHEN): "朝食 キッチン",
|
| 81 |
+
(TimeSlot.DINNER, Position.HALL): "ディナー ホール",
|
| 82 |
+
(TimeSlot.DINNER, Position.KITCHEN): "ディナー キッチン",
|
| 83 |
+
}
|
| 84 |
+
for key, label in _LABELS.items():
|
| 85 |
+
row_widget = QWidget()
|
| 86 |
+
row_layout = QHBoxLayout(row_widget)
|
| 87 |
+
row_layout.setContentsMargins(0, 0, 0, 0)
|
| 88 |
+
row_layout.setSpacing(8)
|
| 89 |
+
|
| 90 |
+
min_spin = QSpinBox(); min_spin.setRange(0, 20); min_spin.setFixedWidth(60)
|
| 91 |
+
max_spin = QSpinBox(); max_spin.setRange(0, 20); max_spin.setFixedWidth(60)
|
| 92 |
+
ldr_spin = QSpinBox(); ldr_spin.setRange(0, 20); ldr_spin.setFixedWidth(60)
|
| 93 |
+
|
| 94 |
+
row_layout.addWidget(QLabel("最低:"))
|
| 95 |
+
row_layout.addWidget(min_spin)
|
| 96 |
+
row_layout.addWidget(QLabel("最大:"))
|
| 97 |
+
row_layout.addWidget(max_spin)
|
| 98 |
+
row_layout.addWidget(QLabel("リーダー最低:"))
|
| 99 |
+
row_layout.addWidget(ldr_spin)
|
| 100 |
+
row_layout.addStretch()
|
| 101 |
+
|
| 102 |
+
grid_layout.addRow(label, row_widget)
|
| 103 |
+
self._constraint_spins[key] = (min_spin, max_spin, ldr_spin)
|
| 104 |
+
|
| 105 |
+
constraint_layout.addWidget(grid_widget)
|
| 106 |
+
|
| 107 |
+
self._btn_save_constraints = QPushButton("人員設定を保存")
|
| 108 |
+
self._btn_save_constraints.setFixedHeight(36)
|
| 109 |
+
self._btn_save_constraints.clicked.connect(self._on_save_constraints)
|
| 110 |
+
constraint_layout.addWidget(self._btn_save_constraints)
|
| 111 |
+
layout.addWidget(constraint_group)
|
| 112 |
+
|
| 113 |
+
self._load_constraints()
|
| 114 |
+
|
| 115 |
# ── インポート(復元)────────────────────────────────────────
|
| 116 |
import_group = QGroupBox("インポート(復元)")
|
| 117 |
import_layout = QVBoxLayout(import_group)
|
|
|
|
| 130 |
|
| 131 |
self._apply_styles()
|
| 132 |
|
| 133 |
+
def _load_constraints(self):
|
| 134 |
+
from db import repositories as repo
|
| 135 |
+
constraints = repo.get_shift_constraints()
|
| 136 |
+
for key, (mn_spin, mx_spin, ldr_spin) in self._constraint_spins.items():
|
| 137 |
+
c = constraints.get(key, {"min": 0, "max": 0, "min_leader": 0})
|
| 138 |
+
mn_spin.setValue(c["min"])
|
| 139 |
+
mx_spin.setValue(c["max"])
|
| 140 |
+
ldr_spin.setValue(c["min_leader"])
|
| 141 |
+
|
| 142 |
+
def _on_save_constraints(self):
|
| 143 |
+
from db import repositories as repo
|
| 144 |
+
constraints = {}
|
| 145 |
+
for key, (mn_spin, mx_spin, ldr_spin) in self._constraint_spins.items():
|
| 146 |
+
constraints[key] = {
|
| 147 |
+
"min": mn_spin.value(),
|
| 148 |
+
"max": mx_spin.value(),
|
| 149 |
+
"min_leader": ldr_spin.value(),
|
| 150 |
+
}
|
| 151 |
+
repo.save_shift_constraints(constraints)
|
| 152 |
+
QMessageBox.information(self, "保存完了", "シフト人員設定を保存しました。")
|
| 153 |
+
|
| 154 |
def _apply_styles(self):
|
| 155 |
c = theme.c
|
| 156 |
+
self._btn_save_constraints.setStyleSheet(
|
| 157 |
+
f"QPushButton {{ background:{c['surface']}; border:1px solid {c['border2']}; "
|
| 158 |
+
f"border-radius:6px; padding:0 16px; color:{c['text']}; }}"
|
| 159 |
+
f" QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 160 |
+
)
|
| 161 |
self._btn_backup.setStyleSheet(
|
| 162 |
f"QPushButton {{ background:{c['primary']}; color:white; border-radius:6px; padding:0 16px; font-weight:bold; }}"
|
| 163 |
f" QPushButton:hover {{ background:{c['primary_hover']}; }}"
|
ui/shift_input_view.py
CHANGED
|
@@ -122,6 +122,7 @@ class ShiftInputView(QWidget):
|
|
| 122 |
self._pattern_cells: dict[str, _PatternCellWidget] = {}
|
| 123 |
# date_str -> QLineEdit (備考)
|
| 124 |
self._note_edits: dict[str, QLineEdit] = {}
|
|
|
|
| 125 |
self._build_ui()
|
| 126 |
self._load_periods()
|
| 127 |
|
|
@@ -165,6 +166,13 @@ class ShiftInputView(QWidget):
|
|
| 165 |
self._btn_set.setFixedHeight(32)
|
| 166 |
self._btn_set.clicked.connect(self._on_set_period)
|
| 167 |
period_layout.addWidget(self._btn_set)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
period_layout.addStretch()
|
| 169 |
layout.addWidget(period_group)
|
| 170 |
|
|
@@ -192,6 +200,22 @@ class ShiftInputView(QWidget):
|
|
| 192 |
emp_nav.addWidget(self._btn_next)
|
| 193 |
layout.addLayout(emp_nav)
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
# パターン凡例
|
| 196 |
legend = QHBoxLayout()
|
| 197 |
legend.addWidget(QLabel("パターン例:"))
|
|
@@ -289,6 +313,18 @@ class ShiftInputView(QWidget):
|
|
| 289 |
f"QPushButton {{ background:{c['success']}; color:white; border-radius:6px; padding:0 20px; font-weight:bold; }}"
|
| 290 |
f" QPushButton:hover {{ background:{c['success_hover']}; }}"
|
| 291 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
self.progress_label.setStyleSheet(f"color:{c['text2']};")
|
| 293 |
for lbl, color_key in self._legend_labels:
|
| 294 |
lbl.setStyleSheet(
|
|
@@ -310,12 +346,91 @@ class ShiftInputView(QWidget):
|
|
| 310 |
self.period_combo.addItem(f"{p.start_date} 〜 {p.end_date}", p)
|
| 311 |
self.period_combo.blockSignals(False)
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
def _on_period_changed(self, idx):
|
| 314 |
p = self.period_combo.currentData()
|
|
|
|
| 315 |
if p:
|
| 316 |
self._period = p
|
| 317 |
self._load_employees()
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
def _on_set_period(self):
|
| 320 |
start = self.start_date_edit.date().toString("yyyy-MM-dd")
|
| 321 |
end = self.end_date_edit.date().toString("yyyy-MM-dd")
|
|
@@ -360,19 +475,58 @@ class ShiftInputView(QWidget):
|
|
| 360 |
total = len(self._employees)
|
| 361 |
self.progress_label.setText(f"入力済: {len(filled)} / {total} 名")
|
| 362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
def _on_employee_changed(self, idx):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
self._current_idx = idx
|
| 365 |
self._render_table()
|
| 366 |
|
| 367 |
def _on_prev_employee(self):
|
| 368 |
if self._current_idx > 0:
|
|
|
|
|
|
|
| 369 |
self._current_idx -= 1
|
|
|
|
| 370 |
self.emp_combo.setCurrentIndex(self._current_idx)
|
|
|
|
|
|
|
| 371 |
|
| 372 |
def _on_next_employee(self):
|
| 373 |
if self._current_idx < len(self._employees) - 1:
|
|
|
|
|
|
|
| 374 |
self._current_idx += 1
|
|
|
|
| 375 |
self.emp_combo.setCurrentIndex(self._current_idx)
|
|
|
|
|
|
|
| 376 |
|
| 377 |
# ── テーブル描画 ──────────────────────────────────────────────────────
|
| 378 |
|
|
@@ -449,6 +603,9 @@ class ShiftInputView(QWidget):
|
|
| 449 |
|
| 450 |
self.table.setRowHeight(row, 38)
|
| 451 |
|
|
|
|
|
|
|
|
|
|
| 452 |
def _apply_row_color(self, row: int, date_str: str, is_unavail: bool):
|
| 453 |
"""選択パターンに応じて行背景を更新(変更時にも呼べるよう分離)"""
|
| 454 |
if is_unavail:
|
|
@@ -509,5 +666,6 @@ class ShiftInputView(QWidget):
|
|
| 509 |
self._requests[(emp.id, date_str)] = req
|
| 510 |
|
| 511 |
repo.save_shift_requests(self._period.id, requests)
|
|
|
|
| 512 |
self._update_progress()
|
| 513 |
QMessageBox.information(self, "保存完了", f"「{emp.name}さん」の希望シフトを保存しました")
|
|
|
|
| 122 |
self._pattern_cells: dict[str, _PatternCellWidget] = {}
|
| 123 |
# date_str -> QLineEdit (備考)
|
| 124 |
self._note_edits: dict[str, QLineEdit] = {}
|
| 125 |
+
self._saved_snapshot: dict = {} # 保存済み状態のスナップショット
|
| 126 |
self._build_ui()
|
| 127 |
self._load_periods()
|
| 128 |
|
|
|
|
| 166 |
self._btn_set.setFixedHeight(32)
|
| 167 |
self._btn_set.clicked.connect(self._on_set_period)
|
| 168 |
period_layout.addWidget(self._btn_set)
|
| 169 |
+
|
| 170 |
+
self._btn_del_period = QPushButton("期間削除")
|
| 171 |
+
self._btn_del_period.setFixedHeight(32)
|
| 172 |
+
self._btn_del_period.setEnabled(False)
|
| 173 |
+
self._btn_del_period.clicked.connect(self._on_delete_period)
|
| 174 |
+
period_layout.addWidget(self._btn_del_period)
|
| 175 |
+
|
| 176 |
period_layout.addStretch()
|
| 177 |
layout.addWidget(period_group)
|
| 178 |
|
|
|
|
| 200 |
emp_nav.addWidget(self._btn_next)
|
| 201 |
layout.addLayout(emp_nav)
|
| 202 |
|
| 203 |
+
# 前期間コピー行
|
| 204 |
+
copy_row = QHBoxLayout()
|
| 205 |
+
copy_lbl = QLabel("前期間から:")
|
| 206 |
+
copy_lbl.setStyleSheet("color:#6b7280; font-size:11px;")
|
| 207 |
+
self._prev_period_combo = QComboBox()
|
| 208 |
+
self._prev_period_combo.setMinimumWidth(200)
|
| 209 |
+
self._btn_copy = QPushButton("この従業員の希望をコピー")
|
| 210 |
+
self._btn_copy.setFixedHeight(28)
|
| 211 |
+
self._btn_copy.setEnabled(False)
|
| 212 |
+
self._btn_copy.clicked.connect(self._on_copy_from_prev)
|
| 213 |
+
copy_row.addWidget(copy_lbl)
|
| 214 |
+
copy_row.addWidget(self._prev_period_combo)
|
| 215 |
+
copy_row.addWidget(self._btn_copy)
|
| 216 |
+
copy_row.addStretch()
|
| 217 |
+
layout.addLayout(copy_row)
|
| 218 |
+
|
| 219 |
# パターン凡例
|
| 220 |
legend = QHBoxLayout()
|
| 221 |
legend.addWidget(QLabel("パターン例:"))
|
|
|
|
| 313 |
f"QPushButton {{ background:{c['success']}; color:white; border-radius:6px; padding:0 20px; font-weight:bold; }}"
|
| 314 |
f" QPushButton:hover {{ background:{c['success_hover']}; }}"
|
| 315 |
)
|
| 316 |
+
self._btn_copy.setStyleSheet(
|
| 317 |
+
f"QPushButton {{ border:1px solid {c['border2']}; border-radius:4px; "
|
| 318 |
+
f"padding:0 10px; color:{c['text']}; background:{c['surface']}; }}"
|
| 319 |
+
f" QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 320 |
+
f" QPushButton:disabled {{ opacity:0.4; }}"
|
| 321 |
+
)
|
| 322 |
+
self._btn_del_period.setStyleSheet(
|
| 323 |
+
f"QPushButton {{ background:{c['danger_bg']}; border:1px solid {c['danger_border']}; "
|
| 324 |
+
f"border-radius:5px; padding:0 12px; color:{c['danger_text']}; }}"
|
| 325 |
+
f" QPushButton:hover {{ background:{c['danger_bg']}; }}"
|
| 326 |
+
f" QPushButton:disabled {{ opacity:0.4; }}"
|
| 327 |
+
)
|
| 328 |
self.progress_label.setStyleSheet(f"color:{c['text2']};")
|
| 329 |
for lbl, color_key in self._legend_labels:
|
| 330 |
lbl.setStyleSheet(
|
|
|
|
| 346 |
self.period_combo.addItem(f"{p.start_date} 〜 {p.end_date}", p)
|
| 347 |
self.period_combo.blockSignals(False)
|
| 348 |
|
| 349 |
+
# コピー元コンボ: 現在の期間を除く
|
| 350 |
+
self._prev_period_combo.blockSignals(True)
|
| 351 |
+
self._prev_period_combo.clear()
|
| 352 |
+
self._prev_period_combo.addItem("(コピー元期間を選択)", None)
|
| 353 |
+
for p in periods:
|
| 354 |
+
if self._period and p.id == self._period.id:
|
| 355 |
+
continue
|
| 356 |
+
self._prev_period_combo.addItem(f"{p.start_date} 〜 {p.end_date}", p)
|
| 357 |
+
self._prev_period_combo.blockSignals(False)
|
| 358 |
+
self._btn_copy.setEnabled(
|
| 359 |
+
self._prev_period_combo.count() > 1 and bool(self._period)
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
def _on_period_changed(self, idx):
|
| 363 |
p = self.period_combo.currentData()
|
| 364 |
+
self._btn_del_period.setEnabled(p is not None)
|
| 365 |
if p:
|
| 366 |
self._period = p
|
| 367 |
self._load_employees()
|
| 368 |
|
| 369 |
+
def _on_copy_from_prev(self):
|
| 370 |
+
src_period = self._prev_period_combo.currentData()
|
| 371 |
+
if not src_period or not self._period or not self._employees:
|
| 372 |
+
return
|
| 373 |
+
emp = self._employees[self._current_idx]
|
| 374 |
+
src_requests = repo.get_shift_requests(src_period.id)
|
| 375 |
+
src_map = {r.date: r for r in src_requests if r.employee_id == emp.id}
|
| 376 |
+
if not src_map:
|
| 377 |
+
QMessageBox.information(
|
| 378 |
+
self, "コピー元なし",
|
| 379 |
+
f"期間「{src_period.start_date} 〜 {src_period.end_date}」に\n"
|
| 380 |
+
f"「{emp.name}さん」の希望データがありません。"
|
| 381 |
+
)
|
| 382 |
+
return
|
| 383 |
+
# 日付のオフセットを計算して対応付け
|
| 384 |
+
from datetime import date as dt_date, timedelta
|
| 385 |
+
src_dates = src_period.date_range()
|
| 386 |
+
dst_dates = self._period.date_range()
|
| 387 |
+
# 曜日ベースでマッピング(同じ曜日オフセット順に対応)
|
| 388 |
+
for i, dst_d in enumerate(dst_dates):
|
| 389 |
+
if i < len(src_dates):
|
| 390 |
+
src_ds = src_dates[i].isoformat()
|
| 391 |
+
else:
|
| 392 |
+
break
|
| 393 |
+
src_req = src_map.get(src_ds)
|
| 394 |
+
dst_ds = dst_d.isoformat()
|
| 395 |
+
cell = self._pattern_cells.get(dst_ds)
|
| 396 |
+
if cell and src_req and cell.combo.isEnabled():
|
| 397 |
+
cell.set_pattern(src_req.pattern_id, src_req.custom_start, src_req.custom_end)
|
| 398 |
+
row = next(
|
| 399 |
+
(r for r in range(self.table.rowCount())
|
| 400 |
+
if (self.table.item(r, 0) or type('', (), {'data': lambda *_: None})()).data(
|
| 401 |
+
Qt.ItemDataRole.UserRole) == dst_ds),
|
| 402 |
+
-1
|
| 403 |
+
)
|
| 404 |
+
if row >= 0:
|
| 405 |
+
self._apply_row_color(row, dst_ds, False)
|
| 406 |
+
QMessageBox.information(
|
| 407 |
+
self, "コピー完了",
|
| 408 |
+
f"「{src_period.start_date} 〜 {src_period.end_date}」から\n"
|
| 409 |
+
f"「{emp.name}さん」の希望をコピーしました。\n保存ボタンで確定してください。"
|
| 410 |
+
)
|
| 411 |
+
|
| 412 |
+
def _on_delete_period(self):
|
| 413 |
+
p = self.period_combo.currentData()
|
| 414 |
+
if not p:
|
| 415 |
+
return
|
| 416 |
+
reply = QMessageBox.question(
|
| 417 |
+
self, "期間削除の確認",
|
| 418 |
+
f"期間「{p.start_date} 〜 {p.end_date}」を削除しますか?\n"
|
| 419 |
+
"関連するシフト希望・アサインデータもすべて削除されます。",
|
| 420 |
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
| 421 |
+
)
|
| 422 |
+
if reply != QMessageBox.StandardButton.Yes:
|
| 423 |
+
return
|
| 424 |
+
repo.delete_period(p.id)
|
| 425 |
+
self._period = None
|
| 426 |
+
self._employees = []
|
| 427 |
+
self._requests = {}
|
| 428 |
+
self._pattern_cells = {}
|
| 429 |
+
self.table.setRowCount(0)
|
| 430 |
+
self._load_periods()
|
| 431 |
+
self._btn_del_period.setEnabled(False)
|
| 432 |
+
self.progress_label.setText("")
|
| 433 |
+
|
| 434 |
def _on_set_period(self):
|
| 435 |
start = self.start_date_edit.date().toString("yyyy-MM-dd")
|
| 436 |
end = self.end_date_edit.date().toString("yyyy-MM-dd")
|
|
|
|
| 475 |
total = len(self._employees)
|
| 476 |
self.progress_label.setText(f"入力済: {len(filled)} / {total} 名")
|
| 477 |
|
| 478 |
+
def _current_snapshot(self) -> dict:
|
| 479 |
+
"""現在の入力状態をスナップショットとして返す"""
|
| 480 |
+
snap = {}
|
| 481 |
+
for ds, cell in self._pattern_cells.items():
|
| 482 |
+
snap[ds] = (cell.get_pattern_id(), cell.custom_edit.text())
|
| 483 |
+
return snap
|
| 484 |
+
|
| 485 |
+
def _has_unsaved_changes(self) -> bool:
|
| 486 |
+
return self._current_snapshot() != self._saved_snapshot
|
| 487 |
+
|
| 488 |
+
def _confirm_leave(self) -> bool:
|
| 489 |
+
"""未保存の変更がある場合に確認ダイアログを表示。離脱してよければ True を返す"""
|
| 490 |
+
if not self._has_unsaved_changes():
|
| 491 |
+
return True
|
| 492 |
+
reply = QMessageBox.question(
|
| 493 |
+
self, "未保存の変更",
|
| 494 |
+
"保存されていない変更があります。\nこのまま切り替えますか?(変更は失われます)",
|
| 495 |
+
QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel,
|
| 496 |
+
)
|
| 497 |
+
return reply == QMessageBox.StandardButton.Discard
|
| 498 |
+
|
| 499 |
def _on_employee_changed(self, idx):
|
| 500 |
+
if idx == self._current_idx:
|
| 501 |
+
return
|
| 502 |
+
if not self._confirm_leave():
|
| 503 |
+
# キャンセル: コンボを元に戻す
|
| 504 |
+
self.emp_combo.blockSignals(True)
|
| 505 |
+
self.emp_combo.setCurrentIndex(self._current_idx)
|
| 506 |
+
self.emp_combo.blockSignals(False)
|
| 507 |
+
return
|
| 508 |
self._current_idx = idx
|
| 509 |
self._render_table()
|
| 510 |
|
| 511 |
def _on_prev_employee(self):
|
| 512 |
if self._current_idx > 0:
|
| 513 |
+
if not self._confirm_leave():
|
| 514 |
+
return
|
| 515 |
self._current_idx -= 1
|
| 516 |
+
self.emp_combo.blockSignals(True)
|
| 517 |
self.emp_combo.setCurrentIndex(self._current_idx)
|
| 518 |
+
self.emp_combo.blockSignals(False)
|
| 519 |
+
self._render_table()
|
| 520 |
|
| 521 |
def _on_next_employee(self):
|
| 522 |
if self._current_idx < len(self._employees) - 1:
|
| 523 |
+
if not self._confirm_leave():
|
| 524 |
+
return
|
| 525 |
self._current_idx += 1
|
| 526 |
+
self.emp_combo.blockSignals(True)
|
| 527 |
self.emp_combo.setCurrentIndex(self._current_idx)
|
| 528 |
+
self.emp_combo.blockSignals(False)
|
| 529 |
+
self._render_table()
|
| 530 |
|
| 531 |
# ── テーブル描画 ──────────────────────────────────────────────────────
|
| 532 |
|
|
|
|
| 603 |
|
| 604 |
self.table.setRowHeight(row, 38)
|
| 605 |
|
| 606 |
+
# テーブル描画後、現在の状態を「保存済み」スナップショットとして記録
|
| 607 |
+
self._saved_snapshot = self._current_snapshot()
|
| 608 |
+
|
| 609 |
def _apply_row_color(self, row: int, date_str: str, is_unavail: bool):
|
| 610 |
"""選択パターンに応じて行背景を更新(変更時にも呼べるよう分離)"""
|
| 611 |
if is_unavail:
|
|
|
|
| 666 |
self._requests[(emp.id, date_str)] = req
|
| 667 |
|
| 668 |
repo.save_shift_requests(self._period.id, requests)
|
| 669 |
+
self._saved_snapshot = self._current_snapshot() # 保存済み状態を更新
|
| 670 |
self._update_progress()
|
| 671 |
QMessageBox.information(self, "保存完了", f"「{emp.name}さん」の希望シフトを保存しました")
|