Commit ·
641a480
1
Parent(s): 8a1adda
シフト表出力にPDF/Excelの「朝食見込・夜予約」行の表示/非表示設定を追加
Browse files全体周知用のシフト表ではこの2行が不要というユーザーからの意見を受け、
設定画面のトグルでPDF・Excel出力時のみ非表示にできるようにした。
デフォルトは表示(従来動作を維持)。シフト表画面上での予約客数の
入力・編集には影響しない。
- export/excel_exporter.py +10 -1
- export/pdf_exporter.py +51 -39
- routes/export_routes.py +4 -2
- routes/settings_routes.py +1 -0
- templates/settings/index.html +17 -0
export/excel_exporter.py
CHANGED
|
@@ -314,8 +314,12 @@ def export_excel(
|
|
| 314 |
period: SchedulePeriod,
|
| 315 |
employees: list[Employee],
|
| 316 |
assignments: dict,
|
|
|
|
| 317 |
):
|
| 318 |
-
"""SDU_shift テンプレートにシフトデータを流し込んで Excel を出力する
|
|
|
|
|
|
|
|
|
|
| 319 |
from db import repositories as repo
|
| 320 |
requests = repo.get_shift_requests(period.id)
|
| 321 |
req_map = {(r.employee_id, r.date): r for r in requests}
|
|
@@ -432,6 +436,11 @@ def export_excel(
|
|
| 432 |
cell.value = label
|
| 433 |
cell.alignment = ALIGN_CC
|
| 434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
# ── 従業員グループの流し込み ───────────────────────────────────────
|
| 436 |
def _fill_group(start_row: int, slot_count: int, emps: list[Employee]):
|
| 437 |
for j in range(slot_count):
|
|
|
|
| 314 |
period: SchedulePeriod,
|
| 315 |
employees: list[Employee],
|
| 316 |
assignments: dict,
|
| 317 |
+
show_reservation_counts: bool = True,
|
| 318 |
):
|
| 319 |
+
"""SDU_shift テンプレートにシフトデータを流し込んで Excel を出力する。
|
| 320 |
+
|
| 321 |
+
show_reservation_counts=False の場合、「朝食見込」「夜予約」行(1・2ブロック目とも)
|
| 322 |
+
を非表示にする(全体周知用シフト表向け。値自体はセルに残るため再表示も可能)。"""
|
| 323 |
from db import repositories as repo
|
| 324 |
requests = repo.get_shift_requests(period.id)
|
| 325 |
req_map = {(r.employee_id, r.date): r for r in requests}
|
|
|
|
| 436 |
cell.value = label
|
| 437 |
cell.alignment = ALIGN_CC
|
| 438 |
|
| 439 |
+
# 「朝食見込・夜予約」行を非表示(全体周知用シフト表向け。値は残し再表示も可能)
|
| 440 |
+
if not show_reservation_counts:
|
| 441 |
+
for r in (R_BF, R_DIN, r_date2 + 2, r_date2 + 3):
|
| 442 |
+
ws.row_dimensions[r].hidden = True
|
| 443 |
+
|
| 444 |
# ── 従業員グループの流し込み ───────────────────────────────────────
|
| 445 |
def _fill_group(start_row: int, slot_count: int, emps: list[Employee]):
|
| 446 |
for j in range(slot_count):
|
export/pdf_exporter.py
CHANGED
|
@@ -244,8 +244,12 @@ def export_pdf(
|
|
| 244 |
period: SchedulePeriod,
|
| 245 |
employees: list[Employee],
|
| 246 |
assignments: dict,
|
|
|
|
| 247 |
):
|
| 248 |
-
"""SDU_shift テンプレートと同じ紙面の PDF を出力する(A4横・1ページフィット)
|
|
|
|
|
|
|
|
|
|
| 249 |
from db import repositories as repo
|
| 250 |
requests = repo.get_shift_requests(period.id)
|
| 251 |
req_map = {(r.employee_id, r.date): r for r in requests}
|
|
@@ -293,11 +297,15 @@ def export_pdf(
|
|
| 293 |
n_cols = 2 + n * COLS_PER_DAY # 月の日数に合わせブロック数を可変にし空白を作らない
|
| 294 |
natural_w = (2 * NAME_W_CH + n * COLS_PER_DAY * DAY_W_CH) * CH_PT
|
| 295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
# 行構成: ヘッダー8行 + K枠 + 2ブロック目4行 + H枠 + フッター2行
|
| 297 |
row_heights_nat: list[float] = []
|
| 298 |
-
row_heights_nat += [H_DATE, H_DATE, H_MEMO1, H_MEMO1, H_MEMO1, H_MEMO2,
|
| 299 |
row_heights_nat += [H_DATE] * (k_ft_n + k_pt_n)
|
| 300 |
-
row_heights_nat += [H_DATE
|
| 301 |
row_heights_nat += [H_DATE] * (h_ft_n + h_pt_n)
|
| 302 |
row_heights_nat += [H_DATE] * 2
|
| 303 |
row_heights_nat += [15.0] # 凡例行
|
|
@@ -404,31 +412,34 @@ def export_pdf(
|
|
| 404 |
c0 = _block_col(i)
|
| 405 |
_span(c0, R_MEMO1, c0 + 2, R_MEMO1 + 2) # メモ1: 3列×3行
|
| 406 |
_span(c0, R_MEMO2, c0 + 2, R_MEMO2)
|
| 407 |
-
|
| 408 |
-
|
|
|
|
| 409 |
if i < n:
|
| 410 |
ds = dates[i].isoformat()
|
| 411 |
note = notes.get(ds, "")
|
| 412 |
note2 = staff_notes.get(ds, "")
|
| 413 |
-
res = reserves.get(ds, {})
|
| 414 |
if note:
|
| 415 |
data[R_MEMO1][c0] = Paragraph(note, memo_style)
|
| 416 |
if note2:
|
| 417 |
data[R_MEMO2][c0] = Paragraph(note2, memo_style)
|
| 418 |
-
if
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
# ── 2ブロック目ヘッダー・フッター ──────────────────────────────────
|
| 434 |
_fill_date_rows(r_date2, r_dow2)
|
|
@@ -436,25 +447,26 @@ def export_pdf(
|
|
| 436 |
_span(n_cols - 1, r_date2, n_cols - 1, r_dow2)
|
| 437 |
_set_title(0, r_date2)
|
| 438 |
_set_title(n_cols - 1, r_date2)
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
|
|
|
| 458 |
|
| 459 |
_fill_date_rows(r_date3, r_dow3)
|
| 460 |
_span(0, r_date3, 0, r_dow3)
|
|
|
|
| 244 |
period: SchedulePeriod,
|
| 245 |
employees: list[Employee],
|
| 246 |
assignments: dict,
|
| 247 |
+
show_reservation_counts: bool = True,
|
| 248 |
):
|
| 249 |
+
"""SDU_shift テンプレートと同じ紙面の PDF を出力する(A4横・1ページフィット)。
|
| 250 |
+
|
| 251 |
+
show_reservation_counts=False の場合、「朝食見込」「夜予約」行(1・2ブロック目とも)
|
| 252 |
+
の高さを0にして出力から省く(全体周知用シフト表向け)。"""
|
| 253 |
from db import repositories as repo
|
| 254 |
requests = repo.get_shift_requests(period.id)
|
| 255 |
req_map = {(r.employee_id, r.date): r for r in requests}
|
|
|
|
| 297 |
n_cols = 2 + n * COLS_PER_DAY # 月の日数に合わせブロック数を可変にし空白を作らない
|
| 298 |
natural_w = (2 * NAME_W_CH + n * COLS_PER_DAY * DAY_W_CH) * CH_PT
|
| 299 |
|
| 300 |
+
# 朝食見込・夜予約行は show_reservation_counts=False の場合、高さ0にして省く
|
| 301 |
+
fore_h = H_FORE if show_reservation_counts else 0.0
|
| 302 |
+
fore_h2 = H_DATE if show_reservation_counts else 0.0
|
| 303 |
+
|
| 304 |
# 行構成: ヘッダー8行 + K枠 + 2ブロック目4行 + H枠 + フッター2行
|
| 305 |
row_heights_nat: list[float] = []
|
| 306 |
+
row_heights_nat += [H_DATE, H_DATE, H_MEMO1, H_MEMO1, H_MEMO1, H_MEMO2, fore_h, fore_h]
|
| 307 |
row_heights_nat += [H_DATE] * (k_ft_n + k_pt_n)
|
| 308 |
+
row_heights_nat += [H_DATE, H_DATE, fore_h2, fore_h2]
|
| 309 |
row_heights_nat += [H_DATE] * (h_ft_n + h_pt_n)
|
| 310 |
row_heights_nat += [H_DATE] * 2
|
| 311 |
row_heights_nat += [15.0] # 凡例行
|
|
|
|
| 412 |
c0 = _block_col(i)
|
| 413 |
_span(c0, R_MEMO1, c0 + 2, R_MEMO1 + 2) # メモ1: 3列×3行
|
| 414 |
_span(c0, R_MEMO2, c0 + 2, R_MEMO2)
|
| 415 |
+
if show_reservation_counts:
|
| 416 |
+
_span(c0, R_BF, c0 + 2, R_BF)
|
| 417 |
+
_span(c0, R_DIN, c0 + 2, R_DIN)
|
| 418 |
if i < n:
|
| 419 |
ds = dates[i].isoformat()
|
| 420 |
note = notes.get(ds, "")
|
| 421 |
note2 = staff_notes.get(ds, "")
|
|
|
|
| 422 |
if note:
|
| 423 |
data[R_MEMO1][c0] = Paragraph(note, memo_style)
|
| 424 |
if note2:
|
| 425 |
data[R_MEMO2][c0] = Paragraph(note2, memo_style)
|
| 426 |
+
if show_reservation_counts:
|
| 427 |
+
res = reserves.get(ds, {})
|
| 428 |
+
if res.get("breakfast") is not None:
|
| 429 |
+
data[R_BF][c0] = str(res["breakfast"])
|
| 430 |
+
if res.get("dinner") is not None:
|
| 431 |
+
data[R_DIN][c0] = str(res["dinner"])
|
| 432 |
+
if show_reservation_counts:
|
| 433 |
+
data[R_BF][0] = "朝食見込"
|
| 434 |
+
data[R_BF][n_cols - 1] = "朝食見込"
|
| 435 |
+
data[R_DIN][0] = "夜予約"
|
| 436 |
+
data[R_DIN][n_cols - 1] = "夜予約"
|
| 437 |
+
_font_size(R_BF, F_FORE)
|
| 438 |
+
_font_size(R_DIN, F_FORE)
|
| 439 |
+
_font_size(R_BF, F_NAME, 0, 0)
|
| 440 |
+
_font_size(R_BF, F_NAME, n_cols - 1, n_cols - 1)
|
| 441 |
+
_font_size(R_DIN, F_NAME, 0, 0)
|
| 442 |
+
_font_size(R_DIN, F_NAME, n_cols - 1, n_cols - 1)
|
| 443 |
|
| 444 |
# ── 2ブロック目ヘッダー・フッター ──────────────────────────────────
|
| 445 |
_fill_date_rows(r_date2, r_dow2)
|
|
|
|
| 447 |
_span(n_cols - 1, r_date2, n_cols - 1, r_dow2)
|
| 448 |
_set_title(0, r_date2)
|
| 449 |
_set_title(n_cols - 1, r_date2)
|
| 450 |
+
if show_reservation_counts:
|
| 451 |
+
for i in range(n):
|
| 452 |
+
c0 = _block_col(i)
|
| 453 |
+
_span(c0, r_bf2, c0 + 2, r_bf2)
|
| 454 |
+
_span(c0, r_din2, c0 + 2, r_din2)
|
| 455 |
+
if i < n:
|
| 456 |
+
res = reserves.get(dates[i].isoformat(), {})
|
| 457 |
+
if res.get("breakfast") is not None:
|
| 458 |
+
data[r_bf2][c0] = str(res["breakfast"])
|
| 459 |
+
if res.get("dinner") is not None:
|
| 460 |
+
data[r_din2][c0] = str(res["dinner"])
|
| 461 |
+
data[r_bf2][0] = "朝食見込"
|
| 462 |
+
data[r_bf2][n_cols - 1] = "朝食見込"
|
| 463 |
+
data[r_din2][0] = "夜予約"
|
| 464 |
+
data[r_din2][n_cols - 1] = "夜予約"
|
| 465 |
+
_font_size(r_bf2, F_FORE)
|
| 466 |
+
_font_size(r_din2, F_FORE)
|
| 467 |
+
for rr in (r_bf2, r_din2):
|
| 468 |
+
_font_size(rr, F_NAME, 0, 0)
|
| 469 |
+
_font_size(rr, F_NAME, n_cols - 1, n_cols - 1)
|
| 470 |
|
| 471 |
_fill_date_rows(r_date3, r_dow3)
|
| 472 |
_span(0, r_date3, 0, r_dow3)
|
routes/export_routes.py
CHANGED
|
@@ -35,8 +35,9 @@ def excel(period_id):
|
|
| 35 |
return redirect(url_for("schedule.index", period_id=period_id))
|
| 36 |
employees = repo.get_all_employees(active_only=True)
|
| 37 |
assignments = _assignments_dict(period_id)
|
|
|
|
| 38 |
buf = io.BytesIO()
|
| 39 |
-
export_excel(buf, period, employees, assignments)
|
| 40 |
buf.seek(0)
|
| 41 |
filename = _period_filename(period, "xlsx")
|
| 42 |
return send_file(buf, as_attachment=True, download_name=filename,
|
|
@@ -53,8 +54,9 @@ def pdf(period_id):
|
|
| 53 |
return redirect(url_for("schedule.index", period_id=period_id))
|
| 54 |
employees = repo.get_all_employees(active_only=True)
|
| 55 |
assignments = _assignments_dict(period_id)
|
|
|
|
| 56 |
buf = io.BytesIO()
|
| 57 |
-
export_pdf(buf, period, employees, assignments)
|
| 58 |
buf.seek(0)
|
| 59 |
filename = _period_filename(period, "pdf")
|
| 60 |
inline = request.args.get("inline") == "1"
|
|
|
|
| 35 |
return redirect(url_for("schedule.index", period_id=period_id))
|
| 36 |
employees = repo.get_all_employees(active_only=True)
|
| 37 |
assignments = _assignments_dict(period_id)
|
| 38 |
+
show_reserve = repo.get_app_setting("export_show_reservation_counts", "1") == "1"
|
| 39 |
buf = io.BytesIO()
|
| 40 |
+
export_excel(buf, period, employees, assignments, show_reservation_counts=show_reserve)
|
| 41 |
buf.seek(0)
|
| 42 |
filename = _period_filename(period, "xlsx")
|
| 43 |
return send_file(buf, as_attachment=True, download_name=filename,
|
|
|
|
| 54 |
return redirect(url_for("schedule.index", period_id=period_id))
|
| 55 |
employees = repo.get_all_employees(active_only=True)
|
| 56 |
assignments = _assignments_dict(period_id)
|
| 57 |
+
show_reserve = repo.get_app_setting("export_show_reservation_counts", "1") == "1"
|
| 58 |
buf = io.BytesIO()
|
| 59 |
+
export_pdf(buf, period, employees, assignments, show_reservation_counts=show_reserve)
|
| 60 |
buf.seek(0)
|
| 61 |
filename = _period_filename(period, "pdf")
|
| 62 |
inline = request.args.get("inline") == "1"
|
routes/settings_routes.py
CHANGED
|
@@ -86,6 +86,7 @@ def save():
|
|
| 86 |
]
|
| 87 |
new_settings = {k: request.form.get(k, "") for k in settings_keys}
|
| 88 |
new_settings["customer_forecast_enabled"] = "1" if request.form.get("customer_forecast_enabled") else "0"
|
|
|
|
| 89 |
repo.save_all_app_settings(new_settings)
|
| 90 |
|
| 91 |
# 緯度・経度を変更したら気象キャッシュ・客数予測キャッシュを破棄して即時反映する
|
|
|
|
| 86 |
]
|
| 87 |
new_settings = {k: request.form.get(k, "") for k in settings_keys}
|
| 88 |
new_settings["customer_forecast_enabled"] = "1" if request.form.get("customer_forecast_enabled") else "0"
|
| 89 |
+
new_settings["export_show_reservation_counts"] = "1" if request.form.get("export_show_reservation_counts") else "0"
|
| 90 |
repo.save_all_app_settings(new_settings)
|
| 91 |
|
| 92 |
# 緯度・経度を変更したら気象キャッシュ・客数予測キャッシュを破棄して即時反映する
|
templates/settings/index.html
CHANGED
|
@@ -208,6 +208,23 @@
|
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
<!-- 人件費設定 -->
|
| 212 |
<div class="card mb-3">
|
| 213 |
<div class="card-body">
|
|
|
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
|
| 211 |
+
<!-- シフト表 出力設定 -->
|
| 212 |
+
<div class="card mb-3">
|
| 213 |
+
<div class="card-body">
|
| 214 |
+
<h6 class="card-title text-muted mb-3">シフト表 出力設定</h6>
|
| 215 |
+
<div class="form-check form-switch mb-1">
|
| 216 |
+
<input class="form-check-input" type="checkbox" role="switch" id="export_show_reservation_counts" name="export_show_reservation_counts"
|
| 217 |
+
{% if settings.get('export_show_reservation_counts', '1') == '1' %}checked{% endif %}>
|
| 218 |
+
<label class="form-check-label small" for="export_show_reservation_counts">
|
| 219 |
+
PDF・Excel出力に「朝食見込」「夜予約」の行を含める
|
| 220 |
+
</label>
|
| 221 |
+
</div>
|
| 222 |
+
<div class="text-muted small">
|
| 223 |
+
全体周知用のシフト表ではオフにすると、出力時にこの2行を省略できます。シフト表画面での予約客数の入力・編集には影響しません。
|
| 224 |
+
</div>
|
| 225 |
+
</div>
|
| 226 |
+
</div>
|
| 227 |
+
|
| 228 |
<!-- 人件費設定 -->
|
| 229 |
<div class="card mb-3">
|
| 230 |
<div class="card-body">
|