Commit ·
5aad2f7
1
Parent(s): bda000c
feat: Flask Webアプリ化・PostgreSQL対応・Render デプロイ設定を追加
Browse filesiPhoneからアクセスできるWebアプリとして動作するよう変換。
既存のソルバー・DBロジック・エクスポート機能はそのまま流用。
- db/database.py: SQLite/PostgreSQL 両対応のDBアダプター実装
- db/repositories.py: PostgreSQL互換SQL構文に修正
- web_app.py: Flask アプリケーションファクトリ
- routes/: 従業員・シフト入力・自動生成・スケジュール・客数・設定・エクスポート
- templates/: Bootstrap5 モバイルファーストレスポンシブ UI(ボトムナビ付き)
- static/manifest.json + sw.js: PWA対応(ホーム画面追加可能)
- Procfile + render.yaml: Render 無料枠へのデプロイ設定
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Procfile +1 -0
- db/database.py +217 -159
- db/repositories.py +5 -7
- render.yaml +18 -0
- requirements.txt +3 -0
- routes/__init__.py +0 -0
- routes/customers.py +47 -0
- routes/employees.py +112 -0
- routes/export_routes.py +39 -0
- routes/generate.py +58 -0
- routes/schedule.py +81 -0
- routes/settings_routes.py +44 -0
- routes/shifts.py +79 -0
- static/manifest.json +14 -0
- static/sw.js +25 -0
- templates/base.html +134 -0
- templates/customers/index.html +58 -0
- templates/employees/form.html +161 -0
- templates/employees/index.html +58 -0
- templates/generate/index.html +63 -0
- templates/schedule/index.html +116 -0
- templates/settings/index.html +60 -0
- templates/shifts/index.html +40 -0
- templates/shifts/input.html +87 -0
- web_app.py +42 -0
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: gunicorn web_app:create_app() --bind 0.0.0.0:$PORT --workers 2 --timeout 120
|
db/database.py
CHANGED
|
@@ -1,193 +1,251 @@
|
|
|
|
|
|
|
|
| 1 |
import sys
|
| 2 |
-
import sqlite3
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
# Windows frozen: EXEと同じフォルダの shift_tool.db
|
| 9 |
-
# 開発時 : ~/.shift_tool/shift_tool.db
|
| 10 |
if getattr(sys, "frozen", False):
|
| 11 |
if sys.platform == "darwin":
|
| 12 |
-
|
| 13 |
-
|
| 14 |
else:
|
| 15 |
-
|
| 16 |
-
import os
|
| 17 |
-
DB_PATH = Path(os.environ.get("APPDATA", Path.home())) / "SDU-Shift" / "shift_tool.db"
|
| 18 |
else:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def initialize_db():
|
| 31 |
conn = get_connection()
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
name TEXT NOT NULL,
|
| 38 |
-
employment_type TEXT NOT NULL CHECK(employment_type IN ('full_time','part_time')),
|
| 39 |
-
hall_skill TEXT NOT NULL DEFAULT 'beginner'
|
| 40 |
-
CHECK(hall_skill IN ('leader','veteran','general','beginner')),
|
| 41 |
-
kitchen_skill TEXT NOT NULL DEFAULT 'beginner'
|
| 42 |
-
CHECK(kitchen_skill IN ('leader','veteran','general','beginner')),
|
| 43 |
-
is_active INTEGER NOT NULL DEFAULT 1
|
| 44 |
-
);
|
| 45 |
-
|
| 46 |
-
CREATE TABLE IF NOT EXISTS fixed_patterns (
|
| 47 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 48 |
-
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 49 |
-
day_of_week INTEGER NOT NULL CHECK(day_of_week BETWEEN 0 AND 6),
|
| 50 |
-
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 51 |
-
dinner INTEGER NOT NULL DEFAULT 0,
|
| 52 |
-
UNIQUE(employee_id, day_of_week)
|
| 53 |
-
);
|
| 54 |
-
|
| 55 |
-
CREATE TABLE IF NOT EXISTS fixed_unavailable_dates (
|
| 56 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 57 |
-
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 58 |
-
date TEXT NOT NULL,
|
| 59 |
-
UNIQUE(employee_id, date)
|
| 60 |
-
);
|
| 61 |
-
|
| 62 |
-
CREATE TABLE IF NOT EXISTS schedule_periods (
|
| 63 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 64 |
-
start_date TEXT NOT NULL,
|
| 65 |
-
end_date TEXT NOT NULL,
|
| 66 |
-
status TEXT NOT NULL DEFAULT 'draft'
|
| 67 |
-
CHECK(status IN ('draft','confirmed')),
|
| 68 |
-
created_at TEXT NOT NULL DEFAULT (datetime('now','localtime')),
|
| 69 |
-
UNIQUE(start_date)
|
| 70 |
-
);
|
| 71 |
-
|
| 72 |
-
CREATE TABLE IF NOT EXISTS shift_requests (
|
| 73 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 74 |
-
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 75 |
-
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 76 |
-
date TEXT NOT NULL,
|
| 77 |
-
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 78 |
-
dinner INTEGER NOT NULL DEFAULT 0,
|
| 79 |
-
note TEXT DEFAULT '',
|
| 80 |
-
UNIQUE(period_id, employee_id, date)
|
| 81 |
-
);
|
| 82 |
-
|
| 83 |
-
CREATE TABLE IF NOT EXISTS shift_assignments (
|
| 84 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 85 |
-
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 86 |
-
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 87 |
-
date TEXT NOT NULL,
|
| 88 |
-
time_slot TEXT NOT NULL CHECK(time_slot IN ('breakfast','dinner')),
|
| 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 |
-
CREATE TABLE IF NOT EXISTS schedule_notes (
|
| 103 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 104 |
-
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 105 |
-
date TEXT NOT NULL,
|
| 106 |
-
note TEXT NOT NULL DEFAULT '',
|
| 107 |
-
UNIQUE(period_id, date)
|
| 108 |
-
);
|
| 109 |
-
|
| 110 |
-
CREATE TABLE IF NOT EXISTS reservation_counts (
|
| 111 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 112 |
-
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 113 |
-
date TEXT NOT NULL,
|
| 114 |
-
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 115 |
-
dinner INTEGER NOT NULL DEFAULT 0,
|
| 116 |
-
UNIQUE(period_id, date)
|
| 117 |
-
);
|
| 118 |
-
|
| 119 |
-
CREATE TABLE IF NOT EXISTS app_settings (
|
| 120 |
-
key TEXT PRIMARY KEY,
|
| 121 |
-
value TEXT NOT NULL DEFAULT ''
|
| 122 |
-
);
|
| 123 |
-
|
| 124 |
-
CREATE TABLE IF NOT EXISTS breakfast_band_constraints (
|
| 125 |
-
band TEXT NOT NULL,
|
| 126 |
-
position TEXT NOT NULL,
|
| 127 |
-
min_staff INTEGER NOT NULL DEFAULT 0,
|
| 128 |
-
max_staff INTEGER NOT NULL DEFAULT 10,
|
| 129 |
-
min_leader INTEGER NOT NULL DEFAULT 0,
|
| 130 |
-
PRIMARY KEY (band, position)
|
| 131 |
-
);
|
| 132 |
-
""")
|
| 133 |
-
|
| 134 |
-
# マイグレーション: 新カラムを既存テーブルへ追加
|
| 135 |
-
migrations = [
|
| 136 |
-
("shift_requests", "pattern_id", "TEXT"),
|
| 137 |
-
("shift_requests", "custom_start", "TEXT"),
|
| 138 |
-
("shift_requests", "custom_end", "TEXT"),
|
| 139 |
-
("employees", "primary_position", "TEXT DEFAULT NULL"),
|
| 140 |
-
("employees", "primary_timeslot", "TEXT DEFAULT NULL"),
|
| 141 |
-
("employees", "can_work_both_positions", "INTEGER NOT NULL DEFAULT 0"),
|
| 142 |
-
("shift_assignments","is_reinforcement", "INTEGER NOT NULL DEFAULT 0"),
|
| 143 |
-
("shift_assignments","reinf_start", "TEXT DEFAULT NULL"),
|
| 144 |
-
("shift_assignments","reinf_end", "TEXT DEFAULT NULL"),
|
| 145 |
-
("employees", "can_open", "INTEGER NOT NULL DEFAULT 0"),
|
| 146 |
-
("employees", "can_cleanup", "INTEGER NOT NULL DEFAULT 0"),
|
| 147 |
-
("employees", "always_available_breakfast", "INTEGER NOT NULL DEFAULT 0"),
|
| 148 |
-
("employees", "always_available_dinner", "INTEGER NOT NULL DEFAULT 0"),
|
| 149 |
-
]
|
| 150 |
-
for table, col, definition in migrations:
|
| 151 |
try:
|
| 152 |
-
|
| 153 |
except Exception:
|
| 154 |
-
pass
|
| 155 |
|
| 156 |
-
|
| 157 |
-
default_constraints = [
|
| 158 |
("breakfast", "hall", 3, 4, 1),
|
| 159 |
("breakfast", "kitchen", 3, 3, 1),
|
| 160 |
("dinner", "hall", 2, 3, 1),
|
| 161 |
("dinner", "kitchen", 3, 3, 2),
|
| 162 |
-
]
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
"
|
| 166 |
(slot, pos, mn, mx, ml)
|
| 167 |
)
|
| 168 |
|
| 169 |
-
|
| 170 |
-
default_app_settings = [
|
| 171 |
("reserv_threshold_breakfast", "100"),
|
| 172 |
("reserv_extra_breakfast", "1"),
|
| 173 |
("reserv_threshold_dinner", "25"),
|
| 174 |
("reserv_extra_dinner", "1"),
|
| 175 |
-
]
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
)
|
| 180 |
|
| 181 |
-
|
| 182 |
-
default_band_constraints = [
|
| 183 |
("open", "hall", 2, 4, 0),
|
| 184 |
("open", "kitchen", 0, 2, 0),
|
| 185 |
("cleanup", "hall", 1, 2, 1),
|
| 186 |
("cleanup", "kitchen", 0, 1, 0),
|
| 187 |
-
]
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
"
|
| 191 |
(band, pos, mn, mx, ml)
|
| 192 |
)
|
| 193 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
import sys
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
+
DATABASE_URL = os.environ.get("DATABASE_URL", "")
|
| 7 |
+
|
| 8 |
+
# SQLite fallback path (desktop / dev)
|
|
|
|
|
|
|
| 9 |
if getattr(sys, "frozen", False):
|
| 10 |
if sys.platform == "darwin":
|
| 11 |
+
_DB_PATH = (Path.home() / "Library" / "Application Support"
|
| 12 |
+
/ "SDU-Shift" / "shift_tool.db")
|
| 13 |
else:
|
| 14 |
+
_DB_PATH = Path(os.environ.get("APPDATA", str(Path.home()))) / "SDU-Shift" / "shift_tool.db"
|
|
|
|
|
|
|
| 15 |
else:
|
| 16 |
+
_DB_PATH = Path.home() / ".shift_tool" / "shift_tool.db"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _to_pg(sql: str) -> str:
|
| 20 |
+
sql = sql.replace("?", "%s")
|
| 21 |
+
sql = re.sub(r"INTEGER\s+PRIMARY\s+KEY\s+AUTOINCREMENT", "SERIAL PRIMARY KEY",
|
| 22 |
+
sql, flags=re.IGNORECASE)
|
| 23 |
+
sql = sql.replace("DEFAULT (datetime('now','localtime'))", "DEFAULT CURRENT_TIMESTAMP")
|
| 24 |
+
return sql
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class _Row:
|
| 28 |
+
"""psycopg2 RealDictRow を sqlite3.Row と同じ interface でラップ"""
|
| 29 |
+
__slots__ = ("_d",)
|
| 30 |
+
def __init__(self, d: dict): self._d = d
|
| 31 |
+
def __getitem__(self, k): return self._d[k]
|
| 32 |
+
def keys(self): return self._d.keys()
|
| 33 |
+
def __contains__(self, k): return k in self._d
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class _PgCursor:
|
| 37 |
+
def __init__(self, cur): self._cur = cur
|
| 38 |
+
def fetchone(self):
|
| 39 |
+
r = self._cur.fetchone()
|
| 40 |
+
return _Row(dict(r)) if r is not None else None
|
| 41 |
+
def fetchall(self):
|
| 42 |
+
return [_Row(dict(r)) for r in self._cur.fetchall()]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class Connection:
|
| 46 |
+
def __init__(self):
|
| 47 |
+
if DATABASE_URL:
|
| 48 |
+
import psycopg2
|
| 49 |
+
import psycopg2.extras
|
| 50 |
+
url = DATABASE_URL
|
| 51 |
+
if url.startswith("postgres://"):
|
| 52 |
+
url = "postgresql://" + url[len("postgres://"):]
|
| 53 |
+
self._conn = psycopg2.connect(url)
|
| 54 |
+
self._factory = psycopg2.extras.RealDictCursor
|
| 55 |
+
self.backend = "postgres"
|
| 56 |
+
else:
|
| 57 |
+
import sqlite3
|
| 58 |
+
_DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 59 |
+
self._conn = sqlite3.connect(str(_DB_PATH))
|
| 60 |
+
self._conn.row_factory = sqlite3.Row
|
| 61 |
+
self._conn.execute("PRAGMA foreign_keys = ON")
|
| 62 |
+
self.backend = "sqlite"
|
| 63 |
+
self.lastrowid = None
|
| 64 |
+
|
| 65 |
+
def execute(self, sql: str, params=()):
|
| 66 |
+
if self.backend == "postgres":
|
| 67 |
+
cur = self._conn.cursor(cursor_factory=self._factory)
|
| 68 |
+
cur.execute(_to_pg(sql), list(params) if params else None)
|
| 69 |
+
self.lastrowid = None
|
| 70 |
+
return _PgCursor(cur)
|
| 71 |
+
else:
|
| 72 |
+
cur = self._conn.execute(sql, params)
|
| 73 |
+
self.lastrowid = cur.lastrowid
|
| 74 |
+
return cur
|
| 75 |
+
|
| 76 |
+
def execute_insert(self, sql: str, params=()) -> int:
|
| 77 |
+
"""INSERT して新規 id を返す(両 backend 対応)"""
|
| 78 |
+
if self.backend == "postgres":
|
| 79 |
+
adapted = _to_pg(sql).rstrip("; ") + " RETURNING id"
|
| 80 |
+
cur = self._conn.cursor(cursor_factory=self._factory)
|
| 81 |
+
cur.execute(adapted, list(params) if params else None)
|
| 82 |
+
row = cur.fetchone()
|
| 83 |
+
return row["id"] if row else None
|
| 84 |
+
else:
|
| 85 |
+
cur = self._conn.execute(sql, params)
|
| 86 |
+
return cur.lastrowid
|
| 87 |
+
|
| 88 |
+
def commit(self): self._conn.commit()
|
| 89 |
+
def close(self): self._conn.close()
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def get_connection() -> Connection:
|
| 93 |
+
return Connection()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# ── DDL helpers ──────────────────────────────────────────────────────────────
|
| 97 |
+
|
| 98 |
+
_CREATE_TABLES = [
|
| 99 |
+
"""CREATE TABLE IF NOT EXISTS employees (
|
| 100 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 101 |
+
name TEXT NOT NULL,
|
| 102 |
+
employment_type TEXT NOT NULL CHECK(employment_type IN ('full_time','part_time')),
|
| 103 |
+
hall_skill TEXT NOT NULL DEFAULT 'beginner'
|
| 104 |
+
CHECK(hall_skill IN ('leader','veteran','general','beginner')),
|
| 105 |
+
kitchen_skill TEXT NOT NULL DEFAULT 'beginner'
|
| 106 |
+
CHECK(kitchen_skill IN ('leader','veteran','general','beginner')),
|
| 107 |
+
is_active INTEGER NOT NULL DEFAULT 1
|
| 108 |
+
)""",
|
| 109 |
+
"""CREATE TABLE IF NOT EXISTS fixed_patterns (
|
| 110 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 111 |
+
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 112 |
+
day_of_week INTEGER NOT NULL CHECK(day_of_week BETWEEN 0 AND 6),
|
| 113 |
+
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 114 |
+
dinner INTEGER NOT NULL DEFAULT 0,
|
| 115 |
+
UNIQUE(employee_id, day_of_week)
|
| 116 |
+
)""",
|
| 117 |
+
"""CREATE TABLE IF NOT EXISTS fixed_unavailable_dates (
|
| 118 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 119 |
+
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 120 |
+
date TEXT NOT NULL,
|
| 121 |
+
UNIQUE(employee_id, date)
|
| 122 |
+
)""",
|
| 123 |
+
"""CREATE TABLE IF NOT EXISTS schedule_periods (
|
| 124 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 125 |
+
start_date TEXT NOT NULL,
|
| 126 |
+
end_date TEXT NOT NULL,
|
| 127 |
+
status TEXT NOT NULL DEFAULT 'draft'
|
| 128 |
+
CHECK(status IN ('draft','confirmed')),
|
| 129 |
+
created_at TEXT NOT NULL DEFAULT (datetime('now','localtime')),
|
| 130 |
+
UNIQUE(start_date)
|
| 131 |
+
)""",
|
| 132 |
+
"""CREATE TABLE IF NOT EXISTS shift_requests (
|
| 133 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 134 |
+
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 135 |
+
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 136 |
+
date TEXT NOT NULL,
|
| 137 |
+
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 138 |
+
dinner INTEGER NOT NULL DEFAULT 0,
|
| 139 |
+
note TEXT DEFAULT '',
|
| 140 |
+
UNIQUE(period_id, employee_id, date)
|
| 141 |
+
)""",
|
| 142 |
+
"""CREATE TABLE IF NOT EXISTS shift_assignments (
|
| 143 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 144 |
+
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 145 |
+
employee_id INTEGER NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
|
| 146 |
+
date TEXT NOT NULL,
|
| 147 |
+
time_slot TEXT NOT NULL CHECK(time_slot IN ('breakfast','dinner')),
|
| 148 |
+
position TEXT NOT NULL CHECK(position IN ('hall','kitchen')),
|
| 149 |
+
UNIQUE(period_id, employee_id, date, time_slot)
|
| 150 |
+
)""",
|
| 151 |
+
"""CREATE TABLE IF NOT EXISTS shift_constraints (
|
| 152 |
+
slot TEXT NOT NULL,
|
| 153 |
+
position TEXT NOT NULL,
|
| 154 |
+
min_staff INTEGER NOT NULL DEFAULT 2,
|
| 155 |
+
max_staff INTEGER NOT NULL DEFAULT 4,
|
| 156 |
+
min_leader INTEGER NOT NULL DEFAULT 1,
|
| 157 |
+
PRIMARY KEY (slot, position)
|
| 158 |
+
)""",
|
| 159 |
+
"""CREATE TABLE IF NOT EXISTS schedule_notes (
|
| 160 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 161 |
+
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 162 |
+
date TEXT NOT NULL,
|
| 163 |
+
note TEXT NOT NULL DEFAULT '',
|
| 164 |
+
UNIQUE(period_id, date)
|
| 165 |
+
)""",
|
| 166 |
+
"""CREATE TABLE IF NOT EXISTS reservation_counts (
|
| 167 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 168 |
+
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 169 |
+
date TEXT NOT NULL,
|
| 170 |
+
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 171 |
+
dinner INTEGER NOT NULL DEFAULT 0,
|
| 172 |
+
UNIQUE(period_id, date)
|
| 173 |
+
)""",
|
| 174 |
+
"""CREATE TABLE IF NOT EXISTS app_settings (
|
| 175 |
+
key TEXT PRIMARY KEY,
|
| 176 |
+
value TEXT NOT NULL DEFAULT ''
|
| 177 |
+
)""",
|
| 178 |
+
"""CREATE TABLE IF NOT EXISTS breakfast_band_constraints (
|
| 179 |
+
band TEXT NOT NULL,
|
| 180 |
+
position TEXT NOT NULL,
|
| 181 |
+
min_staff INTEGER NOT NULL DEFAULT 0,
|
| 182 |
+
max_staff INTEGER NOT NULL DEFAULT 10,
|
| 183 |
+
min_leader INTEGER NOT NULL DEFAULT 0,
|
| 184 |
+
PRIMARY KEY (band, position)
|
| 185 |
+
)""",
|
| 186 |
+
]
|
| 187 |
+
|
| 188 |
+
_MIGRATIONS = [
|
| 189 |
+
("shift_requests", "pattern_id", "TEXT"),
|
| 190 |
+
("shift_requests", "custom_start", "TEXT"),
|
| 191 |
+
("shift_requests", "custom_end", "TEXT"),
|
| 192 |
+
("employees", "primary_position", "TEXT DEFAULT NULL"),
|
| 193 |
+
("employees", "primary_timeslot", "TEXT DEFAULT NULL"),
|
| 194 |
+
("employees", "can_work_both_positions", "INTEGER NOT NULL DEFAULT 0"),
|
| 195 |
+
("shift_assignments", "is_reinforcement", "INTEGER NOT NULL DEFAULT 0"),
|
| 196 |
+
("shift_assignments", "reinf_start", "TEXT DEFAULT NULL"),
|
| 197 |
+
("shift_assignments", "reinf_end", "TEXT DEFAULT NULL"),
|
| 198 |
+
("employees", "can_open", "INTEGER NOT NULL DEFAULT 0"),
|
| 199 |
+
("employees", "can_cleanup", "INTEGER NOT NULL DEFAULT 0"),
|
| 200 |
+
("employees", "always_available_breakfast", "INTEGER NOT NULL DEFAULT 0"),
|
| 201 |
+
("employees", "always_available_dinner", "INTEGER NOT NULL DEFAULT 0"),
|
| 202 |
+
]
|
| 203 |
|
| 204 |
|
| 205 |
def initialize_db():
|
| 206 |
conn = get_connection()
|
| 207 |
+
|
| 208 |
+
for ddl in _CREATE_TABLES:
|
| 209 |
+
conn.execute(ddl)
|
| 210 |
+
|
| 211 |
+
for table, col, definition in _MIGRATIONS:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
try:
|
| 213 |
+
conn.execute(f"ALTER TABLE {table} ADD COLUMN {col} {definition}")
|
| 214 |
except Exception:
|
| 215 |
+
pass
|
| 216 |
|
| 217 |
+
for slot, pos, mn, mx, ml in [
|
|
|
|
| 218 |
("breakfast", "hall", 3, 4, 1),
|
| 219 |
("breakfast", "kitchen", 3, 3, 1),
|
| 220 |
("dinner", "hall", 2, 3, 1),
|
| 221 |
("dinner", "kitchen", 3, 3, 2),
|
| 222 |
+
]:
|
| 223 |
+
conn.execute(
|
| 224 |
+
"INSERT INTO shift_constraints (slot, position, min_staff, max_staff, min_leader)"
|
| 225 |
+
" VALUES (?,?,?,?,?) ON CONFLICT DO NOTHING",
|
| 226 |
(slot, pos, mn, mx, ml)
|
| 227 |
)
|
| 228 |
|
| 229 |
+
for key, val in [
|
|
|
|
| 230 |
("reserv_threshold_breakfast", "100"),
|
| 231 |
("reserv_extra_breakfast", "1"),
|
| 232 |
("reserv_threshold_dinner", "25"),
|
| 233 |
("reserv_extra_dinner", "1"),
|
| 234 |
+
]:
|
| 235 |
+
conn.execute(
|
| 236 |
+
"INSERT INTO app_settings (key, value) VALUES (?,?) ON CONFLICT DO NOTHING",
|
| 237 |
+
(key, val)
|
| 238 |
)
|
| 239 |
|
| 240 |
+
for band, pos, mn, mx, ml in [
|
|
|
|
| 241 |
("open", "hall", 2, 4, 0),
|
| 242 |
("open", "kitchen", 0, 2, 0),
|
| 243 |
("cleanup", "hall", 1, 2, 1),
|
| 244 |
("cleanup", "kitchen", 0, 1, 0),
|
| 245 |
+
]:
|
| 246 |
+
conn.execute(
|
| 247 |
+
"INSERT INTO breakfast_band_constraints (band, position, min_staff, max_staff, min_leader)"
|
| 248 |
+
" VALUES (?,?,?,?,?) ON CONFLICT DO NOTHING",
|
| 249 |
(band, pos, mn, mx, ml)
|
| 250 |
)
|
| 251 |
|
db/repositories.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""DB操作の集約モジュール"""
|
| 2 |
from __future__ import annotations
|
| 3 |
from typing import Optional
|
| 4 |
-
from db.database import get_connection
|
| 5 |
from models.employee import Employee, FixedPattern
|
| 6 |
from models.schedule import ShiftRequest, ShiftAssignment, SchedulePeriod
|
| 7 |
from utils.constants import EmploymentType, SkillLevel, TimeSlot, Position, PrimaryPosition
|
|
@@ -40,11 +40,10 @@ def save_employee(emp: Employee) -> Employee:
|
|
| 40 |
avail_b = int(emp.always_available_breakfast)
|
| 41 |
avail_d = int(emp.always_available_dinner)
|
| 42 |
if emp.id is None:
|
| 43 |
-
|
| 44 |
"INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, is_active) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 45 |
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, opn, cln, avail_b, avail_d, 1)
|
| 46 |
)
|
| 47 |
-
emp.id = cur.lastrowid
|
| 48 |
else:
|
| 49 |
conn.execute(
|
| 50 |
"UPDATE employees SET name=?, employment_type=?, hall_skill=?, kitchen_skill=?, primary_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, can_cleanup=?, always_available_breakfast=?, always_available_dinner=?, is_active=? WHERE id=?",
|
|
@@ -114,7 +113,7 @@ def _save_fixed_patterns(conn, emp: Employee):
|
|
| 114 |
conn.execute("DELETE FROM fixed_patterns WHERE employee_id=?", (emp.id,))
|
| 115 |
for p in emp.fixed_patterns:
|
| 116 |
conn.execute(
|
| 117 |
-
"INSERT
|
| 118 |
(emp.id, p.day_of_week, int(p.breakfast), int(p.dinner))
|
| 119 |
)
|
| 120 |
|
|
@@ -123,7 +122,7 @@ def _save_fixed_unavailable_dates(conn, emp: Employee):
|
|
| 123 |
conn.execute("DELETE FROM fixed_unavailable_dates WHERE employee_id=?", (emp.id,))
|
| 124 |
for d in emp.fixed_unavailable_dates:
|
| 125 |
conn.execute(
|
| 126 |
-
"INSERT
|
| 127 |
(emp.id, d)
|
| 128 |
)
|
| 129 |
|
|
@@ -149,11 +148,10 @@ def get_period(period_id: int) -> Optional[SchedulePeriod]:
|
|
| 149 |
def save_period(period: SchedulePeriod) -> SchedulePeriod:
|
| 150 |
conn = get_connection()
|
| 151 |
if period.id is None:
|
| 152 |
-
|
| 153 |
"INSERT INTO schedule_periods (start_date, end_date, status) VALUES (?,?,?)",
|
| 154 |
(period.start_date, period.end_date, period.status)
|
| 155 |
)
|
| 156 |
-
period.id = cur.lastrowid
|
| 157 |
else:
|
| 158 |
conn.execute(
|
| 159 |
"UPDATE schedule_periods SET start_date=?, end_date=?, status=? WHERE id=?",
|
|
|
|
| 1 |
"""DB操作の集約モジュール"""
|
| 2 |
from __future__ import annotations
|
| 3 |
from typing import Optional
|
| 4 |
+
from db.database import get_connection, Connection
|
| 5 |
from models.employee import Employee, FixedPattern
|
| 6 |
from models.schedule import ShiftRequest, ShiftAssignment, SchedulePeriod
|
| 7 |
from utils.constants import EmploymentType, SkillLevel, TimeSlot, Position, PrimaryPosition
|
|
|
|
| 40 |
avail_b = int(emp.always_available_breakfast)
|
| 41 |
avail_d = int(emp.always_available_dinner)
|
| 42 |
if emp.id is None:
|
| 43 |
+
emp.id = conn.execute_insert(
|
| 44 |
"INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, is_active) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 45 |
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, opn, cln, avail_b, avail_d, 1)
|
| 46 |
)
|
|
|
|
| 47 |
else:
|
| 48 |
conn.execute(
|
| 49 |
"UPDATE employees SET name=?, employment_type=?, hall_skill=?, kitchen_skill=?, primary_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, can_cleanup=?, always_available_breakfast=?, always_available_dinner=?, is_active=? WHERE id=?",
|
|
|
|
| 113 |
conn.execute("DELETE FROM fixed_patterns WHERE employee_id=?", (emp.id,))
|
| 114 |
for p in emp.fixed_patterns:
|
| 115 |
conn.execute(
|
| 116 |
+
"INSERT INTO fixed_patterns (employee_id, day_of_week, breakfast, dinner) VALUES (?,?,?,?)",
|
| 117 |
(emp.id, p.day_of_week, int(p.breakfast), int(p.dinner))
|
| 118 |
)
|
| 119 |
|
|
|
|
| 122 |
conn.execute("DELETE FROM fixed_unavailable_dates WHERE employee_id=?", (emp.id,))
|
| 123 |
for d in emp.fixed_unavailable_dates:
|
| 124 |
conn.execute(
|
| 125 |
+
"INSERT INTO fixed_unavailable_dates (employee_id, date) VALUES (?,?)",
|
| 126 |
(emp.id, d)
|
| 127 |
)
|
| 128 |
|
|
|
|
| 148 |
def save_period(period: SchedulePeriod) -> SchedulePeriod:
|
| 149 |
conn = get_connection()
|
| 150 |
if period.id is None:
|
| 151 |
+
period.id = conn.execute_insert(
|
| 152 |
"INSERT INTO schedule_periods (start_date, end_date, status) VALUES (?,?,?)",
|
| 153 |
(period.start_date, period.end_date, period.status)
|
| 154 |
)
|
|
|
|
| 155 |
else:
|
| 156 |
conn.execute(
|
| 157 |
"UPDATE schedule_periods SET start_date=?, end_date=?, status=? WHERE id=?",
|
render.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
services:
|
| 2 |
+
- type: web
|
| 3 |
+
name: sdu-shift
|
| 4 |
+
runtime: python
|
| 5 |
+
buildCommand: pip install -r requirements.txt
|
| 6 |
+
startCommand: gunicorn "web_app:create_app()" --bind 0.0.0.0:$PORT --workers 2 --timeout 120
|
| 7 |
+
envVars:
|
| 8 |
+
- key: SECRET_KEY
|
| 9 |
+
generateValue: true
|
| 10 |
+
- key: DATABASE_URL
|
| 11 |
+
fromDatabase:
|
| 12 |
+
name: sdu-shift-db
|
| 13 |
+
property: connectionString
|
| 14 |
+
autoDeploy: true
|
| 15 |
+
|
| 16 |
+
databases:
|
| 17 |
+
- name: sdu-shift-db
|
| 18 |
+
plan: free
|
requirements.txt
CHANGED
|
@@ -3,3 +3,6 @@ ortools>=9.7.0
|
|
| 3 |
openpyxl>=3.1.0
|
| 4 |
reportlab>=4.0.0
|
| 5 |
PyInstaller>=6.0.0
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
openpyxl>=3.1.0
|
| 4 |
reportlab>=4.0.0
|
| 5 |
PyInstaller>=6.0.0
|
| 6 |
+
flask>=3.0.0
|
| 7 |
+
gunicorn>=21.0.0
|
| 8 |
+
psycopg2-binary>=2.9.0
|
routes/__init__.py
ADDED
|
File without changes
|
routes/customers.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
| 2 |
+
from db import repositories as repo
|
| 3 |
+
|
| 4 |
+
bp = Blueprint("customers", __name__, url_prefix="/customers")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@bp.get("/")
|
| 8 |
+
def list_periods():
|
| 9 |
+
periods = repo.get_all_periods()
|
| 10 |
+
if periods:
|
| 11 |
+
return redirect(url_for("customers.index", period_id=periods[0].id))
|
| 12 |
+
flash("期間がありません", "info")
|
| 13 |
+
return redirect(url_for("shifts.index"))
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@bp.get("/<int:period_id>")
|
| 17 |
+
def index(period_id):
|
| 18 |
+
period = repo.get_period(period_id)
|
| 19 |
+
if not period:
|
| 20 |
+
flash("期間が見つかりません", "error")
|
| 21 |
+
return redirect(url_for("shifts.index"))
|
| 22 |
+
periods = repo.get_all_periods()
|
| 23 |
+
dates = period.date_range()
|
| 24 |
+
counts = repo.get_reservation_counts(period_id)
|
| 25 |
+
return render_template(
|
| 26 |
+
"customers/index.html",
|
| 27 |
+
period=period,
|
| 28 |
+
periods=periods,
|
| 29 |
+
dates=dates,
|
| 30 |
+
counts=counts,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@bp.post("/<int:period_id>/save")
|
| 35 |
+
def save(period_id):
|
| 36 |
+
period = repo.get_period(period_id)
|
| 37 |
+
if not period:
|
| 38 |
+
flash("期間が見つかりません", "error")
|
| 39 |
+
return redirect(url_for("shifts.index"))
|
| 40 |
+
dates = period.date_range()
|
| 41 |
+
for d in dates:
|
| 42 |
+
ds = str(d)
|
| 43 |
+
b = int(request.form.get(f"b_{ds}", 0) or 0)
|
| 44 |
+
dn = int(request.form.get(f"d_{ds}", 0) or 0)
|
| 45 |
+
repo.save_reservation_count(period_id, ds, b, dn)
|
| 46 |
+
flash("予約客数を保存しました", "success")
|
| 47 |
+
return redirect(url_for("customers.index", period_id=period_id))
|
routes/employees.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
| 2 |
+
from db import repositories as repo
|
| 3 |
+
from models.employee import Employee, FixedPattern
|
| 4 |
+
from utils.constants import EmploymentType, SkillLevel, PrimaryPosition, TimeSlot, DAY_OF_WEEK_LABELS
|
| 5 |
+
|
| 6 |
+
bp = Blueprint("employees", __name__, url_prefix="/employees")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@bp.get("/")
|
| 10 |
+
def index():
|
| 11 |
+
show_archive = request.args.get("archive") == "1"
|
| 12 |
+
employees = repo.get_all_employees(active_only=not show_archive)
|
| 13 |
+
q = request.args.get("q", "").strip()
|
| 14 |
+
if q:
|
| 15 |
+
employees = [e for e in employees if q in e.name]
|
| 16 |
+
return render_template(
|
| 17 |
+
"employees/index.html",
|
| 18 |
+
employees=employees,
|
| 19 |
+
show_archive=show_archive,
|
| 20 |
+
q=q,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@bp.get("/new")
|
| 25 |
+
def new():
|
| 26 |
+
return render_template(
|
| 27 |
+
"employees/form.html",
|
| 28 |
+
emp=None,
|
| 29 |
+
employment_types=EmploymentType,
|
| 30 |
+
skill_levels=SkillLevel,
|
| 31 |
+
primary_positions=PrimaryPosition,
|
| 32 |
+
time_slots=TimeSlot,
|
| 33 |
+
dow_labels=DAY_OF_WEEK_LABELS,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@bp.post("/new")
|
| 38 |
+
def create():
|
| 39 |
+
emp = _form_to_employee(None)
|
| 40 |
+
repo.save_employee(emp)
|
| 41 |
+
flash(f"{emp.name} を登録しました", "success")
|
| 42 |
+
return redirect(url_for("employees.index"))
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@bp.get("/<int:emp_id>/edit")
|
| 46 |
+
def edit(emp_id):
|
| 47 |
+
emp = repo.get_employee(emp_id)
|
| 48 |
+
if not emp:
|
| 49 |
+
flash("従業員が見つかりません", "error")
|
| 50 |
+
return redirect(url_for("employees.index"))
|
| 51 |
+
return render_template(
|
| 52 |
+
"employees/form.html",
|
| 53 |
+
emp=emp,
|
| 54 |
+
employment_types=EmploymentType,
|
| 55 |
+
skill_levels=SkillLevel,
|
| 56 |
+
primary_positions=PrimaryPosition,
|
| 57 |
+
time_slots=TimeSlot,
|
| 58 |
+
dow_labels=DAY_OF_WEEK_LABELS,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@bp.post("/<int:emp_id>/edit")
|
| 63 |
+
def update(emp_id):
|
| 64 |
+
emp = _form_to_employee(emp_id)
|
| 65 |
+
repo.save_employee(emp)
|
| 66 |
+
flash(f"{emp.name} を更新しました", "success")
|
| 67 |
+
return redirect(url_for("employees.index"))
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
@bp.post("/<int:emp_id>/archive")
|
| 71 |
+
def archive(emp_id):
|
| 72 |
+
repo.delete_employee(emp_id)
|
| 73 |
+
flash("アーカイブしました", "success")
|
| 74 |
+
return redirect(url_for("employees.index"))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
@bp.post("/<int:emp_id>/restore")
|
| 78 |
+
def restore(emp_id):
|
| 79 |
+
repo.restore_employee(emp_id)
|
| 80 |
+
flash("復元しました", "success")
|
| 81 |
+
return redirect(url_for("employees.index") + "?archive=1")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _form_to_employee(emp_id):
|
| 85 |
+
f = request.form
|
| 86 |
+
patterns = []
|
| 87 |
+
for dow in range(7):
|
| 88 |
+
b = bool(f.get(f"fp_b_{dow}"))
|
| 89 |
+
d = bool(f.get(f"fp_d_{dow}"))
|
| 90 |
+
if b or d:
|
| 91 |
+
patterns.append(FixedPattern(dow, b, d))
|
| 92 |
+
|
| 93 |
+
pp_val = f.get("primary_position") or None
|
| 94 |
+
pt_val = f.get("primary_timeslot") or None
|
| 95 |
+
|
| 96 |
+
return Employee(
|
| 97 |
+
id=emp_id,
|
| 98 |
+
name=f["name"].strip(),
|
| 99 |
+
employment_type=EmploymentType(f["employment_type"]),
|
| 100 |
+
hall_skill=SkillLevel(f["hall_skill"]),
|
| 101 |
+
kitchen_skill=SkillLevel(f["kitchen_skill"]),
|
| 102 |
+
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
| 103 |
+
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 104 |
+
can_work_both_positions=bool(f.get("can_work_both_positions")),
|
| 105 |
+
can_open=bool(f.get("can_open")),
|
| 106 |
+
can_cleanup=bool(f.get("can_cleanup")),
|
| 107 |
+
always_available_breakfast=bool(f.get("always_available_breakfast")),
|
| 108 |
+
always_available_dinner=bool(f.get("always_available_dinner")),
|
| 109 |
+
fixed_patterns=patterns,
|
| 110 |
+
fixed_unavailable_dates=[],
|
| 111 |
+
is_active=True,
|
| 112 |
+
)
|
routes/export_routes.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
from flask import Blueprint, send_file, flash, redirect, url_for
|
| 3 |
+
from db import repositories as repo
|
| 4 |
+
from export.excel_exporter import export_excel
|
| 5 |
+
from export.pdf_exporter import export_pdf
|
| 6 |
+
|
| 7 |
+
bp = Blueprint("export", __name__, url_prefix="/export")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@bp.get("/<int:period_id>/excel")
|
| 11 |
+
def excel(period_id):
|
| 12 |
+
period = repo.get_period(period_id)
|
| 13 |
+
if not period:
|
| 14 |
+
flash("期間が見つかりません", "error")
|
| 15 |
+
return redirect(url_for("schedule.index", period_id=period_id))
|
| 16 |
+
employees = repo.get_all_employees(active_only=True)
|
| 17 |
+
assignments = repo.get_assignments(period_id)
|
| 18 |
+
buf = io.BytesIO()
|
| 19 |
+
export_excel(period, employees, assignments, buf)
|
| 20 |
+
buf.seek(0)
|
| 21 |
+
filename = f"shift_{period.start_date}_{period.end_date}.xlsx"
|
| 22 |
+
return send_file(buf, as_attachment=True, download_name=filename,
|
| 23 |
+
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@bp.get("/<int:period_id>/pdf")
|
| 27 |
+
def pdf(period_id):
|
| 28 |
+
period = repo.get_period(period_id)
|
| 29 |
+
if not period:
|
| 30 |
+
flash("期間が見つかりません", "error")
|
| 31 |
+
return redirect(url_for("schedule.index", period_id=period_id))
|
| 32 |
+
employees = repo.get_all_employees(active_only=True)
|
| 33 |
+
assignments = repo.get_assignments(period_id)
|
| 34 |
+
buf = io.BytesIO()
|
| 35 |
+
export_pdf(period, employees, assignments, buf)
|
| 36 |
+
buf.seek(0)
|
| 37 |
+
filename = f"shift_{period.start_date}_{period.end_date}.pdf"
|
| 38 |
+
return send_file(buf, as_attachment=True, download_name=filename,
|
| 39 |
+
mimetype="application/pdf")
|
routes/generate.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
| 2 |
+
from db import repositories as repo
|
| 3 |
+
from optimizer.solver import solve, SolverConfig, PRIORITY_SCALE
|
| 4 |
+
|
| 5 |
+
bp = Blueprint("generate", __name__, url_prefix="/generate")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@bp.get("/")
|
| 9 |
+
def index():
|
| 10 |
+
periods = repo.get_all_periods()
|
| 11 |
+
return render_template("generate/index.html", periods=periods, result=None, priority_scale=PRIORITY_SCALE)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@bp.post("/run")
|
| 15 |
+
def run():
|
| 16 |
+
period_id = request.form.get("period_id", type=int)
|
| 17 |
+
if not period_id:
|
| 18 |
+
flash("期間を選択してください", "error")
|
| 19 |
+
return redirect(url_for("generate.index"))
|
| 20 |
+
|
| 21 |
+
period = repo.get_period(period_id)
|
| 22 |
+
if not period:
|
| 23 |
+
flash("期間が見つかりません", "error")
|
| 24 |
+
return redirect(url_for("generate.index"))
|
| 25 |
+
|
| 26 |
+
employees = repo.get_all_employees(active_only=True)
|
| 27 |
+
requests = repo.get_shift_requests(period_id)
|
| 28 |
+
|
| 29 |
+
def _scale(key):
|
| 30 |
+
v = request.form.get(key, "中")
|
| 31 |
+
return PRIORITY_SCALE.get(v, 1.0)
|
| 32 |
+
|
| 33 |
+
config = SolverConfig(
|
| 34 |
+
cost_scale=_scale("cost_scale"),
|
| 35 |
+
pt_pref_scale=_scale("pt_pref_scale"),
|
| 36 |
+
double_penalty_scale=_scale("double_penalty_scale"),
|
| 37 |
+
balance_scale=_scale("balance_scale"),
|
| 38 |
+
late_night_scale=_scale("late_night_scale"),
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
result = solve(period, employees, requests, config)
|
| 42 |
+
|
| 43 |
+
if result.status in ("optimal", "feasible"):
|
| 44 |
+
repo.save_assignments(period_id, result.assignments)
|
| 45 |
+
flash(f"シフトを生成しました({result.status}、{result.solve_time_sec:.1f}秒)", "success")
|
| 46 |
+
if result.warnings:
|
| 47 |
+
for w in result.warnings:
|
| 48 |
+
flash(w, "warning")
|
| 49 |
+
return redirect(url_for("schedule.index", period_id=period_id))
|
| 50 |
+
else:
|
| 51 |
+
periods = repo.get_all_periods()
|
| 52 |
+
return render_template(
|
| 53 |
+
"generate/index.html",
|
| 54 |
+
periods=periods,
|
| 55 |
+
result=result,
|
| 56 |
+
priority_scale=PRIORITY_SCALE,
|
| 57 |
+
selected_period_id=period_id,
|
| 58 |
+
)
|
routes/schedule.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
| 2 |
+
from db import repositories as repo
|
| 3 |
+
from models.schedule import ShiftAssignment
|
| 4 |
+
from utils.constants import TimeSlot, Position
|
| 5 |
+
|
| 6 |
+
bp = Blueprint("schedule", __name__, url_prefix="/schedule")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@bp.get("/")
|
| 10 |
+
def list_periods():
|
| 11 |
+
periods = repo.get_all_periods()
|
| 12 |
+
if periods:
|
| 13 |
+
return redirect(url_for("schedule.index", period_id=periods[0].id))
|
| 14 |
+
flash("期間がありません。まずシフト期間を作成してください", "info")
|
| 15 |
+
return redirect(url_for("shifts.index"))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@bp.get("/<int:period_id>")
|
| 19 |
+
def index(period_id):
|
| 20 |
+
period = repo.get_period(period_id)
|
| 21 |
+
if not period:
|
| 22 |
+
flash("期間が見つかりません", "error")
|
| 23 |
+
return redirect(url_for("shifts.index"))
|
| 24 |
+
|
| 25 |
+
periods = repo.get_all_periods()
|
| 26 |
+
employees = repo.get_all_employees(active_only=True)
|
| 27 |
+
emp_map = {e.id: e for e in employees}
|
| 28 |
+
assignments = repo.get_assignments(period_id)
|
| 29 |
+
dates = period.date_range()
|
| 30 |
+
|
| 31 |
+
# {date_str: {time_slot: [ShiftAssignment, ...]}}
|
| 32 |
+
asgn_map: dict = {}
|
| 33 |
+
for a in assignments:
|
| 34 |
+
asgn_map.setdefault(a.date, {}).setdefault(a.time_slot.value, []).append(a)
|
| 35 |
+
|
| 36 |
+
slot = request.args.get("slot", "breakfast")
|
| 37 |
+
|
| 38 |
+
return render_template(
|
| 39 |
+
"schedule/index.html",
|
| 40 |
+
period=period,
|
| 41 |
+
periods=periods,
|
| 42 |
+
employees=employees,
|
| 43 |
+
emp_map=emp_map,
|
| 44 |
+
dates=dates,
|
| 45 |
+
asgn_map=asgn_map,
|
| 46 |
+
slot=slot,
|
| 47 |
+
TimeSlot=TimeSlot,
|
| 48 |
+
Position=Position,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@bp.post("/<int:period_id>/assign")
|
| 53 |
+
def assign(period_id):
|
| 54 |
+
data = request.get_json()
|
| 55 |
+
emp_id = data.get("employee_id")
|
| 56 |
+
date_str = data.get("date")
|
| 57 |
+
slot_val = data.get("time_slot")
|
| 58 |
+
pos_val = data.get("position")
|
| 59 |
+
action = data.get("action", "add")
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
slot = TimeSlot(slot_val)
|
| 63 |
+
if action == "remove":
|
| 64 |
+
repo.remove_assignment(period_id, emp_id, date_str, slot)
|
| 65 |
+
else:
|
| 66 |
+
pos = Position(pos_val)
|
| 67 |
+
a = ShiftAssignment(employee_id=emp_id, date=date_str, time_slot=slot, position=pos)
|
| 68 |
+
repo.add_assignment(period_id, a)
|
| 69 |
+
return jsonify({"ok": True})
|
| 70 |
+
except Exception as e:
|
| 71 |
+
return jsonify({"ok": False, "error": str(e)}), 400
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
@bp.post("/<int:period_id>/confirm")
|
| 75 |
+
def confirm(period_id):
|
| 76 |
+
period = repo.get_period(period_id)
|
| 77 |
+
if period:
|
| 78 |
+
period.status = "confirmed"
|
| 79 |
+
repo.save_period(period)
|
| 80 |
+
flash("シフトを確定しました", "success")
|
| 81 |
+
return redirect(url_for("schedule.index", period_id=period_id))
|
routes/settings_routes.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
| 2 |
+
from db import repositories as repo
|
| 3 |
+
from utils.constants import TimeSlot, Position
|
| 4 |
+
|
| 5 |
+
bp = Blueprint("settings", __name__, url_prefix="/settings")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@bp.get("/")
|
| 9 |
+
def index():
|
| 10 |
+
constraints = repo.get_shift_constraints()
|
| 11 |
+
settings = repo.get_all_app_settings()
|
| 12 |
+
band_constraints = repo.get_breakfast_band_constraints()
|
| 13 |
+
return render_template(
|
| 14 |
+
"settings/index.html",
|
| 15 |
+
constraints=constraints,
|
| 16 |
+
settings=settings,
|
| 17 |
+
band_constraints=band_constraints,
|
| 18 |
+
TimeSlot=TimeSlot,
|
| 19 |
+
Position=Position,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@bp.post("/save")
|
| 24 |
+
def save():
|
| 25 |
+
constraints = repo.get_shift_constraints()
|
| 26 |
+
new_constraints = {}
|
| 27 |
+
for (slot, pos) in constraints:
|
| 28 |
+
prefix = f"{slot.value}_{pos.value}"
|
| 29 |
+
new_constraints[(slot, pos)] = {
|
| 30 |
+
"min": int(request.form.get(f"min_{prefix}", 0)),
|
| 31 |
+
"max": int(request.form.get(f"max_{prefix}", 0)),
|
| 32 |
+
"min_leader": int(request.form.get(f"ml_{prefix}", 0)),
|
| 33 |
+
}
|
| 34 |
+
repo.save_shift_constraints(new_constraints)
|
| 35 |
+
|
| 36 |
+
settings_keys = [
|
| 37 |
+
"reserv_threshold_breakfast", "reserv_extra_breakfast",
|
| 38 |
+
"reserv_threshold_dinner", "reserv_extra_dinner",
|
| 39 |
+
]
|
| 40 |
+
new_settings = {k: request.form.get(k, "") for k in settings_keys}
|
| 41 |
+
repo.save_all_app_settings(new_settings)
|
| 42 |
+
|
| 43 |
+
flash("設定を保存しました", "success")
|
| 44 |
+
return redirect(url_for("settings.index"))
|
routes/shifts.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import date, timedelta
|
| 2 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
| 3 |
+
from db import repositories as repo
|
| 4 |
+
from models.schedule import SchedulePeriod, ShiftRequest
|
| 5 |
+
from utils.shift_patterns import ALL_PATTERNS, PATTERN_MAP
|
| 6 |
+
|
| 7 |
+
bp = Blueprint("shifts", __name__, url_prefix="/shifts")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@bp.get("/")
|
| 11 |
+
def index():
|
| 12 |
+
periods = repo.get_all_periods()
|
| 13 |
+
return render_template("shifts/index.html", periods=periods)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@bp.post("/period/new")
|
| 17 |
+
def new_period():
|
| 18 |
+
start_str = request.form.get("start_date", "")
|
| 19 |
+
try:
|
| 20 |
+
start = date.fromisoformat(start_str)
|
| 21 |
+
except ValueError:
|
| 22 |
+
flash("日付が不正です", "error")
|
| 23 |
+
return redirect(url_for("shifts.index"))
|
| 24 |
+
end = start + timedelta(days=13)
|
| 25 |
+
period = SchedulePeriod(id=None, start_date=str(start), end_date=str(end))
|
| 26 |
+
period = repo.save_period(period)
|
| 27 |
+
return redirect(url_for("shifts.input", period_id=period.id))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@bp.get("/<int:period_id>")
|
| 31 |
+
def input(period_id):
|
| 32 |
+
period = repo.get_period(period_id)
|
| 33 |
+
if not period:
|
| 34 |
+
flash("期間が見つかりません", "error")
|
| 35 |
+
return redirect(url_for("shifts.index"))
|
| 36 |
+
employees = repo.get_all_employees(active_only=True)
|
| 37 |
+
requests = repo.get_shift_requests(period_id)
|
| 38 |
+
req_map = {(r.employee_id, r.date): r for r in requests}
|
| 39 |
+
|
| 40 |
+
dates = period.date_range()
|
| 41 |
+
return render_template(
|
| 42 |
+
"shifts/input.html",
|
| 43 |
+
period=period,
|
| 44 |
+
employees=employees,
|
| 45 |
+
dates=dates,
|
| 46 |
+
req_map=req_map,
|
| 47 |
+
patterns=ALL_PATTERNS,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@bp.post("/<int:period_id>/save")
|
| 52 |
+
def save(period_id):
|
| 53 |
+
period = repo.get_period(period_id)
|
| 54 |
+
if not period:
|
| 55 |
+
flash("期間が見つかりません", "error")
|
| 56 |
+
return redirect(url_for("shifts.index"))
|
| 57 |
+
employees = repo.get_all_employees(active_only=True)
|
| 58 |
+
dates = period.date_range()
|
| 59 |
+
|
| 60 |
+
new_requests = []
|
| 61 |
+
for emp in employees:
|
| 62 |
+
for d in dates:
|
| 63 |
+
key = f"pattern_{emp.id}_{d}"
|
| 64 |
+
pid = request.form.get(key)
|
| 65 |
+
if not pid:
|
| 66 |
+
continue
|
| 67 |
+
cs = request.form.get(f"custom_start_{emp.id}_{d}") or None
|
| 68 |
+
ce = request.form.get(f"custom_end_{emp.id}_{d}") or None
|
| 69 |
+
new_requests.append(ShiftRequest(
|
| 70 |
+
employee_id=emp.id,
|
| 71 |
+
date=str(d),
|
| 72 |
+
pattern_id=pid,
|
| 73 |
+
custom_start=cs,
|
| 74 |
+
custom_end=ce,
|
| 75 |
+
))
|
| 76 |
+
|
| 77 |
+
repo.save_shift_requests(period_id, new_requests)
|
| 78 |
+
flash("希望シフトを保存しました", "success")
|
| 79 |
+
return redirect(url_for("shifts.input", period_id=period_id))
|
static/manifest.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "SDU-Shift",
|
| 3 |
+
"short_name": "Shift",
|
| 4 |
+
"description": "飲食店向けシフト管理アプリ",
|
| 5 |
+
"start_url": "/",
|
| 6 |
+
"display": "standalone",
|
| 7 |
+
"background_color": "#1e293b",
|
| 8 |
+
"theme_color": "#1e293b",
|
| 9 |
+
"orientation": "portrait",
|
| 10 |
+
"icons": [
|
| 11 |
+
{ "src": "/static/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
|
| 12 |
+
{ "src": "/static/icons/icon-512.png", "sizes": "512x512", "type": "image/png" }
|
| 13 |
+
]
|
| 14 |
+
}
|
static/sw.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Service Worker: オフラインキャッシュ(シェル)
|
| 2 |
+
const CACHE = "sdu-shift-v1";
|
| 3 |
+
const SHELL = ["/", "/static/manifest.json"];
|
| 4 |
+
|
| 5 |
+
self.addEventListener("install", e => {
|
| 6 |
+
e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)));
|
| 7 |
+
self.skipWaiting();
|
| 8 |
+
});
|
| 9 |
+
|
| 10 |
+
self.addEventListener("activate", e => {
|
| 11 |
+
e.waitUntil(
|
| 12 |
+
caches.keys().then(keys =>
|
| 13 |
+
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
|
| 14 |
+
)
|
| 15 |
+
);
|
| 16 |
+
self.clients.claim();
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
self.addEventListener("fetch", e => {
|
| 20 |
+
// ネットワーク優先、失敗時にキャッシュ
|
| 21 |
+
if (e.request.method !== "GET") return;
|
| 22 |
+
e.respondWith(
|
| 23 |
+
fetch(e.request).catch(() => caches.match(e.request))
|
| 24 |
+
);
|
| 25 |
+
});
|
templates/base.html
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="ja">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
| 6 |
+
<meta name="theme-color" content="#1e293b">
|
| 7 |
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 8 |
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
| 9 |
+
<meta name="apple-mobile-web-app-title" content="SDU-Shift">
|
| 10 |
+
<link rel="manifest" href="/static/manifest.json">
|
| 11 |
+
<title>{% block title %}SDU-Shift{% endblock %}</title>
|
| 12 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
|
| 13 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
|
| 14 |
+
<style>
|
| 15 |
+
:root {
|
| 16 |
+
--nav-h: 60px;
|
| 17 |
+
--safe-bottom: env(safe-area-inset-bottom, 0px);
|
| 18 |
+
}
|
| 19 |
+
body { padding-bottom: calc(var(--nav-h) + var(--safe-bottom)); background: #f8fafc; }
|
| 20 |
+
.bottom-nav {
|
| 21 |
+
position: fixed; bottom: 0; left: 0; right: 0;
|
| 22 |
+
height: calc(var(--nav-h) + var(--safe-bottom));
|
| 23 |
+
padding-bottom: var(--safe-bottom);
|
| 24 |
+
background: #1e293b; display: flex; z-index: 1000;
|
| 25 |
+
border-top: 1px solid #334155;
|
| 26 |
+
}
|
| 27 |
+
.bottom-nav a {
|
| 28 |
+
flex: 1; display: flex; flex-direction: column; align-items: center;
|
| 29 |
+
justify-content: center; color: #94a3b8; text-decoration: none;
|
| 30 |
+
font-size: 10px; gap: 2px; transition: color .15s;
|
| 31 |
+
}
|
| 32 |
+
.bottom-nav a.active, .bottom-nav a:hover { color: #38bdf8; }
|
| 33 |
+
.bottom-nav a i { font-size: 22px; }
|
| 34 |
+
.page-header {
|
| 35 |
+
background: #1e293b; color: white;
|
| 36 |
+
padding: .75rem 1rem; position: sticky; top: 0; z-index: 100;
|
| 37 |
+
display: flex; align-items: center; gap: .5rem;
|
| 38 |
+
}
|
| 39 |
+
.page-header h1 { font-size: 1.1rem; margin: 0; font-weight: 600; }
|
| 40 |
+
.content { padding: 1rem; }
|
| 41 |
+
.card { border: none; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-radius: 12px; }
|
| 42 |
+
.btn-primary { background: #0ea5e9; border-color: #0ea5e9; }
|
| 43 |
+
.btn-primary:hover { background: #0284c7; border-color: #0284c7; }
|
| 44 |
+
.badge-hall { background: #dbeafe; color: #1d4ed8; }
|
| 45 |
+
.badge-kitchen { background: #dcfce7; color: #15803d; }
|
| 46 |
+
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; }
|
| 47 |
+
@media (min-width: 768px) {
|
| 48 |
+
body { padding-bottom: 0; padding-left: 200px; }
|
| 49 |
+
.bottom-nav { display: none; }
|
| 50 |
+
.sidebar {
|
| 51 |
+
position: fixed; left: 0; top: 0; bottom: 0; width: 200px;
|
| 52 |
+
background: #1e293b; display: flex; flex-direction: column;
|
| 53 |
+
padding: 1rem 0; z-index: 100;
|
| 54 |
+
}
|
| 55 |
+
.sidebar .brand {
|
| 56 |
+
color: white; font-weight: 700; font-size: 1.1rem;
|
| 57 |
+
padding: .5rem 1.25rem 1.25rem; border-bottom: 1px solid #334155;
|
| 58 |
+
}
|
| 59 |
+
.sidebar a {
|
| 60 |
+
display: flex; align-items: center; gap: .75rem;
|
| 61 |
+
color: #94a3b8; text-decoration: none; padding: .6rem 1.25rem;
|
| 62 |
+
font-size: .9rem; transition: all .15s;
|
| 63 |
+
}
|
| 64 |
+
.sidebar a.active, .sidebar a:hover { color: #38bdf8; background: #0f172a; }
|
| 65 |
+
.sidebar a i { font-size: 18px; width: 20px; }
|
| 66 |
+
}
|
| 67 |
+
.sidebar { display: none; }
|
| 68 |
+
@media (min-width: 768px) { .sidebar { display: flex; } }
|
| 69 |
+
</style>
|
| 70 |
+
{% block head %}{% endblock %}
|
| 71 |
+
</head>
|
| 72 |
+
<body>
|
| 73 |
+
|
| 74 |
+
<!-- Desktop Sidebar -->
|
| 75 |
+
<nav class="sidebar">
|
| 76 |
+
<div class="brand">SDU-Shift</div>
|
| 77 |
+
{% set nav_items = [
|
| 78 |
+
('employees.index', 'bi-people-fill', 'スタッフ管理'),
|
| 79 |
+
('shifts.index', 'bi-pencil-square', '希望シフト'),
|
| 80 |
+
('generate.index', 'bi-lightning-fill', '自動生成'),
|
| 81 |
+
('schedule.list_periods', 'bi-calendar3', 'シフト表'),
|
| 82 |
+
('customers.list_periods', 'bi-cup-hot-fill', '客数管理'),
|
| 83 |
+
('settings.index', 'bi-gear-fill', '設定'),
|
| 84 |
+
] %}
|
| 85 |
+
{% for endpoint, icon, label in nav_items %}
|
| 86 |
+
<a href="{{ url_for(endpoint) }}" class="{{ 'active' if request.endpoint and request.endpoint.startswith(endpoint.split('.')[0]) else '' }}">
|
| 87 |
+
<i class="bi {{ icon }}"></i>{{ label }}
|
| 88 |
+
</a>
|
| 89 |
+
{% endfor %}
|
| 90 |
+
</nav>
|
| 91 |
+
|
| 92 |
+
<!-- Mobile Bottom Nav -->
|
| 93 |
+
<div class="bottom-nav">
|
| 94 |
+
{% for endpoint, icon, label in [
|
| 95 |
+
('employees.index', 'bi-people-fill', 'スタッフ'),
|
| 96 |
+
('shifts.index', 'bi-pencil-square', 'シフト入力'),
|
| 97 |
+
('generate.index', 'bi-lightning-fill', '自動生成'),
|
| 98 |
+
('schedule.list_periods', 'bi-calendar3', 'シフト表'),
|
| 99 |
+
('settings.index', 'bi-gear-fill', '設定'),
|
| 100 |
+
] %}
|
| 101 |
+
<a href="{{ url_for(endpoint) }}" class="{{ 'active' if request.endpoint and request.endpoint.startswith(endpoint.split('.')[0]) else '' }}">
|
| 102 |
+
<i class="bi {{ icon }}"></i>{{ label }}
|
| 103 |
+
</a>
|
| 104 |
+
{% endfor %}
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
<!-- Flash Messages -->
|
| 108 |
+
<div class="toast-container">
|
| 109 |
+
{% for cat, msg in get_flashed_messages(with_categories=true) %}
|
| 110 |
+
<div class="toast show align-items-center text-bg-{{ 'success' if cat == 'success' else 'danger' if cat == 'error' else 'warning' if cat == 'warning' else 'info' }} border-0" role="alert">
|
| 111 |
+
<div class="d-flex">
|
| 112 |
+
<div class="toast-body">{{ msg }}</div>
|
| 113 |
+
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
{% endfor %}
|
| 117 |
+
</div>
|
| 118 |
+
|
| 119 |
+
{% block content %}{% endblock %}
|
| 120 |
+
|
| 121 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 122 |
+
<script>
|
| 123 |
+
// Auto-dismiss toasts
|
| 124 |
+
document.querySelectorAll('.toast').forEach(t => {
|
| 125 |
+
setTimeout(() => { bootstrap.Toast.getOrCreateInstance(t).hide(); }, 4000);
|
| 126 |
+
});
|
| 127 |
+
// PWA service worker
|
| 128 |
+
if ('serviceWorker' in navigator) {
|
| 129 |
+
navigator.serviceWorker.register('/static/sw.js').catch(() => {});
|
| 130 |
+
}
|
| 131 |
+
</script>
|
| 132 |
+
{% block scripts %}{% endblock %}
|
| 133 |
+
</body>
|
| 134 |
+
</html>
|
templates/customers/index.html
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}客数管理 - SDU-Shift{% endblock %}
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="page-header">
|
| 5 |
+
<h1><i class="bi bi-cup-hot-fill me-2"></i>客数管理</h1>
|
| 6 |
+
<button form="cust-form" type="submit" class="btn btn-primary btn-sm ms-auto">
|
| 7 |
+
<i class="bi bi-floppy-fill"></i> 保存
|
| 8 |
+
</button>
|
| 9 |
+
</div>
|
| 10 |
+
<div class="content">
|
| 11 |
+
<!-- 期間セレクター -->
|
| 12 |
+
<select class="form-select form-select-sm mb-3" style="max-width:220px"
|
| 13 |
+
onchange="location.href='/customers/'+this.value">
|
| 14 |
+
{% for p in periods %}
|
| 15 |
+
<option value="{{ p.id }}" {{ 'selected' if p.id == period.id else '' }}>
|
| 16 |
+
{{ p.start_date }} 〜 {{ p.end_date }}
|
| 17 |
+
</option>
|
| 18 |
+
{% endfor %}
|
| 19 |
+
</select>
|
| 20 |
+
|
| 21 |
+
<form id="cust-form" method="post" action="{{ url_for('customers.save', period_id=period.id) }}">
|
| 22 |
+
<div class="card">
|
| 23 |
+
<div class="table-responsive">
|
| 24 |
+
<table class="table table-bordered table-sm mb-0">
|
| 25 |
+
<thead class="table-dark">
|
| 26 |
+
<tr>
|
| 27 |
+
<th>日付</th>
|
| 28 |
+
<th class="text-center">朝食</th>
|
| 29 |
+
<th class="text-center">ディナー</th>
|
| 30 |
+
</tr>
|
| 31 |
+
</thead>
|
| 32 |
+
<tbody>
|
| 33 |
+
{% for d in dates %}
|
| 34 |
+
{% set ds = d|string %}
|
| 35 |
+
{% set cnt = counts.get(ds, {}) %}
|
| 36 |
+
{% set dow = d.weekday() %}
|
| 37 |
+
<tr class="{{ 'table-primary' if dow == 5 else 'table-danger' if dow == 6 else '' }}">
|
| 38 |
+
<td>
|
| 39 |
+
{{ d.strftime('%m/%d') }}
|
| 40 |
+
<small class="text-muted">{{ ['月','火','水','木','金','土','日'][dow] }}</small>
|
| 41 |
+
</td>
|
| 42 |
+
<td>
|
| 43 |
+
<input type="number" name="b_{{ ds }}" value="{{ cnt.get('breakfast', 0) }}"
|
| 44 |
+
class="form-control form-control-sm text-center" min="0" style="width:80px">
|
| 45 |
+
</td>
|
| 46 |
+
<td>
|
| 47 |
+
<input type="number" name="d_{{ ds }}" value="{{ cnt.get('dinner', 0) }}"
|
| 48 |
+
class="form-control form-control-sm text-center" min="0" style="width:80px">
|
| 49 |
+
</td>
|
| 50 |
+
</tr>
|
| 51 |
+
{% endfor %}
|
| 52 |
+
</tbody>
|
| 53 |
+
</table>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
</form>
|
| 57 |
+
</div>
|
| 58 |
+
{% endblock %}
|
templates/employees/form.html
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}{{ '従業員編集' if emp else '新規登録' }} - SDU-Shift{% endblock %}
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="page-header">
|
| 5 |
+
<a href="{{ url_for('employees.index') }}" class="text-white me-2"><i class="bi bi-arrow-left"></i></a>
|
| 6 |
+
<h1>{{ '従業員編集' if emp else '新規登録' }}</h1>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="content">
|
| 10 |
+
<form method="post">
|
| 11 |
+
<!-- 基本情報 -->
|
| 12 |
+
<div class="card mb-3">
|
| 13 |
+
<div class="card-body">
|
| 14 |
+
<h6 class="card-title text-muted mb-3">基本情報</h6>
|
| 15 |
+
|
| 16 |
+
<div class="mb-3">
|
| 17 |
+
<label class="form-label fw-semibold">氏名 <span class="text-danger">*</span></label>
|
| 18 |
+
<input type="text" name="name" class="form-control" value="{{ emp.name if emp else '' }}" required>
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<div class="mb-3">
|
| 22 |
+
<label class="form-label fw-semibold">雇用形態</label>
|
| 23 |
+
<select name="employment_type" class="form-select">
|
| 24 |
+
{% for et in employment_types %}
|
| 25 |
+
<option value="{{ et.value }}" {{ 'selected' if emp and emp.employment_type == et else '' }}>
|
| 26 |
+
{{ et.label() }}
|
| 27 |
+
</option>
|
| 28 |
+
{% endfor %}
|
| 29 |
+
</select>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<div class="row g-3">
|
| 33 |
+
<div class="col-6">
|
| 34 |
+
<label class="form-label fw-semibold">ホール習熟度</label>
|
| 35 |
+
<select name="hall_skill" class="form-select">
|
| 36 |
+
{% for sl in skill_levels %}
|
| 37 |
+
<option value="{{ sl.value }}" {{ 'selected' if emp and emp.hall_skill == sl else '' }}>
|
| 38 |
+
{{ sl.label() }}
|
| 39 |
+
</option>
|
| 40 |
+
{% endfor %}
|
| 41 |
+
</select>
|
| 42 |
+
</div>
|
| 43 |
+
<div class="col-6">
|
| 44 |
+
<label class="form-label fw-semibold">キッチン習熟度</label>
|
| 45 |
+
<select name="kitchen_skill" class="form-select">
|
| 46 |
+
{% for sl in skill_levels %}
|
| 47 |
+
<option value="{{ sl.value }}" {{ 'selected' if emp and emp.kitchen_skill == sl else '' }}>
|
| 48 |
+
{{ sl.label() }}
|
| 49 |
+
</option>
|
| 50 |
+
{% endfor %}
|
| 51 |
+
</select>
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<!-- 勤務設定 -->
|
| 58 |
+
<div class="card mb-3">
|
| 59 |
+
<div class="card-body">
|
| 60 |
+
<h6 class="card-title text-muted mb-3">勤務設定</h6>
|
| 61 |
+
|
| 62 |
+
<div class="mb-3">
|
| 63 |
+
<label class="form-label fw-semibold">所属ポジション</label>
|
| 64 |
+
<select name="primary_position" class="form-select">
|
| 65 |
+
<option value="">どちらでも</option>
|
| 66 |
+
{% for pp in primary_positions %}
|
| 67 |
+
<option value="{{ pp.value }}" {{ 'selected' if emp and emp.primary_position == pp else '' }}>
|
| 68 |
+
{{ pp.label() }}
|
| 69 |
+
</option>
|
| 70 |
+
{% endfor %}
|
| 71 |
+
</select>
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
<div class="mb-3">
|
| 75 |
+
<label class="form-label fw-semibold">勤務時間帯</label>
|
| 76 |
+
<select name="primary_timeslot" class="form-select">
|
| 77 |
+
<option value="">どちらでも</option>
|
| 78 |
+
{% for ts in time_slots %}
|
| 79 |
+
<option value="{{ ts.value }}" {{ 'selected' if emp and emp.primary_timeslot == ts else '' }}>
|
| 80 |
+
{{ ts.short_label() }}専任
|
| 81 |
+
</option>
|
| 82 |
+
{% endfor %}
|
| 83 |
+
</select>
|
| 84 |
+
</div>
|
| 85 |
+
|
| 86 |
+
<div class="d-flex flex-column gap-2">
|
| 87 |
+
<div class="form-check">
|
| 88 |
+
<input class="form-check-input" type="checkbox" name="can_work_both_positions" id="cwbp"
|
| 89 |
+
{{ 'checked' if emp and emp.can_work_both_positions else '' }}>
|
| 90 |
+
<label class="form-check-label" for="cwbp">兼務可(主所属外ポジション対応可)</label>
|
| 91 |
+
</div>
|
| 92 |
+
<div class="form-check">
|
| 93 |
+
<input class="form-check-input" type="checkbox" name="can_open" id="co"
|
| 94 |
+
{{ 'checked' if emp and emp.can_open else '' }}>
|
| 95 |
+
<label class="form-check-label" for="co">朝食開店準備対応可(5:45〜)</label>
|
| 96 |
+
</div>
|
| 97 |
+
<div class="form-check">
|
| 98 |
+
<input class="form-check-input" type="checkbox" name="can_cleanup" id="cc"
|
| 99 |
+
{{ 'checked' if emp and emp.can_cleanup else '' }}>
|
| 100 |
+
<label class="form-check-label" for="cc">朝食片付け対応可(〜11:30)</label>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="form-check">
|
| 103 |
+
<input class="form-check-input" type="checkbox" name="always_available_breakfast" id="aab"
|
| 104 |
+
{{ 'checked' if emp and emp.always_available_breakfast else '' }}>
|
| 105 |
+
<label class="form-check-label" for="aab">朝食:希望提出不要(毎日出勤可)</label>
|
| 106 |
+
</div>
|
| 107 |
+
<div class="form-check">
|
| 108 |
+
<input class="form-check-input" type="checkbox" name="always_available_dinner" id="aad"
|
| 109 |
+
{{ 'checked' if emp and emp.always_available_dinner else '' }}>
|
| 110 |
+
<label class="form-check-label" for="aad">ディナー:希望提出不要(毎日出勤可)</label>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
<!-- 固定パターン(アルバイトのみ有意) -->
|
| 117 |
+
<div class="card mb-3">
|
| 118 |
+
<div class="card-body">
|
| 119 |
+
<h6 class="card-title text-muted mb-3">固定シフトパターン(アルバイト)</h6>
|
| 120 |
+
<div class="table-responsive">
|
| 121 |
+
<table class="table table-sm table-bordered text-center mb-0">
|
| 122 |
+
<thead class="table-light">
|
| 123 |
+
<tr>
|
| 124 |
+
<th></th>
|
| 125 |
+
{% for d in dow_labels %}<th>{{ d }}</th>{% endfor %}
|
| 126 |
+
</tr>
|
| 127 |
+
</thead>
|
| 128 |
+
<tbody>
|
| 129 |
+
<tr>
|
| 130 |
+
<td class="fw-semibold">朝食</td>
|
| 131 |
+
{% for i in range(7) %}
|
| 132 |
+
<td>
|
| 133 |
+
<input type="checkbox" name="fp_b_{{ i }}"
|
| 134 |
+
{{ 'checked' if emp and emp.get_pattern(i) and emp.get_pattern(i).breakfast else '' }}>
|
| 135 |
+
</td>
|
| 136 |
+
{% endfor %}
|
| 137 |
+
</tr>
|
| 138 |
+
<tr>
|
| 139 |
+
<td class="fw-semibold">ディナー</td>
|
| 140 |
+
{% for i in range(7) %}
|
| 141 |
+
<td>
|
| 142 |
+
<input type="checkbox" name="fp_d_{{ i }}"
|
| 143 |
+
{{ 'checked' if emp and emp.get_pattern(i) and emp.get_pattern(i).dinner else '' }}>
|
| 144 |
+
</td>
|
| 145 |
+
{% endfor %}
|
| 146 |
+
</tr>
|
| 147 |
+
</tbody>
|
| 148 |
+
</table>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<div class="d-grid gap-2">
|
| 154 |
+
<button type="submit" class="btn btn-primary btn-lg">
|
| 155 |
+
<i class="bi bi-check-lg me-1"></i>{{ '更新する' if emp else '登録する' }}
|
| 156 |
+
</button>
|
| 157 |
+
<a href="{{ url_for('employees.index') }}" class="btn btn-outline-secondary">キャンセル</a>
|
| 158 |
+
</div>
|
| 159 |
+
</form>
|
| 160 |
+
</div>
|
| 161 |
+
{% endblock %}
|
templates/employees/index.html
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}スタッフ管理 - SDU-Shift{% endblock %}
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="page-header">
|
| 5 |
+
<h1><i class="bi bi-people-fill me-2"></i>スタッフ管理</h1>
|
| 6 |
+
<a href="{{ url_for('employees.new') }}" class="btn btn-primary btn-sm ms-auto">
|
| 7 |
+
<i class="bi bi-plus-lg"></i> 新規登録
|
| 8 |
+
</a>
|
| 9 |
+
</div>
|
| 10 |
+
|
| 11 |
+
<div class="content">
|
| 12 |
+
<!-- 検索 / アーカイブ切替 -->
|
| 13 |
+
<form method="get" class="d-flex gap-2 mb-3">
|
| 14 |
+
<input type="search" name="q" value="{{ q }}" class="form-control" placeholder="氏名で検索...">
|
| 15 |
+
{% if show_archive %}
|
| 16 |
+
<input type="hidden" name="archive" value="1">
|
| 17 |
+
<a href="{{ url_for('employees.index') }}" class="btn btn-outline-secondary btn-sm text-nowrap">現役のみ</a>
|
| 18 |
+
{% else %}
|
| 19 |
+
<a href="?archive=1" class="btn btn-outline-secondary btn-sm text-nowrap">アーカイブ</a>
|
| 20 |
+
{% endif %}
|
| 21 |
+
</form>
|
| 22 |
+
|
| 23 |
+
<!-- 従業員一覧 -->
|
| 24 |
+
{% for emp in employees %}
|
| 25 |
+
<div class="card mb-2 {% if not emp.is_active %}opacity-50{% endif %}">
|
| 26 |
+
<div class="card-body py-2 px-3">
|
| 27 |
+
<div class="d-flex align-items-center gap-2">
|
| 28 |
+
<div class="flex-grow-1">
|
| 29 |
+
<div class="fw-semibold">{{ emp.name }}</div>
|
| 30 |
+
<div class="text-muted small">
|
| 31 |
+
{{ emp.employment_type.label() }} ·
|
| 32 |
+
{% if emp.primary_position %}{{ emp.primary_position.label() }}{% else %}どちらでも{% endif %} ·
|
| 33 |
+
H:{{ emp.hall_skill.label() }} / K:{{ emp.kitchen_skill.label() }}
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
<div class="d-flex gap-1">
|
| 37 |
+
<a href="{{ url_for('employees.edit', emp_id=emp.id) }}" class="btn btn-outline-primary btn-sm">編集</a>
|
| 38 |
+
{% if emp.is_active %}
|
| 39 |
+
<form method="post" action="{{ url_for('employees.archive', emp_id=emp.id) }}" onsubmit="return confirm('アーカイブしますか?')">
|
| 40 |
+
<button class="btn btn-outline-danger btn-sm">削除</button>
|
| 41 |
+
</form>
|
| 42 |
+
{% else %}
|
| 43 |
+
<form method="post" action="{{ url_for('employees.restore', emp_id=emp.id) }}">
|
| 44 |
+
<button class="btn btn-outline-success btn-sm">復元</button>
|
| 45 |
+
</form>
|
| 46 |
+
{% endif %}
|
| 47 |
+
</div>
|
| 48 |
+
</div>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
{% else %}
|
| 52 |
+
<div class="text-center text-muted py-5">
|
| 53 |
+
<i class="bi bi-people fs-1 d-block mb-2"></i>
|
| 54 |
+
従業員が登録されていません
|
| 55 |
+
</div>
|
| 56 |
+
{% endfor %}
|
| 57 |
+
</div>
|
| 58 |
+
{% endblock %}
|
templates/generate/index.html
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}シフト自動生成 - SDU-Shift{% endblock %}
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="page-header">
|
| 5 |
+
<h1><i class="bi bi-lightning-fill me-2"></i>シフト自動生成</h1>
|
| 6 |
+
</div>
|
| 7 |
+
<div class="content">
|
| 8 |
+
|
| 9 |
+
{% if result and result.status not in ('optimal','feasible') %}
|
| 10 |
+
<div class="alert alert-danger">
|
| 11 |
+
<strong>生成失敗:{{ result.status }}</strong>
|
| 12 |
+
{% for e in result.errors %}<div class="small">{{ e }}</div>{% endfor %}
|
| 13 |
+
</div>
|
| 14 |
+
{% endif %}
|
| 15 |
+
|
| 16 |
+
<form method="post" action="{{ url_for('generate.run') }}">
|
| 17 |
+
<!-- 期間選択 -->
|
| 18 |
+
<div class="card mb-3">
|
| 19 |
+
<div class="card-body">
|
| 20 |
+
<h6 class="card-title text-muted mb-3">対象期間</h6>
|
| 21 |
+
<select name="period_id" class="form-select" required>
|
| 22 |
+
<option value="">選択してください</option>
|
| 23 |
+
{% for p in periods %}
|
| 24 |
+
<option value="{{ p.id }}" {{ 'selected' if selected_period_id == p.id else '' }}>
|
| 25 |
+
{{ p.start_date }} 〜 {{ p.end_date }}
|
| 26 |
+
</option>
|
| 27 |
+
{% endfor %}
|
| 28 |
+
</select>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<!-- 優先度設定 -->
|
| 33 |
+
<div class="card mb-3">
|
| 34 |
+
<div class="card-body">
|
| 35 |
+
<h6 class="card-title text-muted mb-3">優先度設定</h6>
|
| 36 |
+
{% for key, label in [
|
| 37 |
+
('cost_scale', '人件費最小化'),
|
| 38 |
+
('pt_pref_scale', 'アルバイト希望充当'),
|
| 39 |
+
('double_penalty_scale', '正社員両掛け持ち回避'),
|
| 40 |
+
('balance_scale', '人員バランス均等化'),
|
| 41 |
+
('late_night_scale', '深夜勤務分散'),
|
| 42 |
+
] %}
|
| 43 |
+
<div class="mb-2">
|
| 44 |
+
<label class="form-label small fw-semibold mb-1">{{ label }}</label>
|
| 45 |
+
<select name="{{ key }}" class="form-select form-select-sm">
|
| 46 |
+
{% for v in priority_scale.keys() %}
|
| 47 |
+
<option value="{{ v }}" {{ 'selected' if v == '中' else '' }}>{{ v }}</option>
|
| 48 |
+
{% endfor %}
|
| 49 |
+
</select>
|
| 50 |
+
</div>
|
| 51 |
+
{% endfor %}
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<div class="d-grid">
|
| 56 |
+
<button type="submit" class="btn btn-primary btn-lg">
|
| 57 |
+
<i class="bi bi-lightning-fill me-1"></i>シフトを生成する
|
| 58 |
+
</button>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="text-muted small text-center mt-2">※ 生成には数十秒かかる場合があります</div>
|
| 61 |
+
</form>
|
| 62 |
+
</div>
|
| 63 |
+
{% endblock %}
|
templates/schedule/index.html
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}シフト表 - SDU-Shift{% endblock %}
|
| 3 |
+
{% block head %}
|
| 4 |
+
<style>
|
| 5 |
+
.sched-grid { overflow-x: auto; -webkit-overflow-scrolling: touch; }
|
| 6 |
+
.sched-grid table { min-width: max-content; font-size: .82rem; }
|
| 7 |
+
.sched-grid th, .sched-grid td { white-space: nowrap; padding: .3rem .5rem; vertical-align: middle; }
|
| 8 |
+
.sched-grid .emp-col { position: sticky; left: 0; background: white; z-index: 1; min-width: 90px; font-weight: 600; }
|
| 9 |
+
.sched-grid thead th { background: #1e293b; color: white; }
|
| 10 |
+
.sched-grid thead th.emp-col { background: #0f172a; }
|
| 11 |
+
.sat td, .sat th { background: #eff6ff !important; }
|
| 12 |
+
.sun td, .sun th { background: #fff1f2 !important; }
|
| 13 |
+
.chip-hall { background: #dbeafe; color: #1e40af; border-radius: 4px; padding: 1px 5px; font-size: .75rem; }
|
| 14 |
+
.chip-kitchen { background: #dcfce7; color: #166534; border-radius: 4px; padding: 1px 5px; font-size: .75rem; }
|
| 15 |
+
.chip-empty { color: #cbd5e1; }
|
| 16 |
+
</style>
|
| 17 |
+
{% endblock %}
|
| 18 |
+
{% block content %}
|
| 19 |
+
<div class="page-header">
|
| 20 |
+
<h1 class="fs-6"><i class="bi bi-calendar3 me-1"></i>シフト表</h1>
|
| 21 |
+
<div class="ms-auto d-flex gap-1">
|
| 22 |
+
{% if period %}
|
| 23 |
+
<a href="{{ url_for('export.excel', period_id=period.id) }}" class="btn btn-outline-light btn-sm">
|
| 24 |
+
<i class="bi bi-file-earmark-excel"></i>
|
| 25 |
+
</a>
|
| 26 |
+
<a href="{{ url_for('export.pdf', period_id=period.id) }}" class="btn btn-outline-light btn-sm">
|
| 27 |
+
<i class="bi bi-file-earmark-pdf"></i>
|
| 28 |
+
</a>
|
| 29 |
+
{% endif %}
|
| 30 |
+
</div>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<div class="content">
|
| 34 |
+
{% if not period %}
|
| 35 |
+
<div class="text-center text-muted py-5">
|
| 36 |
+
<i class="bi bi-calendar-x fs-1 d-block mb-2"></i>
|
| 37 |
+
シフト期間がありません
|
| 38 |
+
</div>
|
| 39 |
+
{% else %}
|
| 40 |
+
|
| 41 |
+
<!-- 期間セレクター -->
|
| 42 |
+
<div class="d-flex gap-2 mb-3 align-items-center flex-wrap">
|
| 43 |
+
<select class="form-select form-select-sm" style="max-width:220px"
|
| 44 |
+
onchange="location.href='/schedule/'+this.value">
|
| 45 |
+
{% for p in periods %}
|
| 46 |
+
<option value="{{ p.id }}" {{ 'selected' if p.id == period.id else '' }}>
|
| 47 |
+
{{ p.start_date }} 〜 {{ p.end_date }}
|
| 48 |
+
</option>
|
| 49 |
+
{% endfor %}
|
| 50 |
+
</select>
|
| 51 |
+
|
| 52 |
+
<!-- 朝食/ディナー タブ -->
|
| 53 |
+
<div class="btn-group btn-group-sm">
|
| 54 |
+
<a href="?slot=breakfast" class="btn {{ 'btn-primary' if slot == 'breakfast' else 'btn-outline-secondary' }}">朝食</a>
|
| 55 |
+
<a href="?slot=dinner" class="btn {{ 'btn-primary' if slot == 'dinner' else 'btn-outline-secondary' }}">ディナー</a>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
{% if period.status == 'draft' %}
|
| 59 |
+
<form method="post" action="{{ url_for('schedule.confirm', period_id=period.id) }}" class="ms-auto">
|
| 60 |
+
<button class="btn btn-success btn-sm">
|
| 61 |
+
<i class="bi bi-check-lg"></i> 確定
|
| 62 |
+
</button>
|
| 63 |
+
</form>
|
| 64 |
+
{% else %}
|
| 65 |
+
<span class="badge bg-success ms-auto">確定済</span>
|
| 66 |
+
{% endif %}
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<!-- シフトグリッド -->
|
| 70 |
+
<div class="sched-grid">
|
| 71 |
+
<table class="table table-bordered table-sm mb-0">
|
| 72 |
+
<thead>
|
| 73 |
+
<tr>
|
| 74 |
+
<th class="emp-col">名前</th>
|
| 75 |
+
{% for d in dates %}
|
| 76 |
+
{% set dow = d.weekday() %}
|
| 77 |
+
<th class="text-center {{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }}">
|
| 78 |
+
{{ d.strftime('%m/%d') }}<br>
|
| 79 |
+
<small>{{ ['月','火','水','木','金','土','日'][dow] }}</small>
|
| 80 |
+
</th>
|
| 81 |
+
{% endfor %}
|
| 82 |
+
</tr>
|
| 83 |
+
</thead>
|
| 84 |
+
<tbody>
|
| 85 |
+
{% for emp in employees %}
|
| 86 |
+
<tr>
|
| 87 |
+
<td class="emp-col">{{ emp.name }}</td>
|
| 88 |
+
{% for d in dates %}
|
| 89 |
+
{% set ds = d|string %}
|
| 90 |
+
{% set dow = d.weekday() %}
|
| 91 |
+
{% set day_assignments = asgn_map.get(ds, {}).get(slot, []) %}
|
| 92 |
+
{% set emp_asgn = day_assignments | selectattr('employee_id', 'equalto', emp.id) | list | first %}
|
| 93 |
+
<td class="text-center {{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }}">
|
| 94 |
+
{% if emp_asgn %}
|
| 95 |
+
<span class="{{ 'chip-hall' if emp_asgn.position.value == 'hall' else 'chip-kitchen' }}">
|
| 96 |
+
{{ 'H' if emp_asgn.position.value == 'hall' else 'K' }}
|
| 97 |
+
</span>
|
| 98 |
+
{% else %}
|
| 99 |
+
<span class="chip-empty">—</span>
|
| 100 |
+
{% endif %}
|
| 101 |
+
</td>
|
| 102 |
+
{% endfor %}
|
| 103 |
+
</tr>
|
| 104 |
+
{% endfor %}
|
| 105 |
+
</tbody>
|
| 106 |
+
</table>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<!-- 凡例 -->
|
| 110 |
+
<div class="d-flex gap-3 mt-2 small text-muted">
|
| 111 |
+
<span><span class="chip-hall">H</span> ホール</span>
|
| 112 |
+
<span><span class="chip-kitchen">K</span> キッチン</span>
|
| 113 |
+
</div>
|
| 114 |
+
{% endif %}
|
| 115 |
+
</div>
|
| 116 |
+
{% endblock %}
|
templates/settings/index.html
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}設定 - SDU-Shift{% endblock %}
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="page-header">
|
| 5 |
+
<h1><i class="bi bi-gear-fill me-2"></i>設定</h1>
|
| 6 |
+
<button form="settings-form" type="submit" class="btn btn-primary btn-sm ms-auto">
|
| 7 |
+
<i class="bi bi-floppy-fill"></i> 保存
|
| 8 |
+
</button>
|
| 9 |
+
</div>
|
| 10 |
+
<div class="content">
|
| 11 |
+
<form id="settings-form" method="post" action="{{ url_for('settings.save') }}">
|
| 12 |
+
|
| 13 |
+
<!-- シフト人員制約 -->
|
| 14 |
+
<div class="card mb-3">
|
| 15 |
+
<div class="card-body">
|
| 16 |
+
<h6 class="card-title text-muted mb-3">シフト人員制約</h6>
|
| 17 |
+
<div class="table-responsive">
|
| 18 |
+
<table class="table table-sm table-bordered mb-0">
|
| 19 |
+
<thead class="table-light">
|
| 20 |
+
<tr><th>時間帯</th><th>ポジション</th><th>最少</th><th>最多</th><th>リーダー最少</th></tr>
|
| 21 |
+
</thead>
|
| 22 |
+
<tbody>
|
| 23 |
+
{% for (slot, pos), vals in constraints.items() %}
|
| 24 |
+
{% set prefix = slot.value + '_' + pos.value %}
|
| 25 |
+
<tr>
|
| 26 |
+
<td>{{ slot.short_label() }}</td>
|
| 27 |
+
<td>{{ pos.label() }}</td>
|
| 28 |
+
<td><input type="number" name="min_{{ prefix }}" value="{{ vals.min }}" class="form-control form-control-sm" min="0" style="width:60px"></td>
|
| 29 |
+
<td><input type="number" name="max_{{ prefix }}" value="{{ vals.max }}" class="form-control form-control-sm" min="0" style="width:60px"></td>
|
| 30 |
+
<td><input type="number" name="ml_{{ prefix }}" value="{{ vals.min_leader }}" class="form-control form-control-sm" min="0" style="width:60px"></td>
|
| 31 |
+
</tr>
|
| 32 |
+
{% endfor %}
|
| 33 |
+
</tbody>
|
| 34 |
+
</table>
|
| 35 |
+
</div>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
<!-- 予約客数による増員設定 -->
|
| 40 |
+
<div class="card mb-3">
|
| 41 |
+
<div class="card-body">
|
| 42 |
+
<h6 class="card-title text-muted mb-3">予約客数による増員設定</h6>
|
| 43 |
+
{% for key, label in [
|
| 44 |
+
('reserv_threshold_breakfast', '朝食:閾値(人)'),
|
| 45 |
+
('reserv_extra_breakfast', '朝食:増員数(人)'),
|
| 46 |
+
('reserv_threshold_dinner', 'ディナー:閾値(人)'),
|
| 47 |
+
('reserv_extra_dinner', 'ディナー:増員数(人)'),
|
| 48 |
+
] %}
|
| 49 |
+
<div class="mb-2 d-flex align-items-center gap-2">
|
| 50 |
+
<label class="form-label mb-0 small fw-semibold" style="min-width:180px">{{ label }}</label>
|
| 51 |
+
<input type="number" name="{{ key }}" value="{{ settings.get(key, '') }}"
|
| 52 |
+
class="form-control form-control-sm" style="max-width:100px" min="0">
|
| 53 |
+
</div>
|
| 54 |
+
{% endfor %}
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
</form>
|
| 59 |
+
</div>
|
| 60 |
+
{% endblock %}
|
templates/shifts/index.html
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}希望シフト入力 - SDU-Shift{% endblock %}
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="page-header">
|
| 5 |
+
<h1><i class="bi bi-pencil-square me-2"></i>希望シフト入力</h1>
|
| 6 |
+
</div>
|
| 7 |
+
<div class="content">
|
| 8 |
+
<!-- 新しい期間を作成 -->
|
| 9 |
+
<div class="card mb-3">
|
| 10 |
+
<div class="card-body">
|
| 11 |
+
<h6 class="card-title text-muted mb-3">新しい期間を作成</h6>
|
| 12 |
+
<form method="post" action="{{ url_for('shifts.new_period') }}" class="d-flex gap-2">
|
| 13 |
+
<input type="date" name="start_date" class="form-control" required>
|
| 14 |
+
<button class="btn btn-primary text-nowrap">作成</button>
|
| 15 |
+
</form>
|
| 16 |
+
<div class="text-muted small mt-1">開始日から 14 日間の期間が作成されます</div>
|
| 17 |
+
</div>
|
| 18 |
+
</div>
|
| 19 |
+
|
| 20 |
+
<!-- 既存の期間一覧 -->
|
| 21 |
+
<h6 class="text-muted mb-2">既存の期間</h6>
|
| 22 |
+
{% for period in periods %}
|
| 23 |
+
<div class="card mb-2">
|
| 24 |
+
<div class="card-body py-2 px-3 d-flex align-items-center">
|
| 25 |
+
<div class="flex-grow-1">
|
| 26 |
+
<div class="fw-semibold">{{ period.start_date }} 〜 {{ period.end_date }}</div>
|
| 27 |
+
<span class="badge {{ 'bg-success' if period.status == 'confirmed' else 'bg-secondary' }}">
|
| 28 |
+
{{ '確定' if period.status == 'confirmed' else '下書き' }}
|
| 29 |
+
</span>
|
| 30 |
+
</div>
|
| 31 |
+
<a href="{{ url_for('shifts.input', period_id=period.id) }}" class="btn btn-outline-primary btn-sm">
|
| 32 |
+
入力する
|
| 33 |
+
</a>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
{% else %}
|
| 37 |
+
<div class="text-center text-muted py-4">期間がありません</div>
|
| 38 |
+
{% endfor %}
|
| 39 |
+
</div>
|
| 40 |
+
{% endblock %}
|
templates/shifts/input.html
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}シフト入力 {{ period.start_date }} - SDU-Shift{% endblock %}
|
| 3 |
+
{% block head %}
|
| 4 |
+
<style>
|
| 5 |
+
.shift-grid { overflow-x: auto; -webkit-overflow-scrolling: touch; }
|
| 6 |
+
.shift-grid table { min-width: max-content; font-size: .82rem; }
|
| 7 |
+
.shift-grid th, .shift-grid td { white-space: nowrap; padding: .3rem .4rem; vertical-align: middle; }
|
| 8 |
+
.shift-grid .emp-col { position: sticky; left: 0; background: white; z-index: 1; min-width: 90px; font-weight: 600; }
|
| 9 |
+
.shift-grid thead th { background: #1e293b; color: white; }
|
| 10 |
+
.shift-grid thead th.emp-col { background: #0f172a; }
|
| 11 |
+
.shift-grid .sat { background: #eff6ff; }
|
| 12 |
+
.shift-grid .sun { background: #fff1f2; }
|
| 13 |
+
select.pattern-sel { font-size: .78rem; min-width: 140px; padding: 2px 4px; }
|
| 14 |
+
.custom-time { display: none; gap: 4px; margin-top: 3px; }
|
| 15 |
+
.custom-time input { width: 80px; font-size: .78rem; padding: 2px 4px; }
|
| 16 |
+
</style>
|
| 17 |
+
{% endblock %}
|
| 18 |
+
{% block content %}
|
| 19 |
+
<div class="page-header">
|
| 20 |
+
<a href="{{ url_for('shifts.index') }}" class="text-white me-2"><i class="bi bi-arrow-left"></i></a>
|
| 21 |
+
<h1 class="fs-6">{{ period.start_date }} 〜 {{ period.end_date }}</h1>
|
| 22 |
+
<button form="shift-form" type="submit" class="btn btn-primary btn-sm ms-auto">
|
| 23 |
+
<i class="bi bi-floppy-fill"></i> 保存
|
| 24 |
+
</button>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<form id="shift-form" method="post" action="{{ url_for('shifts.save', period_id=period.id) }}">
|
| 28 |
+
<div class="shift-grid p-2">
|
| 29 |
+
<table class="table table-bordered table-sm mb-0">
|
| 30 |
+
<thead>
|
| 31 |
+
<tr>
|
| 32 |
+
<th class="emp-col">名前</th>
|
| 33 |
+
{% for d in dates %}
|
| 34 |
+
{% set dow = d.weekday() %}
|
| 35 |
+
<th class="{{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }} text-center">
|
| 36 |
+
{{ d.strftime('%m/%d') }}<br>
|
| 37 |
+
<small>{{ ['月','火','水','木','金','土','日'][dow] }}</small>
|
| 38 |
+
</th>
|
| 39 |
+
{% endfor %}
|
| 40 |
+
</tr>
|
| 41 |
+
</thead>
|
| 42 |
+
<tbody>
|
| 43 |
+
{% for emp in employees %}
|
| 44 |
+
<tr>
|
| 45 |
+
<td class="emp-col">{{ emp.name }}</td>
|
| 46 |
+
{% for d in dates %}
|
| 47 |
+
{% set req = req_map.get((emp.id, d|string)) %}
|
| 48 |
+
{% set dow = d.weekday() %}
|
| 49 |
+
<td class="{{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }}">
|
| 50 |
+
<select name="pattern_{{ emp.id }}_{{ d }}"
|
| 51 |
+
class="form-select form-select-sm pattern-sel"
|
| 52 |
+
onchange="toggleCustom(this, '{{ emp.id }}_{{ d }}')">
|
| 53 |
+
<option value="">(休み)</option>
|
| 54 |
+
{% for p in patterns %}
|
| 55 |
+
<option value="{{ p.id }}"
|
| 56 |
+
{{ 'selected' if req and req.pattern_id == p.id else '' }}>
|
| 57 |
+
{{ p.label }}
|
| 58 |
+
</option>
|
| 59 |
+
{% endfor %}
|
| 60 |
+
</select>
|
| 61 |
+
<div id="custom_{{ emp.id }}_{{ d }}" class="custom-time"
|
| 62 |
+
style="{{ 'display:flex' if req and req.pattern_id == 'custom' else '' }}">
|
| 63 |
+
<input type="time" name="custom_start_{{ emp.id }}_{{ d }}"
|
| 64 |
+
value="{{ req.custom_start if req and req.custom_start else '' }}"
|
| 65 |
+
class="form-control form-control-sm" placeholder="開始">
|
| 66 |
+
<span class="align-self-center">〜</span>
|
| 67 |
+
<input type="time" name="custom_end_{{ emp.id }}_{{ d }}"
|
| 68 |
+
value="{{ req.custom_end if req and req.custom_end else '' }}"
|
| 69 |
+
class="form-control form-control-sm" placeholder="終了">
|
| 70 |
+
</div>
|
| 71 |
+
</td>
|
| 72 |
+
{% endfor %}
|
| 73 |
+
</tr>
|
| 74 |
+
{% endfor %}
|
| 75 |
+
</tbody>
|
| 76 |
+
</table>
|
| 77 |
+
</div>
|
| 78 |
+
</form>
|
| 79 |
+
{% endblock %}
|
| 80 |
+
{% block scripts %}
|
| 81 |
+
<script>
|
| 82 |
+
function toggleCustom(sel, key) {
|
| 83 |
+
const div = document.getElementById('custom_' + key);
|
| 84 |
+
if (div) div.style.display = sel.value === 'custom' ? 'flex' : 'none';
|
| 85 |
+
}
|
| 86 |
+
</script>
|
| 87 |
+
{% endblock %}
|
web_app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Flask Web Application Entry Point"""
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
sys.path.insert(0, os.path.dirname(__file__))
|
| 5 |
+
|
| 6 |
+
from flask import Flask
|
| 7 |
+
from db.database import initialize_db
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def create_app():
|
| 11 |
+
app = Flask(__name__, template_folder="templates", static_folder="static")
|
| 12 |
+
app.secret_key = os.environ.get("SECRET_KEY", "dev-secret-key-change-in-prod")
|
| 13 |
+
|
| 14 |
+
initialize_db()
|
| 15 |
+
|
| 16 |
+
from routes.employees import bp as emp_bp
|
| 17 |
+
from routes.shifts import bp as shifts_bp
|
| 18 |
+
from routes.generate import bp as gen_bp
|
| 19 |
+
from routes.schedule import bp as sched_bp
|
| 20 |
+
from routes.customers import bp as cust_bp
|
| 21 |
+
from routes.settings_routes import bp as settings_bp
|
| 22 |
+
from routes.export_routes import bp as export_bp
|
| 23 |
+
|
| 24 |
+
app.register_blueprint(emp_bp)
|
| 25 |
+
app.register_blueprint(shifts_bp)
|
| 26 |
+
app.register_blueprint(gen_bp)
|
| 27 |
+
app.register_blueprint(sched_bp)
|
| 28 |
+
app.register_blueprint(cust_bp)
|
| 29 |
+
app.register_blueprint(settings_bp)
|
| 30 |
+
app.register_blueprint(export_bp)
|
| 31 |
+
|
| 32 |
+
@app.get("/")
|
| 33 |
+
def index():
|
| 34 |
+
from flask import redirect, url_for
|
| 35 |
+
return redirect(url_for("employees.index"))
|
| 36 |
+
|
| 37 |
+
return app
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
app = create_app()
|
| 42 |
+
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
|