app / templates /schedule /stats_multi.html
Ryo_Shimano
Claude Sonnet 5
fix: 戻るボタンにaria-labelを追加、既知の不具合バッジの楕円崩れを修正
e88761f
Raw History Blame Contribute Delete
12.4 kB
{% extends "base.html" %}
{% block title %}勤務統計 - SDU-Shift{% endblock %}
{% block head %}
<style>
.period-chip {
display: inline-flex; align-items: center; gap: .3rem;
padding: .25rem .65rem; border-radius: 20px;
font-size: .75rem; font-weight: 600; cursor: pointer;
border: 1.5px solid #334155; color: #94a3b8;
background: transparent; transition: all .15s;
text-decoration: none;
}
.period-chip.active {
border-color: #0ea5e9; color: #0ea5e9; background: #0f172a;
}
.stat-table th, .stat-table td { white-space: nowrap; }
.stat-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cost-col { color: #fbbf24; font-weight: 700; }
.chart-wrap { position: relative; height: 220px; }
</style>
{% endblock %}
{% block content %}
<div class="page-header">
<a href="{{ url_for('schedule.list_periods') }}" class="text-white me-2" aria-label="戻る" style="padding:.5rem;margin:-.5rem 0">
<i class="bi bi-arrow-left"></i>
</a>
<h1 class="fs-6"><i class="bi bi-bar-chart-fill me-1"></i>勤務統計</h1>
</div>
<div class="content">
<!-- 期間選択 -->
<div class="card mb-3">
<div class="card-body">
<div class="small fw-semibold text-muted mb-2">集計対象期間(複数選択可)</div>
<form method="get" id="period-form">
<div class="d-flex flex-wrap gap-2 mb-3">
{% for p in all_periods %}
<label class="period-chip {{ 'active' if p.id in sel_ids else '' }}">
<input type="checkbox" name="p" value="{{ p.id }}"
{{ 'checked' if p.id in sel_ids else '' }}
class="d-none" onchange="this.closest('form').submit()">
{{ p.start_date[5:] }}〜{{ p.end_date[5:] }}
</label>
{% endfor %}
</div>
</form>
{% if sel_periods %}
<div class="text-muted small">
{{ sel_periods|length }}期間 / 合計{{ sel_periods|map(attribute='start_date')|list|length }}〜 選択中
</div>
{% endif %}
</div>
</div>
{% if not sel_ids %}
<div class="alert alert-info small">期間を選択してください。</div>
{% else %}
{% if any_wage %}
<!-- 集計テーブル -->
<div class="card mb-3">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm stat-table mb-0">
<thead class="table-dark">
<tr>
<th>名前</th>
<th class="text-center cost-col">推計人件費</th>
</tr>
</thead>
<tbody>
{% set total_cost = namespace(v=0.0) %}
{% for emp in employees %}
{% set d = stats_data.get(emp.id, {}) %}
{% set cost = d.get('cost', 0.0) %}
{% set total_cost.v = total_cost.v + cost %}
<tr>
<td class="fw-semibold">{{ emp.name }}</td>
<td class="num text-center">
{% if emp.employment_type.value == 'full_time' %}
<span class="text-muted small">対象外</span>
{% elif cost > 0 %}
<span class="cost-col">¥{{ "{:,.0f}".format(cost) }}</span>
{% elif emp.hourly_wage == 0 %}
<span class="text-muted small">時給未設定</span>
{% else %}—{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot class="table-dark fw-bold">
<tr>
<td>合計</td>
<td class="num text-center cost-col">¥{{ "{:,.0f}".format(total_cost.v) }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
{% endif %}
<!-- 36協定チェック -->
<div class="card mb-3 {% if overtime_alerts %}border-warning{% endif %}">
<div class="card-body">
<div class="small fw-semibold mb-2 {% if overtime_alerts %}text-warning{% else %}text-success{% endif %}">
<i class="bi bi-{% if overtime_alerts %}exclamation-triangle-fill{% else %}check-circle-fill{% endif %} me-1"></i>
法定労働時間チェック(週{{ weekly_limit|int }}時間)
</div>
{% if overtime_alerts %}
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead class="table-dark">
<tr><th>名前</th><th>週</th><th class="text-end">推計時間</th></tr>
</thead>
<tbody>
{% for a in overtime_alerts %}
<tr>
<td class="fw-semibold">{{ a.name }}</td>
<td class="text-muted small">{{ a.week_label }}</td>
<td class="text-end text-danger fw-bold">{{ "%.1f"|format(a.hours) }}h</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<p class="text-muted small mb-0 mt-2">
※ 週40時間を超えた場合、36協定の締結・届出が必要です。推計値のため実際の勤怠と照合してください。
</p>
{% else %}
<p class="text-muted small mb-0">選択期間内に週40時間超えはありません。</p>
{% endif %}
</div>
</div>
{% if any_wage %}
<!-- 客数あたり人件費(人員配置の妥当性指標) -->
<div class="card mb-3">
<div class="card-body">
<div class="small fw-semibold text-muted mb-2">
<i class="bi bi-graph-up me-1"></i>客数あたり人件費
</div>
{% if cost_per_customer is not none %}
<div class="d-flex align-items-baseline gap-2 mb-2">
<span class="fs-3 fw-bold cost-col">¥{{ "{:,.0f}".format(cost_per_customer) }}</span>
<span class="text-muted small">/ 来客1人あたり</span>
</div>
<div class="text-muted small">
合計人件費 ¥{{ "{:,.0f}".format(total_labor_cost) }} ÷
来客数 {{ "{:,}".format(customer_counts.total) }}人
(朝食 {{ "{:,}".format(customer_counts.breakfast) }} / ディナー {{ "{:,}".format(customer_counts.dinner) }})
</div>
<p class="text-muted small mb-0 mt-2">
※ 選択期間の合計人件費を、同期間の来客数(「客数管理」で入力した予約客数)で割った概算値です。
前期間と比べて高ければ、忙しさに対して人員を厚く配置しすぎている可能性があります。
</p>
{% else %}
<p class="text-muted small mb-0">
来客数が未入力のため算出できません。「客数管理」画面で予約客数を入力してください。
</p>
{% endif %}
</div>
</div>
{% endif %}
<!-- シフトの公平性 -->
<div class="card mb-3">
<div class="card-body p-0">
<div class="small fw-semibold text-muted px-3 pt-3 pb-2">
<i class="bi bi-people-fill me-1"></i>シフトの公平性
</div>
<div class="table-responsive">
<table class="table table-sm stat-table mb-0">
<thead class="table-dark">
<tr>
<th>名前</th>
<th class="text-center">希望採用率</th>
<th class="text-center">最大連続勤務</th>
<th class="text-center">総休日数</th>
</tr>
</thead>
<tbody>
{% for emp in employees %}
{% set f = fairness_stats.get(emp.id, {}) %}
<tr>
<td class="fw-semibold">{{ emp.name }}</td>
<td class="num text-center">
{% if f.fulfillment_rate is not none %}
{{ "%.0f"|format(f.fulfillment_rate * 100) }}%
<span class="text-muted small">({{ f.req_matched }}/{{ f.req_total }})</span>
{% else %}
<span class="text-muted">—</span>
{% endif %}
</td>
<td class="num text-center {{ 'text-danger fw-bold' if f.max_consecutive > max_consecutive_setting else '' }}">
{{ f.max_consecutive }}日
{% if f.max_consecutive > max_consecutive_setting %}
<i class="bi bi-exclamation-triangle-fill ms-1" title="設定値({{ max_consecutive_setting }}日)を超過"></i>
{% endif %}
</td>
<td class="num text-center">
{{ f.days_off }}<span class="text-muted small"> / {{ f.total_days }}日</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<p class="text-muted small mb-0 px-3 pb-3 pt-2">
※ 希望採用率=休み希望・出勤希望(朝食/ディナー)が実際の割当と一致した割合。希望未提出の方は「—」。<br>
※ 最大連続勤務日数が設定値({{ max_consecutive_setting }}日)を超える場合は警告表示しています。
</p>
</div>
</div>
<!-- 人員不足の発生頻度 -->
<div class="card mb-3">
<div class="card-body">
<div class="small fw-semibold text-muted mb-2">
<i class="bi bi-exclamation-diamond-fill me-1"></i>人員不足の発生頻度
</div>
{% if shortage_summary and shortage_summary[0].total_days > 0 %}
{% for s in shortage_summary %}
<div class="mb-3">
<div class="d-flex justify-content-between small mb-1">
<span class="fw-semibold">{{ s.slot }}・{{ s.pos }}</span>
<span class="text-muted">
人員不足 {{ s.short_staff_days }}/{{ s.total_days }}日
{% if s.short_leader_days > 0 %}
/ うちリーダー不足 {{ s.short_leader_days }}日
{% endif %}
</span>
</div>
<div class="progress" style="height:6px">
<div class="progress-bar {{ 'bg-danger' if s.short_staff_days > 0 else 'bg-success' }}"
style="width: {{ (s.short_staff_days / s.total_days * 100) }}%"></div>
</div>
</div>
{% endfor %}
<p class="text-muted small mb-0 mt-1">
※ 選択期間(合計{{ shortage_summary[0].total_days }}日)のうち、各区分で必要人数を満たせなかった日数の割合です。多い区分から順に表示しています。
</p>
{% else %}
<p class="text-muted small mb-0">対象期間がありません。</p>
{% endif %}
</div>
</div>
{% if any_wage %}
<!-- 人件費グラフ -->
<div class="card mb-3">
<div class="card-body">
<div class="small fw-semibold text-muted mb-3">スタッフ別推計人件費</div>
<div class="chart-wrap">
<canvas id="costChart"></canvas>
</div>
</div>
</div>
{% endif %}
<p class="text-muted small px-1">
※ 人件費は(基本給+個人昇給額)×時間(朝食は早朝手当加算)の概算です。休憩・交通費等は含みません。<br>
※ 基本給・早朝手当・昇給額は設定画面の「人件費設定」で変更できます。
</p>
{% endif %}
</div>
{% endblock %}
{% block scripts %}
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.2/dist/chart.umd.min.js"></script>
<script>
const EMPLOYEES = {{ employees | map(attribute='name') | list | tojson }};
const STATS = {{ stats_data | tojson }};
const EMP_IDS = {{ employees | map(attribute='id') | list | tojson }};
const costs = EMP_IDS.map(id => {
const d = STATS[String(id)];
return d ? Math.round(d.cost) : 0;
});
const COLORS = [
'#38bdf8','#34d399','#fbbf24','#f87171','#a78bfa',
'#fb923c','#4ade80','#60a5fa','#e879f9','#2dd4bf',
];
function mkChart(id, label, data, color) {
const ctx = document.getElementById(id);
if (!ctx) return;
new Chart(ctx, {
type: 'bar',
data: {
labels: EMPLOYEES,
datasets: [{
label,
data,
backgroundColor: EMPLOYEES.map((_, i) => COLORS[i % COLORS.length] + 'cc'),
borderColor: EMPLOYEES.map((_, i) => COLORS[i % COLORS.length]),
borderWidth: 1,
}],
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: {
x: { ticks: { color: '#94a3b8', font: { size: 11 } }, grid: { color: '#1e293b' } },
y: { ticks: { color: '#94a3b8' }, grid: { color: '#334155' } },
},
},
});
}
mkChart('costChart', '推計人件費 (¥)', costs, '#fbbf24');
</script>
{% endblock %}