CI / build (push) Failing after 20s
Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ
5975 lines
363 KiB
HTML
5975 lines
363 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-TW">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>MoonShine LeadBoard</title>
|
||
<script>
|
||
// Day / night: the viewer's saved choice, else the system setting. Stored per browser only.
|
||
(function () {
|
||
var theme = null;
|
||
try { theme = localStorage.getItem('pmb-theme'); } catch (e) {}
|
||
if (theme !== 'light' && theme !== 'dark') {
|
||
theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
||
}
|
||
document.documentElement.setAttribute('data-theme', theme);
|
||
})();
|
||
</script>
|
||
<script src="/i18n.js"></script>
|
||
<style>
|
||
:root {
|
||
/* Color Palette - Premium Dark Mode SaaS */
|
||
--bg-deep: #030712;
|
||
--bg-surface: rgba(10, 10, 10, 0.5);
|
||
--bg-glass: rgba(255, 255, 255, 0.02);
|
||
--border-glass: rgba(255, 255, 255, 0.08);
|
||
|
||
--accent-primary: #3b82f6;
|
||
--accent-secondary: #8b5cf6;
|
||
--accent-success: #10b981;
|
||
--accent-warning: #f59e0b;
|
||
--accent-danger: #ef4444;
|
||
|
||
/* Text on the dark canvas: every role meets WCAG AA (4.5:1) on cards and table headers. */
|
||
--text-main: #ffffff;
|
||
--text-muted: #9ca3af;
|
||
--text-dim: #8b93a1;
|
||
/* Accent hues used as text need the lighter step; the base hues stay for fills and borders. */
|
||
--accent-primary-text: #60a5fa;
|
||
--accent-secondary-text: #a78bfa;
|
||
--accent-primary-strong: #2563eb;
|
||
|
||
--panel-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
|
||
--transition-speed: 0.3s;
|
||
}
|
||
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||
}
|
||
|
||
body {
|
||
background-color: var(--bg-deep);
|
||
color: var(--text-main);
|
||
overflow-x: hidden;
|
||
min-height: 100vh;
|
||
position: relative;
|
||
}
|
||
|
||
/* --- Keyframe Animations --- */
|
||
@keyframes blobShift {
|
||
0% {
|
||
background: var(--accent-primary);
|
||
opacity: 0.15;
|
||
}
|
||
|
||
50% {
|
||
background: var(--accent-secondary);
|
||
opacity: 0.18;
|
||
}
|
||
|
||
100% {
|
||
background: var(--accent-primary);
|
||
opacity: 0.15;
|
||
}
|
||
}
|
||
|
||
@keyframes blobMorph {
|
||
0% {
|
||
border-radius: 50%;
|
||
}
|
||
|
||
33% {
|
||
border-radius: 60% 40% 55% 45%;
|
||
}
|
||
|
||
66% {
|
||
border-radius: 40% 60% 45% 55%;
|
||
}
|
||
|
||
100% {
|
||
border-radius: 50%;
|
||
}
|
||
}
|
||
|
||
/* Glowing Nebula Background Blobs */
|
||
body::before,
|
||
body::after {
|
||
content: "";
|
||
position: fixed;
|
||
border-radius: 50%;
|
||
filter: blur(120px);
|
||
z-index: -1;
|
||
opacity: 0.15;
|
||
pointer-events: none;
|
||
transition: background 1.5s ease, opacity 1.5s ease;
|
||
}
|
||
|
||
body::before {
|
||
top: -10%;
|
||
left: -10%;
|
||
width: 50vw;
|
||
height: 50vw;
|
||
background: var(--accent-primary);
|
||
animation: blobMorph 8s ease-in-out infinite, blobShift 6s ease-in-out infinite;
|
||
}
|
||
|
||
body::after {
|
||
bottom: -10%;
|
||
right: -10%;
|
||
width: 60vw;
|
||
height: 60vw;
|
||
background: var(--accent-secondary);
|
||
animation: blobMorph 10s ease-in-out infinite reverse, blobShift 8s ease-in-out infinite reverse;
|
||
}
|
||
|
||
/* --- Layout --- */
|
||
.app-container {
|
||
display: grid;
|
||
grid-template-columns: 260px minmax(0, 1fr);
|
||
grid-template-rows: auto minmax(0, 1fr);
|
||
grid-template-areas: "sidebar notice" "sidebar content";
|
||
height: 100vh;
|
||
height: 100dvh;
|
||
}
|
||
|
||
#data-source-banner {
|
||
grid-area: notice;
|
||
min-width: 0;
|
||
}
|
||
|
||
/* --- Sidebar --- */
|
||
header {
|
||
grid-area: sidebar;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
background-color: transparent;
|
||
border-right: 1px solid var(--border-glass);
|
||
padding: 2rem 1.5rem;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 1.5rem;
|
||
position: sticky;
|
||
top: 0;
|
||
height: 100%;
|
||
backdrop-filter: blur(10px);
|
||
}
|
||
|
||
.logo {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-start;
|
||
padding: 0.5rem 0;
|
||
}
|
||
|
||
.logo img {
|
||
max-width: 100%;
|
||
height: auto;
|
||
max-height: 32px;
|
||
filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.3));
|
||
}
|
||
|
||
.nav-group {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.5rem;
|
||
}
|
||
|
||
header > .logo { flex-shrink: 0; }
|
||
.sidebar-navigation { flex: 1; min-height: 0; overflow-y: auto; }
|
||
.sidebar-account { flex-shrink: 0; margin-top: auto; padding-top: 0.75rem; border-top: 1px solid var(--border-glass); }
|
||
.sidebar-account .btn { width: 100%; justify-content: center; text-align: center; }
|
||
|
||
.nav-item {
|
||
background: none;
|
||
border: 0;
|
||
width: 100%;
|
||
text-align: left;
|
||
font: inherit;
|
||
padding: 0.75rem 1rem;
|
||
border-radius: 99px;
|
||
cursor: pointer;
|
||
transition: all var(--transition-speed);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.75rem;
|
||
color: var(--text-muted);
|
||
font-weight: 500;
|
||
}
|
||
|
||
.nav-item:hover,
|
||
.nav-item.active {
|
||
background-color: rgba(255, 255, 255, 0.05);
|
||
color: var(--text-main);
|
||
}
|
||
|
||
.nav-item.active {
|
||
box-shadow: inset 0 0 0 1px var(--border-glass), 0 0 15px rgba(59, 130, 246, 0.1);
|
||
background: rgba(59, 130, 246, 0.05);
|
||
}
|
||
|
||
/* --- Input & Forms --- */
|
||
input::-webkit-outer-spin-button,
|
||
input::-webkit-inner-spin-button {
|
||
-webkit-appearance: none;
|
||
appearance: none;
|
||
margin: 0;
|
||
}
|
||
|
||
input[type=number] {
|
||
-moz-appearance: textfield;
|
||
appearance: textfield;
|
||
}
|
||
|
||
input {
|
||
background: rgba(255, 255, 255, 0.03);
|
||
border: 1px solid var(--border-glass);
|
||
padding: 6px 10px;
|
||
border-radius: 6px;
|
||
color: white;
|
||
font-size: 0.85rem;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
input:focus {
|
||
outline: none;
|
||
border-color: var(--accent-primary);
|
||
background: rgba(255, 255, 255, 0.08);
|
||
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
||
}
|
||
|
||
.input-mini {
|
||
padding: 4px 2px !important;
|
||
text-align: center;
|
||
}
|
||
|
||
.sub-item.active::before {
|
||
background: var(--accent-primary);
|
||
opacity: 1;
|
||
}
|
||
|
||
@keyframes slideDown {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(-5px);
|
||
}
|
||
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
|
||
/* --- Main Content --- */
|
||
main {
|
||
grid-area: content;
|
||
min-width: 0;
|
||
min-height: 0;
|
||
padding: 1.25rem 2rem;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
/* Dashboard grows with its content; the main panel owns scrolling. */
|
||
#dashboard.view.active {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 1rem;
|
||
}
|
||
.dashboard-heading { display:flex; flex-wrap:wrap; align-items:center; gap:1rem; }
|
||
#dashboard-invoice-hero { flex:1 1 600px; min-width:0; }
|
||
#dashboard-invoice-hero > div { flex-wrap:wrap; }
|
||
#dashboard-invoice-hero > div > div:last-child { flex-wrap:wrap; }
|
||
.dashboard-panels {
|
||
display:grid;
|
||
grid-template-columns:repeat(auto-fit, minmax(min(100%, 280px), 1fr));
|
||
gap:1rem;
|
||
align-items:stretch;
|
||
}
|
||
.dashboard-panels > .card { min-width:0; margin:0; }
|
||
#dashboard .kpi-grid { margin:0; }
|
||
#dashboard .card-value { overflow-wrap:anywhere; }
|
||
|
||
.view {
|
||
display: none;
|
||
animation: fadeIn 0.4s ease-out;
|
||
}
|
||
|
||
.view.active {
|
||
display: block;
|
||
}
|
||
|
||
.invoice-allocation-scroll { overflow-x: auto; }
|
||
#personnel > div:first-child { flex-wrap: wrap; gap: 1rem; }
|
||
#personnel > div:first-child > div:last-child { flex-wrap: wrap; }
|
||
#personnel > div:first-child .card { flex-wrap: wrap; }
|
||
#personnel-search { min-width: 190px; }
|
||
#personnel .btn { white-space: nowrap; }
|
||
#personnel-detail-kpi { flex-wrap: wrap; }
|
||
#personnel-detail-kpi > div { min-width: 160px; }
|
||
#personnel .table-container { overflow-x: auto; }
|
||
#person-table { min-width: 1300px; }
|
||
#person-table th { white-space: nowrap; }
|
||
#person-table td:first-child input { width: 125px !important; }
|
||
.invoice-allocation-table { min-width: 1000px; }
|
||
.invoice-allocation-row {
|
||
display: grid;
|
||
grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr 1.2fr 1.2fr auto;
|
||
gap: 0.5rem;
|
||
align-items: center;
|
||
}
|
||
|
||
@media (max-width: 1350px) {
|
||
#global-params { grid-template-columns: minmax(0, 1fr) !important; }
|
||
.org-tree-container { align-items: flex-start; overflow-x: auto; }
|
||
.app-container { grid-template-columns: 210px minmax(0, 1fr); }
|
||
header { padding: 1.25rem 1rem; }
|
||
main { padding: 1rem; }
|
||
}
|
||
|
||
@keyframes fadeIn {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(10px);
|
||
}
|
||
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
|
||
/* --- KPI Cards --- */
|
||
.kpi-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||
gap: 0.9rem;
|
||
margin-bottom: 0.9rem;
|
||
}
|
||
|
||
/* Dept Invoice Target Bars */
|
||
.dept-invoice-bar-row {
|
||
margin-bottom: 0.65rem;
|
||
}
|
||
|
||
.dept-invoice-bar-row:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.dept-invoice-bar-label {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
margin-bottom: 4px;
|
||
font-size: 0.8rem;
|
||
}
|
||
|
||
.dept-invoice-bar-track {
|
||
height: 8px;
|
||
background: rgba(255, 255, 255, 0.06);
|
||
border-radius: 4px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.dept-invoice-bar-fill {
|
||
height: 100%;
|
||
border-radius: 4px;
|
||
transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
|
||
}
|
||
|
||
.card {
|
||
background: var(--bg-glass);
|
||
backdrop-filter: blur(20px);
|
||
border: 1px solid var(--border-glass);
|
||
border-radius: 16px;
|
||
padding: 1.25rem 1.5rem;
|
||
box-shadow: var(--panel-shadow);
|
||
position: relative;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.card::before {
|
||
content: "";
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100%;
|
||
height: 2px;
|
||
background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
|
||
opacity: 0.8;
|
||
}
|
||
|
||
.card.secondary::before {
|
||
background: linear-gradient(90deg, transparent, var(--accent-secondary), transparent);
|
||
}
|
||
|
||
.card.success::before {
|
||
background: linear-gradient(90deg, transparent, var(--accent-success), transparent);
|
||
}
|
||
|
||
.card.warning::before {
|
||
background: linear-gradient(90deg, transparent, var(--accent-warning), transparent);
|
||
}
|
||
|
||
.card-label {
|
||
color: var(--text-dim);
|
||
font-size: 0.75rem;
|
||
text-transform: uppercase;
|
||
letter-spacing: 1px;
|
||
margin-bottom: 0.5rem;
|
||
}
|
||
|
||
.card-value {
|
||
font-size: 1.65rem;
|
||
font-weight: 800;
|
||
color: var(--text-main);
|
||
}
|
||
|
||
.card.primary .card-value {
|
||
color: var(--accent-primary-text);
|
||
}
|
||
|
||
.card-trend {
|
||
font-size: 0.75rem;
|
||
margin-top: 0.25rem;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
/* --- Chart Bars --- */
|
||
.chart-bar-container {
|
||
height: 30px;
|
||
background: rgba(255, 255, 255, 0.05);
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
display: flex;
|
||
margin-top: 10px;
|
||
border: 1px solid var(--border-glass);
|
||
}
|
||
|
||
.chart-bar {
|
||
height: 100%;
|
||
transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.75rem;
|
||
font-weight: 700;
|
||
color: white;
|
||
white-space: nowrap;
|
||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
|
||
}
|
||
|
||
/* --- Table Styling --- */
|
||
.table-container {
|
||
margin-top: 1rem;
|
||
border-radius: 20px;
|
||
overflow: auto;
|
||
border: 1px solid var(--border-glass);
|
||
background: var(--bg-glass);
|
||
backdrop-filter: blur(10px);
|
||
max-height: 70vh;
|
||
}
|
||
|
||
table {
|
||
width: 100%;
|
||
border-collapse: separate;
|
||
border-spacing: 0;
|
||
background: transparent;
|
||
font-size: 0.82rem;
|
||
}
|
||
|
||
thead {
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 10;
|
||
}
|
||
|
||
th {
|
||
background: rgba(255, 255, 255, 0.03);
|
||
text-align: left;
|
||
padding: 1rem;
|
||
color: var(--text-dim);
|
||
font-weight: 600;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.5px;
|
||
}
|
||
|
||
th.sortable {
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
position: relative;
|
||
padding-right: 1.5rem;
|
||
}
|
||
|
||
th.sortable:hover {
|
||
color: var(--accent-primary-text);
|
||
background: rgba(255, 255, 255, 0.05);
|
||
}
|
||
|
||
.sort-icon {
|
||
font-size: 0.75rem;
|
||
margin-left: 4px;
|
||
opacity: 0.5;
|
||
display: inline-block;
|
||
width: 12px;
|
||
}
|
||
|
||
th.active-sort {
|
||
color: var(--accent-primary-text);
|
||
background: rgba(59, 130, 246, 0.05);
|
||
}
|
||
|
||
th.active-sort .sort-icon {
|
||
opacity: 1;
|
||
}
|
||
|
||
th.num,
|
||
td.num {
|
||
text-align: right;
|
||
}
|
||
|
||
td {
|
||
padding: 0.75rem 0.5rem;
|
||
border-top: 1px solid var(--border-glass);
|
||
vertical-align: middle;
|
||
}
|
||
|
||
tr:hover td {
|
||
background: rgba(255, 255, 255, 0.02);
|
||
}
|
||
|
||
.role-pill {
|
||
padding: 4px 10px;
|
||
border-radius: 6px;
|
||
font-size: 0.75rem;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.role-a {
|
||
background: rgba(59, 130, 246, 0.2);
|
||
color: #60a5fa;
|
||
}
|
||
|
||
.role-p {
|
||
background: rgba(16, 185, 129, 0.2);
|
||
color: #34d399;
|
||
}
|
||
|
||
.role-o {
|
||
background: rgba(245, 158, 11, 0.2);
|
||
color: #fbbf24;
|
||
}
|
||
|
||
/* --- Inputs & Buttons --- */
|
||
input {
|
||
background: rgba(0, 0, 0, 0.3);
|
||
border: 1px solid var(--border-glass);
|
||
border-radius: 99px;
|
||
padding: 0.5rem 1rem;
|
||
color: var(--text-main);
|
||
outline: none;
|
||
width: 100%;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.table-container input {
|
||
padding: 0.4rem 0.6rem;
|
||
border-radius: 6px;
|
||
border-color: transparent;
|
||
background: transparent;
|
||
}
|
||
|
||
.table-container input:hover,
|
||
.table-container input:focus {
|
||
background: rgba(0, 0, 0, 0.5);
|
||
border-color: var(--accent-primary);
|
||
}
|
||
|
||
input:focus {
|
||
border-color: var(--accent-primary);
|
||
}
|
||
|
||
.btn {
|
||
padding: 0.6rem 1.2rem;
|
||
border-radius: 99px;
|
||
/* Pill shape */
|
||
cursor: pointer;
|
||
font-weight: 600;
|
||
border: none;
|
||
transition: all 0.3s;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 0.5rem;
|
||
}
|
||
|
||
.btn-primary {
|
||
background: var(--accent-primary-strong);
|
||
color: white;
|
||
box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
|
||
}
|
||
|
||
.btn-primary:hover {
|
||
box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
|
||
transform: translateY(-2px);
|
||
}
|
||
|
||
.btn-outline {
|
||
background: transparent;
|
||
border: 1px solid var(--border-glass);
|
||
color: var(--text-main);
|
||
}
|
||
|
||
.btn-outline:hover {
|
||
background: rgba(255, 255, 255, 0.05);
|
||
border-color: rgba(255, 255, 255, 0.2);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
/* Customize Personnel Search Selects */
|
||
select.btn-outline {
|
||
background-color: #000 !important;
|
||
color: #fff !important;
|
||
appearance: none;
|
||
-webkit-appearance: none;
|
||
padding-right: 2rem !important;
|
||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
|
||
background-repeat: no-repeat;
|
||
background-position: calc(100% - 0.75rem) center;
|
||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||
}
|
||
|
||
select.btn-outline:hover {
|
||
background-color: #fff !important;
|
||
color: #000 !important;
|
||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='black' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
|
||
}
|
||
|
||
/* Ensure options are visible */
|
||
select.btn-outline option {
|
||
background-color: #151b23;
|
||
color: #fff;
|
||
}
|
||
|
||
/* --- Bottom Controls --- */
|
||
.bottom-shelf {
|
||
position: fixed;
|
||
bottom: 1.5rem;
|
||
right: 1.5rem;
|
||
display: flex;
|
||
gap: 1rem;
|
||
z-index: 100;
|
||
}
|
||
|
||
/* --- Add Person Modal --- */
|
||
.modal-backdrop {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.7);
|
||
backdrop-filter: blur(6px);
|
||
z-index: 2000;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
opacity: 0;
|
||
visibility: hidden;
|
||
pointer-events: none;
|
||
transition: opacity 0.25s ease, visibility 0s linear 0.25s;
|
||
}
|
||
|
||
.modal-backdrop.open {
|
||
opacity: 1;
|
||
visibility: visible;
|
||
pointer-events: all;
|
||
transition: opacity 0.25s ease, visibility 0s;
|
||
}
|
||
|
||
.modal-overlay {
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100vw;
|
||
height: 100vh;
|
||
background: rgba(0, 0, 0, 0.6);
|
||
backdrop-filter: blur(8px);
|
||
z-index: 9999;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
transition: opacity 0.3s;
|
||
}
|
||
|
||
.modal-overlay.open {
|
||
opacity: 1;
|
||
pointer-events: auto;
|
||
}
|
||
|
||
.modal-box {
|
||
background: #171b22;
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
border-radius: 16px;
|
||
width: 90%;
|
||
max-width: 800px;
|
||
padding: 2rem;
|
||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
|
||
transform: translateY(20px) scale(0.97);
|
||
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
|
||
opacity: 0;
|
||
position: relative;
|
||
}
|
||
|
||
.modal-backdrop.open .modal-box {
|
||
transform: translateY(0) scale(1);
|
||
opacity: 1;
|
||
}
|
||
|
||
.modal-box::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
height: 3px;
|
||
border-radius: 20px 20px 0 0;
|
||
background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
|
||
}
|
||
|
||
.modal-title {
|
||
font-size: 1.15rem;
|
||
font-weight: 800;
|
||
color: var(--text-main);
|
||
margin-bottom: 1.5rem;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.5rem;
|
||
}
|
||
|
||
.modal-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 1rem 1.25rem;
|
||
}
|
||
|
||
.modal-field {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.4rem;
|
||
}
|
||
|
||
.modal-field.full-width {
|
||
grid-column: 1 / -1;
|
||
}
|
||
|
||
.modal-label {
|
||
font-size: 0.75rem;
|
||
font-weight: 700;
|
||
color: var(--text-dim);
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.8px;
|
||
}
|
||
|
||
.modal-input {
|
||
background: rgba(255, 255, 255, 0.04);
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
border-radius: 10px;
|
||
padding: 0.55rem 0.9rem;
|
||
color: var(--text-main);
|
||
font-size: 0.9rem;
|
||
font-family: inherit;
|
||
transition: border-color 0.2s, box-shadow 0.2s;
|
||
width: 100%;
|
||
appearance: none;
|
||
-webkit-appearance: none;
|
||
}
|
||
|
||
.modal-input:focus {
|
||
outline: none;
|
||
border-color: var(--accent-primary);
|
||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
|
||
background: rgba(59, 130, 246, 0.05);
|
||
}
|
||
|
||
select.modal-input {
|
||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
|
||
background-repeat: no-repeat;
|
||
background-position: calc(100% - 0.75rem) center;
|
||
background-color: rgba(255, 255, 255, 0.04);
|
||
padding-right: 2rem;
|
||
}
|
||
|
||
select.modal-input option {
|
||
background: #0d1117;
|
||
color: white;
|
||
}
|
||
|
||
.modal-h-period {
|
||
display: grid;
|
||
grid-template-columns: 1fr auto 1fr;
|
||
align-items: center;
|
||
gap: 0.5rem;
|
||
}
|
||
|
||
.modal-h-period span {
|
||
text-align: center;
|
||
color: var(--text-dim);
|
||
font-size: 0.85rem;
|
||
}
|
||
|
||
.salary-mask {
|
||
color: var(--text-dim);
|
||
letter-spacing: 2px;
|
||
user-select: none;
|
||
}
|
||
|
||
.modal-salary-wrapper {
|
||
display: grid;
|
||
grid-template-columns: auto 1fr;
|
||
align-items: center;
|
||
gap: 0;
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
border-radius: 10px;
|
||
overflow: hidden;
|
||
background: rgba(255, 255, 255, 0.04);
|
||
}
|
||
|
||
.modal-salary-prefix {
|
||
background: rgba(255, 255, 255, 0.06);
|
||
padding: 0.55rem 0.75rem;
|
||
font-size: 0.75rem;
|
||
color: var(--text-dim);
|
||
font-weight: 700;
|
||
border-right: 1px solid rgba(255, 255, 255, 0.08);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.modal-salary-input {
|
||
background: transparent;
|
||
border: none;
|
||
padding: 0.55rem 0.9rem;
|
||
color: var(--text-main);
|
||
font-size: 0.9rem;
|
||
font-family: inherit;
|
||
width: 100%;
|
||
}
|
||
|
||
.modal-salary-input:focus {
|
||
outline: none;
|
||
}
|
||
|
||
.modal-salary-wrapper:focus-within {
|
||
border-color: var(--accent-primary);
|
||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
|
||
}
|
||
|
||
.modal-checkbox-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.6rem;
|
||
padding: 0.55rem 0.9rem;
|
||
background: rgba(255, 255, 255, 0.04);
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
border-radius: 10px;
|
||
cursor: pointer;
|
||
transition: background 0.15s;
|
||
}
|
||
|
||
.modal-checkbox-row:hover {
|
||
background: rgba(255, 255, 255, 0.07);
|
||
}
|
||
|
||
.modal-checkbox-row input[type=checkbox] {
|
||
width: 15px;
|
||
height: 15px;
|
||
cursor: pointer;
|
||
accent-color: var(--accent-primary);
|
||
background: transparent;
|
||
border: none;
|
||
}
|
||
|
||
.modal-checkbox-row label {
|
||
font-size: 0.88rem;
|
||
color: var(--text-muted);
|
||
cursor: pointer;
|
||
}
|
||
|
||
.modal-footer {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
gap: 0.75rem;
|
||
margin-top: 1.75rem;
|
||
padding-top: 1.25rem;
|
||
border-top: 1px solid rgba(255, 255, 255, 0.06);
|
||
}
|
||
|
||
/* --- R&D Tag UI --- */
|
||
.rd-search-container {
|
||
position: relative;
|
||
margin-top: 0.5rem;
|
||
}
|
||
|
||
.rd-tag-container {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0.5rem;
|
||
margin-top: 0.5rem;
|
||
}
|
||
|
||
.currency-wrap {
|
||
display: inline-grid;
|
||
grid-template-columns: var(--symbol-width, 35px) 1fr;
|
||
gap: var(--symbol-gap, 0.5rem);
|
||
font-variant-numeric: tabular-nums;
|
||
text-align: right;
|
||
align-items: baseline;
|
||
}
|
||
|
||
.rd-tag {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
background: rgba(59, 130, 246, 0.1);
|
||
border: 1px solid rgba(59, 130, 246, 0.3);
|
||
color: var(--accent-primary-text);
|
||
padding: 4px 12px;
|
||
border-radius: 99px;
|
||
font-size: 0.8rem;
|
||
font-weight: 600;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.rd-tag:hover {
|
||
background: rgba(59, 130, 246, 0.2);
|
||
border-color: var(--accent-primary);
|
||
}
|
||
|
||
.rd-tag-remove {
|
||
cursor: pointer;
|
||
opacity: 0.6;
|
||
transition: opacity 0.2s;
|
||
font-size: 1.1rem;
|
||
line-height: 1;
|
||
}
|
||
|
||
.rd-tag-remove:hover {
|
||
opacity: 1;
|
||
color: var(--accent-danger);
|
||
}
|
||
|
||
.rd-suggestions {
|
||
position: absolute;
|
||
top: 100%;
|
||
left: 0;
|
||
right: 0;
|
||
background: var(--bg-deep);
|
||
border: 1px solid var(--border-glass);
|
||
border-radius: 12px;
|
||
margin-top: 4px;
|
||
max-height: 200px;
|
||
overflow-y: auto;
|
||
z-index: 1000;
|
||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
|
||
display: none;
|
||
}
|
||
|
||
.rd-suggestion-item {
|
||
padding: 10px 15px;
|
||
cursor: pointer;
|
||
font-size: 0.85rem;
|
||
color: var(--text-muted);
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.rd-suggestion-item:hover {
|
||
background: rgba(255, 255, 255, 0.05);
|
||
color: var(--text-main);
|
||
}
|
||
|
||
.rd-search-input {
|
||
width: 100%;
|
||
background: rgba(255, 255, 255, 0.03);
|
||
border: 1px solid var(--border-glass);
|
||
border-radius: 99px;
|
||
padding: 10px 20px;
|
||
color: var(--text-main);
|
||
font-size: 0.9rem;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.rd-search-input:focus {
|
||
outline: none;
|
||
border-color: var(--accent-primary);
|
||
background: rgba(255, 255, 255, 0.06);
|
||
box-shadow: 0 0 15px rgba(59, 130, 246, 0.1);
|
||
}
|
||
|
||
input[type="number"] {
|
||
background: rgba(255, 255, 255, 0.03);
|
||
border: 1px solid var(--border-glass);
|
||
border-radius: 8px;
|
||
padding: 6px 12px;
|
||
color: var(--text-main);
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
/* --- Hierarchical Org Chart (Tree) --- */
|
||
.org-tree-container {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
padding: 1rem;
|
||
width: 100%;
|
||
justify-content: flex-start;
|
||
}
|
||
|
||
.org-root-node {
|
||
background: #b91c1c;
|
||
/* Deep Red for Control Center */
|
||
color: white;
|
||
padding: 0.6rem 2rem;
|
||
border-radius: 8px;
|
||
font-weight: 800;
|
||
font-size: 1rem;
|
||
box-shadow: 0 4px 15px rgba(185, 28, 28, 0.3);
|
||
position: relative;
|
||
z-index: 2;
|
||
margin-bottom: 1.5rem;
|
||
}
|
||
|
||
/* Root to Depts Vertical Line */
|
||
.org-root-node::after {
|
||
content: '';
|
||
position: absolute;
|
||
bottom: -1.5rem;
|
||
left: 50%;
|
||
width: 2px;
|
||
height: 1.5rem;
|
||
background: var(--border-glass);
|
||
}
|
||
|
||
.org-branches-row {
|
||
display: flex;
|
||
gap: 1rem;
|
||
position: relative;
|
||
padding-top: 1rem;
|
||
align-items: flex-start;
|
||
justify-content: center;
|
||
}
|
||
|
||
/* Horizontal Connector Line */
|
||
.org-branches-row::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0;
|
||
left: 100px;
|
||
right: 100px;
|
||
height: 2px;
|
||
background: var(--border-glass);
|
||
}
|
||
|
||
.org-dept-branch {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
position: relative;
|
||
width: 200px;
|
||
}
|
||
|
||
/* Vertical Connector from Horizontal Line to Dept Header */
|
||
.org-dept-branch::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: -1rem;
|
||
left: 50%;
|
||
width: 2px;
|
||
height: 1rem;
|
||
background: var(--border-glass);
|
||
}
|
||
|
||
.org-dept-card {
|
||
width: 100%;
|
||
background: var(--bg-surface);
|
||
border: 1px solid var(--border-glass);
|
||
border-radius: 10px;
|
||
padding: 0.75rem;
|
||
backdrop-filter: blur(20px);
|
||
transition: all 0.3s ease;
|
||
margin-bottom: 1.5rem;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
.org-dept-card:hover {
|
||
border-color: var(--accent-primary);
|
||
box-shadow: 0 0 30px rgba(59, 130, 246, 0.1);
|
||
transform: translateY(-3px);
|
||
}
|
||
|
||
.org-dept-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
border-bottom: 1px solid var(--border-glass);
|
||
padding-bottom: 0.75rem;
|
||
margin-bottom: 1rem;
|
||
}
|
||
|
||
/* Vertical Groups under Dept */
|
||
.org-group-list-vertical {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.5rem;
|
||
position: relative;
|
||
}
|
||
|
||
/* Line from Dept Box to Groups */
|
||
.org-dept-card::after {
|
||
content: '';
|
||
position: absolute;
|
||
bottom: -2rem;
|
||
left: 50%;
|
||
width: 2px;
|
||
height: 2rem;
|
||
background: var(--border-glass);
|
||
display: none;
|
||
/* Only show if we want lines BETWEEN group items too */
|
||
}
|
||
|
||
.org-group-item {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
background: rgba(255, 255, 255, 0.03);
|
||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||
padding: 0.5rem 0.75rem;
|
||
border-radius: 6px;
|
||
font-size: 0.8rem;
|
||
transition: all 0.2s;
|
||
width: 100%;
|
||
}
|
||
|
||
.org-group-item:hover {
|
||
background: rgba(255, 255, 255, 0.07);
|
||
border-color: rgba(255, 255, 255, 0.15);
|
||
}
|
||
|
||
.status-pill {
|
||
padding: 3px 10px;
|
||
border-radius: 99px;
|
||
font-size: 0.75rem;
|
||
font-weight: 600;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
white-space: nowrap;
|
||
line-height: 1;
|
||
vertical-align: middle;
|
||
}
|
||
|
||
.status-active {
|
||
background: rgba(16, 185, 129, 0.1);
|
||
color: #10b981;
|
||
border: 1px solid rgba(16, 185, 129, 0.2);
|
||
}
|
||
|
||
.status-new {
|
||
background: rgba(59, 130, 246, 0.1);
|
||
color: #3b82f6;
|
||
border: 1px solid rgba(59, 130, 246, 0.2);
|
||
}
|
||
|
||
.status-resign {
|
||
background: rgba(239, 68, 68, 0.1);
|
||
color: #ef4444;
|
||
border: 1px solid rgba(239, 68, 68, 0.2);
|
||
}
|
||
|
||
.status-temp {
|
||
background: rgba(245, 158, 11, 0.1);
|
||
color: #f59e0b;
|
||
border: 1px solid rgba(245, 158, 11, 0.2);
|
||
}
|
||
|
||
input[type="number"]:focus {
|
||
outline: none;
|
||
border-color: var(--accent-primary);
|
||
}
|
||
|
||
/* Local preview identity; this badge does not provide authentication. */
|
||
.auth-user-badge {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.5rem;
|
||
padding: 0.5rem 0.75rem;
|
||
background: rgba(59, 130, 246, 0.08);
|
||
border: 1px solid rgba(59, 130, 246, 0.2);
|
||
border-radius: 10px;
|
||
margin-bottom: 0.5rem;
|
||
}
|
||
|
||
.auth-user-badge .user-avatar {
|
||
width: 28px;
|
||
height: 28px;
|
||
border-radius: 50%;
|
||
background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.75rem;
|
||
font-weight: 800;
|
||
color: white;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.auth-user-badge .user-info {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.auth-user-badge .user-name {
|
||
font-size: 0.82rem;
|
||
font-weight: 700;
|
||
color: var(--text-main);
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.auth-user-badge .user-role {
|
||
font-size: 0.75rem;
|
||
color: var(--text-dim);
|
||
}
|
||
|
||
/* --- Browser surfaces & accessibility polish --- */
|
||
:root { color-scheme: dark; }
|
||
::selection { background: rgba(96, 165, 250, 0.35); color: #fff; }
|
||
html { scrollbar-color: rgba(255, 255, 255, 0.18) transparent; }
|
||
table, .num, .kpi-value { font-variant-numeric: tabular-nums; }
|
||
|
||
/* One visible focus ring for keyboard users; mouse clicks keep the quieter styles. */
|
||
:focus-visible,
|
||
input:focus-visible,
|
||
select:focus-visible,
|
||
textarea:focus-visible,
|
||
.modal-input:focus-visible,
|
||
.modal-salary-input:focus-visible,
|
||
.rd-search-input:focus-visible,
|
||
input[type="number"]:focus-visible {
|
||
outline: 2px solid var(--accent-primary-text);
|
||
outline-offset: 2px;
|
||
}
|
||
.nav-item:focus-visible { outline-offset: -2px; }
|
||
|
||
/* Respect the OS "reduce motion" setting: stop decorative loops, keep state changes. */
|
||
@media (prefers-reduced-motion: reduce) {
|
||
body::before,
|
||
body::after { animation: none !important; }
|
||
*, *::before, *::after {
|
||
animation-iteration-count: 1 !important;
|
||
scroll-behavior: auto !important;
|
||
}
|
||
.view.active, [style*="fadeIn"] { animation: none !important; }
|
||
.btn-primary:hover { transform: none; }
|
||
}
|
||
/* =====================================================================
|
||
Design language 2027 — day / night, tinted frosted glass.
|
||
Background: three static colour lights. Floating chrome is clear
|
||
glass; data cards are denser glass tinted by content:
|
||
amber = invoice, blue = cost / CODA, sage = multiplier / people.
|
||
===================================================================== */
|
||
@font-face { font-family: 'PMB Num'; src: url('/fonts/poppins-light.woff') format('woff'); font-weight: 100 349; font-display: swap; unicode-range: U+0024-0025, U+002B-002E, U+0030-003A; }
|
||
@font-face { font-family: 'PMB Num'; src: url('/fonts/poppins-regular.woff') format('woff'); font-weight: 350 499; font-display: swap; unicode-range: U+0024-0025, U+002B-002E, U+0030-003A; }
|
||
@font-face { font-family: 'PMB Num'; src: url('/fonts/poppins-medium.woff') format('woff'); font-weight: 500 900; font-display: swap; unicode-range: U+0024-0025, U+002B-002E, U+0030-003A; }
|
||
|
||
:root, :root[data-theme="dark"] {
|
||
color-scheme: dark;
|
||
--font-ui: 'PMB Num', -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', 'Segoe UI', sans-serif;
|
||
--page: #111211;
|
||
--glow-amber: rgba(214, 140, 64, var(--glow-strength, 0.3));
|
||
--glow-blue: rgba(70, 112, 150, var(--glow-strength, 0.3));
|
||
--glow-sage: rgba(110, 135, 100, var(--glow-strength, 0.3));
|
||
--glass: rgba(30, 31, 29, 0.55);
|
||
--glass-border: rgba(255, 255, 255, 0.08);
|
||
--glass-strong: rgba(34, 35, 33, 0.85);
|
||
--surface: #222321;
|
||
--surface-solid: #1C1D1B;
|
||
--tile: rgba(255, 255, 255, 0.05);
|
||
--line: rgba(255, 255, 255, 0.07);
|
||
--wash: rgba(255, 255, 255, 0.04);
|
||
--wash-2: rgba(255, 255, 255, 0.08);
|
||
--inset: rgba(0, 0, 0, 0.25);
|
||
--text-main: #F0EFEC;
|
||
--text-muted: #C8C6BE;
|
||
--text-dim: #A9A79F;
|
||
--lime: #D9EE5C;
|
||
--on-lime: #111211;
|
||
--sage: #8C9886;
|
||
--bar-strong: #C9D3C2;
|
||
--bar-soft: #6F7B6A;
|
||
--btn-bg: #D9EE5C;
|
||
--btn-fg: #111211;
|
||
--tint-amber: rgba(44, 38, 31, 0.85); --tint-amber-border: rgba(214, 140, 64, 0.22); --dot-amber: #E0A15A;
|
||
--tint-blue: rgba(32, 37, 40, 0.85); --tint-blue-border: rgba(110, 150, 185, 0.24); --dot-blue: #7FA7C4;
|
||
--tint-sage: rgba(36, 40, 34, 0.85); --tint-sage-border: rgba(140, 165, 128, 0.26); --dot-sage: #9BB38D;
|
||
--kpi-amber: rgba(48, 42, 33, 0.62);
|
||
--kpi-blue: rgba(34, 39, 41, 0.62);
|
||
--kpi-sage: rgba(38, 42, 36, 0.62);
|
||
--st-lean-fg: #6EE7A8; --st-lean-bg: #15352A; --st-lean-dot: #3FCF8E;
|
||
--st-nearlean-fg: #5EEAD4; --st-nearlean-bg: #123634; --st-nearlean-dot: #2DD4BF;
|
||
--st-nearover-fg: #F2D35A; --st-nearover-bg: #36300F; --st-nearover-dot: #E8C33F;
|
||
--st-high-fg: #FDA060; --st-high-bg: #3A2416; --st-high-dot: #FB923C;
|
||
--st-over-fg: #FF8F86; --st-over-bg: #3D1D1B; --st-over-dot: #F87171;
|
||
/* legacy names used across the views */
|
||
--bg-deep: var(--page);
|
||
--bg-surface: var(--surface);
|
||
--bg-glass: var(--wash);
|
||
--border-glass: var(--line);
|
||
--accent-primary: #8FB1DA;
|
||
--accent-secondary: #A9C79B;
|
||
--accent-success: #5FD39B;
|
||
--accent-warning: #F5B544;
|
||
--accent-danger: #F87171;
|
||
--accent-primary-text: #A7C3E6;
|
||
--accent-secondary-text: #BCD6B0;
|
||
--accent-primary-strong: #D9EE5C;
|
||
--panel-shadow: none;
|
||
}
|
||
|
||
:root[data-theme="light"] {
|
||
color-scheme: light;
|
||
--page: #E6E6E2;
|
||
--glow-amber: rgba(232, 168, 92, var(--glow-strength, 0.42));
|
||
--glow-blue: rgba(108, 144, 168, var(--glow-strength, 0.42));
|
||
--glow-sage: rgba(150, 168, 138, var(--glow-strength, 0.42));
|
||
--glass: rgba(255, 255, 255, 0.6);
|
||
--glass-border: rgba(255, 255, 255, 0.75);
|
||
--glass-strong: rgba(255, 255, 255, 0.84);
|
||
--surface: #FFFFFF;
|
||
--surface-solid: #FFFFFF;
|
||
--tile: rgba(255, 255, 255, 0.6);
|
||
--line: rgba(11, 11, 11, 0.08);
|
||
--wash: rgba(11, 11, 11, 0.04);
|
||
--wash-2: rgba(11, 11, 11, 0.08);
|
||
--inset: rgba(11, 11, 11, 0.04);
|
||
--text-main: #0B0B0B;
|
||
--text-muted: #3D3C39;
|
||
--text-dim: #5C5A55;
|
||
--lime: #E4F47A;
|
||
--on-lime: #0B0B0B;
|
||
--sage: #A9B3A3;
|
||
--bar-strong: #3F463B;
|
||
--bar-soft: #A9B3A3;
|
||
--btn-bg: #0B0B0B;
|
||
--btn-fg: #FFFFFF;
|
||
--tint-amber: rgba(252, 246, 238, 0.84); --tint-amber-border: rgba(232, 168, 92, 0.3); --dot-amber: #B5722A;
|
||
--tint-blue: rgba(240, 244, 246, 0.84); --tint-blue-border: rgba(108, 144, 168, 0.28); --dot-blue: #5B7F98;
|
||
--tint-sage: rgba(240, 243, 239, 0.84); --tint-sage-border: rgba(150, 168, 138, 0.34); --dot-sage: #6F8463;
|
||
--kpi-amber: rgba(252, 246, 238, 0.68);
|
||
--kpi-blue: rgba(240, 244, 246, 0.68);
|
||
--kpi-sage: rgba(236, 240, 234, 0.72);
|
||
--st-lean-fg: #17663F; --st-lean-bg: #DDF0E4; --st-lean-dot: #1F8A55;
|
||
--st-nearlean-fg: #0F665F; --st-nearlean-bg: #D6EFEB; --st-nearlean-dot: #0F8F86;
|
||
--st-nearover-fg: #725300; --st-nearover-bg: #F9EDC2; --st-nearover-dot: #B58A00;
|
||
--st-high-fg: #A8420A; --st-high-bg: #FBE2D2; --st-high-dot: #C2410C;
|
||
--st-over-fg: #A61B12; --st-over-bg: #FADCD8; --st-over-dot: #C62828;
|
||
--accent-primary: #3D5F86;
|
||
--accent-secondary: #4F7046;
|
||
--accent-success: #047857;
|
||
--accent-warning: #A85F00;
|
||
--accent-danger: #C62828;
|
||
--accent-primary-text: #34557B;
|
||
--accent-secondary-text: #44633C;
|
||
--accent-primary-strong: #0B0B0B;
|
||
}
|
||
|
||
* { font-family: var(--font-ui); }
|
||
body { background: var(--page); color: var(--text-main); }
|
||
body::before {
|
||
content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
|
||
width: auto; height: auto; border-radius: 0; filter: none; opacity: 1; animation: none; transition: none;
|
||
background:
|
||
radial-gradient(ellipse 34% 58% at 18% 10%, var(--glow-amber), transparent 70%),
|
||
radial-gradient(ellipse 30% 50% at 88% 6%, var(--glow-blue), transparent 70%),
|
||
radial-gradient(ellipse 34% 45% at 60% 104%, var(--glow-sage), transparent 72%);
|
||
}
|
||
body::after { display: none; }
|
||
::selection { background: color-mix(in srgb, var(--lime) 55%, transparent); color: var(--text-main); }
|
||
html { scrollbar-color: var(--wash-2) transparent; }
|
||
h1 { font-weight: 300; letter-spacing: -0.5px; }
|
||
h2, h3 { font-weight: 500; }
|
||
[style*="font-weight:800"], [style*="font-weight: 800"], [style*="font-weight:900"], [style*="font-weight: 900"] { font-weight: 500 !important; }
|
||
|
||
/* Layout: floating sidebar, slim notice pill, scrolling content */
|
||
.app-container { padding: 16px; gap: 14px 16px; grid-template-columns: 228px minmax(0, 1fr); }
|
||
header {
|
||
background: var(--glass); border: 1px solid var(--glass-border); border-radius: 24px;
|
||
backdrop-filter: blur(24px) saturate(140%); -webkit-backdrop-filter: blur(24px) saturate(140%);
|
||
padding: 22px 12px 14px; gap: 14px; border-right: 1px solid var(--glass-border);
|
||
}
|
||
.logo { flex-direction: column; align-items: flex-start; gap: 2px; padding: 0 10px 6px; }
|
||
.logo .wordmark { font-size: 17px; font-weight: 500; letter-spacing: 4px; color: var(--text-main); }
|
||
.logo .wordmark-sub { font-size: 12px; color: var(--text-dim); }
|
||
.nav-group { gap: 2px; }
|
||
.nav-item { padding: 9px 12px; gap: 10px; font-size: 14px; font-weight: 400; color: var(--text-muted); border-radius: 999px; transition: background 0.15s, color 0.15s; }
|
||
.nav-item svg { flex: 0 0 auto; width: 17px; height: 17px; }
|
||
.nav-item:hover { background: var(--wash); color: var(--text-main); }
|
||
.nav-item.active, .nav-item.active:hover { background: var(--lime); color: var(--on-lime); font-weight: 500; box-shadow: none; }
|
||
.sidebar-account { border-top: 0; padding-top: 0; gap: 8px !important; }
|
||
.theme-toggle { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--inset); }
|
||
.theme-toggle button { flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 0; border: 0; border-radius: 999px; background: transparent; color: var(--text-muted); font-size: 13px; cursor: pointer; }
|
||
.theme-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text-main); font-weight: 500; }
|
||
.auth-user-badge { background: var(--inset) !important; border: 0 !important; border-radius: 18px !important; }
|
||
.auth-user-badge .user-avatar { background: var(--lime) !important; color: var(--on-lime) !important; }
|
||
.auth-user-badge .user-name { color: var(--text-main) !important; }
|
||
.auth-user-badge .user-role { color: var(--text-dim) !important; }
|
||
|
||
#data-source-banner.notice-pill {
|
||
margin: 0; padding: 8px 16px; border-radius: 999px; font-size: 13px; color: var(--text-muted);
|
||
background: var(--glass); border: 1px solid var(--glass-border);
|
||
backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%);
|
||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||
}
|
||
main { padding: 0 2px 8px 0; }
|
||
|
||
/* Cards: tinted frosted glass; the tint comes from the section's content */
|
||
.card {
|
||
--card-bg: var(--glass-strong); --card-border: var(--glass-border); --dot: var(--text-dim);
|
||
background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 22px;
|
||
box-shadow: none; backdrop-filter: blur(24px) saturate(140%); -webkit-backdrop-filter: blur(24px) saturate(140%);
|
||
}
|
||
.card::before { display: none; }
|
||
#simulate-content { --sx-card: var(--glass-strong); --sx-text: var(--text-main); --sx-muted: var(--text-muted); --sx-line: var(--line); --sx-accent: var(--btn-bg); --sx-on-accent: var(--btn-fg); --sx-warn: var(--accent-warning); --sx-good: var(--accent-success); --sx-input: var(--surface); --sx-up: var(--accent-primary-text); --sx-down: var(--accent-warning);
|
||
--sx-tint-coda: var(--tint-blue); --sx-tint-coda-border: var(--tint-blue-border); --sx-dot-coda: var(--dot-blue);
|
||
--sx-tint-inv: var(--tint-amber); --sx-tint-inv-border: var(--tint-amber-border); --sx-dot-inv: var(--dot-amber);
|
||
--sx-tint-inv2: color-mix(in srgb, var(--tint-amber) 45%, transparent);
|
||
--sx-tint-group: var(--tint-sage); --sx-tint-group-border: var(--tint-sage-border); --sx-dot-group: var(--dot-sage);
|
||
--sx-tint-sim: var(--wash); --sx-sim-bar: var(--lime); --sx-kpi-bg: var(--glass); --sx-strong: var(--wash-2); }
|
||
#simulate-content .sx-card { border-radius: 22px; border-color: var(--glass-border); backdrop-filter: blur(24px) saturate(140%); -webkit-backdrop-filter: blur(24px) saturate(140%); }
|
||
#simulate-content .sx-pick button, #simulate-content .sx-row button { border-radius: 999px; padding: 5px 14px; }
|
||
#simulate-content details summary { color: var(--text-main); text-decoration: underline; text-underline-offset: 3px; }
|
||
.card:hover { transform: none; box-shadow: none; }
|
||
.tint-amber { --card-bg: var(--tint-amber); --card-border: var(--tint-amber-border); --dot: var(--dot-amber); }
|
||
.tint-blue { --card-bg: var(--tint-blue); --card-border: var(--tint-blue-border); --dot: var(--dot-blue); }
|
||
.tint-sage { --card-bg: var(--tint-sage); --card-border: var(--tint-sage-border); --dot: var(--dot-sage); }
|
||
#invoice .card, #sales .card { --card-bg: var(--tint-amber); --card-border: var(--tint-amber-border); --dot: var(--dot-amber); }
|
||
#coda .card, #artists .card, #personnel-overview .card { --card-bg: var(--tint-blue); --card-border: var(--tint-blue-border); --dot: var(--dot-blue); }
|
||
#group .card, #org-structure .card { --card-bg: var(--tint-sage); --card-border: var(--tint-sage-border); --dot: var(--dot-sage); }
|
||
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex: 0 0 auto; }
|
||
.card-label { font-size: 13px; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
|
||
.card-value { font-weight: 300; letter-spacing: -0.5px; }
|
||
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 999px; font-size: 13px; color: var(--text-muted); background: var(--glass); border: 1px solid var(--glass-border); backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%); white-space: nowrap; }
|
||
.pill b { font-weight: 400; color: var(--text-main); }
|
||
|
||
/* Tables, inputs, buttons */
|
||
.table-container { background: transparent; border: 0; }
|
||
thead, th { background: var(--surface-solid) !important; color: var(--text-dim); }
|
||
th { border-bottom: 1px solid var(--line); text-transform: none; letter-spacing: 0; font-weight: 500; padding: 0.9rem 0.5rem; }
|
||
th:first-child, td:first-child { padding-left: 1rem; }
|
||
th:last-child, td:last-child { padding-right: 1rem; }
|
||
td { border-bottom: 1px solid var(--line); color: var(--text-main); }
|
||
tr:hover td { background: var(--wash); }
|
||
input, select, textarea { background: var(--inset); border: 1px solid var(--line); color: var(--text-main); }
|
||
input:focus, .table-container input:focus, .table-container input:hover { background: var(--surface); border-color: var(--accent-primary); box-shadow: none; }
|
||
.table-container input { background: transparent; }
|
||
.btn { border-radius: 999px; font-weight: 500; }
|
||
.btn-primary { background: var(--btn-bg); color: var(--btn-fg); box-shadow: none; }
|
||
.btn-primary:hover { box-shadow: none; transform: none; filter: brightness(1.08); }
|
||
.btn-outline { background: var(--glass); border: 1px solid var(--line); color: var(--text-main); }
|
||
.btn-outline:hover { background: var(--wash-2); border-color: var(--line); }
|
||
select.btn-outline { background-color: var(--surface); color: var(--text-main); }
|
||
select.btn-outline option, select option { background: var(--surface); color: var(--text-main); }
|
||
.role-a { background: color-mix(in srgb, var(--accent-primary) 16%, transparent); color: var(--accent-primary-text); }
|
||
.role-p { background: color-mix(in srgb, var(--accent-secondary) 16%, transparent); color: var(--accent-secondary-text); }
|
||
.role-o { background: color-mix(in srgb, var(--accent-warning) 18%, transparent); color: var(--accent-warning); }
|
||
.status-pill { border: 0; }
|
||
.modal-box { background: var(--surface); border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
|
||
.modal-box::before { display: none; }
|
||
.modal-input, .modal-salary-wrapper { background: var(--inset); border-color: var(--line); color: var(--text-main); }
|
||
.modal-checkbox-row { background: var(--inset); border-color: var(--line); }
|
||
.rd-tag { background: var(--wash-2); color: var(--text-main); }
|
||
.rd-suggestions { background: var(--surface); border-color: var(--line); }
|
||
.org-root-node, .org-dept-card { background: var(--card-bg, var(--glass-strong)); border-color: var(--line); box-shadow: none; color: var(--text-main); }
|
||
.org-group-item { background: var(--tile); border-color: var(--line); color: var(--text-main); }
|
||
.dept-invoice-bar-track { background: var(--wash-2); }
|
||
|
||
/* Dashboard — one page at 1920 × 970, reflows below */
|
||
#dashboard.view.active { min-height: 100%; gap: 14px; }
|
||
.dash-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
|
||
.dash-head h1 { margin: 0; font-size: 34px; line-height: 1.1; }
|
||
.dash-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
|
||
.kpi { border-radius: 22px; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: var(--text-main); border: 1px solid var(--glass-border); backdrop-filter: blur(24px) saturate(140%); -webkit-backdrop-filter: blur(24px) saturate(140%); }
|
||
.kpi .kpi-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; font-size: 13px; color: var(--text-muted); }
|
||
.kpi .kpi-label > span { display: flex; align-items: center; gap: 7px; }
|
||
.kpi .kpi-value { display: flex; align-items: baseline; gap: 6px; font-size: 34px; font-weight: 300; letter-spacing: -0.5px; line-height: 1; }
|
||
.kpi .kpi-value small { font-size: 14px; color: var(--text-muted); letter-spacing: 0; }
|
||
.kpi-lime { background: var(--lime); color: var(--on-lime); border-color: transparent; backdrop-filter: none; }
|
||
.kpi-lime .kpi-label, .kpi-lime .kpi-value small { color: var(--on-lime); }
|
||
.kpi-lime .kpi-go { width: 28px; height: 28px; border-radius: 50%; background: var(--on-lime); color: var(--lime); display: flex; align-items: center; justify-content: center; }
|
||
.kpi-amber { background: var(--kpi-amber); border-color: var(--tint-amber-border); --dot: var(--dot-amber); }
|
||
.kpi-blue { background: var(--kpi-blue); border-color: var(--tint-blue-border); --dot: var(--dot-blue); }
|
||
.kpi-sage { background: var(--kpi-sage); border-color: var(--tint-sage-border); --dot: var(--dot-sage); }
|
||
.dash-grid { flex: 1 1 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 14px; align-items: stretch; }
|
||
.dash-grid > .card, .dash-col > .card { margin: 0; padding: 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
||
.dash-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
|
||
.dash-col > .card:last-child { flex: 1 1 auto; }
|
||
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||
.card-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 500; color: var(--text-main); }
|
||
.card-head .meta { font-size: 12px; color: var(--text-dim); }
|
||
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-dim); }
|
||
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
|
||
.inv-row { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
|
||
.inv-row .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
||
.inv-row .name { display: flex; align-items: center; gap: 10px; font-size: 18px; }
|
||
.inv-row .amount { font-size: 24px; font-weight: 300; }
|
||
.inv-row .meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); }
|
||
.inv-row .meta b, .coda-row b { font-weight: 400; color: var(--text-main); }
|
||
.track { height: 6px; border-radius: 3px; background: var(--wash-2); overflow: hidden; }
|
||
.track > span { display: block; height: 100%; border-radius: 3px; }
|
||
.coda-row { display: flex; flex-direction: column; gap: 5px; }
|
||
.coda-row .top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
|
||
.coda-row .mult { font-size: 12px; color: var(--text-dim); margin-left: 4px; }
|
||
.card-foot { margin-top: auto; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-dim); }
|
||
.card-foot span { display: inline-flex; align-items: center; gap: 5px; }
|
||
.tile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
|
||
.tile { background: var(--tile); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
||
.tile .v { font-size: 28px; font-weight: 300; line-height: 1; }
|
||
.tile .l { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
.tile.lime { background: var(--lime); color: var(--on-lime); }
|
||
.tile.lime .l, .tile.sage .l { color: var(--on-lime); }
|
||
.tile.sage { background: var(--sage); color: var(--on-lime); }
|
||
.stack { display: flex; gap: 3px; height: 8px; }
|
||
.stack > span { border-radius: 4px; }
|
||
.lean-pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; white-space: nowrap; }
|
||
.lean-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
|
||
|
||
@media (max-width: 1350px) {
|
||
.app-container { grid-template-columns: 210px minmax(0, 1fr); }
|
||
}
|
||
@media (max-width: 900px) {
|
||
.app-container { display: flex; flex-direction: column; height: auto; min-height: 100vh; }
|
||
header { position: static; height: auto; }
|
||
.sidebar-navigation { flex-direction: row; flex-wrap: wrap; overflow: visible; }
|
||
.sidebar-navigation .nav-item { width: auto; }
|
||
main { overflow: visible; }
|
||
.dash-head h1 { font-size: 28px; }
|
||
.kpi .kpi-value { font-size: 28px; }
|
||
}
|
||
@media (prefers-reduced-transparency: reduce) {
|
||
header, .card, .kpi, .pill, #data-source-banner.notice-pill { backdrop-filter: none; -webkit-backdrop-filter: none; background-color: var(--surface-solid); }
|
||
}
|
||
/* Org chart group rows */
|
||
.org-dept-branch { width: 216px; }
|
||
.org-group-item.og-row { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 9px 10px; border-radius: 10px; }
|
||
.og-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
||
.og-name { font-size: 13px; line-height: 1.35; color: var(--text-main); word-break: keep-all; overflow-wrap: anywhere; }
|
||
.og-count { flex: none; font-size: 12px; color: var(--text-dim); font-family: var(--font-num, inherit); }
|
||
.og-flags { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
|
||
.og-flag, .og-assign { font: inherit; font-size: 11px; line-height: 1; padding: 5px 9px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text-dim); cursor: pointer; }
|
||
.og-flag:hover, .og-assign:hover { color: var(--text-main); border-color: var(--text-dim); }
|
||
.og-rd[aria-pressed="true"] { background: var(--accent-secondary); border-color: transparent; color: var(--page); }
|
||
.og-cg[aria-pressed="true"] { background: var(--accent-primary); border-color: transparent; color: var(--page); }
|
||
.og-row.is-rd { border-color: color-mix(in srgb, var(--accent-secondary) 45%, transparent); background: color-mix(in srgb, var(--accent-secondary) 10%, var(--tile)); }
|
||
.og-row.is-cg { border-color: color-mix(in srgb, var(--accent-primary) 45%, transparent); background: color-mix(in srgb, var(--accent-primary) 10%, var(--tile)); }
|
||
.og-manual { font-size: 11px; color: var(--accent-warning); }
|
||
.og-assign-wrap { margin-top: -2px; }
|
||
|
||
/* Invoice role table */
|
||
.ir-card { padding: 22px 24px; gap: 14px; }
|
||
.ir-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
|
||
.ir-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
|
||
.ir-company { border: 1px solid var(--line); border-radius: 14px; background: var(--tile); padding: 6px 14px 8px; }
|
||
.ir-head, .ir-row { display: grid; grid-template-columns: minmax(7em, 1fr) auto auto 5.5em; align-items: center; gap: 12px; padding: 8px 0; }
|
||
.ir-head { grid-template-columns: minmax(7em, 1fr) auto 5.5em; border-bottom: 1px solid var(--line); padding: 10px 0; }
|
||
.ir-row + .ir-row { border-top: 1px solid var(--line); }
|
||
.ir-name { font-size: 13px; color: var(--text-main); display: flex; flex-direction: column; gap: 2px; word-break: keep-all; }
|
||
.ir-name b { font-weight: 500; font-size: 15px; }
|
||
.ir-name small { font-size: 11px; color: var(--text-dim); }
|
||
.ir-cost { font-size: 12px; color: var(--text-dim); text-align: right; white-space: nowrap; }
|
||
.ir-src { font-size: 11px; color: var(--text-dim); text-align: right; }
|
||
.ir-src .link-button { font: inherit; font-size: 11px; background: none; border: 0; padding: 0; color: var(--accent-primary-text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
|
||
.ir-card .card-head { margin-bottom: 2px; }
|
||
.ir-empty { font-size: 12px; color: var(--text-dim); padding: 10px 0; }
|
||
.role-seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line); }
|
||
.role-seg button { font: inherit; font-size: 12px; line-height: 1; padding: 6px 11px; border: 0; border-radius: 999px; background: transparent; color: var(--text-dim); cursor: pointer; white-space: nowrap; }
|
||
.role-seg button:hover { color: var(--text-main); }
|
||
.role-seg button[aria-pressed="true"][data-r="bear"] { background: var(--lime); color: #111211; }
|
||
.role-seg button[aria-pressed="true"][data-r="share"] { background: var(--st-nearover-bg); color: var(--st-nearover-fg); }
|
||
.role-seg button[aria-pressed="true"][data-r="exclude"] { background: var(--wash-2); color: var(--text-main); }
|
||
@media (max-width: 1350px) { .ir-grid { grid-template-columns: 1fr; } }
|
||
@media (max-width: 900px) {
|
||
.ir-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||
.ir-row, .ir-head { grid-template-columns: 1fr auto; }
|
||
.ir-row .role-seg, .ir-head .role-seg { grid-column: 1 / -1; justify-self: start; }
|
||
}
|
||
/* Filter selects: one calm pill, hover brightens, a set filter is marked lime */
|
||
select.btn-outline {
|
||
appearance: none; -webkit-appearance: none;
|
||
background-color: var(--glass) !important;
|
||
color: var(--text-main) !important;
|
||
border: 1px solid var(--line) !important;
|
||
border-radius: 999px !important;
|
||
padding: 9px 36px 9px 16px !important;
|
||
font-size: 13px; line-height: 1.2;
|
||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A3A8B0' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") !important;
|
||
background-repeat: no-repeat !important;
|
||
background-position: right 14px center !important;
|
||
background-size: 12px 12px !important;
|
||
transform: none !important;
|
||
box-shadow: none !important;
|
||
transition: background-color .15s ease, border-color .15s ease;
|
||
}
|
||
:root[data-theme="light"] select.btn-outline {
|
||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235A5E66' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") !important;
|
||
}
|
||
select.btn-outline:hover { background-color: var(--wash-2) !important; border-color: var(--text-dim) !important; }
|
||
select.btn-outline:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
|
||
select.btn-outline:has(option:checked:not(:first-child)) {
|
||
background-color: color-mix(in srgb, var(--lime) 18%, var(--glass)) !important;
|
||
border-color: color-mix(in srgb, var(--lime) 60%, transparent) !important;
|
||
}
|
||
:root[data-theme="light"] select.btn-outline:has(option:checked:not(:first-child)) {
|
||
background-color: color-mix(in srgb, var(--lime) 45%, var(--glass)) !important;
|
||
border-color: color-mix(in srgb, #8A9A1F 50%, transparent) !important;
|
||
}
|
||
select.btn-outline option { background-color: var(--surface); color: var(--text-main); }
|
||
|
||
/* Excluded-units tables share one column grid */
|
||
.ex-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
|
||
.ex-table col.c-people { width: 14%; }
|
||
.ex-table col.c-money { width: 22%; }
|
||
.ex-table th, .ex-table td { padding: 12px 20px; }
|
||
.ex-table th:first-child, .ex-table td:first-child { text-align: left; }
|
||
.ex-table th.num, .ex-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
|
||
.ex-table td:first-child { overflow-wrap: anywhere; }
|
||
|
||
/* Expandable row headers: soft wash on hover, no inline handlers */
|
||
.row-toggle { transition: background-color .15s ease; border-radius: inherit; }
|
||
.row-toggle:hover { background-color: var(--wash); }
|
||
/* One hover language: a soft wash or a clearer edge, never movement or glow */
|
||
.btn-outline:hover, .btn:hover { transform: none; }
|
||
[data-row-toggle] { transition: background-color .15s ease; }
|
||
[data-row-toggle]:hover { background-color: var(--wash) !important; }
|
||
th.sortable:hover { color: var(--text-main); background: var(--wash); }
|
||
.table-container input:hover { background: var(--surface); border-color: var(--text-dim); }
|
||
.table-container input:focus { background: var(--surface); border-color: var(--accent-primary); }
|
||
.org-dept-card { transition: border-color .15s ease; }
|
||
.org-dept-card:hover { border-color: var(--text-dim); box-shadow: none; transform: none; }
|
||
.org-group-item { transition: background-color .15s ease, border-color .15s ease; }
|
||
.org-group-item:not(.is-rd):not(.is-cg):hover { background: color-mix(in srgb, var(--text-main) 5%, var(--tile)); border-color: var(--text-dim); }
|
||
.modal-checkbox-row:hover { background: var(--wash); }
|
||
.rd-tag:hover { background: color-mix(in srgb, var(--accent-primary) 16%, transparent); border-color: var(--accent-primary); }
|
||
.rd-suggestion-item:hover { background: var(--wash); color: var(--text-main); }
|
||
a.kpi { transition: filter .15s ease; }
|
||
a.kpi:hover { filter: brightness(1.04); }
|
||
a.kpi:focus-visible { outline: 2px solid var(--text-main); outline-offset: 3px; }
|
||
tr:hover td { background: var(--wash); transition: background-color .12s ease; }
|
||
/* Invoice page: total explained, metric 3 cell */
|
||
.inv-explain { margin: 0 0 1.25rem; padding: 16px 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--glass); font-size: 13px; color: var(--text-dim); line-height: 1.6; }
|
||
.inv-explain-title { font-size: 14px; color: var(--text-main); margin-bottom: 4px; }
|
||
.inv-explain b { color: var(--text-main); font-weight: 500; }
|
||
.inv-formula { color: var(--text-main); margin-bottom: 8px; }
|
||
.inv-explain ul { margin: 0; padding-left: 1.1em; display: flex; flex-direction: column; gap: 2px; }
|
||
.m3-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
|
||
.m3-pct { font-size: 0.9rem; font-weight: 700; color: var(--accent-warning); }
|
||
.m3-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
|
||
.m3-gap { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
|
||
.info-tip { display: inline-block; cursor: help; color: var(--text-dim); font-size: 12px; text-transform: none; }
|
||
.info-tip:hover, .info-tip:focus-visible { color: var(--text-main); }
|
||
/* Polish: inner pages share the dashboard language */
|
||
.dept-name, .card .dept-name { font-size: 1.15rem; font-weight: 500; color: var(--text-main); }
|
||
.page-sub { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
|
||
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; line-height: 1; padding: 5px 10px; border-radius: 999px; background: var(--wash-2); color: var(--text-main); white-space: nowrap; font-weight: 400; border: 0; }
|
||
.tag strong { font-weight: 500; }
|
||
.tag-warn { background: var(--st-nearover-bg); color: var(--st-nearover-fg); }
|
||
.tag-rd { background: color-mix(in srgb, var(--accent-secondary) 22%, transparent); color: var(--accent-secondary-text); }
|
||
.tag-cg { background: color-mix(in srgb, var(--accent-primary) 22%, transparent); color: var(--accent-primary-text); }
|
||
.currency-wrap { display: inline-flex !important; align-items: baseline; justify-content: flex-end; gap: 0.3em !important; min-width: 0 !important; width: auto !important; }
|
||
.currency-wrap > span:first-child { font-size: 0.62em; color: var(--text-dim); font-weight: 400; }
|
||
[onclick^="toggleArtistsDept"], [onclick^="toggleSalesDept"] { padding-top: 14px !important; padding-bottom: 14px !important; }
|
||
[onclick^="toggleArtistsGroup"] { padding-top: 10px !important; padding-bottom: 10px !important; }
|
||
input[type="checkbox"], input[type="radio"] { accent-color: var(--lime); }
|
||
:root[data-theme="light"] input[type="checkbox"], :root[data-theme="light"] input[type="radio"] { accent-color: #5E6E10; }
|
||
::placeholder { color: var(--text-dim); opacity: 1; }
|
||
#dash-year-pill { background: transparent; border-color: transparent; padding-left: 4px; }
|
||
.org-group-item:not(.is-rd):not(.is-cg) { border-color: transparent; }
|
||
.ir-company { border-color: transparent; }
|
||
.card h2 { font-size: 1rem; }
|
||
/* One-page dashboard: lists fill their card, no empty glass */
|
||
.fill-list { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; min-height: 0; }
|
||
.fill-list > .card-foot { margin-top: 0; }
|
||
.inv-row .pair { display: flex; flex-direction: column; gap: 4px; }
|
||
.inv-row .pair .track { height: 6px; }
|
||
.coda-group { display: flex; flex-direction: column; gap: 8px; }
|
||
.coda-group-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); padding-bottom: 2px; border-bottom: 1px solid var(--line); }
|
||
.tile-grid-fill { flex: 1 1 auto; grid-auto-rows: 1fr; }
|
||
.tile-grid-fill .tile { justify-content: center; gap: 10px; padding: 14px 18px; }
|
||
.tile-grid-fill .tile .v { font-size: clamp(28px, 2.4vw, 44px); }
|
||
.tile-grid-fill .tile .l { font-size: 13px; }
|
||
.tile-grid-fill .tile .l { white-space: normal; overflow: visible; line-height: 1.35; }
|
||
.kpi .kpi-note { font-size: 12px; color: var(--text-dim); }
|
||
/* One-page dashboard on laptop screens (e.g. MacBook 1512 × 982 → ~1512 × 860 in Chrome):
|
||
keep three columns and tighten type and spacing instead of wrapping */
|
||
@media (min-width: 1200px) {
|
||
.dash-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||
.dash-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr); }
|
||
}
|
||
@media (min-width: 1200px) and (max-width: 1700px), (min-width: 1200px) and (max-height: 900px) {
|
||
.app-container { padding: 12px; gap: 10px 12px; grid-template-columns: 200px minmax(0, 1fr); }
|
||
header { padding: 18px 10px 12px; gap: 10px; border-radius: 20px; }
|
||
.nav-item { padding: 8px 12px; font-size: 13px; }
|
||
#data-source-banner.notice-pill { padding: 6px 14px; font-size: 12px; }
|
||
#dashboard.view.active { gap: 10px; }
|
||
.dash-head h1 { font-size: 26px; }
|
||
.dash-head .pill { padding: 5px 12px; font-size: 12px; }
|
||
.dash-kpis, .dash-grid, .dash-col { gap: 10px; }
|
||
.kpi { padding: 12px 16px; gap: 6px; border-radius: 18px; }
|
||
.kpi .kpi-label { min-height: 24px; font-size: 12px; }
|
||
.kpi .kpi-value { font-size: 26px; }
|
||
.kpi .kpi-value small { font-size: 12px; }
|
||
.kpi-lime .kpi-go { width: 24px; height: 24px; }
|
||
.dash-grid > .card, .dash-col > .card { padding: 14px 16px; gap: 8px; border-radius: 20px; }
|
||
.card-head h2 { font-size: 14px; }
|
||
.card-head .meta, .legend { font-size: 11px; }
|
||
.inv-row { padding: 8px 0; gap: 5px; }
|
||
.inv-row .name { font-size: 15px; gap: 8px; }
|
||
.inv-row .amount { font-size: 19px; }
|
||
.inv-row .meta { font-size: 11px; }
|
||
.coda-group { gap: 5px; }
|
||
.coda-row { gap: 3px; }
|
||
.coda-row .top { font-size: 12px; }
|
||
.coda-group-head { font-size: 11px; }
|
||
.tile { padding: 10px 12px; border-radius: 14px; gap: 6px; }
|
||
.tile .v { font-size: 22px; }
|
||
.tile .l { font-size: 11px; }
|
||
.tile-grid-fill .tile .v { font-size: 30px; }
|
||
.card-foot { font-size: 11px; padding-top: 8px; }
|
||
}
|
||
.tile-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||
.tile-grid-4 .tile .l { white-space: normal; line-height: 1.35; }
|
||
.tile-grid-4 .tile { gap: 4px; }
|
||
.tile-grid-4 .tile .v { margin-bottom: 4px; }
|
||
.tile-grid-4 .tile .pct { color: var(--text-dim); }
|
||
.pending-link { color: var(--st-nearover-fg); text-decoration: underline; text-underline-offset: 3px; }
|
||
/* Save confirmation: a short status note, bottom right. */
|
||
.save-toast { position: fixed; right: 20px; bottom: 20px; z-index: 2000; display: flex; align-items: center; gap: 8px;
|
||
padding: 8px 14px; border-radius: 999px; font-size: 13px; color: var(--text-main);
|
||
background: var(--glass-strong); border: 1px solid var(--glass-border); backdrop-filter: blur(16px);
|
||
opacity: 0; transform: translateY(6px); transition: opacity .2s ease, transform .2s ease; pointer-events: none; }
|
||
.save-toast.show { opacity: 1; transform: none; }
|
||
.save-toast .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-success); }
|
||
@media (prefers-reduced-motion: reduce) { .save-toast { transition: none; transform: none; } }
|
||
|
||
/* Undo after delete: 7 seconds, with a countdown bar. */
|
||
.undo-toast { position: fixed; left: 50%; bottom: 24px; z-index: 2000; display: flex; align-items: center; gap: 14px;
|
||
padding: 10px 12px 10px 18px; border-radius: 999px; font-size: 13px; color: var(--text-main); overflow: hidden;
|
||
background: var(--glass-strong); border: 1px solid var(--glass-border); backdrop-filter: blur(16px);
|
||
opacity: 0; transform: translate(-50%, 8px); transition: opacity .2s ease, transform .2s ease; pointer-events: none; }
|
||
.undo-toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
|
||
.undo-toast button { border: 0; border-radius: 999px; padding: 6px 14px; font: inherit; font-weight: 500; cursor: pointer;
|
||
background: var(--lime); color: var(--on-lime); }
|
||
.undo-toast button:focus-visible { outline: 2px solid var(--text-main); outline-offset: 2px; }
|
||
.undo-toast .undo-bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--text-dim); transform-origin: left; }
|
||
.undo-toast.show .undo-bar { animation: undo-count 7s linear forwards; }
|
||
@keyframes undo-count { from { transform: scaleX(1); } to { transform: scaleX(0); } }
|
||
@media (prefers-reduced-motion: reduce) { .undo-toast { transition: none; } .undo-toast.show .undo-bar { animation: none; } }
|
||
|
||
/* ⓘ tip popover */
|
||
.info-tip { cursor: pointer; border-radius: 999px; }
|
||
.info-tip:focus-visible { outline: 2px solid var(--text-main); outline-offset: 2px; }
|
||
.tip-pop { position: fixed; z-index: 2100; max-width: 320px; padding: 10px 12px; border-radius: 12px; font-size: 12.5px; line-height: 1.55;
|
||
color: var(--text-main); background: var(--glass-strong); border: 1px solid var(--glass-border); backdrop-filter: blur(16px);
|
||
box-shadow: 0 8px 24px rgba(0, 0, 0, .18); text-transform: none; letter-spacing: 0; font-weight: 400; text-align: left;
|
||
opacity: 0; visibility: hidden; transition: opacity .12s ease; }
|
||
.tip-pop.show { opacity: 1; visibility: visible; }
|
||
|
||
/* Checkboxes: one site-wide style (管理職 and the add-person modal). */
|
||
input[type="checkbox"] { appearance: none; -webkit-appearance: none; flex: 0 0 auto; box-sizing: border-box; width: 18px; height: 18px; min-width: 18px; margin: 0; padding: 0;
|
||
border-radius: 6px; border: 1.5px solid var(--text-dim); background: var(--inset); cursor: pointer; vertical-align: middle;
|
||
display: inline-grid; place-content: center; transition: background .15s ease, border-color .15s ease; }
|
||
input[type="checkbox"]:hover { border-color: var(--text-main); }
|
||
input[type="checkbox"]:checked { background: var(--lime) no-repeat center / 12px 12px; border-color: var(--lime);
|
||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111211' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E"); }
|
||
input[type="checkbox"]:focus-visible { outline: 2px solid var(--text-main); outline-offset: 2px; }
|
||
input[type="checkbox"]:disabled { opacity: .45; cursor: not-allowed; }
|
||
.modal-checkbox-row input[type=checkbox] { width: 18px; height: 18px; accent-color: unset; border: 1.5px solid var(--text-dim); }
|
||
.modal-checkbox-row input[type=checkbox]:checked { border-color: var(--lime); }
|
||
.modal-checkbox-row span { font-size: 0.88rem; color: var(--text-muted); }
|
||
|
||
/* Short laptop windows and browser zoom: keep every menu item visible without scrolling. */
|
||
@media (min-width: 901px) and (max-height: 760px) {
|
||
.nav-item { padding: 6px 12px; font-size: 13px; }
|
||
.theme-toggle button { padding: 5px 0; }
|
||
header { gap: 8px; }
|
||
}
|
||
@media (min-width: 901px) and (max-height: 620px) {
|
||
.nav-item { padding: 4px 12px; }
|
||
.nav-item svg { width: 15px; height: 15px; }
|
||
.sidebar-account .user-sub, .sidebar-account small { display: none; }
|
||
}
|
||
/* 權限管理:版面沿用原本獨立頁的設計,顏色改吃看板的變數;選擇器全部鎖在 #permissions 底下,不影響其他區塊。 */
|
||
#permissions {
|
||
--card: var(--surface); --raised: var(--wash-2); --text: var(--text-main);
|
||
--muted: var(--text-muted); --dim: var(--text-dim); --bg: var(--surface);
|
||
--accent: var(--accent-primary-text); --accent-soft: color-mix(in srgb, var(--accent-primary-text) 16%, transparent);
|
||
--warn: var(--accent-warning); --warn-soft: color-mix(in srgb, var(--accent-warning) 16%, transparent);
|
||
--good: var(--accent-success); --good-soft: color-mix(in srgb, var(--accent-success) 16%, transparent);
|
||
}
|
||
#permissions .lead { color:var(--muted); font-size:.88rem; margin:0 0 20px; max-width:760px; }
|
||
#permissions .rules { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:10px; margin-bottom:22px; }
|
||
#permissions .rule { background:var(--card); border:1px solid var(--line); border-radius:12px; padding:12px 14px; font-size:.82rem; color:var(--muted); }
|
||
#permissions .rule b { display:block; color:var(--text); font-size:.9rem; margin-bottom:2px; }
|
||
#permissions .toolbar { display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin-bottom:12px; }
|
||
#permissions .search { flex:1; min-width:220px; font:inherit; padding:9px 12px; border:1px solid var(--line); border-radius:10px; background:var(--card); color:var(--text); }
|
||
#permissions .tabs { display:flex; gap:6px; flex-wrap:wrap; }
|
||
#permissions .tab { font:inherit; font-size:.82rem; border:1px solid var(--line); background:var(--card); color:var(--muted); border-radius:99px; padding:5px 12px; cursor:pointer; }
|
||
#permissions .tab[aria-pressed="true"] { background:var(--text); color:var(--bg); border-color:var(--text); }
|
||
#permissions .tab .n { opacity:.7; margin-left:4px; font-variant-numeric:tabular-nums; }
|
||
#permissions .list { background:var(--card); border:1px solid var(--line); border-radius:14px; overflow:hidden; }
|
||
#permissions .row { display:grid; grid-template-columns: minmax(170px, 1.1fr) minmax(130px, .8fr) minmax(220px, 1.6fr) 72px; gap:14px; align-items:center; padding:12px 16px; border-top:1px solid var(--line); }
|
||
#permissions .row:first-child { border-top:0; }
|
||
#permissions .who b { display:block; font-size:.95rem; }
|
||
#permissions .who span, #permissions .where span { color:var(--dim); font-size:.78rem; }
|
||
#permissions .where { font-size:.86rem; }
|
||
#permissions .chips { display:flex; flex-wrap:wrap; gap:5px; }
|
||
#permissions .chip { font-size:.75rem; padding:2px 9px; border-radius:99px; background:var(--raised); border:1px solid var(--line); color:var(--muted); white-space:nowrap; }
|
||
#permissions .chip.hr { background:var(--accent-soft); border-color:transparent; color:var(--accent); }
|
||
#permissions .chip.manual { background:var(--good-soft); border-color:transparent; color:var(--good); }
|
||
#permissions .chip.warn { background:var(--warn-soft); border-color:transparent; color:var(--warn); }
|
||
#permissions .chip.admin { background:var(--text); color:var(--bg); border-color:transparent; }
|
||
#permissions .chip.old { opacity:.55; text-decoration:line-through; }
|
||
#permissions .none { color:var(--dim); font-size:.78rem; }
|
||
#permissions .act { text-align:right; }
|
||
#permissions .btn { font:inherit; font-size:.82rem; border:1px solid var(--line); background:var(--card); color:var(--text); border-radius:10px; padding:6px 12px; cursor:pointer; }
|
||
#permissions .btn:hover { background:var(--raised); }
|
||
#permissions .btn.primary { background:var(--accent); border-color:var(--accent); color:var(--surface); }
|
||
#permissions .editor { grid-column:1 / -1; display:grid; gap:14px; padding:14px; margin-top:4px; background:var(--raised); border:1px solid var(--line); border-radius:12px; }
|
||
#permissions .editor h4 { margin:0 0 8px; font-size:.85rem; color:var(--muted); font-weight:600; }
|
||
#permissions .toggles { display:grid; grid-template-columns:repeat(auto-fit, minmax(210px, 1fr)); gap:8px; }
|
||
#permissions .toggle { display:flex; gap:8px; align-items:flex-start; font-size:.85rem; cursor:pointer; }
|
||
#permissions .toggle small { display:block; color:var(--dim); font-size:.75rem; }
|
||
#permissions .pick { display:flex; flex-wrap:wrap; gap:6px 14px; font-size:.82rem; }
|
||
#permissions .pick label { display:inline-flex; gap:5px; align-items:center; white-space:nowrap; }
|
||
#permissions .actions { display:flex; gap:8px; justify-content:flex-end; align-items:center; }
|
||
#permissions .status { color:var(--good); font-size:.8rem; margin-right:auto; }
|
||
#permissions .empty { padding:28px 16px; text-align:center; color:var(--dim); font-size:.85rem; }
|
||
#permissions .log { background:var(--card); border:1px solid var(--line); border-radius:14px; overflow:hidden; }
|
||
#permissions .log-row { display:grid; grid-template-columns:150px minmax(130px,1fr) minmax(220px,2fr) minmax(130px,1fr); gap:12px; align-items:center; padding:10px 16px; border-top:1px solid var(--line); font-size:.82rem; }
|
||
#permissions .log-row:first-child { border-top:0; }
|
||
#permissions .log-row time, #permissions .log-row .by { color:var(--dim); font-variant-numeric:tabular-nums; }
|
||
#permissions .change { display:flex; flex-wrap:wrap; gap:5px; align-items:center; }
|
||
#permissions .arrow { color:var(--dim); }
|
||
@media (max-width: 820px) {
|
||
#permissions .row, #permissions .log-row { grid-template-columns:1fr 1fr; }
|
||
#permissions .row > .chips, #permissions .log-row > .change { grid-column:1 / -1; }
|
||
#permissions .where br { display:none; }
|
||
#permissions .where span:not(:empty)::before { content:' · '; }
|
||
}
|
||
</style>
|
||
|
||
<link rel="stylesheet" href="/buttons.css">
|
||
</head>
|
||
|
||
<body class="mode-admin">
|
||
|
||
<div class="app-container">
|
||
<header>
|
||
<div class="logo">
|
||
<span class="wordmark">MOONSHINE</span>
|
||
<span class="wordmark-sub" id="wordmark-year">LeadBoard · 2027 試算</span>
|
||
</div>
|
||
|
||
<nav class="nav-group sidebar-navigation" aria-label="主選單">
|
||
<button type="button" class="nav-item active" id="nav-dashboard" onclick="showView('dashboard')" aria-current="page"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="7" height="7" rx="1.5"></rect><rect x="13.5" y="3.5" width="7" height="7" rx="1.5"></rect><rect x="3.5" y="13.5" width="7" height="7" rx="1.5"></rect><rect x="13.5" y="13.5" width="7" height="7" rx="1.5"></rect></svg>儀表板</button>
|
||
<button type="button" class="nav-item" id="nav-invoice" onclick="showView('invoice')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3h12v18l-3-2-3 2-3-2-3 2z"></path><path d="M9 8h6M9 12h6M9 16h3"></path></svg>年度發票額</button>
|
||
<button type="button" class="nav-item" id="nav-preview-personnel" onclick="showPersonnelView('all', 'internal')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="3" width="16" height="18" rx="2"></rect><path d="M8 7h8M8 11h2M12 11h2M8 15h2M12 15h2M8 18h2M12 18h4"></path></svg>人員資料</button>
|
||
<button type="button" class="nav-item" id="nav-contractors" onclick="showPersonnelView('all', 'contractors')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="8" r="3.5"></circle><path d="M3 20c0-3.3 2.7-6 6-6s6 2.7 6 6"></path><path d="M16 4.5a3.5 3.5 0 0 1 0 7M21 20c0-2.6-1.6-4.8-4-5.6"></path></svg>常態型外包</button>
|
||
<button type="button" class="nav-item" id="nav-plans" onclick="showView('plans')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="5" width="17" height="15.5" rx="2"></rect><path d="M3.5 10h17M8 3v4M16 3v4M8 14h3M8 17h6"></path></svg>預排異動</button>
|
||
|
||
<button type="button" class="nav-item" id="nav-org" onclick="showView('org-structure')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="3" width="6" height="5" rx="1"></rect><rect x="3" y="16" width="6" height="5" rx="1"></rect><rect x="15" y="16" width="6" height="5" rx="1"></rect><path d="M12 8v4M6 16v-2.5h12V16"></path></svg>組織架構</button>
|
||
<button type="button" class="nav-item" id="nav-params" onclick="showView('params')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h9M17 6h3M4 12h3M11 12h9M4 18h11M19 18h1"></path><circle cx="15" cy="6" r="2"></circle><circle cx="9" cy="12" r="2"></circle><circle cx="17" cy="18" r="2"></circle></svg>核心參數</button>
|
||
<button type="button" class="nav-item" id="nav-sales" onclick="showView('sales')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="7" width="18" height="13" rx="2"></rect><path d="M9 7V5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2M3 13h18"></path></svg>業務管理</button>
|
||
<button type="button" class="nav-item" id="nav-artists" onclick="showView('artists')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a9 9 0 1 0 0 18c1.1 0 1.6-.8 1.6-1.6 0-.9-.8-1.4-.8-2.3 0-1 .8-1.6 1.8-1.6H17a4 4 0 0 0 4-4c0-4.7-4-8.5-9-8.5z"></path><circle cx="7.5" cy="11" r="1"></circle><circle cx="10.5" cy="7" r="1"></circle><circle cx="15" cy="7.5" r="1"></circle></svg>藝術家</button>
|
||
<button type="button" class="nav-item" id="nav-coda" onclick="showView('coda')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"></circle><circle cx="12" cy="12" r="5"></circle><circle cx="12" cy="12" r="1"></circle></svg>部門 CODA</button>
|
||
<button type="button" class="nav-item" id="nav-group" onclick="showView('group')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l9 5-9 5-9-5z"></path><path d="M3 13l9 5 9-5"></path></svg>組別分析</button>
|
||
<button type="button" class="nav-item" id="nav-simulate" onclick="showView('simulate')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="5" y="3" width="14" height="18" rx="2"></rect><path d="M8 7h8M8 11h2M12 11h2M16 11h0M8 15h2M12 15h2M8 19h0"></path></svg>模擬試算</button>
|
||
<button type="button" class="nav-item" id="nav-permissions" onclick="showView('permissions')"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="5" y="11" width="14" height="9" rx="2"></rect><path d="M8 11V8a4 4 0 0 1 8 0v3"></path></svg>權限管理</button>
|
||
</nav>
|
||
|
||
<div class="nav-group sidebar-account" style="gap: 0.5rem;">
|
||
<div class="theme-toggle" role="group" aria-label="配色">
|
||
<button type="button" data-theme-set="light" onclick="setTheme('light')"><svg aria-hidden="true" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="12" r="4"></circle><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"></path></svg>日間</button>
|
||
<button type="button" data-theme-set="dark" onclick="setTheme('dark')"><svg aria-hidden="true" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z"></path></svg>夜間</button>
|
||
</div>
|
||
<div data-pmb-switches="theme-toggle" style="display:flex; flex-direction:column; gap:0.5rem;"></div>
|
||
<!-- Local preview badge; this is not an authenticated user. -->
|
||
<div id="auth-user-badge" class="auth-user-badge" title="本機預覽,尚未啟用登入或權限控管">
|
||
<div class="user-avatar" id="auth-avatar-initial">?</div>
|
||
<div class="user-info">
|
||
<div class="user-name" id="auth-username-display">未登入</div>
|
||
<div class="user-role" id="auth-role-display">-</div>
|
||
</div>
|
||
</div>
|
||
<form id="company-logout-form" method="post" action="/api/auth/company-logout" style="display:none; margin:0;">
|
||
<button class="btn btn-primary" type="submit" style="width:100%;" title="同時登出 MoonShine 公司帳號">登出</button>
|
||
</form>
|
||
<a id="login-link" class="btn btn-outline" href="/api/auth/login">公司帳號登入</a>
|
||
</div>
|
||
</header>
|
||
|
||
<div id="data-source-banner" class="notice-pill" role="status">
|
||
正在從預覽伺服器載入合成資料…
|
||
</div>
|
||
<main>
|
||
<!-- DASHBOARD VIEW -->
|
||
<div id="dashboard" class="view active">
|
||
<div class="dash-head">
|
||
<h1>營運概況</h1>
|
||
<span class="pill" id="dash-ap-pill"></span>
|
||
<span class="pill" id="dash-floor-pill"></span>
|
||
<span class="pill" id="dash-year-pill"></span>
|
||
</div>
|
||
<div class="dash-kpis" id="main-kpis"></div>
|
||
<div class="dash-grid">
|
||
<section class="card tint-amber">
|
||
<div class="card-head"><h2><span class="dot"></span>各部門 發票 vs CODA</h2><span class="legend"><span><i style="background:var(--bar-strong)"></i>年度發票目標</span><span><i style="background:var(--bar-soft)"></i>CODA</span></span></div>
|
||
<div id="dept-invoice-targets" class="fill-list"></div>
|
||
</section>
|
||
<section class="card tint-blue">
|
||
<div class="card-head"><h2><span class="dot"></span>部門 CODA</h2><span class="legend"><span><i style="background:var(--bar-strong)"></i>承擔發票</span><span><i style="background:var(--bar-soft)"></i>其他</span></span></div>
|
||
<div id="dept-bars" class="fill-list"></div>
|
||
</section>
|
||
<div class="dash-col">
|
||
<section class="card tint-sage">
|
||
<div class="card-head"><h2><span class="dot"></span>人力分佈</h2><span class="meta" id="role-total"></span></div>
|
||
<div id="role-stats" style="display:flex; flex-direction:column; gap:12px;"></div>
|
||
</section>
|
||
<section class="card tint-sage">
|
||
<div class="card-head"><h2><span class="dot"></span>部門倍率</h2><span class="meta">人薪倍率 × 內部成本 ÷ A 成本</span></div>
|
||
<div id="dash-multipliers" class="tile-grid tile-grid-fill"></div>
|
||
</section>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- INVOICE VIEW -->
|
||
<div id="invoice" class="view">
|
||
</div>
|
||
|
||
<!-- PERSONNEL OVERVIEW (Landing Page) -->
|
||
<div id="personnel-overview" class="view">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
||
<h1>人員概況</h1>
|
||
<button class="btn btn-primary" onclick="showPersonnelView('all')">查看完整名單</button>
|
||
</div>
|
||
|
||
<div class="card" style="margin-bottom: 2rem;">
|
||
<h3 style="margin-bottom: 1.5rem;">各部門人力預算佔比</h3>
|
||
<div id="dept-cost-stack-chart">
|
||
<!-- Custom Stacked Bar Chart -->
|
||
</div>
|
||
</div>
|
||
|
||
<div class="kpi-grid" id="dept-kpi-grid">
|
||
<!-- Dept Mini Cards -->
|
||
</div>
|
||
</div>
|
||
|
||
<!-- PERSONNEL LIST VIEW -->
|
||
<div id="personnel" class="view">
|
||
<div
|
||
style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem;">
|
||
<div>
|
||
<h1 id="personnel-view-title" style="margin-bottom: 0.5rem;">人員主表 (全部門)</h1>
|
||
<p id="personnel-source-note" style="color:var(--text-muted); margin-bottom:1rem;"></p>
|
||
<div id="personnel-detail-kpi"
|
||
style="display: flex; gap: 1rem; align-items: center; margin-top: 0.5rem;">
|
||
<!-- KPI cards will be injected here by JS -->
|
||
</div>
|
||
</div>
|
||
<div style="display: flex; gap: 0.75rem; align-items: center;">
|
||
<div class="card"
|
||
style="margin-bottom: 0; display: flex; gap: 1rem; align-items: center; background: var(--inset); border-color: var(--wash); padding: 0.5rem 1rem;">
|
||
<div style="flex-grow: 1;">
|
||
<input type="text" id="personnel-search" placeholder="搜尋姓名、職稱..."
|
||
style="width: 100%; padding: 10px 16px; border-radius: 99px; border: 1px solid var(--border-glass); background: var(--wash); color: var(--text-main);"
|
||
onkeyup="renderPersonnel()">
|
||
</div>
|
||
<select id="personnel-company-filter" class="btn btn-outline"
|
||
onchange="updateDeptFilter(); updateGroupFilter(); renderPersonnel()"
|
||
style="min-width: 130px; cursor: pointer;">
|
||
<option value="all">所有公司</option>
|
||
</select>
|
||
<select id="personnel-dept-filter" class="btn btn-outline"
|
||
onchange="updateGroupFilter(); renderPersonnel()"
|
||
style="min-width: 130px; cursor: pointer;">
|
||
<option value="all">所有部門</option>
|
||
</select>
|
||
<select id="personnel-group-filter" class="btn btn-outline" onchange="renderPersonnel()"
|
||
style="min-width: 130px; cursor: pointer;">
|
||
<option value="all">所有組別</option>
|
||
</select>
|
||
</div>
|
||
<button type="button" class="btn btn-outline salary-toggle" onclick="toggleSalaryVisibility()" aria-pressed="false" title="顯示每個人的薪資與成本">顯示薪資</button>
|
||
<button id="personnel-add-button" class="btn btn-primary" onclick="addPerson()">+ 新增內部人員</button>
|
||
</div>
|
||
</div>
|
||
<div class="table-container">
|
||
<table id="person-table">
|
||
<thead>
|
||
<tr>
|
||
<th class="sortable" onclick="toggleSort('company')">公司 <span id="sort-company"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable" onclick="toggleSort('name')">姓名 <span id="sort-name"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable" onclick="toggleSort('title')">職稱 <span id="sort-title"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable" onclick="toggleSort('dept')">部門 <span id="sort-dept"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable" onclick="toggleSort('group')">組別 <span id="sort-group"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable" onclick="toggleSort('role')">職能 <span id="sort-role"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable" onclick="toggleSort('isManager')">管理職 <span id="sort-isManager"
|
||
class="sort-icon"></span></th>
|
||
<th class="sortable num" onclick="toggleSort('salary')">月/時薪 <span id="sort-salary"
|
||
class="sort-icon"></span></th>
|
||
<th class="num">每週天數</th>
|
||
<th class="num">H1 起</th>
|
||
<th class="num">H1 迄</th>
|
||
<th class="num">H2 起</th>
|
||
<th class="num">H2 迄</th>
|
||
<th>狀態</th>
|
||
<th class="sortable num" onclick="toggleSort('totalCost')">個人總成本 <span
|
||
id="sort-totalCost" class="sort-icon"></span></th>
|
||
<th>操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody></tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- SALES VIEW -->
|
||
<div id="sales" class="view">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
||
<div><h1>業務管理</h1><p class="page-sub">全體 P 系列預算</p></div>
|
||
<div style="display:flex; gap:0.75rem; align-items:center;">
|
||
<button type="button" class="btn btn-outline salary-toggle" onclick="toggleSalaryVisibility()" aria-pressed="false" title="顯示每個人的薪資與成本">顯示薪資</button>
|
||
<div class="card" style="padding: 1rem 2rem; margin-bottom:0;">
|
||
<div class="card-label">P 年度薪資承擔額(依管理/PC比例)</div>
|
||
<div class="card-value" id="sales-grand-total">NT$ 0</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="sales-content">
|
||
<!-- Dept Tables -->
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ARTISTS VIEW -->
|
||
<div id="artists" class="view">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
||
<h1>藝術家</h1>
|
||
<div class="card" style="padding: 1rem 2rem;">
|
||
<div class="card-label">製作部門藝術家成本(含支援分攤)</div>
|
||
<div class="card-value" id="artists-grand-total">NT$ 0</div>
|
||
</div>
|
||
</div>
|
||
<div id="artists-content">
|
||
<!-- Dept Tables -->
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<!-- PERMISSIONS VIEW -->
|
||
<div id="permissions" class="view">
|
||
<div style="margin-bottom: 2rem;">
|
||
<h1 style="margin-bottom: 0.5rem;">權限管理</h1>
|
||
<p class="lead">HR 的主管會自動帶入權限;HR 拿掉主管身分,這些權限就自動消失。這裡加的是「手動」權限,要在這裡拿掉。只有最高管理者能改核心參數、按定錨、刪資料、管理權限。</p>
|
||
</div>
|
||
<div class="rules">
|
||
<div class="rule"><b>部主管(HR)</b>看部門、個人明細(含薪資)、部門模擬試算</div>
|
||
<div class="rule"><b>組主管(HR)</b>看自己組的實際 CODA、平均日 CODA、定錨 CODA</div>
|
||
<div class="rule"><b>手動加權限</b>全公司檢視、其他部門或組、個人明細、模擬</div>
|
||
</div>
|
||
<div class="toolbar">
|
||
<input class="search" id="perm-q" type="search" placeholder="搜尋姓名、工號、部門、組" oninput="permDraw()" aria-label="搜尋">
|
||
<div class="tabs" id="perm-tabs" role="group" aria-label="篩選"></div>
|
||
</div>
|
||
<div class="list" id="perm-rows"><div class="empty">讀取中…</div></div>
|
||
<details style="margin-top:1.5rem;">
|
||
<summary style="cursor:pointer; font-size:.9rem; color:var(--text-muted);">修改紀錄</summary>
|
||
<p class="lead" style="margin-top:.75rem;">權限每次儲存都會留下紀錄:什麼時候、誰改的、改了誰、改前改後。紀錄不能刪除(最多保留最近 2000 筆,這裡顯示最近 200 筆)。</p>
|
||
<div class="log" id="perm-log"></div>
|
||
</details>
|
||
</div>
|
||
|
||
<!-- PARAMETERS VIEW -->
|
||
<div id="params" class="view">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
||
<div>
|
||
<h1 style="margin-bottom: 0.5rem;">核心參數</h1>
|
||
<p style="color: var(--text-muted); font-size: 0.9rem;">調整全公司營運基準、倍率、以及各項自動計算參數。變動將立即影響所有視圖。</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="anchor-card" class="card" style="padding: 1.25rem; margin-bottom: 1.5rem;"></div>
|
||
<div id="global-params"
|
||
style="display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.2fr) minmax(320px, 1fr); gap: 1.5rem; align-items: start;">
|
||
<!-- Cards will be injected here -->
|
||
</div>
|
||
<div id="invoice-roles" style="margin-top: 1.5rem;"></div>
|
||
</div>
|
||
|
||
<!-- CODA VIEW -->
|
||
<div id="coda" class="view">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
||
<div>
|
||
<h1>部門 CODA</h1>
|
||
<p style="color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem;">P 系列預算 + A/O
|
||
藝術家預算 = 各部門最終 CODA。成本=年薪 × 人薪倍率,不除以產出率。</p>
|
||
</div>
|
||
<div style="display: flex; gap: 1rem; align-items: stretch;">
|
||
<div class="card" id="coda-avg-card" style="padding: 1rem 2rem;" title="夢想創造與夢境現實各部門「部門平均日工作 CODA」的簡單平均(不依人數加權)">
|
||
<div class="card-label">各部門平均日工作 CODA</div>
|
||
<div class="card-value" id="coda-avg-daily">NT$ 0</div>
|
||
</div>
|
||
<div class="card" style="padding: 1rem 2rem;">
|
||
<div class="card-label">全公司總 CODA</div>
|
||
<div class="card-value" id="coda-grand-total">NT$ 0</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="coda-content">
|
||
<!-- Dept CODA Cards -->
|
||
</div>
|
||
</div>
|
||
|
||
<!-- SIMULATE VIEW:和 /my 共用 scope-ui.js -->
|
||
<div id="simulate" class="view">
|
||
<h1>模擬試算</h1>
|
||
<p style="color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem;">選一個部門,試試加人或調薪後實際 CODA、平均日 CODA、定錨 CODA、發票會變多少。只是試算,不會存檔、不影響正式數字。部長們看到的是同一份畫面(/my)。</p>
|
||
<div id="simulate-content" style="margin-top: 1.5rem;"></div>
|
||
</div>
|
||
|
||
<!-- PLANNED CHANGES VIEW -->
|
||
<div id="plans" class="view">
|
||
<h1>預排異動</h1>
|
||
<p style="color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem;">HR 還沒同步之前,先把已知的離職、新進排進試算。定錨時會照這份算;HR 一有結果就自動移除那一筆、改用 HR 的資料;時間過了 HR 還沒改,寬限 1 個月後也會自動移除。只有你看得到這一頁和備註;部長看到的是套用後的數字,看不到原因。</p>
|
||
<div id="plans-content" style="margin-top: 1.5rem;"></div>
|
||
</div>
|
||
|
||
<!-- ORG STRUCTURE VIEW -->
|
||
<div id="org-structure" class="view">
|
||
<div id="org-structure-content">
|
||
<!-- Dynamic Org Chart -->
|
||
</div>
|
||
</div>
|
||
|
||
<!-- GROUP ANALYTICS VIEW -->
|
||
<div id="group" class="view">
|
||
<h1>組別分析</h1>
|
||
<p style="color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem;">公司 → 部門 → 組別。外包依所在部門與組別歸入該部門的公司;沒有部門的人列在各公司的「未歸部門」(不列入部門 CODA)。</p>
|
||
<div style="display:flex; gap:0.75rem; align-items:center; flex-wrap:wrap; margin-top:1.5rem;">
|
||
<select id="group-company-filter" class="btn btn-outline" onchange="renderGroup()" style="min-width:150px; cursor:pointer;">
|
||
<option value="all">所有公司</option>
|
||
</select>
|
||
<button class="btn btn-outline" onclick="setGroupExpansion(true)">全部展開</button>
|
||
<button class="btn btn-outline" onclick="setGroupExpansion(false)">全部收合</button>
|
||
</div>
|
||
<div class="table-container" style="margin-top: 1rem;">
|
||
<table id="group-table">
|
||
<thead>
|
||
<tr>
|
||
<th>公司/部門/組別</th>
|
||
<th class="num">人數</th>
|
||
<th class="num">總成本</th>
|
||
<th>佔上一層比例</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody></tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
</main>
|
||
</div>
|
||
|
||
<script src="/calc-core.js"></script>
|
||
<script src="/scope-ui.js"></script>
|
||
<script>
|
||
// --- CONFIGURATION LAYER ---
|
||
window.IS_PUBLIC_VERSION = false;
|
||
let personnelCategory = 'internal';
|
||
function matchesPersonnelCategory(person, category = personnelCategory) {
|
||
const isContractor = (person.role || '').startsWith('O');
|
||
return category === 'contractors' ? isContractor : !isContractor;
|
||
}
|
||
// --- DATA LAYER ---
|
||
let baseData = []; // Loaded from the server API
|
||
let simData = []; // Current simulation data
|
||
let previewParamsBeforeSimulation = null;
|
||
let isSimMode = false;
|
||
window.IS_PUBLIC_DEPLOY = true; // Security Lock Enabled
|
||
|
||
|
||
|
||
let globalParams = {}; // Loaded from the server API
|
||
|
||
|
||
let currentDeptFilter = 'all';
|
||
let currentGroupFilter = 'all';
|
||
let sortConfig = { field: 'dept', direction: 'asc' };
|
||
// 個人薪資預設隱藏;每次重新載入都回到隱藏狀態,不記住上次的選擇。
|
||
let salaryHidden = true;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 金額:依右上角的幣別(NT$/US$)顯示;US$ 依核心參數的匯率換算。
|
||
function money(v) {
|
||
return PMI18n.amt(v || 0);
|
||
}
|
||
|
||
|
||
|
||
|
||
// The invoice is compared with 夢想創造's CODA without 研發部 (營運 and other companies are shown for reference).
|
||
const DASHBOARD_CODA_EXCLUDE = ['研發部'];
|
||
|
||
function renderDashboard() {
|
||
const current = isSimMode ? simData : baseData;
|
||
const { deptStats, studioTotalDT, studioRawTotalDT } = calculateAll(current);
|
||
initOrgStructure();
|
||
const businessDepts = Object.keys(globalParams.orgStructure);
|
||
|
||
const invoiceSum = calculateInvoiceSummary(current);
|
||
const finalInvoiceTotal = invoiceSum.finalInvoiceTotal;
|
||
const tripInvoices = invoiceSum.tripInvoices;
|
||
const opMult = globalParams.opMultiplier || 2.0;
|
||
const multiplierUnits = dashboardMultiplierUnits(current, businessDepts, deptStats);
|
||
const { overallRatio } = calculateDeptAllocations(current, finalInvoiceTotal);
|
||
|
||
const apPill = document.getElementById('dash-ap-pill');
|
||
if (apPill) apPill.innerHTML = `整體 A:P 成本比 <b>${formatAPRatio(overallRatio)}</b>`;
|
||
const yearPill = document.getElementById('dash-year-pill');
|
||
const wordmarkYear = document.getElementById('wordmark-year');
|
||
if (wordmarkYear) wordmarkYear.textContent = `LeadBoard · ${globalParams.reportYear || 2027} 試算`;
|
||
if (yearPill) yearPill.innerHTML = `<a href="/archive" title="切換年份(查看已封存的年度)" style="color:inherit;text-decoration:none;"><b>${globalParams.reportYear || 2027}</b> ▾</a>`;
|
||
|
||
let diffHtml = '';
|
||
if (isSimMode) {
|
||
const baseResult = calculateAll(baseData);
|
||
const diff = studioTotalDT - baseResult.studioTotalDT;
|
||
diffHtml = `<span style="font-size:12px; color:${diff > 0 ? 'var(--accent-danger)' : 'var(--accent-success)'};">${diff > 0 ? '+' : ''}${PMI18n.amt(diff)}(vs 正式)</span>`;
|
||
}
|
||
|
||
const pageCoda = codaPageByDept(current);
|
||
const companyOfDept = deptCompanyMap(current);
|
||
const mainCoda = Object.entries(pageCoda).filter(([d]) => shortCompanyName(companyOfDept.get(d) || '') === INVOICE_COMPANY && !DASHBOARD_CODA_EXCLUDE.includes(d)).reduce((s, [, v]) => s + v, 0);
|
||
// 全企業總成本 is its own figure: full-time staff (A / P / G, not interns) annual salary × 人薪倍率
|
||
// + 常態型外包 cost × 外包倍率. No 產出率 here; interns are not counted.
|
||
const isContractor = x => String(x.role || '').startsWith('O');
|
||
const staffSalary = current.filter(x => !isContractor(x) && !isCostExcludedIntern(x)).reduce((s, x) => s + (x.realSalaryTotal || 0), 0);
|
||
const contractorRaw = current.filter(isContractor).reduce((s, x) => s + (x.realSalaryTotal || 0), 0);
|
||
const allCost = staffSalary * opMult + contractorRaw * contractorMultiplier();
|
||
// 底線發票(全企業): the invoice that only covers cost — 全企業總成本 + 專案委外 + 員旅, no profit.
|
||
const floorPill = document.getElementById('dash-floor-pill');
|
||
if (floorPill) {
|
||
const floorTotal = allCost + invoiceSum.extOutsource + invoiceSum.tripInvoices;
|
||
floorPill.innerHTML = `底線發票 <b>${PMI18n.sym()} ${money(floorTotal)}</b> <span class="info-tip" tabindex="0" role="button" aria-label="底線發票說明" data-tip="全企業不虧本至少要開的發票,不含利潤:全企業總成本 ${money(allCost)} + 專案委外 ${money(invoiceSum.extOutsource)} + 員旅 ${money(invoiceSum.tripInvoices)}。只供參考,不影響任何計算。">ⓘ</span>`;
|
||
}
|
||
const kpiGrid = document.getElementById('main-kpis');
|
||
if (kpiGrid) {
|
||
kpiGrid.innerHTML = `
|
||
<a href="#" class="kpi kpi-lime" onclick="showView('invoice'); return false;" aria-label="年度發票目標,查看分配明細">
|
||
<span class="kpi-label"><span><span class="dot" style="background:var(--dot-amber)"></span>年度發票目標</span><span class="kpi-go"><svg aria-hidden="true" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 17L17 7M8 7h9v9"></path></svg></span></span>
|
||
<span class="kpi-value"><small>${PMI18n.sym()}</small>${money(finalInvoiceTotal)}</span>
|
||
</a>
|
||
<a href="#" class="kpi kpi-blue" onclick="showView('coda'); return false;" title="與「部門 CODA」頁相同:P + A 成本,不含營運支援與外包">
|
||
<span class="kpi-label"><span><span class="dot"></span>夢想創造 CODA(不含研發部)</span></span>
|
||
<span class="kpi-value"><small>${PMI18n.sym()}</small>${money(mainCoda)}</span>
|
||
</a>
|
||
<div class="kpi kpi-blue">
|
||
<span class="kpi-label"><span><span class="dot"></span>全企業總成本 <span class="info-tip" tabindex="0" role="button" aria-label="全企業總成本說明" data-tip="全體正職 ${money(staffSalary)} × 人薪倍率 ${opMult} + 常態型外包 ${money(contractorRaw)} × ${contractorMultiplier()}">ⓘ</span></span>${diffHtml}</span>
|
||
<span class="kpi-value"><small>${PMI18n.sym()}</small>${money(allCost)}</span>
|
||
</div>
|
||
<div class="kpi kpi-sage" title="年度發票目標 ÷ 夢想創造 CODA(不含研發部)">
|
||
<span class="kpi-label"><span><span class="dot"></span>發票/CODA 覆蓋率</span><span class="kpi-note">${finalInvoiceTotal >= mainCoda ? '多 ' + PMI18n.sym() + ' ' + money(finalInvoiceTotal - mainCoda) : '差 ' + PMI18n.sym() + ' ' + money(mainCoda - finalInvoiceTotal)}</span></span>
|
||
<span class="kpi-value">${mainCoda > 0 ? (finalInvoiceTotal / mainCoda * 100).toFixed(1) : '—'}<small>%</small></span>
|
||
</div>`;
|
||
}
|
||
|
||
// CODA by unit, grouped by company with a subtotal; dark bars carry the invoice.
|
||
// Units at 0 share one line at the bottom.
|
||
const barContainer = document.getElementById('dept-bars');
|
||
if (barContainer) {
|
||
const bearing = new Set(invoiceDepts(current));
|
||
const companyOf = deptCompanyMap(current);
|
||
// Departments touched by CODA sharing scale their multiplier by shared ÷ own CODA.
|
||
const ownCoda = codaPageByDept(current, true);
|
||
const multOf = (d, val) => {
|
||
const m = deptStats[d].multiplier || 0;
|
||
if (!m || Math.abs(val - (ownCoda[d] || 0)) < 0.5) return m;
|
||
return ownCoda[d] > 0 ? m * val / ownCoda[d] : 0;
|
||
};
|
||
const units = businessDepts.filter(d => deptStats[d]).map(d => ({ d, s: deptStats[d], company: shortCompanyName(companyOf.get(d) || '') || '未對應公司', val: pageCoda[d] || 0, mult: multOf(d, pageCoda[d] || 0) }));
|
||
const shown = units.filter(u => u.val > 0);
|
||
const empty = units.filter(u => u.val <= 0);
|
||
const maxCoda = Math.max(...shown.map(u => u.val), 1);
|
||
const groups = [];
|
||
shown.forEach(u => { let g = groups.find(x => x.company === u.company); if (!g) groups.push(g = { company: u.company, units: [], total: 0 }); g.units.push(u); g.total += u.val; });
|
||
groups.sort((x, y) => y.total - x.total);
|
||
barContainer.innerHTML = groups.map(g => `
|
||
<div class="coda-group">
|
||
<div class="coda-group-head"><span>${escapeHtml(g.company)}</span><span>${money(g.total)}</span></div>
|
||
${g.units.sort((x, y) => y.val - x.val).map(u => `
|
||
<div class="coda-row">
|
||
<div class="top"><span>${escapeHtml(u.d)}<span class="mult">${u.mult ? (u.mult * opMult).toFixed(2) + 'x' : '—'}</span></span><span>${money(u.val)}</span></div>
|
||
<div class="track"><span style="width:${(u.val / maxCoda * 100).toFixed(1)}%; background:${bearing.has(u.d) ? 'var(--bar-strong)' : 'var(--bar-soft)'};"></span></div>
|
||
</div>`).join('')}
|
||
</div>`).join('') + (empty.length ? `<div class="card-foot"><span>CODA 為 0(只有營運支援或外包,或已分攤至其他部門):${empty.map(u => escapeHtml(u.d)).join('、')}</span></div>` : '');
|
||
}
|
||
|
||
const tiles = document.getElementById('dash-multipliers');
|
||
if (tiles) {
|
||
const top = Math.max(...multiplierUnits.map(u => u.multiplier), 0);
|
||
tiles.innerHTML = multiplierUnits.map(u => {
|
||
const cls = u.company ? 'tile sage' : (u.multiplier === top ? 'tile lime' : 'tile');
|
||
const note = u.company ? ' · 全公司' : (u.multiplier === top ? ' · 最高' : '');
|
||
return `<div class="${cls}" ${u.company ? `title="${escapeHtml(u.label)} 全公司(含未歸部門人員)"` : ''}><span class="v">${(u.multiplier * opMult).toFixed(2)}x</span><span class="l">${escapeHtml(u.label)}${note}</span></div>`;
|
||
}).join('');
|
||
}
|
||
|
||
renderDeptInvoiceTargets(current, finalInvoiceTotal, pageCoda);
|
||
|
||
renderParams();
|
||
renderGroup();
|
||
renderRoleStats(current);
|
||
renderPersonnelOverview();
|
||
}
|
||
|
||
// Per-department invoice targets on the dashboard: one row per department.
|
||
function renderDeptInvoiceTargets(current, finalInvoiceTotal, pageCoda) {
|
||
const container = document.getElementById('dept-invoice-targets');
|
||
if (!container) return;
|
||
const { deptData } = calculateDeptAllocations(current, finalInvoiceTotal);
|
||
const businessDepts = invoiceDepts(current);
|
||
const codaOf = d => (pageCoda && pageCoda[d]) || 0;
|
||
const maxVal = Math.max(...businessDepts.map(d => Math.max(deptData[d].invoiceTarget, codaOf(d))), 1);
|
||
const pctW = v => (v / maxVal * 100).toFixed(1);
|
||
container.innerHTML = businessDepts.map(d => {
|
||
const data = deptData[d];
|
||
const coda = codaOf(d);
|
||
const gap = data.invoiceTarget - coda;
|
||
return `
|
||
<div class="inv-row">
|
||
<div class="top"><span class="name">${escapeHtml(d)} ${leanBadge(data, true)}</span><span class="amount">${money(data.invoiceTarget)}</span></div>
|
||
<div class="pair">
|
||
<div class="track"><span style="width:${pctW(data.invoiceTarget)}%; background:var(--bar-strong);"></span></div>
|
||
<div class="track"><span style="width:${pctW(coda)}%; background:var(--bar-soft);"></span></div>
|
||
</div>
|
||
<div class="meta"><span>CODA <b>${money(coda)}</b> · 差額 <b>${gap >= 0 ? '+' : '−'}${money(Math.abs(gap))}</b></span><span>佔比 <b>${(data.finalPct * 100).toFixed(1)}%</b> · 上半年 <b>${money(data.invoiceTarget / 2)}</b></span></div>
|
||
</div>`;
|
||
}).join('') + `
|
||
<div class="card-foot" style="justify-content:flex-start;">
|
||
<span>燈號依四部門 A:P 成本比相對排名:</span>
|
||
<span><span class="dot" style="background:var(--st-lean-dot)"></span>精實</span>
|
||
<span><span class="dot" style="background:var(--st-nearlean-dot)"></span>接近精實</span>
|
||
<span><span class="dot" style="background:var(--st-nearover-dot)"></span><span class="dot" style="background:var(--st-high-dot)"></span>臨近超標</span>
|
||
<span><span class="dot" style="background:var(--st-over-dot)"></span>超標</span>
|
||
</div>`;
|
||
}
|
||
|
||
|
||
const LEAN_STYLES = {
|
||
lean: { label: '精實', color: 'var(--st-lean-fg)', bg: 'var(--st-lean-bg)', dot: 'var(--st-lean-dot)' },
|
||
nearLean: { label: '接近精實', color: 'var(--st-nearlean-fg)', bg: 'var(--st-nearlean-bg)', dot: 'var(--st-nearlean-dot)' },
|
||
nearOver: { label: '臨近超標', color: 'var(--st-nearover-fg)', bg: 'var(--st-nearover-bg)', dot: 'var(--st-nearover-dot)' },
|
||
nearOverHigh: { label: '臨近超標', color: 'var(--st-high-fg)', bg: 'var(--st-high-bg)', dot: 'var(--st-high-dot)' },
|
||
over: { label: '超標', color: 'var(--st-over-fg)', bg: 'var(--st-over-bg)', dot: 'var(--st-over-dot)' },
|
||
};
|
||
|
||
function formatAPRatio(r) {
|
||
return Number.isFinite(r) ? `${r.toFixed(1)} : 1` : '無 P';
|
||
}
|
||
|
||
function formatPGap(v, base) {
|
||
if (Math.abs(v) < 0.05) return `與${base}相同`;
|
||
return `比${base}${v > 0 ? '多' : '少'} ${Math.abs(v).toFixed(1)} 位 P`;
|
||
}
|
||
|
||
function leanBadge(data, compact) {
|
||
const lean = data.lean || { status: 'nearLean' };
|
||
const style = LEAN_STYLES[lean.status] || LEAN_STYLES.nearOver;
|
||
const dot = `<span aria-hidden="true" style="display:inline-block; width:6px; height:6px; border-radius:50%; background:${style.dot}; margin-right:5px; vertical-align:1px;"></span>`;
|
||
const pill = `<span style="font-size:12px; color:${style.color}; background:${style.bg}; padding:${compact ? '3px 9px' : '4px 10px'}; border-radius:999px; white-space:nowrap;">${dot}${style.label}</span>`;
|
||
if (compact || !data.lean) return pill;
|
||
// P cost compared with the overall A:P cost ratio of the invoice-bearing departments.
|
||
const gap = lean.vsOverall;
|
||
const wan = v => PMI18n.compact(v);
|
||
const gapText = `成本比 ${formatAPRatio(lean.ratio)} · ${Math.abs(gap) < 5000 ? '與平均相同' : `P 比平均${gap > 0 ? '多' : '少'} ${wan(gap)}`}`;
|
||
return `<div class="m3-cell" title="A:P 成本比 ${formatAPRatio(lean.ratio)}(承擔部門平均 ${formatAPRatio(lean.overallRatio)})。A 成本含常態型外包。">
|
||
<div class="m3-line"><span class="m3-pct">${(data.m3 * 100).toFixed(2)}%</span>${pill}</div>
|
||
<div class="m3-gap">${gapText}</div>
|
||
</div>`;
|
||
}
|
||
|
||
// 發票頁的定錨數字(全年/H1/H2 與異動),從伺服器讀;還沒讀過就先讀一次再重畫。
|
||
let anchorInvoiceLoading = false;
|
||
function anchoredInvoiceHtml(d, inline) {
|
||
const st = anchorState;
|
||
const v = st?.active && st.invoice?.[d];
|
||
if (!v) return '';
|
||
const m = x => PMI18n.amt(x || 0);
|
||
if (inline) return `<div style="font-size:0.75rem;color:var(--text-dim);font-weight:500;">定錨後 ${PMI18n.sym()} ${m(v.annual)} H1 ${m(v.h1)}${v.h2 === null ? '' : ` H2 ${m(v.h2)}`}</div>`;
|
||
const changes = (st.changes || []).filter(c => c.dept === d || c.from?.dept === d);
|
||
const typeLabel = { new: '新進', leave: '離職', cost: '調薪/成本變動', role: '職能改變', transfer: '調動' };
|
||
return `<div style="padding:0.75rem 1.5rem;font-size:0.85rem;border-bottom:1px solid var(--line);">
|
||
<b>定錨(${st.active.half})</b>:定錨全年 ${PMI18n.sym()} ${m(v.anchored)} 調動移轉 ${v.transferNet >= 0 ? '+' : '−'}${m(Math.abs(v.transferNet))} 半年內增加(最高點)+${m(v.peak)} = 全年 ${PMI18n.sym()} ${m(v.annual)} | H1 ${PMI18n.sym()} ${m(v.h1)}${v.h1Settled ? '(已結算)' : ''} H2 ${v.h2 === null ? `${PMI18n.sym()} ${m(v.annual - v.h1)}(暫定)` : `${PMI18n.sym()} ${m(v.h2)}`}
|
||
${changes.length ? `<div style="margin-top:.4rem;color:var(--text-dim);">異動:${changes.map(c => `${typeLabel[c.type] || c.type} ${escapeHtml(c.name)}${c.type === 'transfer' ? `(${escapeHtml(c.from.dept)} → ${escapeHtml(c.dept)})` : `(發票 ${c.invoiceDelta >= 0 ? '+' : ''}${m(c.invoiceDelta)})`}`).join('、')}</div>` : ''}
|
||
</div>`;
|
||
}
|
||
|
||
function renderInvoice() {
|
||
if (!anchorState && !anchorInvoiceLoading) {
|
||
anchorInvoiceLoading = true;
|
||
fetch('/api/anchors', { cache: 'no-store' }).then(r => r.ok ? r.json() : null).then(data => {
|
||
if (data) { anchorState = data; if (data.active) renderInvoice(); }
|
||
}).catch(() => {});
|
||
}
|
||
const current = isSimMode ? simData : baseData;
|
||
calculateAll(current);
|
||
const res = calculateInvoiceSummary(current);
|
||
const finalInvoiceTotal = res.finalInvoiceTotal;
|
||
const tripInvoices = res.tripInvoices;
|
||
|
||
const { deptData, totalWeight3, wP, wA, wS, overallRatio } = calculateDeptAllocations(current, finalInvoiceTotal);
|
||
const businessDepts = invoiceDepts(current);
|
||
|
||
const pManagerReductionPct = Number(globalParams.pManagerReductionPct ?? 0.6);
|
||
const pPCReductionPct = Number(globalParams.pPCReductionPct ?? 0.7);
|
||
|
||
const _authUserInv = typeof getCurrentUser === 'function' ? getCurrentUser() : null;
|
||
const _isAdminInv = !_authUserInv || _authUserInv.role === 'admin';
|
||
|
||
const container = document.getElementById('invoice');
|
||
if (!container) return;
|
||
|
||
// Company of each department: the company most of its HR staff belong to.
|
||
const deptCompanyVotes = {};
|
||
current.filter(p => !(p.role || '').startsWith('O') && p.company && p.dept).forEach(p => {
|
||
deptCompanyVotes[p.dept] = deptCompanyVotes[p.dept] || {};
|
||
deptCompanyVotes[p.dept][p.company] = (deptCompanyVotes[p.dept][p.company] || 0) + 1;
|
||
});
|
||
const companyOfDept = d => {
|
||
const votes = deptCompanyVotes[d];
|
||
return votes ? Object.entries(votes).sort((a, b) => b[1] - a[1])[0][0] : '未對應公司';
|
||
};
|
||
const deptCards = [];
|
||
|
||
let tableRowsHtml = '';
|
||
businessDepts.forEach((d, i) => {
|
||
if (!_isAdminInv && _authUserInv.dept && d !== _authUserInv.dept) return;
|
||
tableRowsHtml = '';
|
||
|
||
const data = deptData[d];
|
||
data.m3 = totalWeight3 > 0 ? (data.weight3 / totalWeight3) : 0;
|
||
data.finalPct = (data.m1 * wP) + (data.m2 * wA) + (data.m3 * wS);
|
||
data.invoiceTarget = finalInvoiceTotal * data.finalPct;
|
||
|
||
const surplusBadge = leanBadge(data, false);
|
||
|
||
const tripTargetAnnual = tripInvoices * data.finalPct;
|
||
const tripTargetHalf = tripTargetAnnual / 2;
|
||
|
||
const pPeople = current.filter(p => p.dept === d && p.role.startsWith('P'));
|
||
const pWithEffective = pPeople.map(p => {
|
||
const raw = p.totalCost || 0;
|
||
let disc = 1.0;
|
||
const isPCRole = isProductionCoordinator(p);
|
||
if (p.isManager) disc = pManagerReductionPct;
|
||
if (isPCRole) disc = pPCReductionPct;
|
||
return { ...p, effectiveCost: raw * disc, isPCRole };
|
||
});
|
||
|
||
const totalEffectiveP = pWithEffective.reduce((s, p) => s + p.effectiveCost, 0);
|
||
|
||
let pRowsHtml = '';
|
||
pWithEffective.forEach(p => {
|
||
const sharePct = totalEffectiveP > 0 ? (p.effectiveCost / totalEffectiveP) : 0;
|
||
const personalInvoice = data.invoiceTarget * sharePct;
|
||
let discBadge = '';
|
||
let discLabel = '有效比例 (全額承擔)';
|
||
if (p.isPCRole) {
|
||
discBadge = `<span style="background:color-mix(in srgb, var(--accent-success) 15%, transparent); color:var(--accent-success); font-size:0.75rem; padding:1px 6px; border-radius:4px; margin-left:4px;">PC ×${pPCReductionPct}</span>`;
|
||
discLabel = `有效比例 (×${pPCReductionPct} PC承擔)`;
|
||
} else if (p.isManager) {
|
||
discBadge = `<span style="background:color-mix(in srgb, var(--accent-secondary) 15%, transparent); color:var(--accent-secondary-text); font-size:0.75rem; padding:1px 6px; border-radius:4px; margin-left:4px;">管理職 ×${pManagerReductionPct}</span>`;
|
||
discLabel = `有效比例 (×${pManagerReductionPct} 主管承擔)`;
|
||
}
|
||
|
||
pRowsHtml += `
|
||
<div class="invoice-allocation-row" style="padding:0.5rem 1.25rem; border-bottom:1px solid var(--wash);">
|
||
<div style="display:flex; align-items:center; gap:6px;">
|
||
<span style="font-weight:700; font-size:0.9rem; color:var(--text-main);">${p.name}</span>
|
||
${discBadge}
|
||
<span style="font-size:0.75rem; color:var(--text-dim);">${p.title || ''}</span>
|
||
</div>
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
<div style="text-align:center;">
|
||
<div style="font-size:0.95rem; font-weight:700; color:var(--accent-warning);">${(sharePct * 100).toFixed(2)}%</div>
|
||
<div style="font-size:0.75rem; color:var(--text-dim);">${discLabel}</div>
|
||
</div>
|
||
<div style="text-align:right; font-weight:800; color:var(--text-main); font-size:0.95rem;">
|
||
${PMI18n.cur(personalInvoice)}
|
||
</div>
|
||
<div style="text-align:right; font-size:0.75rem; color:var(--accent-success);">
|
||
${PMI18n.cur(tripTargetAnnual * sharePct)}
|
||
</div>
|
||
<div></div>
|
||
</div>
|
||
`;
|
||
});
|
||
|
||
const safeDeptId = 'dept_' + i;
|
||
tableRowsHtml += `
|
||
<div style="margin-bottom: 0.75rem; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg-glass);">
|
||
<div class="invoice-allocation-row" onclick="toggleInvoiceDept('${safeDeptId}')" style="padding: 1rem 1.25rem; cursor:pointer;">
|
||
<div style="font-weight: 700; color:var(--text-main); font-size:1rem; display:flex; align-items:center; gap:6px;">
|
||
<span id="invoice-chevron-${safeDeptId}" style="font-size:0.75rem; color:var(--text-dim);">▶</span>
|
||
${d}
|
||
</div>
|
||
<div style="text-align:center;">
|
||
<div style="font-size:0.9rem; color:var(--accent-secondary-text); font-weight:700;">${(data.m1 * 100).toFixed(2)}%</div>
|
||
</div>
|
||
<div style="text-align:center;">
|
||
<div style="font-size:0.9rem; color:var(--accent-primary-text); font-weight:700;">${(data.m2 * 100).toFixed(2)}%</div>
|
||
</div>
|
||
<div style="text-align:center;">${surplusBadge}</div>
|
||
<div style="text-align:center; font-weight:800; color:var(--text-main);">${(data.finalPct * 100).toFixed(2)}%</div>
|
||
<div style="text-align:right; font-weight:800; color:var(--text-main);">${PMI18n.cur(data.invoiceTarget)}${anchoredInvoiceHtml(d, true)}</div>
|
||
<div style="text-align:right; color:var(--accent-secondary-text); font-size:0.85rem;">${PMI18n.cur(tripTargetAnnual)}</div>
|
||
<div></div>
|
||
</div>
|
||
<div id="invoice-detail-${safeDeptId}" style="display:none; border-top:1px solid var(--line);">
|
||
${anchoredInvoiceHtml(d, false)}
|
||
${pRowsHtml}
|
||
</div>
|
||
</div>
|
||
`;
|
||
deptCards.push({ dept: d, company: companyOfDept(d), html: tableRowsHtml, data, trip: tripTargetAnnual });
|
||
});
|
||
|
||
// Group department cards by company (display only; the allocation itself is company-wide).
|
||
const companyGroups = new Map();
|
||
deptCards.forEach(card => {
|
||
if (!companyGroups.has(card.company)) companyGroups.set(card.company, []);
|
||
companyGroups.get(card.company).push(card);
|
||
});
|
||
const companyNames = [...companyGroups.keys()].sort((a, b) =>
|
||
companyGroups.get(b).reduce((s, c) => s + c.data.invoiceTarget, 0) - companyGroups.get(a).reduce((s, c) => s + c.data.invoiceTarget, 0));
|
||
window.invoiceCompanyFilter = window.invoiceCompanyFilter || 'all';
|
||
const pct = v => `${(v * 100).toFixed(2)}%`;
|
||
tableRowsHtml = companyNames.filter(name => window.invoiceCompanyFilter === 'all' || name === window.invoiceCompanyFilter).map(name => {
|
||
const cards = companyGroups.get(name);
|
||
const sum = key => cards.reduce((s, c) => s + (c.data[key] || 0), 0);
|
||
const tripSum = cards.reduce((s, c) => s + c.trip, 0);
|
||
return `
|
||
<div class="invoice-allocation-row" style="padding: 0.9rem 1.25rem; margin: 1.25rem 0 0.5rem; border-radius: 12px; background: color-mix(in srgb, var(--accent-primary) 8%, transparent); border: 1px solid color-mix(in srgb, var(--accent-primary) 25%, transparent);">
|
||
<div style="font-weight: 800; color: var(--text-main); font-size: 1.05rem;">${escapeHtml(shortCompanyName(name))}<span style="font-size:0.75rem; font-weight:400; color:var(--text-dim); margin-left:6px;">${cards.length} 個部門</span></div>
|
||
<div style="text-align:center; font-weight:700; color:var(--accent-secondary-text);">${pct(sum('m1'))}</div>
|
||
<div style="text-align:center; font-weight:700; color:var(--accent-primary-text);">${pct(sum('m2'))}</div>
|
||
<div style="text-align:center; font-weight:700; color:var(--accent-warning);">${pct(sum('m3'))}</div>
|
||
<div style="text-align:center; font-weight:800; color:var(--text-main);">${pct(sum('finalPct'))}</div>
|
||
<div style="text-align:right; font-weight:800; color:var(--text-main);">${PMI18n.cur(sum('invoiceTarget'))}</div>
|
||
<div style="text-align:right; color:var(--accent-secondary-text); font-size:0.85rem;">${PMI18n.cur(tripSum)}</div>
|
||
<div></div>
|
||
</div>
|
||
${cards.map(c => c.html).join('')}`;
|
||
}).join('');
|
||
|
||
// Shared-cost units (role "share") are in the invoice total but get no allocation.
|
||
const companyMap = deptCompanyMap(current);
|
||
const sharedCost = res.sharedCost || 0;
|
||
|
||
// Units outside the invoice (role "exclude"): annual salary cost × 人薪倍率 only.
|
||
const opMultiplier = Number(globalParams.opMultiplier) || 1;
|
||
const others = new Map();
|
||
current.forEach(p => {
|
||
const company = personCompany(p, companyMap) || '未指定公司';
|
||
if (personInvoiceRole(p, companyMap) !== 'exclude') return;
|
||
if (!others.has(company)) others.set(company, new Map());
|
||
const dept = (p.dept || '').trim() || '未歸部門';
|
||
const depts = others.get(company);
|
||
if (!depts.has(dept)) depts.set(dept, { people: 0, pending: 0, contractors: 0, salary: 0, cost: 0 });
|
||
const row = depts.get(dept);
|
||
row.people += 1;
|
||
const contractor = (p.role || '').startsWith('O');
|
||
if (contractor) row.contractors += 1;
|
||
const counted = contractor || p.source !== 'hr-sync' || p.calculationReady || p.costCountedUnclassified;
|
||
if (!counted) { row.pending += 1; return; }
|
||
const salary = p.realSalaryTotal || 0;
|
||
row.salary += salary;
|
||
row.cost += p.totalCost || 0;
|
||
});
|
||
const otherNames = [...others.keys()].sort((x, y) =>
|
||
[...others.get(y).values()].reduce((s, r) => s + r.cost, 0) - [...others.get(x).values()].reduce((s, r) => s + r.cost, 0));
|
||
const allCompanyNames = [...companyNames, ...otherNames];
|
||
if (!allCompanyNames.includes(window.invoiceCompanyFilter)) window.invoiceCompanyFilter = 'all';
|
||
const money = v => PMI18n.cur(v);
|
||
const otherHtml = otherNames.filter(n => window.invoiceCompanyFilter === 'all' || n === window.invoiceCompanyFilter).map(name => {
|
||
const rows = [...others.get(name).entries()].sort((x, y) => y[1].cost - x[1].cost);
|
||
const total = rows.reduce((acc, [, r]) => ({ people: acc.people + r.people, pending: acc.pending + r.pending, salary: acc.salary + r.salary, cost: acc.cost + r.cost }), { people: 0, pending: 0, salary: 0, cost: 0 });
|
||
const line = (label, r, strong) => `
|
||
<tr style="${strong ? 'background:var(--wash); font-weight:800;' : ''}">
|
||
<td style="${strong ? '' : 'padding-left:2rem;'}">${label}</td>
|
||
<td class="num">${r.people} 人${r.pending ? `<div style="font-size:0.75rem; color:var(--accent-warning);">${r.pending} 位待確認未計入</div>` : ''}${r.contractors ? `<div style="font-size:0.75rem; color:var(--accent-warning);">含外包 ${r.contractors}</div>` : ''}</td>
|
||
<td class="num">${money(r.salary)}</td>
|
||
<td class="num" style="color:var(--accent-primary-text);">${money(r.cost)}</td>
|
||
</tr>`;
|
||
return `
|
||
<div class="card" style="margin-top:1rem; padding:0;">
|
||
<table class="ex-table">
|
||
<colgroup><col><col class="c-people"><col class="c-money"><col class="c-money"></colgroup>
|
||
<thead><tr><th>${escapeHtml(shortCompanyName(name))}</th><th class="num">人數</th><th class="num">年度薪資成本</th><th class="num">成本(× 人薪倍率)</th></tr></thead>
|
||
<tbody>
|
||
${line('公司合計', total, true)}
|
||
${rows.map(([dept, r]) => line(escapeHtml(dept), r, false)).join('')}
|
||
</tbody>
|
||
</table>
|
||
</div>`;
|
||
}).join('');
|
||
|
||
const filterHtml = `
|
||
<div style="display:flex; gap:0.75rem; align-items:center; flex-wrap:wrap; margin-bottom:1rem;">
|
||
<select class="btn btn-outline" style="min-width:150px; cursor:pointer;" onchange="window.invoiceCompanyFilter=this.value; renderInvoice();">
|
||
<option value="all" ${window.invoiceCompanyFilter === 'all' ? 'selected' : ''}>所有公司</option>
|
||
${allCompanyNames.map(n => `<option value="${escapeHtml(n)}" ${window.invoiceCompanyFilter === n ? 'selected' : ''}>${escapeHtml(shortCompanyName(n))}</option>`).join('')}
|
||
</select>
|
||
</div>
|
||
<div class="inv-explain">
|
||
<div class="inv-explain-title">發票總額 <b>${money(finalInvoiceTotal)}</b> 怎麼來</div>
|
||
<div class="inv-formula">內部人力成本 <b>${money(res.totalPA)}</b> ÷ 毛利率 <b>${Math.round(res.grossMargin * 100)}%</b> + 常態型外包 <b>${money(res.totalORaw)}</b> × ${contractorMultiplier()} + 專案委外 <b>${money(res.extOutsource)}</b> + 員旅 <b>${money(res.tripInvoices)}</b></div>
|
||
<ul>
|
||
<li><b>誰來分:</b>只有「承擔發票」的部門分這筆總額,依下面三個指標的加權比例分配。${sharedCost > 0 ? `「成本分攤」單位的成本 ${money(sharedCost)} 也算在內,由承擔部門吸收。` : ''}</li>
|
||
<li><b>不計入的單位:</b>不分發票,列出年度薪資成本與成本供參考。角色在「核心參數 › 發票承擔設定」調整。</li>
|
||
<li><b>「成本」的意思:</b>本站的成本=年薪 × 人薪倍率 ${opMultiplier};A 再除以產出率 ${Math.round((globalParams.utilizationA ?? 1) * 100)}%。「年度薪資成本」是實際年薪。</li>
|
||
<li><b>燈號:</b>依四個部門的 A:P 成本比<b>相對排名</b>:最精實的是「精實」、最重的是「超標」,其餘和四部門平均比較,分成「接近精實」和「臨近超標」(橘色表示比其他臨近超標的部門更重)。燈號只是標示,不影響計算。</li>
|
||
<li><b>指標3 P 輕重:</b>P 成本 × (P 成本 ÷ A 成本),A 成本含常態型外包,再換算成四個部門的佔比;A:P 成本比 = A 成本 ÷ P 成本。</li>
|
||
</ul>
|
||
</div>`;
|
||
|
||
container.innerHTML = `
|
||
<h1 style="margin-bottom:1rem;">年度發票額</h1>
|
||
${filterHtml}
|
||
<div class="invoice-allocation-scroll">
|
||
<div class="invoice-allocation-table">
|
||
<div class="invoice-allocation-row" id="invoice-allocation-headings" style="padding:0.75rem 1.25rem; margin:0 1px 0.5rem;">
|
||
<div style="font-size:0.75rem; color:var(--text-dim);">公司/部門/人員</div>
|
||
<div style="font-size:0.75rem; color:var(--accent-secondary-text); text-align:center;">指標1 P佔比<br><span style="color:var(--text-muted);">權重 ${(wP * 100).toFixed(0)}%</span></div>
|
||
<div style="font-size:0.75rem; color:var(--accent-primary-text); text-transform:uppercase; letter-spacing:0.5px; text-align:center;">指標2 A佔比<br><span style="color:var(--text-muted);">權重 ${(wA * 100).toFixed(0)}%</span></div>
|
||
<div style="font-size:0.75rem; color:var(--accent-warning); text-transform:uppercase; letter-spacing:0.5px; text-align:center;">指標3 P 輕重 <span class="info-tip" tabindex="0" role="button" aria-label="指標3 說明" data-tip="指標3=P 成本 × (P 成本 ÷ A 成本),A 成本含常態型外包,再換算成佔比:P 相對 A 越重,分得越多。下方「P 比平均多/少」是和四部門整體成本比(${formatAPRatio(overallRatio)})相比。">ⓘ</span><br><span style="color:var(--text-muted);">權重 ${(wS * 100).toFixed(0)}%</span></div>
|
||
<div style="font-size:0.75rem; color:var(--text-dim); text-transform:uppercase; letter-spacing:0.5px; text-align:center;">最終比例</div>
|
||
<div style="font-size:0.75rem; color:var(--text-dim); text-transform:uppercase; letter-spacing:0.5px; text-align:right;">責任發票額</div>
|
||
<div style="font-size:0.75rem; color:var(--accent-secondary-text); text-transform:uppercase; letter-spacing:0.5px; text-align:right;">員旅配額</div>
|
||
<div></div>
|
||
</div>
|
||
|
||
<!-- Dept Accordion Cards -->
|
||
<div id="invoice-dept-list">
|
||
${tableRowsHtml}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
${otherHtml ? `<h2 style="margin-top:2rem; font-size:1.1rem;">不計入發票的單位(成本 × 人薪倍率)</h2><div id="invoice-other-companies">${otherHtml}</div>` : ''}
|
||
|
||
<div class="card" style="margin-top: 2rem; padding: 1rem 1.5rem; background: color-mix(in srgb, var(--accent-secondary) 6%, transparent); border-color: color-mix(in srgb, var(--accent-secondary) 15%, transparent); font-size:0.82rem; color:var(--text-dim);">
|
||
<div style="font-weight:700; color:var(--accent-secondary-text); margin-bottom:0.5rem;">P 人員承擔比計算說明</div>
|
||
<div style="display:flex; gap:2rem; flex-wrap:wrap; line-height:1.8;">
|
||
<span>一般 P:有效承擔成本 = 全額薪資成本(×100%)</span>
|
||
<span>P 管理職(isManager):有效承擔成本 × <strong style="color:var(--accent-secondary-text);">${(pManagerReductionPct * 100).toFixed(0)}%</strong>(釋出 ${((1 - pManagerReductionPct) * 100).toFixed(0)}%)</span>
|
||
<span>PC(Production Coordinator):有效承擔成本 × <strong style="color:var(--accent-success);">${(pPCReductionPct * 100).toFixed(0)}%</strong>(釋出 ${((1 - pPCReductionPct) * 100).toFixed(0)}%)</span>
|
||
<span>各 P 的個人承擔額 = 部門發票目標 × (個人有效成本 / 部門有效P成本合計)</span>
|
||
</div>
|
||
</div>
|
||
`;
|
||
}
|
||
|
||
|
||
|
||
function renderPersonnelOverview() {
|
||
const current = isSimMode ? simData : baseData;
|
||
const { deptStats, studioRawTotalDT } = calculateAll(current);
|
||
const container = document.getElementById('dept-cost-stack-chart');
|
||
const kpiGrid = document.getElementById('dept-kpi-grid');
|
||
const orderedDepts = Object.keys(globalParams.orgStructure);
|
||
|
||
// Calculate P, A, and O breakdown per department and globally
|
||
const deptBreakdowns = {};
|
||
let globalP = 0;
|
||
let globalA = 0;
|
||
let globalO = 0;
|
||
orderedDepts.forEach(d => { deptBreakdowns[d] = { p: 0, a: 0, o: 0 }; });
|
||
|
||
current.forEach(person => {
|
||
const cost = person.totalCost || 0;
|
||
if (person.role.startsWith('P')) {
|
||
globalP += cost;
|
||
if (deptBreakdowns[person.dept]) deptBreakdowns[person.dept].p += cost;
|
||
} else if (person.role.startsWith('A')) {
|
||
globalA += cost;
|
||
if (deptBreakdowns[person.dept]) deptBreakdowns[person.dept].a += cost;
|
||
} else if (person.role.startsWith('O')) {
|
||
globalO += cost;
|
||
if (deptBreakdowns[person.dept]) deptBreakdowns[person.dept].o += cost;
|
||
}
|
||
});
|
||
|
||
// 1. Render Stacked Bar + Grand Total Header with Global PAO
|
||
let stackHtml = `
|
||
<div style="display:flex; justify-content:space-between; align-items:flex-end; margin-bottom: 0.5rem;">
|
||
<div style="font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px;">原始薪資預算總計</div>
|
||
<div style="font-size: 1.5rem; font-weight: 800; color: var(--text-main);">${PMI18n.cur(studioRawTotalDT)}</div>
|
||
</div>
|
||
<div style="display:flex; gap: 1rem; margin-bottom: 1.2rem; font-size: 0.8rem; background: var(--inset); padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-glass);">
|
||
<div style="display:flex; align-items:center; gap: 6px;">
|
||
<span style="color:var(--accent-secondary-text); background:color-mix(in srgb, var(--accent-secondary) 10%, transparent); padding:2px 6px; border-radius:4px;">全公司 P 總計</span>
|
||
<span style="font-weight:700; color:var(--accent-secondary-text);">${PMI18n.cur(globalP)}</span>
|
||
</div>
|
||
<div style="display:flex; align-items:center; gap: 6px; border-left: 1px solid var(--border-glass); padding-left: 1rem;">
|
||
<span style="color:var(--accent-primary-text); background:color-mix(in srgb, var(--accent-primary) 10%, transparent); padding:2px 6px; border-radius:4px;">全公司 A 總計</span>
|
||
<span style="font-weight:700; color:var(--accent-primary-text);">${PMI18n.cur(globalA)}</span>
|
||
</div>
|
||
<div style="display:flex; align-items:center; gap: 6px; border-left: 1px solid var(--border-glass); padding-left: 1rem;">
|
||
<span style="color:var(--accent-warning); background:color-mix(in srgb, var(--accent-warning) 12%, transparent); padding:2px 6px; border-radius:4px;">全公司 O 總計</span>
|
||
<span style="font-weight:700; color:var(--accent-warning);">${PMI18n.cur(globalO)}</span>
|
||
</div>
|
||
</div>
|
||
<div class="chart-bar-container">
|
||
`;
|
||
const colors = ['var(--accent-primary)', 'var(--accent-secondary)', 'var(--accent-success)', 'var(--accent-warning)', 'var(--lime)', 'var(--bar-soft)'];
|
||
|
||
// Iterate over ordered departments
|
||
orderedDepts.forEach((d, i) => {
|
||
const s = deptStats[d];
|
||
if (!s) return; // Skip if department has no stats
|
||
const pct = studioRawTotalDT === 0 ? 0 : (s.rawDt / studioRawTotalDT * 100);
|
||
if (pct > 2) {
|
||
stackHtml += `<div class="chart-bar" style="width: ${pct}%; background: ${colors[i % colors.length]}">${d}</div>`;
|
||
}
|
||
});
|
||
stackHtml += '</div>';
|
||
container.innerHTML = stackHtml;
|
||
|
||
// 2. Render KPIs with P, A, and O breakdown
|
||
kpiGrid.innerHTML = '';
|
||
|
||
Object.keys(globalParams.orgStructure).forEach((d, i) => { // Only business departments for this grid
|
||
const s = deptStats[d];
|
||
if (!s) return;
|
||
const parts = deptBreakdowns[d] || { p: 0, a: 0, o: 0 };
|
||
const pct = studioRawTotalDT === 0 ? 0 : (s.rawDt / studioRawTotalDT * 100);
|
||
|
||
const pPct = globalP === 0 ? 0 : (parts.p / globalP * 100);
|
||
const aPct = globalA === 0 ? 0 : (parts.a / globalA * 100);
|
||
|
||
kpiGrid.innerHTML += `
|
||
<div class="card ${i % 2 === 0 ? 'secondary' : 'success'}" style="cursor:pointer; display:flex; flex-direction:column; justify-content:space-between; height: 100%;" onclick="showPersonnelView('${d}')">
|
||
<div>
|
||
<div class="card-label">${d}</div>
|
||
<div class="card-value" style="font-size: 1.25rem;">${PMI18n.cur(s.rawDt)}</div>
|
||
<div class="card-trend">${s.personnel} 人員 | 佔比 ${formatPct(pct)}%</div>
|
||
</div>
|
||
<div style="margin-top: 1rem; border-top: 1px solid var(--wash); padding-top: 0.5rem; display: flex; gap: 0.25rem; flex-direction: column;">
|
||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 2px;">
|
||
<span style="font-size:0.75rem; color:var(--accent-secondary-text); background:color-mix(in srgb, var(--accent-secondary) 10%, transparent); padding:2px 6px; border-radius:4px;">專案 P</span>
|
||
<div style="text-align:right;">
|
||
<span style="font-size:0.8rem; font-weight:700; color:var(--accent-secondary-text);">${PMI18n.cur(parts.p)}</span>
|
||
<span style="font-size:0.75rem; color:var(--text-dim); margin-left: 4px;">(${formatPct(pPct)}%)</span>
|
||
</div>
|
||
</div>
|
||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 2px;">
|
||
<span style="font-size:0.75rem; color:var(--accent-primary-text); background:color-mix(in srgb, var(--accent-primary) 10%, transparent); padding:2px 6px; border-radius:4px;">內製 A</span>
|
||
<div style="text-align:right;">
|
||
<span style="font-size:0.8rem; font-weight:700; color:var(--accent-primary-text);">${PMI18n.cur(parts.a)}</span>
|
||
<span style="font-size:0.75rem; color:var(--text-dim); margin-left: 4px;">(${formatPct(aPct)}%)</span>
|
||
</div>
|
||
</div>
|
||
<div style="display:flex; justify-content:space-between; align-items:center;">
|
||
<span style="font-size:0.75rem; color:var(--accent-warning); background:color-mix(in srgb, var(--accent-warning) 12%, transparent); padding:2px 6px; border-radius:4px;">外包 O</span>
|
||
<span style="font-size:0.8rem; font-weight:700; color:var(--accent-warning);">${PMI18n.cur(parts.o)}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
});
|
||
}
|
||
|
||
function setInvoiceRole(kind, name, role) {
|
||
const roles = globalParams.invoiceRoles = globalParams.invoiceRoles || { companies: {}, depts: {} };
|
||
roles.companies = roles.companies || {};
|
||
roles.depts = roles.depts || {};
|
||
const bucket = kind === 'company' ? roles.companies : roles.depts;
|
||
if (role) bucket[name] = role; else delete bucket[name];
|
||
saveAndRefresh();
|
||
renderInvoiceRoles();
|
||
}
|
||
|
||
// Company default to every department: drop the departments' own choices.
|
||
function resetCompanyDeptRoles(company) {
|
||
const roles = globalParams.invoiceRoles = globalParams.invoiceRoles || { companies: {}, depts: {} };
|
||
roles.depts = roles.depts || {};
|
||
const map = deptCompanyMap(isSimMode ? simData : baseData);
|
||
Object.keys(roles.depts).forEach(d => { if (map.get(d) === company) delete roles.depts[d]; });
|
||
saveAndRefresh();
|
||
renderInvoiceRoles();
|
||
}
|
||
|
||
|
||
// ---- CODA 分配規則(核心參數):來源部門的整包 CODA 依各接收部門的 CODA 比例分下去 ----
|
||
// 沒設定過時用 calc-core 的內建預設;第一次編輯就把內建預設一起寫成明確設定,才不會被默默換掉。
|
||
function effectiveCodaShareRules() {
|
||
return Array.isArray(globalParams.codaShareRules) ? globalParams.codaShareRules : codaShareRules();
|
||
}
|
||
function saveCodaShareRules(rules) {
|
||
globalParams.codaShareRules = rules;
|
||
saveAndRefresh();
|
||
renderInvoiceRoles();
|
||
}
|
||
function removeCodaShareRule(index) {
|
||
saveCodaShareRules(effectiveCodaShareRules().filter((rule, i) => i !== index));
|
||
}
|
||
function addCodaShareRule() {
|
||
const from = document.getElementById('coda-share-from').value;
|
||
const to = [...document.querySelectorAll('.coda-share-to:checked')].map(input => input.value).filter(name => name !== from);
|
||
if (!from || !to.length) { alert('請選擇來源部門,並勾選至少一個接收部門。'); return; }
|
||
const map = deptCompanyMap(isSimMode ? simData : baseData);
|
||
const rules = effectiveCodaShareRules().filter(rule => !(rule.from || []).includes(from));
|
||
rules.push({ company: shortCompanyName(map.get(from) || ''), from: [from], to,
|
||
noDeptP: document.getElementById('coda-share-nodeptp').checked });
|
||
saveCodaShareRules(rules);
|
||
}
|
||
function codaShareCard() {
|
||
const depts = Object.keys(globalParams.orgStructure || {});
|
||
const known = new Set(depts);
|
||
const warn = name => known.has(name) ? escapeHtml(name)
|
||
: `<span style="color:var(--accent-warning);" title="目前名單上沒有這個部門">${escapeHtml(name)}</span>`;
|
||
const rules = effectiveCodaShareRules();
|
||
const rows = rules.map((rule, index) => `
|
||
<div class="ir-row">
|
||
<span class="ir-name">${(rule.from || []).map(warn).join('、')}</span>
|
||
<span class="ir-cost" style="white-space:normal;">分給 ${(rule.to || []).map(warn).join('、')}${rule.noDeptP ? ',並含該公司沒有部門的 P' : ''}</span>
|
||
<span class="ir-src"><button type="button" class="link-button" style="color:var(--accent-danger);" onclick="removeCodaShareRule(${index})">刪除</button></span>
|
||
</div>`).join('') || '<div class="ir-empty">目前沒有分配規則,每個部門的 CODA 都算自己的。</div>';
|
||
const options = depts.map(d => `<option value="${escapeHtml(d)}">${escapeHtml(d)}</option>`).join('');
|
||
const boxes = depts.map(d => `<label style="font-size:.8rem;display:inline-flex;align-items:center;gap:4px;margin-right:10px;white-space:nowrap;"><input type="checkbox" class="coda-share-to" value="${escapeHtml(d)}">${escapeHtml(d)}</label>`).join('');
|
||
return `
|
||
<div class="card ir-card" style="margin-top:1.5rem;">
|
||
<div class="card-head"><h2><span class="dot" style="background:var(--dot-amber)"></span>CODA 分配規則</h2></div>
|
||
<p style="font-size:.8rem;color:var(--text-dim);margin:.25rem 0 .75rem;">把來源部門的整包 CODA,依各接收部門自己的 CODA 比例分下去。來源部門的 CODA 會歸零,也不顯示部門倍率,等於只算成本、不談指標。這裡不影響發票分配,發票看的是上面的「發票承擔設定」。</p>
|
||
<div class="ir-grid"><section class="ir-company">${rows}</section></div>
|
||
<div style="display:grid;grid-template-columns:minmax(160px,1fr) minmax(260px,3fr) auto;gap:.5rem;align-items:start;margin-top:.75rem;">
|
||
<select id="coda-share-from" aria-label="來源部門"><option value="">來源部門…</option>${options}</select>
|
||
<div><div style="font-size:.75rem;color:var(--text-dim);margin-bottom:.25rem;">分給(可複選)</div>${boxes}
|
||
<label style="font-size:.8rem;display:inline-flex;align-items:center;gap:4px;margin-top:.35rem;"><input type="checkbox" id="coda-share-nodeptp">含該公司沒有部門的 P</label>
|
||
</div>
|
||
<button type="button" class="btn-primary" onclick="addCodaShareRule()">+ 加入</button>
|
||
</div>
|
||
<div class="card-foot"><span>同一個來源部門只會有一條規則,重複加入會覆蓋舊的。</span></div>
|
||
</div>`;
|
||
}
|
||
function renderInvoiceRoles() {
|
||
const container = document.getElementById('invoice-roles');
|
||
if (!container) return;
|
||
const current = isSimMode ? simData : baseData;
|
||
initOrgStructure();
|
||
calculateAll(current);
|
||
const map = deptCompanyMap(current);
|
||
const companies = new Map();
|
||
current.filter(p => !(p.role || '').startsWith('O') && p.company).forEach(p => {
|
||
if (!companies.has(p.company)) companies.set(p.company, new Set());
|
||
});
|
||
Object.keys(globalParams.orgStructure).forEach(d => {
|
||
const company = map.get(d);
|
||
if (!company) return;
|
||
if (!companies.has(company)) companies.set(company, new Set());
|
||
companies.get(company).add(d);
|
||
});
|
||
const costOf = filter => current.filter(filter).reduce((s, p) => s + (p.totalCost || 0), 0);
|
||
const money = v => PMI18n.cur(v);
|
||
const seg = (kind, name, role, label) => `
|
||
<div class="role-seg" role="group" aria-label="${escapeHtml(label)}">${['bear', 'share', 'exclude'].map(r => `
|
||
<button type="button" data-r="${r}" aria-pressed="${role === r}" onclick='setInvoiceRole(${escapeHtml(JSON.stringify(kind))}, ${escapeHtml(JSON.stringify(name))}, "${r}")'>${INVOICE_ROLE_LABELS[r]}</button>`).join('')}
|
||
</div>`;
|
||
const savedDepts = globalParams.invoiceRoles?.depts || {};
|
||
const companyBlocks = [...companies.entries()].sort((a, b) => (companyDefaultRole(a[0]) === 'bear' ? 0 : 1) - (companyDefaultRole(b[0]) === 'bear' ? 0 : 1) || b[1].size - a[1].size || a[0].localeCompare(b[0], 'zh-Hant')).map(([company, depts]) => {
|
||
const short = shortCompanyName(company);
|
||
const cRole = companyDefaultRole(company);
|
||
const anyCustom = [...depts].some(d => Object.prototype.hasOwnProperty.call(savedDepts, d));
|
||
const deptRows = [...depts].sort((a, b) => a.localeCompare(b, 'zh-Hant')).map(d => {
|
||
const custom = Object.prototype.hasOwnProperty.call(savedDepts, d);
|
||
const role = deptRole(d, company);
|
||
const cost = costOf(p => (p.dept || '').trim() === d);
|
||
return `
|
||
<div class="ir-row">
|
||
<span class="ir-name">${escapeHtml(d)}</span>
|
||
<span class="ir-cost">${money(cost)}</span>
|
||
${seg('dept', d, role, d + ' 發票角色')}
|
||
<span class="ir-src">${custom ? `<button type="button" class="link-button" onclick='setInvoiceRole("dept", ${escapeHtml(JSON.stringify(d))}, "")'>改回跟隨</button>` : '跟隨公司'}</span>
|
||
</div>`;
|
||
}).join('');
|
||
return `
|
||
<section class="ir-company">
|
||
<div class="ir-head">
|
||
<span class="ir-name"><b>${escapeHtml(short)}</b><small>${depts.size} 個部門 · 預設</small></span>
|
||
${seg('company', company, cRole, short + ' 公司預設')}
|
||
<span class="ir-src">${anyCustom ? `<button type="button" class="link-button" onclick='resetCompanyDeptRoles(${escapeHtml(JSON.stringify(company))})'>全部跟隨</button>` : ''}</span>
|
||
</div>
|
||
${deptRows || '<div class="ir-empty">沒有部門,公司內所有人套用公司預設。</div>'}
|
||
</section>`;
|
||
}).join('');
|
||
|
||
const bearDepts = invoiceDepts(current);
|
||
const inv = calculateInvoiceSummary(current);
|
||
const excludedCost = costOf(p => personInvoiceRole(p, map) === 'exclude');
|
||
const stale = Object.keys(savedDepts).filter(d => !Object.prototype.hasOwnProperty.call(globalParams.orgStructure, d));
|
||
container.innerHTML = `
|
||
<div class="card ir-card">
|
||
<div class="card-head"><h2><span class="dot" style="background:var(--dot-amber)"></span>發票承擔設定</h2>
|
||
<span class="legend"><span><i style="background:var(--lime)"></i>承擔發票:計入總額並分配發票</span><span><i style="background:var(--st-nearover-dot)"></i>成本分攤:計入總額、不分配</span><span><i style="background:var(--wash-2)"></i>不計入:只看成本 × 人薪倍率</span></span>
|
||
</div>
|
||
<div class="ir-kpis">
|
||
<div class="tile lime"><span class="v">${money(inv.finalInvoiceTotal)}</span><span class="l">發票總額</span></div>
|
||
<div class="tile"><span class="v">${bearDepts.length}</span><span class="l">承擔發票的部門</span></div>
|
||
<div class="tile"><span class="v">${money(inv.sharedCost || 0)}</span><span class="l">成本分攤</span></div>
|
||
<div class="tile"><span class="v">${money(excludedCost)}</span><span class="l">不計入單位成本</span></div>
|
||
</div>
|
||
${bearDepts.length ? '' : '<div style="color:var(--accent-danger); font-weight:600; margin:0.25rem 0 0.5rem;">目前沒有任何「承擔發票」的部門,發票無法分配。</div>'}
|
||
<div class="ir-grid">${companyBlocks}</div>
|
||
<div class="card-foot"><span>新部門自動套用所屬公司的預設;部門可以個別改。</span>${stale.length ? `<span style="color:var(--accent-warning);">已失效的部門設定:${stale.map(d => `${escapeHtml(d)} <button type="button" class="link-button" onclick='setInvoiceRole("dept", ${escapeHtml(JSON.stringify(d))}, "")'>移除</button>`).join('、')}</span>` : ''}</div>
|
||
</div>${codaShareCard()}`;
|
||
}
|
||
|
||
// --- 定錨(發票+定錨 CODA)。數字全部由伺服器算,這裡只顯示。 ---
|
||
let anchorState = null;
|
||
let anchorConfirming = false;
|
||
|
||
async function renderAnchors() {
|
||
const card = document.getElementById('anchor-card');
|
||
if (!card) return;
|
||
try {
|
||
const response = await fetch('/api/anchors', { cache: 'no-store' });
|
||
if (!response.ok) throw new Error(String(response.status));
|
||
anchorState = await response.json();
|
||
} catch (error) {
|
||
card.innerHTML = `<h2 style="font-size:1rem;margin-bottom:.5rem;">定錨</h2><p style="color:var(--accent-warning);font-size:.85rem;">定錨資料讀取失敗,請重新整理。</p>`;
|
||
return;
|
||
}
|
||
const st = anchorState;
|
||
const m = v => PMI18n.amt(v || 0);
|
||
const halfLabel = h => h === 'H1' ? 'H1(1–6 月)' : 'H2(7–12 月)';
|
||
const status = st.active
|
||
? `${st.year} ${halfLabel(st.active.half)} 已定錨 ${new Date(st.active.at).toLocaleString('zh-TW', { hour12: false })} 說明:${escapeHtml(st.active.note)}`
|
||
: `${st.year} 尚未定錨。第一次正式定錨:${st.year} 年 1 月。`;
|
||
let action = '';
|
||
if (st.canAnchor && st.nextHalf) {
|
||
action = anchorConfirming
|
||
? `<div style="display:flex;gap:.5rem;align-items:center;flex-wrap:wrap;margin-top:.75rem;">
|
||
<input id="anchor-note" type="text" maxlength="500" placeholder="說明(必填)" style="flex:1;min-width:220px;" aria-label="定錨說明">
|
||
<button type="button" class="btn-primary" onclick="confirmAnchor('${st.nextHalf}')">確定 ${st.year} ${st.nextHalf} 定錨</button>
|
||
<button type="button" onclick="anchorConfirming=false;renderAnchors()">取消</button>
|
||
<div style="width:100%;font-size:.75rem;color:var(--text-dim);">定錨後這半年的發票與定錨 CODA 只增不減,快照不能修改,只能由下一次定錨取代。</div>
|
||
${planSummaryLine()}
|
||
</div>`
|
||
: `<button type="button" class="btn-primary" style="margin-top:.75rem;" onclick="anchorConfirming=true;renderAnchors()">確認 ${st.year} ${st.nextHalf} 定錨…</button>`;
|
||
}
|
||
let table = '';
|
||
if (st.active) {
|
||
const depts = Object.keys(st.coda || {}).filter(d => (st.coda[d].actual || st.coda[d].value || st.invoice?.[d]));
|
||
const rows = depts.map(d => {
|
||
const c = st.coda[d]; const inv = st.invoice?.[d];
|
||
return `<tr><td>${escapeHtml(d)}</td><td class="num">${m(c.actual)}</td><td class="num">${m(c.value)}</td><td class="num">${m(c.h1)}</td><td class="num">${c.h2 === null ? '—' : m(c.h2)}</td>
|
||
<td class="num">${inv ? m(inv.annual) : '—'}</td><td class="num">${inv ? m(inv.h1) : '—'}</td><td class="num">${inv && inv.h2 !== null ? m(inv.h2) : '—'}</td></tr>`;
|
||
}).join('');
|
||
table = `<div style="overflow-x:auto;margin-top:1rem;"><table class="ex-table" style="width:100%;font-size:.85rem;">
|
||
<thead><tr><th>部門</th><th class="num">實際 CODA</th><th class="num">定錨 CODA 全年</th><th class="num">H1</th><th class="num">H2</th><th class="num">發票全年</th><th class="num">H1</th><th class="num">H2</th></tr></thead>
|
||
<tbody>${rows}</tbody></table></div>
|
||
<p style="font-size:.75rem;color:var(--text-dim);margin-top:.5rem;">定錨 CODA:各組取半年內的最高點,部門=各組加總;沒有全公司合計(調動時原單位不降、新單位增加,加總會重複)。發票:定錨全年+調動淨額+半年內自身增加的最高點。H1=全年÷2;H2=最新全年−H1 結算。</p>`;
|
||
if ((st.transfers || []).length) {
|
||
const opts = sel => Array.from({ length: 12 }, (_, i) => `<option value="${i + 1}" ${i + 1 === sel ? 'selected' : ''}>${i + 1} 月</option>`).join('');
|
||
table += `<h3 style="font-size:.9rem;margin-top:1rem;">調動(定錨後)</h3><table class="ex-table" style="width:100%;font-size:.85rem;"><thead><tr><th>姓名</th><th>從</th><th>到</th><th>生效月份</th></tr></thead><tbody>${st.transfers.map(t => `<tr><td>${escapeHtml(t.name)}</td><td>${escapeHtml(t.from.dept)} ${escapeHtml(t.from.group)}</td><td>${escapeHtml(t.to.dept)} ${escapeHtml(t.to.group)}</td><td>${st.canAnchor ? `<select aria-label="${escapeHtml(t.name)} 生效月份" onchange="setTransferMonth('${encodeURIComponent(t.key)}', this.value)">${opts(t.effectiveMonth)}</select>` : `${t.effectiveMonth} 月`}${t.confirmed ? '' : '<span style="font-size:.75rem;color:var(--accent-warning);margin-left:.4rem;">偵測到的月份,待確認</span>'}</td></tr>`).join('')}</tbody></table>`;
|
||
}
|
||
}
|
||
let extra = '';
|
||
if (st.active) {
|
||
const typeLabel = { new: '新進', leave: '離職', cost: '調薪/成本變動', role: '職能改變', transfer: '調動' };
|
||
const signed = v => `${v > 0 ? '+' : ''}${PMI18n.amt(v || 0)}`;
|
||
const changes = st.changes || [];
|
||
extra += `<h3 style="font-size:.9rem;margin-top:1rem;">異動清單(與定錨快照比對,${changes.length} 筆)</h3>`
|
||
+ (changes.length ? `<div style="overflow-x:auto;"><table class="ex-table" style="width:100%;font-size:.85rem;"><thead><tr><th>類型</th><th>姓名</th><th>部門/組</th><th>生效月份</th><th class="num">全年成本增減</th><th class="num">發票增減</th></tr></thead><tbody>${changes.map(c => `<tr><td>${typeLabel[c.type] || c.type}${c.type === 'role' ? `<div style="font-size:.75rem;color:var(--text-dim);">${escapeHtml(c.fromRole)} → ${escapeHtml(c.toRole)}</div>` : ''}</td><td>${escapeHtml(c.name)}</td><td>${c.from ? `${escapeHtml(c.from.dept)} ${escapeHtml(c.from.group)} → ` : ''}${escapeHtml(c.dept)} ${escapeHtml(c.group)}</td><td>${c.effectiveMonth ? c.effectiveMonth + ' 月' : '—'}</td><td class="num">${c.type === 'transfer' ? '見調動' : signed(c.costDelta)}</td><td class="num">${c.type === 'transfer' ? '移轉' : signed(c.invoiceDelta)}</td></tr>`).join('')}</tbody></table></div>`
|
||
: '<p style="font-size:.8rem;color:var(--text-dim);">定錨後沒有異動。</p>');
|
||
if (st.canAnchor) {
|
||
const targets = [
|
||
...Object.keys(st.invoice || {}).map(d => `<option value="invoice|${escapeHtml(d)}">發票:${escapeHtml(d)}</option>`),
|
||
...Object.entries(st.coda || {}).flatMap(([d, v]) => Object.keys(v.groups || {}).map(g => `<option value="coda|${escapeHtml(d)}|${escapeHtml(g)}">定錨 CODA:${escapeHtml(d)} ${escapeHtml(g)}</option>`)),
|
||
].join('');
|
||
const resets = st.peakResets || [];
|
||
extra += `<h3 style="font-size:.9rem;margin-top:1rem;">重設最高點(資料打錯時用,只有你能按,會留紀錄)</h3>
|
||
<div style="display:flex;gap:.5rem;flex-wrap:wrap;align-items:center;"><select id="peak-target" aria-label="要重設的項目">${targets}</select>
|
||
<input id="peak-reason" type="text" maxlength="300" placeholder="原因(必填)" style="min-width:220px;" aria-label="重設原因">
|
||
<button type="button" onclick="resetPeakUI()">重設</button></div>
|
||
${resets.length ? `<table class="ex-table" style="width:100%;font-size:.85rem;margin-top:.5rem;"><thead><tr><th>項目</th><th class="num">重設前</th><th>原因</th><th>時間</th><th></th></tr></thead><tbody>${resets.map(r => `<tr><td>${r.kind === 'invoice' ? '發票' : '定錨 CODA'}:${escapeHtml(r.key.replace('|', ' '))}</td><td class="num">${PMI18n.amt(r.previous?.value || 0)}</td><td>${escapeHtml(r.reason)}</td><td>${new Date(r.at).toLocaleString('zh-TW', { hour12: false })}</td><td>${r.restoredAt ? '已還原' : `<button type="button" onclick="restorePeakUI('${escapeHtml(r.id)}')">還原</button>`}</td></tr>`).join('')}</tbody></table>` : ''}`;
|
||
extra += `<h3 style="font-size:.9rem;margin-top:1rem;">撤銷最近一次定錨(只有你能按,會留紀錄)</h3>
|
||
<div style="display:flex;gap:.5rem;flex-wrap:wrap;align-items:center;"><input id="undo-reason" type="text" maxlength="300" placeholder="原因(必填)" style="min-width:220px;" aria-label="撤銷原因">
|
||
<button type="button" onclick="undoAnchorUI()">${anchorUndoConfirming ? `確定撤銷 ${st.active.half} 定錨` : `撤銷 ${st.active.half} 定錨…`}</button>${anchorUndoConfirming ? '<button type="button" onclick="anchorUndoConfirming=false;renderAnchors()">取消</button>' : ''}</div>
|
||
<div style="font-size:.75rem;color:var(--text-dim);">撤銷後回到定錨前的狀態,可以重新定錨;外部系統會看到資料版本換號。</div>`;
|
||
}
|
||
}
|
||
if (st.pendingSettings) {
|
||
const p = st.pendingSettings;
|
||
const items = [...p.params.map(x => `${escapeHtml(x.key)}:${x.from ?? '—'} → ${x.to}`), p.rdGroups ? '研發組勾選' : '', p.cgLeadGroups ? 'CG Lead 組勾選' : '', p.invoiceRoles ? '發票角色' : ''].filter(Boolean);
|
||
extra += `<div style="margin-top:1rem;padding:.75rem;border:1px dashed var(--accent-warning);border-radius:10px;font-size:.85rem;"><b>下一次定錨才生效的修改</b>(${new Date(p.savedAt).toLocaleString('zh-TW', { hour12: false })}):${items.length ? items.join('、') : '與目前相同'}
|
||
${st.canAnchor ? '<button type="button" style="margin-left:.5rem;" onclick="cancelPendingSettings()">取消這些修改</button>' : ''}</div>`;
|
||
}
|
||
if ((st.undone || []).length) extra += `<p style="font-size:.75rem;color:var(--text-dim);margin-top:.75rem;">撤銷紀錄:${st.undone.map(u => `${u.half}(v${u.version || '?'})${new Date(u.undoneAt).toLocaleString('zh-TW', { hour12: false })},原因:${escapeHtml(u.reason)}`).join(';')}</p>`;
|
||
card.innerHTML = `<h2 style="font-size:1rem;margin-bottom:.5rem;">定錨(發票+定錨 CODA)</h2>
|
||
<p style="color:var(--text-muted);font-size:.85rem;">${status}</p>${action}${table}${extra}`;
|
||
}
|
||
|
||
let anchorUndoConfirming = false;
|
||
async function cancelPendingSettings() {
|
||
await fetch('/api/anchors', { method: 'DELETE' });
|
||
renderAnchors();
|
||
}
|
||
async function anchorPost(path, body) {
|
||
const response = await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
||
const result = await response.json().catch(() => ({}));
|
||
await renderAnchors();
|
||
if (!response.ok) document.getElementById('anchor-card')?.insertAdjacentHTML('beforeend', `<p role="alert" style="color:var(--accent-warning);font-size:.85rem;">沒有完成:${escapeHtml(result.error || String(response.status))}</p>`);
|
||
}
|
||
function resetPeakUI() {
|
||
const reason = (document.getElementById('peak-reason')?.value || '').trim();
|
||
if (!reason) { document.getElementById('peak-reason')?.focus(); return; }
|
||
const [kind, ...rest] = document.getElementById('peak-target').value.split('|');
|
||
anchorPost('/api/anchors/peak-reset', { kind, key: rest.join('|'), reason });
|
||
}
|
||
function restorePeakUI(id) { anchorPost('/api/anchors/peak-restore', { id }); }
|
||
function undoAnchorUI() {
|
||
const reason = (document.getElementById('undo-reason')?.value || '').trim();
|
||
if (!reason) { document.getElementById('undo-reason')?.focus(); return; }
|
||
if (!anchorUndoConfirming) { anchorUndoConfirming = true; renderAnchors().then(() => { const el = document.getElementById('undo-reason'); if (el) el.value = reason; }); return; }
|
||
anchorUndoConfirming = false;
|
||
anchorPost('/api/anchors/undo', { reason, confirm: true });
|
||
}
|
||
|
||
async function confirmAnchor(half) {
|
||
const note = (document.getElementById('anchor-note')?.value || '').trim();
|
||
if (!note) { document.getElementById('anchor-note')?.focus(); return; }
|
||
const response = await fetch('/api/anchors', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ half, note, confirm: true }) });
|
||
anchorConfirming = false;
|
||
if (!response.ok) {
|
||
const card = document.getElementById('anchor-card');
|
||
const error = await response.json().catch(() => ({}));
|
||
await renderAnchors();
|
||
card?.insertAdjacentHTML('beforeend', `<p role="alert" style="color:var(--accent-warning);font-size:.85rem;">定錨沒有完成:${escapeHtml(error.error || String(response.status))}</p>`);
|
||
return;
|
||
}
|
||
renderAnchors();
|
||
}
|
||
|
||
async function setTransferMonth(key, month) {
|
||
await fetch('/api/anchors/transfers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: decodeURIComponent(key), month: Number(month) }) });
|
||
renderAnchors();
|
||
}
|
||
|
||
function renderParams() {
|
||
renderAnchors();
|
||
initOrgStructure();
|
||
const container = document.getElementById('global-params');
|
||
if (!container) return;
|
||
|
||
|
||
// Card Builder Helper
|
||
const buildParamRow = (label, key, unit = "", isMoney = false, step = "1") => {
|
||
let val = globalParams[key] ?? ({ contractorMultiplier: 1.5, usdRate: 30 })[key] ?? 0;
|
||
let onchange = `updateGlobalParam('${key}', this.value)`;
|
||
let displayVal = val;
|
||
|
||
if (unit === '%' || unit === '率') {
|
||
displayVal = Number((val * 100).toFixed(6));
|
||
unit = '%';
|
||
step = String(Number(step) * 100);
|
||
onchange = `updateGlobalParam('${key}', Number(this.value) / 100)`;
|
||
}
|
||
|
||
if (isMoney) {
|
||
displayVal = val.toLocaleString();
|
||
onchange = `updateGlobalParamMoney('${key}', this.value)`;
|
||
}
|
||
|
||
return `
|
||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 0.75rem; gap: 0.5rem;">
|
||
<label style="color: var(--text-muted); font-size: 0.85rem; flex:1; line-height: 1.2;">${label}</label>
|
||
<div style="display:flex; align-items:center; gap:8px;">
|
||
<input type="${isMoney ? 'text' : 'number'}" step="${step}"
|
||
style="width: 115px; text-align:right; font-weight:700; color:var(--text-main); background:var(--wash); border-color:var(--wash-2); padding: 4px 8px;"
|
||
value="${displayVal}" onchange="${onchange}">
|
||
<span style="font-size:0.75rem; color:var(--text-dim); min-width:32px; text-align:left;">${unit}</span>
|
||
</div>
|
||
</div>
|
||
`;
|
||
};
|
||
|
||
container.innerHTML = `
|
||
<!-- Column 1: Base Core Params -->
|
||
<div class="card" style="height: 100%; padding: 1.25rem;">
|
||
<h2 style="margin-bottom: 0.5rem; color: var(--text-main); font-size: 1rem; display:flex; align-items:center; gap:8px;">
|
||
<span style="background:color-mix(in srgb, var(--accent-primary) 10%, transparent); padding:4px; border-radius:6px;"></span> 基本參數
|
||
</h2>
|
||
<p style="color: var(--text-dim); font-size: 0.75rem; margin-bottom: 1rem; line-height: 1.4;">
|
||
調整人薪倍率、年度工作天數與產出率,這些值會直接影響各部門 CODA 的計算基準。
|
||
</p>
|
||
<div style="display:flex; flex-direction:column; gap:0.25rem;">
|
||
${buildParamRow("人薪倍率(正職)", "opMultiplier", "倍", false, "0.1")}
|
||
${buildParamRow("外包倍率", "contractorMultiplier", "倍", false, "0.1")}
|
||
${buildParamRow("年度工作天數", "annualWorkDays", "天")}
|
||
${buildParamRow("月平均工作天數", "workingDays", "天")}
|
||
${buildParamRow("P 產出率", "utilizationP", "率", false, "0.05")}
|
||
${buildParamRow("A 產出率", "utilizationA", "率", false, "0.05")}
|
||
${buildParamRow("美金匯率(1 USD = 幾 TWD)", "usdRate", "TWD", false, "0.1")}
|
||
</div>
|
||
<div style="margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--wash);">
|
||
<p style="color: var(--text-dim); font-size: 0.75rem; line-height:1.4;">
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Column 2: Invoice & Targets -->
|
||
<div class="card" style="height: 100%; padding: 1.25rem;">
|
||
<h2 style="margin-bottom: 0.5rem; color: var(--text-main); font-size: 1rem; display:flex; align-items:center; gap:8px;">
|
||
<span style="background:color-mix(in srgb, var(--accent-success) 12%, transparent); padding:4px; border-radius:6px;"></span> 發票分配與目標
|
||
</h2>
|
||
<p style="color: var(--text-dim); font-size: 0.75rem; margin-bottom: 1rem; line-height: 1.4;">
|
||
設定各項指標權重與年度專案成本,系統將依此自動演算出各部門應達成的發票目標。
|
||
</p>
|
||
<div style="display:flex; flex-direction:column; gap:0.25rem;">
|
||
${buildParamRow("指標1:P 成本", "invoiceWeightP", "%", false, "0.05")}
|
||
${buildParamRow("指標2:A 成本", "invoiceWeightA", "%", false, "0.05")}
|
||
${buildParamRow("指標3:P 輕重(A:P 成本比)", "invoiceWeightSurplus", "%", false, "0.05")}
|
||
</div>
|
||
|
||
<div style="margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px dashed var(--wash-2);">
|
||
<h5 style="margin-bottom:1rem; font-size:0.85rem; color:var(--text-dim); display:flex; align-items:center; gap:6px;">發票總額參數</h5>
|
||
${buildParamRow("專案委外", "externalProjectOutsourcing", "NT$", true)}
|
||
${buildParamRow("員旅(不除毛利率)", "employeeTripInvoices", "NT$", true)}
|
||
${buildParamRow("毛利率", "grossMarginPct", "%", false, "0.05")}
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Column 3: RD & Management Reductions -->
|
||
<div style="display: flex; flex-direction: column; gap: 1.25rem;">
|
||
|
||
<!-- Combined RD Block -->
|
||
<div class="card" style="padding: 1.25rem;">
|
||
<h2 style="margin-bottom: 0.5rem; color: var(--text-main); font-size: 1rem; display:flex; align-items:center; gap:8px;">
|
||
<span style="background:color-mix(in srgb, var(--accent-secondary) 10%, transparent); padding:4px; border-radius:6px;"></span> 研發參數與標註
|
||
</h2>
|
||
<p style="color: var(--text-dim); font-size: 0.75rem; margin-bottom: 0.75rem; line-height: 1.4;">
|
||
設定研發減免比例。
|
||
</p>
|
||
${buildParamRow("研發組減免比例", "rdReductionPct", "率", false, "0.05")}
|
||
</div>
|
||
|
||
<!-- Management Reductions -->
|
||
<div class="card" style="padding: 1.25rem;">
|
||
<h2 style="margin-bottom: 0.5rem; color: var(--text-main); font-size: 1rem; display:flex; align-items:center; gap:8px;">
|
||
<span style="background:color-mix(in srgb, var(--accent-warning) 12%, transparent); padding:4px; border-radius:6px;"></span> 管理職與 PC 承擔比例
|
||
</h2>
|
||
<p style="color: var(--text-dim); font-size: 0.75rem; margin-bottom: 0.75rem; line-height: 1.4;">
|
||
定義管理職與 PC 職位的成本承擔比例,未承擔的成本將由組員共同分攤。
|
||
</p>
|
||
<div style="display:flex; flex-direction:column; gap:0.15rem;">
|
||
${buildParamRow("管理職 P 承擔比例", "pManagerReductionPct", "率", false, "0.05")}
|
||
${buildParamRow("PC 承擔比例", "pPCReductionPct", "率", false, "0.05")}
|
||
${buildParamRow("管理職 A 承擔比例", "managerReductionPct", "率", false, "0.05")}
|
||
${buildParamRow("CG Lead 承擔比例", "cgLeadReductionPct", "率", false, "0.05")}
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
`;
|
||
renderInvoiceRoles();
|
||
}
|
||
function toggleInvoiceDept(deptId) {
|
||
const panel = document.getElementById(`invoice-detail-${deptId}`);
|
||
const chevron = document.getElementById(`invoice-chevron-${deptId}`);
|
||
if (panel.style.display === 'none') {
|
||
panel.style.display = 'block';
|
||
chevron.style.transform = 'rotate(90deg)';
|
||
chevron.style.color = 'var(--accent-secondary)';
|
||
} else {
|
||
panel.style.display = 'none';
|
||
chevron.style.transform = 'rotate(0deg)';
|
||
chevron.style.color = 'var(--text-dim)';
|
||
}
|
||
}
|
||
|
||
function renderOrgStructure() {
|
||
initOrgStructure();
|
||
const container = document.getElementById('org-structure-content');
|
||
if (!container) return;
|
||
|
||
// Company → department → group, built from the HR roster (contractors are not employees; 工讀生 are).
|
||
const people = (isSimMode ? simData : baseData).filter(p => p.partTime || !(p.role || '').startsWith('O'));
|
||
window.orgAssignOpen = window.orgAssignOpen || new Set();
|
||
const deptOrder = Object.keys(globalParams.orgStructure);
|
||
const companies = new Map();
|
||
people.forEach(p => {
|
||
const company = p.company || '未指定公司';
|
||
const dept = (p.dept || '').trim();
|
||
const group = (p.group || '').trim() || '未分組';
|
||
if (!companies.has(company)) companies.set(company, { name: company, count: 0, depts: new Map() });
|
||
const c = companies.get(company);
|
||
c.count += 1;
|
||
const deptKey = dept || '';
|
||
if (!c.depts.has(deptKey)) c.depts.set(deptKey, new Map());
|
||
const groups = c.depts.get(deptKey);
|
||
if (!groups.has(group)) groups.set(group, { count: 0, manual: 0, members: [] });
|
||
const entry = groups.get(group);
|
||
entry.count += 1;
|
||
if (p.groupSource === 'manual' || p.deptSource === 'manual') entry.manual += 1;
|
||
entry.members.push(p);
|
||
});
|
||
|
||
const deptRank = d => {
|
||
if (!d) return Number.MAX_SAFE_INTEGER;
|
||
const i = deptOrder.indexOf(d);
|
||
return i === -1 ? deptOrder.length : i;
|
||
};
|
||
|
||
// People without a group (or without a department) can be placed by hand; HR wins later.
|
||
const assignPanel = (company, dept, g, entry) => {
|
||
const panelKey = `${company}|${dept}|${g}`;
|
||
const open = window.orgAssignOpen.has(panelKey);
|
||
const label = !dept ? '指定部門' : g === '未分組' ? '手動分組' : '修改手動';
|
||
const toggle = `<button type="button" class="og-assign" onclick='toggleOrgAssign(${escapeHtml(JSON.stringify(panelKey))})'>${open ? '收合' : label}</button>`;
|
||
if (!open) return toggle;
|
||
const slug = 'org-opts-' + btoa(unescape(encodeURIComponent(panelKey))).replace(/[^a-zA-Z0-9]/g, '');
|
||
const deptOptions = [...(companies.get(company)?.depts.keys() || [])].filter(Boolean);
|
||
const groupOptions = dept ? [...(companies.get(company)?.depts.get(dept)?.keys() || [])].filter(x => x !== '未分組') : [];
|
||
const members = entry.members.filter(m => m.source === 'hr-sync' && (m.deptSource !== 'hr' || m.groupSource !== 'hr'));
|
||
const input = (m, field, list, placeholder) => `<input list="${list}" placeholder="${placeholder}" value="${escapeHtml(m[field + 'Source'] === 'manual' ? m[field] : '')}"
|
||
style="flex:1; min-width:0; font-size:0.75rem; padding:3px 6px;"
|
||
onchange='setHrPlacement(${escapeHtml(JSON.stringify(m.employeeNumber))}, "${field}", this.value)'>`;
|
||
const rows = members.map(m => {
|
||
const hasManual = m.deptSource === 'manual' || m.groupSource === 'manual';
|
||
return `
|
||
<div style="margin-top:8px;">
|
||
<div style="display:flex; justify-content:space-between; font-size:0.78rem;">
|
||
<span>${escapeHtml(m.name)}</span>
|
||
${hasManual ? `<button class="link-button" style="font-size:0.75rem; color:var(--accent-danger);" onclick='clearHrPlacement(${escapeHtml(JSON.stringify(m.employeeNumber))})'>清除手動</button>` : ''}
|
||
</div>
|
||
<div style="display:flex; gap:6px; margin-top:4px;">
|
||
${m.deptSource === 'hr' ? `<span style="font-size:0.75rem; color:var(--text-dim); flex:1;">部門:${escapeHtml(m.dept)}(HR)</span>` : input(m, 'dept', slug + '-d', '部門')}
|
||
${m.groupSource === 'hr' ? `<span style="font-size:0.75rem; color:var(--text-dim); flex:1;">組別:${escapeHtml(m.group)}(HR)</span>` : input(m, 'group', slug + '-g', '組別')}
|
||
</div>
|
||
</div>`;
|
||
}).join('');
|
||
return `${toggle}
|
||
<datalist id="${slug}-d">${deptOptions.map(o => `<option value="${escapeHtml(o)}"></option>`).join('')}</datalist>
|
||
<datalist id="${slug}-g">${groupOptions.map(o => `<option value="${escapeHtml(o)}"></option>`).join('')}</datalist>
|
||
<div style="margin-top:4px; padding:6px 8px; border:1px dashed var(--border-glass); border-radius:8px;">
|
||
<div style="font-size:0.75rem; color:var(--text-dim);">修改後自動儲存;清空欄位或按「清除手動」可還原。HR 之後提供資料時以 HR 為準。</div>
|
||
${rows || '<div style="font-size:0.75rem; color:var(--text-dim);">沒有可指定的人員。</div>'}
|
||
</div>`;
|
||
};
|
||
|
||
const manualTag = entry => entry.manual ? `<span class="og-manual">手動 ${entry.manual}</span>` : '';
|
||
|
||
// The card already names the department, so 「前製部_設計組」 shows as 「設計組」.
|
||
const shortGroup = (dept, g) => {
|
||
if (!dept) return g;
|
||
for (const sep of ['_', '-', ' ', '/', '/']) {
|
||
if (g.startsWith(dept + sep) && g.length > dept.length + 1) return g.slice(dept.length + 1);
|
||
}
|
||
return g;
|
||
};
|
||
|
||
const groupRow = (company, dept, g, entry) => {
|
||
const count = entry.count;
|
||
const name = shortGroup(dept, g);
|
||
const top = `
|
||
<div class="og-top">
|
||
<span class="og-name" title="${escapeHtml(g)}">${escapeHtml(name)}</span>
|
||
<span class="og-count">${count} 人</span>
|
||
</div>`;
|
||
if (!dept) {
|
||
return `
|
||
<div class="org-group-item og-row">${top}
|
||
<div class="og-flags">${manualTag(entry)}${assignPanel(company, dept, g, entry)}</div>
|
||
</div>`;
|
||
}
|
||
const key = `${dept}|${g}`;
|
||
const isRD = (globalParams.rdGroups || []).includes(key);
|
||
const isCGLead = (globalParams.cgLeadGroups || []).includes(key);
|
||
const dArg = escapeHtml(JSON.stringify(dept));
|
||
const gArg = escapeHtml(JSON.stringify(g));
|
||
const assign = (g === '未分組' || entry.manual) ? assignPanel(company, dept, g, entry) : '';
|
||
return `
|
||
<div class="org-group-item og-row${isRD ? ' is-rd' : ''}${isCGLead ? ' is-cg' : ''}">${top}
|
||
<div class="og-flags">
|
||
<button type="button" class="og-flag og-rd" aria-pressed="${isRD}" onclick="toggleRDGroup(${dArg}, ${gArg})" title="RD 研發組:成本扣除研發比例">RD</button>
|
||
<button type="button" class="og-flag og-cg" aria-pressed="${isCGLead}" onclick="toggleCGLeadGroup(${dArg}, ${gArg})" title="CG Lead 管理組">CG Lead</button>
|
||
${manualTag(entry)}
|
||
</div>
|
||
${assign ? `<div class="og-assign-wrap">${assign}</div>` : ''}
|
||
</div>`;
|
||
};
|
||
|
||
let html = `
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
||
<div>
|
||
<h1 style="margin-bottom: 0.5rem;">組織架構</h1>
|
||
<p style="color: var(--text-muted); font-size: 0.9rem;">依 HR 組織資料自動產生:公司 → 部門 → 組別。RD/CG 勾選會自動儲存;未歸部門的人員不列入部門 CODA。</p>
|
||
</div>
|
||
</div>`;
|
||
|
||
[...companies.values()].sort((a, b) => b.count - a.count).forEach(company => {
|
||
const depts = [...company.depts.entries()].sort((a, b) => deptRank(a[0]) - deptRank(b[0]) || a[0].localeCompare(b[0], 'zh-Hant'));
|
||
html += `
|
||
<div class="org-tree-container" style="margin-bottom: 3rem;">
|
||
<div class="org-root-node">${escapeHtml(shortCompanyName(company.name))}<span style="font-weight:500; opacity:0.8; margin-left:0.5rem;">${company.count} 人</span></div>
|
||
<div class="org-branches-row">
|
||
${depts.map(([dept, groups]) => {
|
||
const total = [...groups.values()].reduce((s, n) => s + n.count, 0);
|
||
const sortedGroups = [...groups.entries()].sort((a, b) => (a[0] === '未分組') - (b[0] === '未分組') || a[0].localeCompare(b[0], 'zh-Hant'));
|
||
return `
|
||
<div class="org-dept-branch">
|
||
<div class="org-dept-card" style="${dept ? '' : 'border-style: dashed;'}">
|
||
<div class="org-dept-header">
|
||
<h3 class="dept-name" style="color: ${dept ? 'var(--text-main)' : 'var(--text-dim)'};">${dept ? escapeHtml(dept) : '未歸部門'}</h3>
|
||
<span style="font-size:0.75rem; color:var(--text-dim);">${total} 人</span>
|
||
</div>
|
||
<div class="org-group-list-vertical">
|
||
${sortedGroups.map(([g, entry]) => groupRow(company.name, dept, g, entry)).join('')}
|
||
</div>
|
||
</div>
|
||
</div>`;
|
||
}).join('')}
|
||
</div>
|
||
</div>`;
|
||
});
|
||
|
||
container.innerHTML = html;
|
||
}
|
||
|
||
function toggleOrgAssign(key) {
|
||
window.orgAssignOpen = window.orgAssignOpen || new Set();
|
||
if (window.orgAssignOpen.has(key)) window.orgAssignOpen.delete(key); else window.orgAssignOpen.add(key);
|
||
renderOrgStructure();
|
||
}
|
||
|
||
function updateRDSuggestions(query) {
|
||
const suggestionsEl = document.getElementById('rd-suggestions');
|
||
if (!query && query !== "") {
|
||
suggestionsEl.style.display = 'none';
|
||
return;
|
||
}
|
||
|
||
const current = isSimMode ? simData : baseData;
|
||
const allGroups = [...new Set(current.filter(p => p.group).map(p => `${p.dept}|${p.group}`))];
|
||
const activeGroups = globalParams.rdGroups || [];
|
||
|
||
const filtered = allGroups.filter(g =>
|
||
!activeGroups.includes(g) &&
|
||
g.toLowerCase().includes(query.toLowerCase())
|
||
).sort();
|
||
|
||
if (filtered.length === 0) {
|
||
suggestionsEl.innerHTML = '<div class="rd-suggestion-item" style="color: var(--text-dim);">無結果</div>';
|
||
suggestionsEl.style.display = 'block';
|
||
return;
|
||
}
|
||
|
||
suggestionsEl.innerHTML = filtered.map(g => `
|
||
<div class="rd-suggestion-item" onclick="addRDTag('${g}')">
|
||
${g.replace('|', ' - ')}
|
||
</div>
|
||
`).join('');
|
||
suggestionsEl.style.display = 'block';
|
||
}
|
||
|
||
function toggleRDGroup(dept, group) {
|
||
const key = `${dept}|${group}`;
|
||
if (!globalParams.rdGroups) globalParams.rdGroups = [];
|
||
const idx = globalParams.rdGroups.indexOf(key);
|
||
if (idx > -1) {
|
||
globalParams.rdGroups.splice(idx, 1);
|
||
} else {
|
||
globalParams.rdGroups.push(key);
|
||
}
|
||
saveAndRefresh();
|
||
renderOrgStructure();
|
||
}
|
||
|
||
function toggleCGLeadGroup(dept, group) {
|
||
const key = `${dept}|${group}`;
|
||
if (!globalParams.cgLeadGroups) globalParams.cgLeadGroups = [];
|
||
const idx = globalParams.cgLeadGroups.indexOf(key);
|
||
if (idx > -1) {
|
||
globalParams.cgLeadGroups.splice(idx, 1);
|
||
} else {
|
||
globalParams.cgLeadGroups.push(key);
|
||
}
|
||
saveAndRefresh();
|
||
renderOrgStructure();
|
||
}
|
||
|
||
function removeRDTag(groupKey) {
|
||
if (!globalParams.rdGroups) return;
|
||
globalParams.rdGroups = globalParams.rdGroups.filter(g => g !== groupKey);
|
||
saveAndRefresh();
|
||
}
|
||
|
||
|
||
function updateGlobalParamMoney(key, rawVal) {
|
||
const numStr = String(rawVal).replace(/,/g, '');
|
||
const parsed = parseFloat(numStr);
|
||
if (!isNaN(parsed)) {
|
||
globalParams[key] = parsed;
|
||
saveAndRefresh();
|
||
} else {
|
||
renderParams(); // revert back to original value visually
|
||
}
|
||
}
|
||
|
||
function updateGlobalParam(key, val) {
|
||
const parsed = parseFloat(val);
|
||
if (!isNaN(parsed)) {
|
||
globalParams[key] = parsed;
|
||
document.getElementById('coda-grand-total').innerText = "重新計算中..."; // Placeholder
|
||
saveAndRefresh();
|
||
}
|
||
}
|
||
|
||
|
||
function renderRoleStats(data) {
|
||
const statsEl = document.getElementById('role-stats');
|
||
if (!statsEl) return;
|
||
// Four boxes that add up to the total: interns (title "Intern") are counted with
|
||
// 常態型外包, not with their A / P role. Anyone without a role is flagged separately.
|
||
const total = data.length;
|
||
const role = person => String(person.role || '');
|
||
const intern = person => isCostExcludedIntern(person);
|
||
const a = data.filter(x => role(x).startsWith('A') && !intern(x)).length;
|
||
const p = data.filter(x => role(x).startsWith('P') && !intern(x)).length;
|
||
const g = data.filter(x => role(x).startsWith('G') && !intern(x)).length;
|
||
const oi = data.filter(x => role(x).startsWith('O') || intern(x)).length;
|
||
const pending = total - a - p - g - oi;
|
||
const pct = n => total ? (n / total * 100) : 0;
|
||
const totalEl = document.getElementById('role-total');
|
||
if (totalEl) totalEl.textContent = `${total} 人`;
|
||
const tile = (n, label) => `<div class="tile"><span class="v">${n}</span><span class="l">${label}</span><span class="l pct">${formatPct(pct(n))}%</span></div>`;
|
||
statsEl.innerHTML = `
|
||
<div class="tile-grid tile-grid-4">${tile(a, '藝術家')}${tile(p, '專案管理')}${tile(g, '營運支援')}${tile(oi, '常態型外包+實習生')}</div>
|
||
<div class="stack" aria-hidden="true">
|
||
<span style="flex:${pct(a)} 1 0; background:var(--bar-strong);"></span>
|
||
<span style="flex:${pct(p)} 1 0; background:var(--bar-soft);"></span>
|
||
<span style="flex:${pct(g)} 1 0; background:var(--wash-2);"></span>
|
||
<span style="flex:${pct(oi)} 1 0; background:var(--lime);"></span>
|
||
${pending ? `<span style="flex:${pct(pending)} 1 0; background:var(--st-nearover-dot);"></span>` : ''}
|
||
</div>
|
||
${pending ? `<div class="card-foot" style="margin-top:0;"><a href="#" class="pending-link" onclick="showPersonnelView('all','internal'); return false;">${pending} 人待設定職能,前往人員資料</a></div>` : ''}`;
|
||
}
|
||
|
||
// Group analysis: company → department → group. Contractors follow their department's
|
||
// company; people without a department are listed under 未歸部門 for their company.
|
||
const groupCollapsed = new Set();
|
||
|
||
function groupAnalysisTree(current) {
|
||
const isContractor = p => (p.role || '').startsWith('O');
|
||
const deptCompanyVotes = {};
|
||
current.filter(p => !isContractor(p) && p.company && p.dept).forEach(p => {
|
||
deptCompanyVotes[p.dept] = deptCompanyVotes[p.dept] || {};
|
||
deptCompanyVotes[p.dept][p.company] = (deptCompanyVotes[p.dept][p.company] || 0) + 1;
|
||
});
|
||
const companyOfDept = dept => {
|
||
const votes = deptCompanyVotes[dept];
|
||
return votes ? Object.entries(votes).sort((a, b) => b[1] - a[1])[0][0] : null;
|
||
};
|
||
const companies = new Map();
|
||
current.forEach(p => {
|
||
const contractor = isContractor(p);
|
||
const dept = (p.dept || '').trim();
|
||
const company = contractor ? (companyOfDept(dept) || '外包(未對應公司)') : (p.company || '未指定公司');
|
||
const group = (p.group || '').trim() || '未分組';
|
||
const cost = p.totalCost || 0;
|
||
if (!companies.has(company)) companies.set(company, { name: company, people: 0, contractors: 0, cost: 0, depts: new Map() });
|
||
const c = companies.get(company);
|
||
if (!c.depts.has(dept)) c.depts.set(dept, { name: dept, people: 0, contractors: 0, cost: 0, groups: new Map() });
|
||
const d = c.depts.get(dept);
|
||
if (!d.groups.has(group)) d.groups.set(group, { name: group, people: 0, contractors: 0, cost: 0 });
|
||
const g = d.groups.get(group);
|
||
[c, d, g].forEach(node => { node.people += 1; node.cost += cost; if (contractor) node.contractors += 1; });
|
||
});
|
||
return companies;
|
||
}
|
||
|
||
function setGroupExpansion(expand) {
|
||
groupCollapsed.clear();
|
||
if (!expand) {
|
||
const companies = groupAnalysisTree(isSimMode ? simData : baseData);
|
||
companies.forEach(c => {
|
||
groupCollapsed.add(`c|${c.name}`);
|
||
c.depts.forEach(d => groupCollapsed.add(`d|${c.name}|${d.name}`));
|
||
});
|
||
}
|
||
renderGroup();
|
||
}
|
||
|
||
function toggleGroupNode(key) {
|
||
if (groupCollapsed.has(key)) groupCollapsed.delete(key); else groupCollapsed.add(key);
|
||
renderGroup();
|
||
}
|
||
|
||
function renderGroup() {
|
||
const current = isSimMode ? simData : baseData;
|
||
const tbody = document.querySelector('#group-table tbody');
|
||
if (!tbody) return;
|
||
const companies = groupAnalysisTree(current);
|
||
|
||
const filterEl = document.getElementById('group-company-filter');
|
||
if (filterEl) {
|
||
const names = [...companies.values()].sort((a, b) => b.cost - a.cost).map(c => c.name);
|
||
const selected = filterEl.value;
|
||
filterEl.replaceChildren(new Option('所有公司', 'all'), ...names.map(n => new Option(shortCompanyName(n), n)));
|
||
filterEl.value = names.includes(selected) ? selected : 'all';
|
||
}
|
||
const companyFilter = filterEl?.value || 'all';
|
||
const shown = [...companies.values()].filter(c => companyFilter === 'all' || c.name === companyFilter).sort((a, b) => b.cost - a.cost);
|
||
const grandTotal = [...companies.values()].reduce((s, c) => s + c.cost, 0);
|
||
|
||
const bar = (pct, color) => `
|
||
<div style="display:flex; align-items:center; gap:10px;">
|
||
<div style="flex-grow:1; height:6px; background:var(--wash); border-radius:3px;">
|
||
<div style="width:${Math.min(100, pct)}%; height:100%; background:${color};"></div>
|
||
</div>
|
||
<span style="font-size:0.8rem; min-width:48px; text-align:right;">${formatPct(pct)}%</span>
|
||
</div>`;
|
||
const peopleText = n => `${n.people} 人${n.contractors ? `<div style="font-size:0.75rem; color:var(--accent-warning);">含外包 ${n.contractors}</div>` : ''}`;
|
||
const arrow = key => `<span style="display:inline-block; width:1.2em; color:var(--text-dim);">${groupCollapsed.has(key) ? '▶' : '▼'}</span>`;
|
||
const keyArg = key => escapeHtml(JSON.stringify(key));
|
||
|
||
let html = '';
|
||
shown.forEach(c => {
|
||
const cKey = `c|${c.name}`;
|
||
html += `
|
||
<tr style="background:var(--wash); cursor:pointer;" onclick="toggleGroupNode(${keyArg(cKey)})">
|
||
<td style="font-weight:500; font-size:1rem;">${arrow(cKey)}${escapeHtml(shortCompanyName(c.name))}</td>
|
||
<td class="num" style="font-weight:700;">${peopleText(c)}</td>
|
||
<td class="num" style="font-weight:500;">${PMI18n.cur(c.cost)}</td>
|
||
<td>${bar(grandTotal ? c.cost / grandTotal * 100 : 0, 'var(--bar-strong)')}<div style="font-size:0.75rem; color:var(--text-dim);">佔全部</div></td>
|
||
</tr>`;
|
||
if (groupCollapsed.has(cKey)) return;
|
||
[...c.depts.values()].sort((a, b) => (!a.name) - (!b.name) || b.cost - a.cost).forEach(d => {
|
||
const dKey = `d|${c.name}|${d.name}`;
|
||
html += `
|
||
<tr style="cursor:pointer;" onclick="toggleGroupNode(${keyArg(dKey)})">
|
||
<td style="padding-left:2rem; font-weight:500; ${d.name ? '' : 'color:var(--text-dim);'}">${arrow(dKey)}${d.name ? escapeHtml(d.name) : '未歸部門 <span style="font-size:0.75rem; font-weight:400;">(不列入部門 CODA)</span>'}</td>
|
||
<td class="num">${peopleText(d)}</td>
|
||
<td class="num" style="font-weight:500;">${PMI18n.cur(d.cost)}</td>
|
||
<td>${bar(c.cost ? d.cost / c.cost * 100 : 0, 'var(--bar-strong)')}<div style="font-size:0.75rem; color:var(--text-dim);">佔${escapeHtml(shortCompanyName(c.name))}</div></td>
|
||
</tr>`;
|
||
if (groupCollapsed.has(dKey)) return;
|
||
[...d.groups.values()].sort((a, b) => b.cost - a.cost).forEach(g => {
|
||
html += `
|
||
<tr>
|
||
<td style="padding-left:4rem;" title="${escapeHtml(g.name)}">${escapeHtml(shortGroupName(d.name, g.name))}</td>
|
||
<td class="num">${peopleText(g)}</td>
|
||
<td class="num">${PMI18n.cur(g.cost)}</td>
|
||
<td>${bar(d.cost ? g.cost / d.cost * 100 : 0, 'var(--bar-soft)')}<div style="font-size:0.75rem; color:var(--text-dim);">佔${d.name ? escapeHtml(d.name) : '未歸部門'}</div></td>
|
||
</tr>`;
|
||
});
|
||
});
|
||
});
|
||
tbody.innerHTML = html || '<tr><td colspan="4" style="text-align:center; padding:2rem;">沒有資料。</td></tr>';
|
||
}
|
||
|
||
function renderSales() {
|
||
initOrgStructure();
|
||
const current = isSimMode ? simData : baseData;
|
||
calculateAll(current);
|
||
const container = document.getElementById('sales-content');
|
||
|
||
// 1. Filter: Role starts with P and must be in valid business departments
|
||
const targetDepts = Object.keys(globalParams.orgStructure);
|
||
const pPeople = current.filter(p => p.role.startsWith('P') && targetDepts.includes(p.dept));
|
||
|
||
// 2. Calculations
|
||
let grandTotal = 0;
|
||
const depts = {};
|
||
|
||
const processed = pPeople.map(p => {
|
||
const m1 = (p.h1Start && p.h1End) ? Math.max(0, parseInt(p.h1End) - parseInt(p.h1Start) + 1) : 0;
|
||
const m2 = (p.h2Start && p.h2End) ? Math.max(0, parseInt(p.h2End) - parseInt(p.h2Start) + 1) : 0;
|
||
const months = m1 + m2;
|
||
const salary = parseFloat(p.salary) || 0;
|
||
|
||
let workRate = 1.0;
|
||
const isPC = isProductionCoordinator(p);
|
||
|
||
if (p.isManager) {
|
||
// Manager rate overrides (or applies as) the main factor
|
||
workRate = globalParams.pManagerReductionPct !== undefined ? globalParams.pManagerReductionPct : 0.6;
|
||
} else if (isPC) {
|
||
workRate = globalParams.pPCReductionPct !== undefined ? globalParams.pPCReductionPct : 0.7; // PC fixed rate
|
||
}
|
||
|
||
const yearlyCost = p.realSalaryTotal * workRate;
|
||
|
||
grandTotal += yearlyCost;
|
||
|
||
const groupName = p.group || '未分組';
|
||
|
||
// Check if group is valid in orgStructure
|
||
const isValidGroup = globalParams.orgStructure[p.dept]?.includes(groupName);
|
||
const assignedGroup = isValidGroup ? groupName : '未分組 (需由管理清單指派)';
|
||
|
||
if (!depts[p.dept]) depts[p.dept] = { name: p.dept, total: 0, groups: {} };
|
||
if (!depts[p.dept].groups[assignedGroup]) {
|
||
depts[p.dept].groups[assignedGroup] = { name: assignedGroup, total: 0, people: [] };
|
||
}
|
||
|
||
depts[p.dept].total += yearlyCost;
|
||
depts[p.dept].groups[assignedGroup].total += yearlyCost;
|
||
|
||
const processedPerson = { ...p, yearlyCost, workRate };
|
||
depts[p.dept].groups[assignedGroup].people.push(processedPerson);
|
||
|
||
return processedPerson;
|
||
});
|
||
|
||
// Update Grand Total UI
|
||
document.getElementById('sales-grand-total').innerText = `${PMI18n.cur(grandTotal)}`;
|
||
|
||
// 3. Render Tables Grouped by Dept
|
||
container.innerHTML = '';
|
||
Object.keys(globalParams.orgStructure).forEach(deptName => { // Iterate over predefined order
|
||
const dept = depts[deptName];
|
||
if (!dept) return; // Skip if department has no P people
|
||
|
||
const deptPct = grandTotal === 0 ? 0 : (dept.total / grandTotal * 100);
|
||
const safeDeptId = dept.name.replace(/\s+/g, '-');
|
||
const totalPeople = Object.values(dept.groups).reduce((acc, g) => acc + g.people.length, 0);
|
||
|
||
let deptHtml = `
|
||
<div class="card" style="margin-bottom: 1.5rem; padding: 0;">
|
||
<!-- Clikable Header -->
|
||
<div class="row-toggle" onclick="toggleSalesDept('${safeDeptId}')" style="cursor: pointer; padding: 1.5rem; display: flex; justify-content: space-between; align-items: center;">
|
||
<div style="display: flex; align-items: center; gap: 2rem; flex-grow: 1;">
|
||
<h2 class="dept-name" style="margin: 0; min-width: 200px;">${dept.name}</h2>
|
||
<div style="min-width: 80px; text-align: left;">
|
||
<span style="font-size: 0.85rem; color: var(--text-muted); background: var(--wash); padding: 4px 10px; border-radius: 99px;">${totalPeople} 人</span>
|
||
</div>
|
||
<div style="display: flex; flex-direction: column; min-width: 300px; text-align: left;">
|
||
<div style="font-size: 1.1rem; font-weight: 700; color: var(--text-main);">
|
||
${PMI18n.cur(dept.total)}
|
||
</div>
|
||
<div style="font-size: 0.85rem; color: var(--text-dim);">
|
||
佔總 P 預算 ${formatPct(deptPct)}%
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="sales-chevron-${safeDeptId}" style="color: var(--text-muted); transition: transform 0.3s;">▼</div>
|
||
</div>
|
||
|
||
<!-- Togglable Detail Table -->
|
||
<div id="sales-detail-${safeDeptId}" style="display: none; padding: 0 0 1.5rem 0; border-top: 1px solid var(--border-glass); margin-top: 0.5rem; animation: fadeIn 0.3s ease-out;">
|
||
<div style="padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--wash); padding-left: 1.5rem; padding-right: 1.5rem;">
|
||
`;
|
||
|
||
// Everyone in the department in one list; groups are not shown here.
|
||
const people = Object.values(dept.groups).flatMap(g => g.people).sort((a, b) => (b.yearlyCost || 0) - (a.yearlyCost || 0));
|
||
deptHtml += `
|
||
<div class="table-container" style="border: none; margin-top: 0;">
|
||
<table style="background: transparent;">
|
||
<thead>
|
||
<tr>
|
||
<th>姓名</th>
|
||
<th>職稱</th>
|
||
<th>職能</th>
|
||
<th class="num">月薪</th>
|
||
<th class="num">H1 起</th>
|
||
<th class="num">H1 迄</th>
|
||
<th class="num">H2 起</th>
|
||
<th class="num">H2 迄</th>
|
||
<th class="num">管理率</th>
|
||
<th>狀態</th>
|
||
<th class="num">年度預算估計</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
${people.map(p => {
|
||
const nameDisplay = p.isManager
|
||
? `${escapeHtml(p.name)} <span style="font-size:0.75rem; color:var(--accent-warning); font-weight:700; background:color-mix(in srgb, var(--accent-warning) 12%, transparent); padding:2px 6px; border-radius:999px; margin-left:4px;">主管</span>`
|
||
: escapeHtml(p.name);
|
||
return `
|
||
<tr>
|
||
<td>${nameDisplay}</td>
|
||
<td>${escapeHtml(p.title || '')}</td>
|
||
<td><span class="role-pill role-p">${escapeHtml(p.role.split(' - ')[0])}</span></td>
|
||
<td class="num">${salaryHidden ? salaryMask() : `${PMI18n.cur(parseFloat(p.salary) || 0)}`}</td>
|
||
<td class="num">${p.h1Start || '-'}</td>
|
||
<td class="num">${p.h1End || '-'}</td>
|
||
<td class="num">${p.h2Start || '-'}</td>
|
||
<td class="num">${p.h2End || '-'}</td>
|
||
<td class="num" style="${p.workRate !== 1.0 ? 'color: var(--accent-warning); font-weight: 700;' : ''}">${p.workRate.toFixed(2)}</td>
|
||
<td>${getStatusBadge(p)}</td>
|
||
<td class="num" style="color: var(--accent-primary-text); font-weight: 700;">${salaryHidden ? salaryMask() : `${PMI18n.cur(p.yearlyCost)}`}</td>
|
||
</tr>`;
|
||
}).join('')}
|
||
</tbody>
|
||
</table>
|
||
</div>`;
|
||
|
||
deptHtml += `
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
container.innerHTML += deptHtml;
|
||
});
|
||
}
|
||
|
||
function toggleSalesDept(deptId) {
|
||
const detailView = document.getElementById(`sales-detail-${deptId}`);
|
||
const chevron = document.getElementById(`sales-chevron-${deptId}`);
|
||
|
||
if (detailView.style.display === 'none') {
|
||
detailView.style.display = 'block';
|
||
chevron.style.transform = 'rotate(180deg)';
|
||
chevron.style.color = 'var(--accent-primary)';
|
||
} else {
|
||
detailView.style.display = 'none';
|
||
chevron.style.transform = 'rotate(0deg)';
|
||
chevron.style.color = 'var(--text-muted)';
|
||
}
|
||
}
|
||
|
||
function toggleSalesGroup(groupId) {
|
||
const detailView = document.getElementById(`sales-group-detail-${groupId}`);
|
||
const chevron = document.getElementById(`sales-group-chevron-${groupId}`);
|
||
|
||
if (detailView.style.display === 'none') {
|
||
detailView.style.display = 'block';
|
||
chevron.style.transform = 'rotate(180deg)';
|
||
} else {
|
||
detailView.style.display = 'none';
|
||
chevron.style.transform = 'rotate(0deg)';
|
||
}
|
||
}
|
||
|
||
|
||
function renderArtists() {
|
||
initOrgStructure();
|
||
const current = isSimMode ? simData : baseData;
|
||
calculateAll(current);
|
||
const container = document.getElementById('artists-content');
|
||
|
||
// 1. Filter: Valid Depts from OrgStructure + Role A or O
|
||
const targetDepts = Object.keys(globalParams.orgStructure);
|
||
const targetPeople = current.filter(p =>
|
||
targetDepts.includes(p.dept) &&
|
||
(p.role.startsWith('A') || p.role.startsWith('O'))
|
||
);
|
||
|
||
// 2. Calculations
|
||
let grandTotal = 0; // Raw in-house artist total for business depts
|
||
let grandOutsourceTotal = 0;
|
||
const depts = {};
|
||
|
||
targetPeople.forEach(p => {
|
||
const cost = p.totalCost || 0;
|
||
const isOutsource = p.role.startsWith('O');
|
||
const deptName = p.dept;
|
||
const groupName = p.group || '未分組';
|
||
|
||
// Check if group is valid in orgStructure
|
||
const isValidGroup = globalParams.orgStructure[deptName]?.includes(groupName);
|
||
const assignedGroup = isValidGroup ? groupName : '未分組 (需由管理清單指派)';
|
||
|
||
if (!depts[deptName]) depts[deptName] = { name: deptName, total: 0, outsourceTotal: 0, groups: {} };
|
||
if (!depts[deptName].groups[assignedGroup]) {
|
||
depts[deptName].groups[assignedGroup] = { name: assignedGroup, total: 0, outsourceTotal: 0, people: [] };
|
||
}
|
||
|
||
if (!isOutsource) {
|
||
grandTotal += cost;
|
||
depts[deptName].total += cost;
|
||
depts[deptName].groups[assignedGroup].total += cost;
|
||
} else {
|
||
grandOutsourceTotal += cost;
|
||
depts[deptName].outsourceTotal += cost;
|
||
depts[deptName].groups[assignedGroup].outsourceTotal += cost;
|
||
}
|
||
depts[deptName].groups[assignedGroup].people.push(p);
|
||
});
|
||
|
||
|
||
// Update Grand Total UI
|
||
document.getElementById('artists-grand-total').innerHTML = `
|
||
${PMI18n.cur(Math.ceil(grandTotal))}
|
||
${grandOutsourceTotal > 0 ? `<br><span style="font-size: 0.5em; color: var(--accent-warning);font-weight: 500;">+ 外包 ${PMI18n.cur(grandOutsourceTotal)}</span>` : ''}
|
||
`;
|
||
|
||
// 3. Render
|
||
container.innerHTML = '';
|
||
Object.keys(globalParams.orgStructure).forEach(deptName => { // Iterate over predefined order
|
||
const dept = depts[deptName];
|
||
if (!dept) return; // Skip if department has no A/O people
|
||
|
||
const safeDeptId = 'artist-' + dept.name.replace(/\s+/g, '-');
|
||
const totalPeople = Object.values(dept.groups).reduce((acc, g) => acc + g.people.length, 0);
|
||
const deptPct = grandTotal === 0 ? 0 : (dept.total / grandTotal);
|
||
const deptCombined = dept.total;
|
||
|
||
// --- R&D Redistribution Logic ---
|
||
const rdReductionPct = globalParams.rdReductionPct ?? 0.35;
|
||
const rdGroups = globalParams.rdGroups || [];
|
||
|
||
// Calculate temporary combined totals for each group within this dept
|
||
const groupProcessed = Object.values(dept.groups).map(g => {
|
||
const groupCombined = g.total;
|
||
const isRD = rdGroups.includes(`${dept.name}|${g.name}`);
|
||
return { ...g, combined: groupCombined, isRD };
|
||
});
|
||
|
||
const totalRDTax = groupProcessed.filter(g => g.isRD).reduce((acc, g) => acc + (g.combined * rdReductionPct), 0);
|
||
const normalGroupsTotal = groupProcessed.filter(g => !g.isRD).reduce((acc, g) => acc + g.combined, 0);
|
||
|
||
groupProcessed.forEach(g => {
|
||
if (g.isRD) {
|
||
g.finalCombined = g.combined * (1 - rdReductionPct);
|
||
g.rdNote = `研發釋出 -${formatPct(rdReductionPct * 100)}%`;
|
||
} else {
|
||
const shareOfNormal = normalGroupsTotal === 0 ? 0 : (g.combined / normalGroupsTotal);
|
||
g.finalCombined = g.combined + (totalRDTax * shareOfNormal);
|
||
if (totalRDTax > 0) g.rdNote = `分攤研製預算`;
|
||
}
|
||
});
|
||
|
||
let deptHtml = `
|
||
<div class="card" style="margin-bottom: 2rem; padding: 0;">
|
||
<!-- Clikable Header -->
|
||
<div onclick="toggleArtistsDept('${safeDeptId}')" style="cursor: pointer; padding: 1.5rem; display: flex; justify-content: space-between; align-items: center; transition: background 0.2s;" data-row-toggle>
|
||
<div style="display: flex; align-items: center; gap: 2rem; flex-grow: 1;">
|
||
<h2 class="dept-name" style="margin: 0; min-width: 200px; text-align: left;">${dept.name}</h2>
|
||
<div style="min-width: 80px; text-align: left;">
|
||
<span style="font-size: 0.85rem; color: var(--text-muted); background: var(--wash); padding: 4px 12px; border-radius: 99px;">${totalPeople} 人</span>
|
||
</div>
|
||
<div style="display: flex; flex-direction: column; min-width: 300px; text-align: left;">
|
||
<div style="font-size: 1.25rem; font-weight: 800; color: var(--text-main);">
|
||
${PMI18n.cur(Math.ceil(deptCombined))}
|
||
<span style="font-size: 0.85rem; color: var(--text-dim); font-weight: 400; margin-left: 10px;">
|
||
(佔比 ${formatPct(deptPct * 100)}%)
|
||
</span>
|
||
</div>
|
||
<div style="font-size: 0.85rem; color: var(--text-dim); font-weight: 400;">
|
||
原始加總:${PMI18n.cur(dept.total)} (未分攤)
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div style="display: flex; align-items: center; gap: 1rem;">
|
||
${dept.outsourceTotal > 0 ? `<div style="font-size: 0.85rem; color: var(--accent-warning); font-weight: 600;">+ 外包 ${PMI18n.cur(dept.outsourceTotal)}</div>` : ''}
|
||
<div id="artists-chevron-${safeDeptId}" style="color: var(--text-muted); transition: transform 0.3s;">▼</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Togglable Detail Table -->
|
||
<div id="artists-detail-${safeDeptId}" style="display: none; padding: 0 0 1.5rem 0; border-top: 1px solid var(--border-glass); margin-top: 0.5rem; animation: fadeIn 0.3s ease-out;">
|
||
<div style="padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--wash); padding-left: 1.5rem; padding-right: 1.5rem;">
|
||
`;
|
||
|
||
// Render Groups within the Department
|
||
groupProcessed.sort((a, b) => b.finalCombined - a.finalCombined).forEach(group => {
|
||
const safeGroupId = 'artist-group-' + dept.name.replace(/\s+/g, '-') + '-' + group.name.replace(/\s+/g, '-');
|
||
const groupPctOfGrand = grandTotal === 0 ? 0 : (group.total / grandTotal);
|
||
|
||
deptHtml += `
|
||
<div class="card" style="margin-bottom: 1rem; padding: 0; background: var(--inset); border-color: var(--wash); border-radius: 0; border-left: none; border-right: none;">
|
||
<!-- Clikable Group Header -->
|
||
<div onclick="toggleArtistsGroup('${safeGroupId}')" style="cursor: pointer; padding: 1rem 1.5rem; display: flex; justify-content: space-between; align-items: center; transition: background 0.2s;" data-row-toggle>
|
||
<div style="display: flex; align-items: center; gap: 2rem; flex-grow: 1;">
|
||
<h3 style="color: var(--text-main); margin: 0; min-width: 200px; text-align: left; font-size: 1rem; font-weight: 500;" title="${escapeHtml(group.name)}">${escapeHtml(shortGroupName(dept.name, group.name))}</h3>
|
||
<div style="min-width: 80px; text-align: left;">
|
||
<span style="font-size: 0.8rem; color: var(--text-dim); background: var(--wash); padding: 2px 8px; border-radius: 99px;">${group.people.length} 人</span>
|
||
</div>
|
||
<div style="display:flex; flex-direction:column; min-width: 300px; text-align: left;">
|
||
<div style="font-size: 1.1rem; font-weight: 500; color: var(--text-main);">
|
||
${PMI18n.cur(Math.ceil(group.finalCombined))}
|
||
<span style="font-size: 0.8rem; color: var(--text-dim); font-weight: 400; margin-left: 8px;">
|
||
(佔比 ${formatPct(groupPctOfGrand * 100)}%)
|
||
</span>
|
||
</div>
|
||
<div style="font-size: 0.8rem; color: var(--text-dim); font-weight: 400; display: flex; gap: 10px; align-items: center;">
|
||
<span>原始加總:${PMI18n.cur(group.total)}</span>
|
||
${group.rdNote ? `<span class="tag ${group.isRD ? 'tag-rd' : 'tag-cg'}">${group.rdNote}</span>` : ''}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div style="display: flex; align-items: center; gap: 1rem;">
|
||
${group.outsourceTotal > 0 ? `<div style="font-size: 0.8rem; color: var(--accent-warning); font-weight: 600;">+ 外包 ${PMI18n.cur(group.outsourceTotal)}</div>` : ''}
|
||
<div id="artists-group-chevron-${safeGroupId}" style="color: var(--text-dim); transition: transform 0.3s; font-size: 0.8rem;">▼</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Togglable Group Detail Table -->
|
||
<div id="artists-group-detail-${safeGroupId}" style="display: none; padding: 0 1.5rem 1.5rem 1.5rem;">
|
||
<div class="table-container" style="border: none; margin-top: 0;">
|
||
<table style="background: transparent; table-layout: fixed; width: 100%;">
|
||
<colgroup>
|
||
<col style="width:90px">
|
||
<col style="width:100px">
|
||
<col style="width:60px">
|
||
<col style="width:90px">
|
||
<col style="width:52px">
|
||
<col style="width:52px">
|
||
<col style="width:52px">
|
||
<col style="width:52px">
|
||
<col style="width:55px">
|
||
<col style="width:100px">
|
||
<col style="width:120px">
|
||
</colgroup>
|
||
<thead>
|
||
<tr>
|
||
<th style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">姓名</th>
|
||
<th style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">職稱</th>
|
||
<th>職能</th>
|
||
<th class="num">月/日薪</th>
|
||
<th class="num">H1 起</th>
|
||
<th class="num">H1 迄</th>
|
||
<th class="num">H2 起</th>
|
||
<th class="num">H2 迄</th>
|
||
<th class="num">工作率</th>
|
||
<th class="num">狀態</th>
|
||
<th class="num">年度總成本</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
`;
|
||
|
||
// Sort people in group by TotalCost desc
|
||
group.people.sort((a, b) => (b.totalCost || 0) - (a.totalCost || 0)).forEach(p => {
|
||
const isOutsource = p.role.includes('O');
|
||
const salaryPrefix = (isOutsource ? '日 ' : '') + PMI18n.sym() + ' ';
|
||
const salaryVal = isOutsource ? p.dayrate : p.salary;
|
||
|
||
deptHtml += `
|
||
<tr>
|
||
<td style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="${p.name}">${p.name}</td>
|
||
<td style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="${p.title || ''}">${p.title || ''}</td>
|
||
<td><span class="role-pill ${isOutsource ? 'role-o' : 'role-a'}" style="font-size:0.75rem;padding:2px 6px;">${p.role.split(' - ')[0]}</span></td>
|
||
<td class="num" style="color:var(--text-muted); font-size:0.8rem;">${salaryPrefix}${PMI18n.amt(parseFloat(salaryVal) || 0)}</td>
|
||
<td class="num">${p.h1Start || '-'}</td>
|
||
<td class="num">${p.h1End || '-'}</td>
|
||
<td class="num">${p.h2Start || '-'}</td>
|
||
<td class="num">${p.h2End || '-'}</td>
|
||
<td class="num">${p.workRateUsed || 1}</td>
|
||
<td class="num">${getStatusBadge(p)}</td>
|
||
<td class="num" style="color: var(--accent-primary-text); font-weight: 700;">${PMI18n.cur(p.totalCost || 0)}</td>
|
||
</tr>
|
||
`;
|
||
});
|
||
|
||
deptHtml += `
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
});
|
||
|
||
deptHtml += `
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
container.innerHTML += deptHtml;
|
||
});
|
||
|
||
}
|
||
|
||
function toggleArtistsDept(deptId) {
|
||
const detailView = document.getElementById(`artists-detail-${deptId}`);
|
||
const chevron = document.getElementById(`artists-chevron-${deptId}`);
|
||
|
||
if (detailView.style.display === 'none') {
|
||
detailView.style.display = 'block';
|
||
chevron.style.transform = 'rotate(180deg)';
|
||
chevron.style.color = 'var(--accent-primary)';
|
||
} else {
|
||
detailView.style.display = 'none';
|
||
chevron.style.transform = 'rotate(0deg)';
|
||
chevron.style.color = 'var(--text-muted)';
|
||
}
|
||
}
|
||
|
||
function toggleArtistsGroup(groupId) {
|
||
const detailView = document.getElementById(`artists-group-detail-${groupId}`);
|
||
const chevron = document.getElementById(`artists-group-chevron-${groupId}`);
|
||
|
||
if (detailView.style.display === 'none') {
|
||
detailView.style.display = 'block';
|
||
chevron.style.transform = 'rotate(180deg)';
|
||
} else {
|
||
detailView.style.display = 'none';
|
||
chevron.style.transform = 'rotate(0deg)';
|
||
}
|
||
}
|
||
|
||
function updateGlobalParam(key, val) {
|
||
const parsed = Number(val);
|
||
if (!Number.isFinite(parsed) || parsed < 0 ||
|
||
(['grossMarginPct', 'utilizationP', 'utilizationA', 'annualWorkDays', 'workingDays', 'usdRate'].includes(key) && parsed === 0)) {
|
||
alert('請輸入有效數值;工作天數、產出率與毛利率必須大於零。');
|
||
renderParams();
|
||
return;
|
||
}
|
||
globalParams[key] = parsed;
|
||
saveAndRefresh();
|
||
}
|
||
|
||
|
||
function getStatusBadge(p) {
|
||
const months = activeMonths(p);
|
||
|
||
if (months === 12) {
|
||
return '<span class="status-pill status-active">在職 (12m)</span>';
|
||
} else if (months === 0) {
|
||
return '<span class="status-pill status-resign">未安排 (0m)</span>';
|
||
} else {
|
||
return `<span class="status-pill status-temp">非滿年度 (${months}m)</span>`;
|
||
}
|
||
}
|
||
|
||
function renderPersonnel() {
|
||
initOrgStructure(); // Ensure org structure is initialized
|
||
const currentRaw = isSimMode ? simData : baseData;
|
||
const tbody = document.querySelector('#person-table tbody');
|
||
const searchQuery = document.getElementById('personnel-search').value.toLowerCase();
|
||
const deptFilter = document.getElementById('personnel-dept-filter').value;
|
||
const groupFilter = document.getElementById('personnel-group-filter').value;
|
||
populateCompanyFilter({ keepSelection: true });
|
||
const companyFilter = document.getElementById('personnel-company-filter')?.value || 'all';
|
||
|
||
// Update Sort Icons
|
||
document.querySelectorAll('.sort-icon').forEach(el => {
|
||
const field = el.id.replace('sort-', '');
|
||
if (field === sortConfig.field) {
|
||
el.innerText = sortConfig.direction === 'asc' ? '▲' : '▼';
|
||
el.parentElement.classList.add('active-sort');
|
||
} else {
|
||
el.innerText = '';
|
||
el.parentElement.classList.remove('active-sort');
|
||
}
|
||
});
|
||
|
||
// 1. Filter
|
||
let filtered = currentRaw.filter(p => {
|
||
const matchesSearch = p.name.toLowerCase().includes(searchQuery) || (p.title || '').toLowerCase().includes(searchQuery);
|
||
const matchesDept = deptFilter === 'all' || p.dept === deptFilter || (deptFilter === '其他' && !Object.keys(globalParams.orgStructure).includes(p.dept));
|
||
const matchesGroup = groupFilter === 'all' || p.group === groupFilter || (groupFilter === '未分組' && !p.group);
|
||
return matchesPersonnelCategory(p) && matchesSearch && matchesCompany(p, companyFilter) && matchesDept && matchesGroup;
|
||
});
|
||
|
||
// 2. Sort
|
||
filtered.sort((a, b) => {
|
||
let valA = a[sortConfig.field];
|
||
let valB = b[sortConfig.field];
|
||
|
||
// Handle numbers
|
||
if (['salary', 'dayrate', 'h1Start', 'h1End', 'totalCost'].includes(sortConfig.field)) {
|
||
valA = parseFloat(valA) || 0;
|
||
valB = parseFloat(valB) || 0;
|
||
// salary logic: if role is outsource, use dayrate
|
||
if (sortConfig.field === 'salary') {
|
||
valA = a.role.includes('O') ? parseFloat(a.dayrate || 0) : parseFloat(a.salary || 0);
|
||
valB = b.role.includes('O') ? parseFloat(b.dayrate || 0) : parseFloat(b.salary || 0);
|
||
}
|
||
} else {
|
||
valA = (valA || "").toString().toLowerCase();
|
||
valB = (valB || "").toString().toLowerCase();
|
||
}
|
||
|
||
if (valA < valB) return sortConfig.direction === 'asc' ? -1 : 1;
|
||
if (valA > valB) return sortConfig.direction === 'asc' ? 1 : -1;
|
||
return 0;
|
||
});
|
||
|
||
tbody.innerHTML = '';
|
||
if (!filtered.length) tbody.innerHTML = '<tr><td colspan="16" style="text-align:center; padding:2rem;">沒有符合條件的人員,可調整篩選或新增。</td></tr>';
|
||
|
||
let totalCosts = { pa: 0, o: 0, all: 0 };
|
||
|
||
filtered.forEach((p) => {
|
||
// Find original index in currentRaw for updates/deletes
|
||
const origIdx = currentRaw.indexOf(p);
|
||
const roleClass = p.role.includes('A') ? 'role-a' : (p.role.includes('P') ? 'role-p' : 'role-o');
|
||
const isOutsource = p.role.includes('O');
|
||
|
||
// Track costs for KPI
|
||
const pCost = p.totalCost || 0;
|
||
totalCosts.all += pCost;
|
||
if (isOutsource) totalCosts.o += pCost;
|
||
else totalCosts.pa += pCost;
|
||
|
||
const isHourly = p.salaryType === 'hourly';
|
||
const salaryField = isOutsource ? 'dayrate' : 'salary';
|
||
const salaryPrefix = isOutsource ? '日 $' : isHourly ? '時 $' : '$';
|
||
const salaryShownPrefix = (isOutsource ? '日 ' : isHourly ? '時 ' : '') + PMI18n.sym() + ' ';
|
||
const salaryVal = isOutsource ? p.dayrate : isHourly ? p.hourlyRate : p.salary;
|
||
const isHrPerson = p.source === 'hr-sync';
|
||
const isPlanned = p.source === 'planned';
|
||
const safeName = escapeHtml(p.name);
|
||
const safeTitle = escapeHtml(p.title || '');
|
||
const planNote = isPlanned
|
||
? `<div style="font-size:0.75rem;color:var(--accent-secondary-text);margin-top:.35rem;white-space:nowrap;">預排新進:${escapeHtml(p.plannedHire)} 開始</div>`
|
||
: p.plannedLeave ? `<div style="font-size:0.75rem;color:var(--accent-warning);margin-top:.35rem;white-space:nowrap;">預排離職:最後 ${escapeHtml(p.plannedLeave)}</div>` : '';
|
||
const classification = p.transferSplit
|
||
? `<div style="font-size:0.75rem;color:var(--text-dim);margin-top:.35rem;white-space:nowrap;">${p.transferSplit === 'before' ? `調動前:${p.transferMonth} 月起算新部門` : `調動後:${p.transferMonth} 月起`}</div>`
|
||
: isHrPerson && p.partTime
|
||
? `<div style="font-size:0.75rem;color:${p.calculationReady ? 'var(--text-dim)' : 'var(--accent-warning)'};margin-top:.35rem;white-space:nowrap;">${p.calculationReady ? `工讀:日薪 = 時薪 ${PMI18n.cur(p.partTimeHourlyRate || 0)} × 8,算法同常態型外包` : escapeHtml(p.calculationIssue || '待確認')}</div>`
|
||
: isHrPerson && p.calculationReady && isSupportRole(p.role)
|
||
? `<div style="font-size:0.75rem;color:var(--text-dim);margin-top:.35rem;white-space:nowrap;">${p.supportExcluded ? 'G 營運支援:不計入發票與 A/P 指標' : 'G 營運支援:計成本 × 人薪倍率'}</div>`
|
||
: isHrPerson && p.calculationReady && isCostExcludedIntern(p)
|
||
? `<div style="font-size:0.75rem;color:var(--text-dim);margin-top:.35rem;white-space:nowrap;">實習生:薪資 × 1 只算進發票,不算 CODA,計入 A/P 人數</div>`
|
||
: isHrPerson && !p.calculationReady
|
||
? `<div style="font-size:0.75rem;color:var(--accent-warning);margin-top:.35rem;white-space:nowrap;">${escapeHtml(p.calculationIssue || '待確認')}</div>` : '';
|
||
const roleInput = isHrPerson && p.partTime ? `<span class="role-pill ${roleClass}" title="工讀生依 HR 資料一律算 O">O</span>` : isHrPerson ? `<select onchange="updatePerson(${origIdx}, 'role', this.value)" style="width:90px;">
|
||
<option value="" ${!isCalculationRole(p.role) ? 'selected' : ''}>待分類</option>
|
||
<option value="P - 製作" ${p.role === 'P - 製作' ? 'selected' : ''}>P</option>
|
||
<option value="A - 藝術家" ${p.role === 'A - 藝術家' ? 'selected' : ''}>A</option>
|
||
<option value="G - 營運支援" ${p.role === 'G - 營運支援' ? 'selected' : ''}>G</option>
|
||
</select>` : `<span class="role-pill ${roleClass}">${escapeHtml((p.role || '').split(' - ')[0])}</span>`;
|
||
const salaryControl = salaryHidden
|
||
? salaryMask()
|
||
: isHrPerson || isPlanned
|
||
? `<span title="由 HR Sync 提供,目前不可在試算頁覆寫">${salaryShownPrefix}${PMI18n.amt(parseFloat(salaryVal) || 0)}</span>`
|
||
: `<div style="display:flex; align-items:center; justify-content: flex-end;"><span style="font-size:0.75rem; color:var(--text-dim); margin-right:2px;">${salaryPrefix}</span><input type="number" style="text-align:right; width: 85px;" value="${salaryVal}" onchange="updatePerson(${origIdx}, '${salaryField}', this.value)"></div>`;
|
||
const weeklyDays = isHrPerson && isHourly
|
||
? `<input type="number" min="1" max="5" value="${Math.min(5, Math.max(1, Number(p.weeklyWorkDays) || 5))}" onchange="updatePerson(${origIdx}, 'weeklyWorkDays', this.value)" class="input-mini" style="width:38px;">`
|
||
: '—';
|
||
|
||
const statusHtml = getStatusBadge(p);
|
||
|
||
tbody.innerHTML += `
|
||
<tr>
|
||
<td style="white-space:nowrap;" title="${escapeHtml(p.company || '')}">${escapeHtml(shortCompanyName(p.company)) || '<span style="color:var(--text-dim);">未指定</span>'}</td>
|
||
<td>${isHrPerson || isPlanned ? safeName : `<input value="${safeName}" onchange="updatePerson(${origIdx}, 'name', this.value)" style="width: 75px;">`}</td>
|
||
<td>${isHrPerson || isPlanned ? safeTitle : `<input value="${safeTitle}" onchange="updatePerson(${origIdx}, 'title', this.value)" style="width: 85px;">`}</td>
|
||
<td>${isPlanned ? escapeHtml(p.dept || '') : placementCell(p, origIdx, 'dept')}</td>
|
||
<td>${isPlanned ? escapeHtml(shortGroupName(p.dept, p.group || '')) : placementCell(p, origIdx, 'group')}</td>
|
||
<td>${roleInput}${classification}${planNote}</td>
|
||
<td style="text-align:center;">${managerCell(p, origIdx, isHrPerson)}</td>
|
||
<td class="num">${salaryControl}</td>
|
||
<td class="num">${weeklyDays}</td>
|
||
<td class="num"><input type="number" min="1" max="6" value="${p.h1Start || ''}" placeholder="-" onchange="updatePerson(${origIdx}, 'h1Start', this.value)" class="input-mini" style="width: 38px;" ${isPlanned ? 'disabled title="在「預排異動」修改"' : ''}></td>
|
||
<td class="num"><input type="number" min="1" max="6" value="${p.h1End || ''}" placeholder="-" onchange="updatePerson(${origIdx}, 'h1End', this.value)" class="input-mini" style="width: 38px;" ${isPlanned ? 'disabled title="在「預排異動」修改"' : ''}></td>
|
||
<td class="num"><input type="number" min="7" max="12" value="${p.h2Start || ''}" placeholder="-" onchange="updatePerson(${origIdx}, 'h2Start', this.value)" class="input-mini" style="width: 38px;" ${isPlanned ? 'disabled title="在「預排異動」修改"' : ''}></td>
|
||
<td class="num"><input type="number" min="7" max="12" value="${p.h2End || ''}" placeholder="-" onchange="updatePerson(${origIdx}, 'h2End', this.value)" class="input-mini" style="width: 38px;" ${isPlanned ? 'disabled title="在「預排異動」修改"' : ''}></td>
|
||
<td class="num" style="text-align:center;">${isHrPerson && !p.calculationReady ? '<span class="status-pill status-temp">待確認</span>' : statusHtml}</td>
|
||
<td class="num" style="color: var(--text-main); font-weight:500;">${salaryHidden ? salaryMask() : `${PMI18n.cur(p.totalCost || 0)}`}</td>
|
||
<td>${isHrPerson ? '<span style="color:var(--text-dim);font-size:.8rem;">HR 同步</span>' : isPlanned ? '<button type="button" onclick="showView(\'plans\')" style="background:none;border:none;color:var(--accent-secondary-text);cursor:pointer;font-size:.8rem;">預排異動</button>' : `<button onclick="removePerson(${origIdx})" style="background:none; border:none; color:var(--accent-danger); cursor:pointer;">刪除</button>`}</td>
|
||
</tr>
|
||
`;
|
||
});
|
||
|
||
// Update KPI Banner
|
||
const kpiContainer = document.getElementById('personnel-detail-kpi');
|
||
if (kpiContainer) {
|
||
kpiContainer.innerHTML = `
|
||
<div style="background: var(--wash); border: 1px solid var(--border-glass); border-radius: 8px; padding: 4px 12px; display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 0.75rem; color: var(--text-dim);">篩選總額</span>
|
||
<span style="font-size: 1.05rem; font-weight: 800; color: var(--text-main);">${PMI18n.cur(totalCosts.all)}</span>
|
||
</div>
|
||
<div style="background: var(--wash); border: 1px solid var(--border-glass); border-radius: 8px; padding: 4px 12px; display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 0.75rem; color: var(--text-dim);">${personnelCategory === 'contractors' ? '常態型外包' : '內部人員'}</span>
|
||
<span style="font-size: 0.95rem; font-weight: 700; color: var(--text-main);">${filtered.length} 人</span>
|
||
</div>
|
||
`;
|
||
}
|
||
}
|
||
|
||
function toggleSort(field) {
|
||
if (sortConfig.field === field) {
|
||
sortConfig.direction = sortConfig.direction === 'asc' ? 'desc' : 'asc';
|
||
} else {
|
||
sortConfig.field = field;
|
||
sortConfig.direction = 'asc';
|
||
}
|
||
renderPersonnel();
|
||
}
|
||
|
||
// --- FUNCTIONS ---
|
||
function updatePerson(idx, field, val) {
|
||
const target = isSimMode ? simData : baseData;
|
||
target[idx][field] = val;
|
||
if (target[idx].source === 'hr-sync') {
|
||
const person = target[idx];
|
||
if (field === 'isManager') person.managerClassification = 'confirmed';
|
||
// 工讀生的可否計算由伺服器依 HR 薪資決定,這裡只改月份,不重算。
|
||
if (!person.partTime) {
|
||
person.calculationReady = Boolean((parseFloat(person.salary) || parseFloat(person.hourlyRate)) && isCalculationRole(person.role));
|
||
person.calculationIssue = person.calculationReady ? '' : (!isCalculationRole(person.role) ? '待設定 P/A 職能' : 'HR 尚未提供可用薪資');
|
||
}
|
||
if (!isSimMode) saveHrCostOverride(person, field, val);
|
||
}
|
||
saveAndRefresh();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
// Invoice role of a department: its own saved role, else its company's default
|
||
// (夢想創造 defaults to bear, every other company to exclude).
|
||
const INVOICE_ROLE_LABELS = { bear: '承擔發票', share: '成本分攤', exclude: '不計入' };
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 「前製部_設計組」 under 前製部 reads as 「設計組」; the full name stays in the tooltip.
|
||
function shortGroupName(dept, g) {
|
||
if (!dept || !g) return g || '';
|
||
for (const sep of ['_', '-', ' ', '/', '/']) {
|
||
if (g.startsWith(dept + sep) && g.length > dept.length + 1) return g.slice(dept.length + 1);
|
||
}
|
||
return g;
|
||
}
|
||
|
||
function escapeHtml(value) {
|
||
return String(value == null ? '' : value).replace(/[&<>\"']/g, char => ({ '&': '&', '<': '<', '>': '>', '\"': '"', "'": ''' })[char]);
|
||
}
|
||
|
||
// Short 「已儲存」 note after a save reaches the server (failures keep using the red banner).
|
||
let saveToastTimer = null;
|
||
function showSaved(text = '已儲存') {
|
||
let el = document.getElementById('save-toast');
|
||
if (!el) {
|
||
el = document.createElement('div');
|
||
el.id = 'save-toast';
|
||
el.className = 'save-toast';
|
||
el.setAttribute('role', 'status');
|
||
el.setAttribute('aria-live', 'polite');
|
||
document.body.appendChild(el);
|
||
}
|
||
el.innerHTML = `<span class="dot" aria-hidden="true"></span>${escapeHtml(text)}`;
|
||
el.classList.add('show');
|
||
clearTimeout(saveToastTimer);
|
||
saveToastTimer = setTimeout(() => el.classList.remove('show'), 1800);
|
||
}
|
||
|
||
async function saveHrCostOverride(person, field, value) {
|
||
try {
|
||
const response = await fetch(`/api/hr/cost-model/employees/${encodeURIComponent(person.employeeNumber)}`, {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ field, value }),
|
||
});
|
||
if (!response.ok) throw new Error('儲存失敗');
|
||
showSaved();
|
||
} catch (error) {
|
||
console.error('Unable to save HR cost override', error);
|
||
document.getElementById('data-source-banner').textContent = 'HR 試算資料更新失敗,請重新整理後再試。';
|
||
document.getElementById('data-source-banner').style.color = 'var(--accent-danger)';
|
||
}
|
||
}
|
||
|
||
// Manual department / group only fill gaps HR leaves empty (HR wins once it has a value).
|
||
async function setHrPlacement(employeeNumber, field, value) {
|
||
if (isSimMode || !['dept', 'group'].includes(field)) return;
|
||
const clean = String(value || '').trim();
|
||
const base = `/api/hr/cost-model/employees/${encodeURIComponent(employeeNumber)}`;
|
||
try {
|
||
const response = clean
|
||
? await fetch(base, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ field, value: clean }) })
|
||
: await fetch(`${base}/overrides/${encodeURIComponent(field)}`, { method: 'DELETE' });
|
||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||
await loadBootstrapData();
|
||
saveAndRefresh();
|
||
if (document.querySelector('.view.active')?.id === 'org-structure') renderOrgStructure();
|
||
showSaved();
|
||
} catch (error) {
|
||
console.error('Unable to save placement', error);
|
||
const banner = document.getElementById('data-source-banner');
|
||
banner.textContent = '部門/組別儲存失敗,請重新整理後再試。';
|
||
banner.style.color = 'var(--accent-danger)';
|
||
}
|
||
}
|
||
|
||
async function clearHrPlacement(employeeNumber) {
|
||
if (isSimMode) return;
|
||
const base = `/api/hr/cost-model/employees/${encodeURIComponent(employeeNumber)}/overrides/`;
|
||
try {
|
||
for (const field of ['group', 'dept']) {
|
||
const response = await fetch(base + field, { method: 'DELETE' });
|
||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||
}
|
||
await loadBootstrapData();
|
||
saveAndRefresh();
|
||
if (document.querySelector('.view.active')?.id === 'org-structure') renderOrgStructure();
|
||
showSaved();
|
||
} catch (error) {
|
||
console.error('Unable to clear placement', error);
|
||
const banner = document.getElementById('data-source-banner');
|
||
banner.textContent = '清除手動部門/組別失敗,請重新整理後再試。';
|
||
banner.style.color = 'var(--accent-danger)';
|
||
}
|
||
}
|
||
|
||
function placementCell(p, origIdx, field) {
|
||
const value = p[field] || '';
|
||
const width = field === 'dept' ? 90 : 135;
|
||
if (p.source !== 'hr-sync') {
|
||
return `<input value="${escapeHtml(value)}" onchange="updatePerson(${origIdx}, '${field}', this.value)" style="width:${width}px;">`;
|
||
}
|
||
const source = p[field + 'Source'];
|
||
const ignored = field === 'dept' ? p.manualDeptIgnored : p.manualGroupIgnored;
|
||
if (source === 'hr') {
|
||
return `${escapeHtml(value)}<div style="font-size:0.75rem;color:var(--text-dim);margin-top:.2rem;">HR${ignored ? '(手動值已改用 HR)' : ''}</div>`;
|
||
}
|
||
const tag = source === 'manual'
|
||
? `<span style="color:var(--accent-warning);">手動</span>`
|
||
: `<span style="color:var(--text-dim);">HR 未提供,可手動補</span>`;
|
||
return `<input value="${escapeHtml(value)}" placeholder="${field === 'dept' ? '輸入部門' : '輸入組別'}" onchange="setHrPlacement(${escapeHtml(JSON.stringify(p.employeeNumber))}, '${field}', this.value)" style="width:${width}px;"><div style="font-size:0.75rem;margin-top:.2rem;">${tag}</div>`;
|
||
}
|
||
|
||
// --- ADD PERSON MODAL FUNCTIONS ---
|
||
function addPerson() { openAddPersonModal(); } // keep backward compat with existing button
|
||
|
||
function openAddPersonModal() {
|
||
initOrgStructure();
|
||
const modal = document.getElementById('add-person-modal');
|
||
|
||
// Populate dept dropdown from orgStructure
|
||
const allDepts = Object.keys(globalParams.orgStructure);
|
||
const deptSel = document.getElementById('modal-dept');
|
||
deptSel.innerHTML = allDepts.map(d => `<option value="${d}">${d}</option>`).join('');
|
||
deptSel.value = allDepts[0] || '';
|
||
|
||
// Populate groups for initial dept
|
||
addPersonModalUpdateGroups();
|
||
|
||
// Reset form fields
|
||
document.getElementById('modal-name').value = '';
|
||
document.getElementById('modal-title-field').value = '';
|
||
const roleSelect = document.getElementById('modal-role');
|
||
for (const option of roleSelect.options) {
|
||
option.disabled = option.hidden = personnelCategory === 'contractors' ? !option.value.startsWith('O') : option.value.startsWith('O');
|
||
}
|
||
roleSelect.value = personnelCategory === 'contractors' ? 'O - 外包' : 'A - 藝術家';
|
||
roleSelect.disabled = personnelCategory === 'contractors';
|
||
document.getElementById('modal-title').textContent = personnelCategory === 'contractors' ? '新增常態型外包' : '新增內部人員';
|
||
document.getElementById('modal-is-manager').checked = false;
|
||
document.getElementById('modal-salary').value = '';
|
||
document.getElementById('modal-h1s').value = '1';
|
||
document.getElementById('modal-h1e').value = '6';
|
||
document.getElementById('modal-h2s').value = '7';
|
||
document.getElementById('modal-h2e').value = '12';
|
||
addPersonModalUpdateSalaryLabel();
|
||
|
||
// Open with animation; remember where focus was so closing can return it.
|
||
modalReturnFocus = document.activeElement;
|
||
modal.classList.add('open');
|
||
setTimeout(() => document.getElementById('modal-name').focus(), 50);
|
||
}
|
||
|
||
let modalReturnFocus = null;
|
||
|
||
function closeAddPersonModal() {
|
||
const modal = document.getElementById('add-person-modal');
|
||
if (!modal.classList.contains('open')) return;
|
||
modal.classList.remove('open');
|
||
if (modalReturnFocus && document.contains(modalReturnFocus)) modalReturnFocus.focus();
|
||
modalReturnFocus = null;
|
||
}
|
||
|
||
function addPersonModalUpdateGroups() {
|
||
initOrgStructure();
|
||
const dept = document.getElementById('modal-dept').value;
|
||
const groupSel = document.getElementById('modal-group');
|
||
const groups = (globalParams.orgStructure[dept]) || [];
|
||
|
||
// Use current data to find actual groups in this dept
|
||
const current = isSimMode ? simData : baseData;
|
||
const liveGroups = [...new Set(current.filter(p => p.dept === dept && p.group).map(p => p.group))].sort();
|
||
const allGroups = [...new Set([...groups, ...liveGroups])];
|
||
|
||
if (allGroups.length === 0) {
|
||
groupSel.innerHTML = '<option value="">— 未分組</option>';
|
||
} else {
|
||
groupSel.innerHTML = '<option value="">— 未分組</option>' + allGroups.map(g => `<option value="${g}">${g}</option>`).join('');
|
||
}
|
||
}
|
||
|
||
function addPersonModalUpdateSalaryLabel() {
|
||
const role = document.getElementById('modal-role').value;
|
||
const isOutsource = role.startsWith('O');
|
||
document.getElementById('modal-salary-label').textContent = isOutsource ? '日薪' : '月薪';
|
||
document.getElementById('modal-salary-prefix').textContent = isOutsource ? 'NT$ / 日' : 'NT$ / 月';
|
||
}
|
||
|
||
function confirmAddPerson() {
|
||
const name = document.getElementById('modal-name').value.trim();
|
||
if (!name) {
|
||
document.getElementById('modal-name').focus();
|
||
document.getElementById('modal-name').style.borderColor = 'var(--accent-danger)';
|
||
setTimeout(() => document.getElementById('modal-name').style.borderColor = '', 1500);
|
||
return;
|
||
}
|
||
|
||
const role = document.getElementById('modal-role').value;
|
||
const isOutsource = role.startsWith('O');
|
||
|
||
const newPerson = {
|
||
name: name,
|
||
title: document.getElementById('modal-title-field').value.trim(),
|
||
dept: document.getElementById('modal-dept').value,
|
||
group: document.getElementById('modal-group').value || '',
|
||
role: role,
|
||
isManager: document.getElementById('modal-is-manager').checked,
|
||
salary: isOutsource ? '' : (document.getElementById('modal-salary').value || '0'),
|
||
dayrate: isOutsource ? (document.getElementById('modal-salary').value || '0') : '',
|
||
h1Start: document.getElementById('modal-h1s').value,
|
||
h1End: document.getElementById('modal-h1e').value,
|
||
h2Start: document.getElementById('modal-h2s').value,
|
||
h2End: document.getElementById('modal-h2e').value,
|
||
};
|
||
|
||
let maxRow = -1;
|
||
[...baseData, ...(simData || [])].forEach(p => { if (p.row !== undefined && p.row > maxRow) maxRow = p.row; });
|
||
newPerson.row = maxRow + 1;
|
||
|
||
const target = isSimMode ? simData : baseData;
|
||
target.unshift(newPerson);
|
||
|
||
// Force orgStructure rebuild & reset filters so new person is immediately visible
|
||
globalParams.orgStructure = null;
|
||
const deptFilterEl = document.getElementById('personnel-dept-filter');
|
||
const groupFilterEl = document.getElementById('personnel-group-filter');
|
||
const companyFilterEl = document.getElementById('personnel-company-filter');
|
||
if (companyFilterEl) companyFilterEl.value = 'all';
|
||
if (deptFilterEl) deptFilterEl.value = 'all';
|
||
if (groupFilterEl) groupFilterEl.value = 'all';
|
||
|
||
closeAddPersonModal();
|
||
saveAndRefresh();
|
||
}
|
||
|
||
// Keyboard access for rendered views: clickable rows/cards built as <div onclick>
|
||
// become focusable buttons, and form fields inside tables get an accessible name
|
||
// from their column header and row.
|
||
const NATIVE_CONTROLS = new Set(['BUTTON', 'A', 'INPUT', 'SELECT', 'TEXTAREA', 'LABEL', 'OPTION', 'FORM']);
|
||
// Expandable rows: which detail panel each toggle opens.
|
||
const TOGGLE_TARGETS = {
|
||
toggleInvoiceDept: 'invoice-detail-', toggleCodaDept: 'coda-detail-', toggleCodaGroup: 'coda-group-detail-',
|
||
toggleSalesDept: 'sales-detail-', toggleSalesGroup: 'sales-group-detail-',
|
||
toggleArtistsDept: 'artists-detail-', toggleArtistsGroup: 'artists-group-detail-',
|
||
};
|
||
function syncExpanded(root = document) {
|
||
root.querySelectorAll('[onclick^="toggle"]').forEach(el => {
|
||
const m = /^(toggle\w+)\('([^']*)'\)/.exec(el.getAttribute('onclick') || '');
|
||
const prefix = m && TOGGLE_TARGETS[m[1]];
|
||
if (!prefix) return;
|
||
const panel = document.getElementById(prefix + m[2]);
|
||
if (!panel) return;
|
||
el.setAttribute('aria-controls', panel.id);
|
||
el.setAttribute('aria-expanded', String(panel.style.display !== 'none'));
|
||
});
|
||
}
|
||
function enhanceAccessibility(root = document) {
|
||
root.querySelectorAll('[onclick]').forEach(el => {
|
||
if (NATIVE_CONTROLS.has(el.tagName) || el.classList.contains('modal-backdrop') || el.hasAttribute('tabindex')) return;
|
||
el.setAttribute('tabindex', '0');
|
||
el.setAttribute('role', 'button');
|
||
});
|
||
syncExpanded(root);
|
||
// ⓘ tips: the text lives in data-tip so it opens on click / keyboard, not only on hover.
|
||
root.querySelectorAll('.info-tip').forEach(el => {
|
||
if (el.hasAttribute('title')) { el.dataset.tip = el.getAttribute('title'); el.removeAttribute('title'); }
|
||
el.setAttribute('tabindex', '0');
|
||
el.setAttribute('role', 'button');
|
||
if (!el.hasAttribute('aria-expanded')) el.setAttribute('aria-expanded', 'false');
|
||
});
|
||
root.querySelectorAll('table input:not([type=hidden]), table select').forEach(field => {
|
||
if (field.hasAttribute('aria-label') || field.hasAttribute('aria-labelledby')) return;
|
||
const cell = field.closest('td');
|
||
const row = field.closest('tr');
|
||
const table = field.closest('table');
|
||
if (!cell || !row || !table) return;
|
||
const headerRow = table.tHead ? table.tHead.rows[table.tHead.rows.length - 1] : null;
|
||
const header = headerRow && headerRow.cells[cell.cellIndex] ? headerRow.cells[cell.cellIndex].textContent.replace(/[▲▼]/g, '').trim() : '';
|
||
// Name the row by its 姓名 column when the table has one, else by its first cell.
|
||
const headers = headerRow ? [...headerRow.cells].map(c => c.textContent.trim()) : [];
|
||
const nameIndex = headers.findIndex(h => h.startsWith('姓名'));
|
||
const nameCell = row.cells[nameIndex >= 0 ? nameIndex : 0];
|
||
const nameInput = nameCell && nameCell.querySelector('input');
|
||
const rowName = (nameInput ? nameInput.value : nameCell ? nameCell.textContent : '').trim().slice(0, 30);
|
||
const label = [header, rowName && nameCell !== cell ? rowName : ''].filter(Boolean).join(',');
|
||
if (label) field.setAttribute('aria-label', label);
|
||
});
|
||
}
|
||
|
||
let enhanceQueued = false;
|
||
new MutationObserver(() => {
|
||
if (enhanceQueued) return;
|
||
enhanceQueued = true;
|
||
requestAnimationFrame(() => { enhanceQueued = false; enhanceAccessibility(); });
|
||
}).observe(document.body, { childList: true, subtree: true });
|
||
enhanceAccessibility();
|
||
|
||
document.addEventListener('click', () => requestAnimationFrame(() => syncExpanded()), true);
|
||
|
||
// ⓘ tip popover: hover or focus shows it, click / Enter / Space pins it, Escape or a click elsewhere closes it.
|
||
let tipOwner = null;
|
||
let tipPinned = false;
|
||
function openTip(el, pin) {
|
||
let pop = document.getElementById('tip-pop');
|
||
if (!pop) {
|
||
pop = document.createElement('div');
|
||
pop.id = 'tip-pop';
|
||
pop.className = 'tip-pop';
|
||
pop.setAttribute('role', 'tooltip');
|
||
document.body.appendChild(pop);
|
||
}
|
||
if (tipOwner && tipOwner !== el) tipOwner.setAttribute('aria-expanded', 'false');
|
||
tipOwner = el;
|
||
tipPinned = !!pin;
|
||
pop.textContent = el.dataset.tip || '';
|
||
pop.classList.add('show');
|
||
el.setAttribute('aria-expanded', 'true');
|
||
el.setAttribute('aria-describedby', 'tip-pop');
|
||
const r = el.getBoundingClientRect();
|
||
const w = pop.offsetWidth, h = pop.offsetHeight;
|
||
let left = Math.min(Math.max(8, r.left + r.width / 2 - w / 2), innerWidth - w - 8);
|
||
let top = r.bottom + 8;
|
||
if (top + h > innerHeight - 8) top = Math.max(8, r.top - h - 8);
|
||
pop.style.left = `${left}px`;
|
||
pop.style.top = `${top}px`;
|
||
}
|
||
function closeTip() {
|
||
const pop = document.getElementById('tip-pop');
|
||
if (pop) pop.classList.remove('show');
|
||
if (tipOwner) { tipOwner.setAttribute('aria-expanded', 'false'); tipOwner.removeAttribute('aria-describedby'); }
|
||
tipOwner = null;
|
||
tipPinned = false;
|
||
}
|
||
document.addEventListener('click', e => {
|
||
const tip = e.target instanceof Element ? e.target.closest('.info-tip') : null;
|
||
if (tip) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
if (tipOwner === tip && tipPinned) closeTip(); else openTip(tip, true);
|
||
return;
|
||
}
|
||
if (tipOwner && !(e.target instanceof Element && e.target.closest('#tip-pop'))) closeTip();
|
||
});
|
||
document.addEventListener('mouseover', e => {
|
||
const tip = e.target instanceof Element ? e.target.closest('.info-tip') : null;
|
||
if (tip && !tipPinned) openTip(tip, false);
|
||
});
|
||
document.addEventListener('mouseout', e => {
|
||
const tip = e.target instanceof Element ? e.target.closest('.info-tip') : null;
|
||
if (tip && tip === tipOwner && !tipPinned) closeTip();
|
||
});
|
||
document.addEventListener('focusin', e => {
|
||
if (e.target instanceof Element && e.target.classList.contains('info-tip') && !tipPinned) openTip(e.target, false);
|
||
});
|
||
document.addEventListener('focusout', e => {
|
||
if (e.target === tipOwner && !tipPinned) closeTip();
|
||
});
|
||
|
||
// Enter / Space activate the focusable div buttons above.
|
||
document.addEventListener('keydown', e => {
|
||
const el = e.target;
|
||
if (!(el instanceof HTMLElement) || el.getAttribute('role') !== 'button' || NATIVE_CONTROLS.has(el.tagName)) return;
|
||
if (e.key === 'Enter' || e.key === ' ') {
|
||
e.preventDefault();
|
||
el.click();
|
||
}
|
||
});
|
||
|
||
// Escape closes the add-person modal (and an open info tip). Enter never submits it:
|
||
// a person is added only with the 「確認新增」 button.
|
||
document.addEventListener('keydown', e => {
|
||
if (e.key === 'Escape') { closeAddPersonModal(); closeTip(); }
|
||
});
|
||
|
||
|
||
// Deleting a manually added person or 常態型外包 can be undone for 7 seconds.
|
||
let undoTimer = null;
|
||
function removePerson(idx) {
|
||
const target = isSimMode ? simData : baseData;
|
||
const [removed] = target.splice(idx, 1);
|
||
saveAndRefresh();
|
||
if (!removed) return;
|
||
showUndo(`已刪除 ${removed.name || '人員'}`, () => {
|
||
target.splice(Math.min(idx, target.length), 0, removed);
|
||
saveAndRefresh();
|
||
showSaved('已復原');
|
||
});
|
||
}
|
||
|
||
// 管理職以 HR 組織資料為準:HR 來源的人唯讀,只有非 HR(外包、手動新增)還能自己勾。
|
||
function managerUnitsText(p) {
|
||
const units = Array.isArray(p.supervisorOf) ? p.supervisorOf : [];
|
||
if (!units.length) return 'HR 組織資料:不是任何單位的主管';
|
||
return 'HR 組織資料:' + units
|
||
.map(u => `${u.deptName}(${u.levelName}${u.secondary ? ',次要' : ''})`)
|
||
.join('、');
|
||
}
|
||
|
||
function managerCell(p, origIdx, isHrPerson) {
|
||
const tip = escapeHtml(managerUnitsText(p));
|
||
if (!isHrPerson) {
|
||
return `<input type="checkbox" ${p.isManager ? 'checked' : ''} onchange="updatePerson(${origIdx}, 'isManager', this.checked)" title="管理職" aria-label="管理職">`;
|
||
}
|
||
return `<input type="checkbox" ${p.isManager ? 'checked' : ''} disabled title="${tip}" aria-label="管理職(由 HR 提供,不可修改)">`;
|
||
}
|
||
|
||
function salaryMask() {
|
||
return '<span class="salary-mask" aria-label="薪資已隱藏">••••</span>';
|
||
}
|
||
|
||
function toggleSalaryVisibility() {
|
||
salaryHidden = !salaryHidden;
|
||
syncSalaryButtons();
|
||
if (document.getElementById('personnel')?.classList.contains('active')) renderPersonnel();
|
||
if (document.getElementById('sales')?.classList.contains('active')) renderSales();
|
||
}
|
||
|
||
function syncSalaryButtons() {
|
||
document.querySelectorAll('.salary-toggle').forEach(btn => {
|
||
btn.textContent = salaryHidden ? '顯示薪資' : '隱藏薪資';
|
||
btn.setAttribute('aria-pressed', salaryHidden ? 'false' : 'true');
|
||
btn.setAttribute('title', salaryHidden ? '顯示每個人的薪資與成本' : '隱藏每個人的薪資與成本');
|
||
});
|
||
}
|
||
|
||
function showUndo(text, onUndo) {
|
||
let el = document.getElementById('undo-toast');
|
||
if (!el) {
|
||
el = document.createElement('div');
|
||
el.id = 'undo-toast';
|
||
el.className = 'undo-toast';
|
||
el.setAttribute('role', 'status');
|
||
el.setAttribute('aria-live', 'polite');
|
||
document.body.appendChild(el);
|
||
}
|
||
el.innerHTML = `<span>${escapeHtml(text)}</span><button type="button">復原</button><span class="undo-bar" aria-hidden="true"></span>`;
|
||
clearTimeout(undoTimer);
|
||
const hide = () => { el.classList.remove('show'); clearTimeout(undoTimer); };
|
||
el.querySelector('button').onclick = () => { hide(); onUndo(); };
|
||
el.classList.remove('show');
|
||
void el.offsetWidth; // restart the countdown bar
|
||
el.classList.add('show');
|
||
undoTimer = setTimeout(hide, 7000);
|
||
}
|
||
|
||
function showView(viewId) {
|
||
if (typeof getCurrentUser === 'function') {
|
||
const user = getCurrentUser();
|
||
if (!user) return;
|
||
|
||
// Route protection
|
||
if (user.role === 'group_head' && viewId !== 'coda' && viewId !== 'personnel' && viewId !== 'dashboard' && viewId !== 'personnel-overview') return;
|
||
if (user.role === 'dept_head' && viewId !== 'coda' && viewId !== 'invoice' && viewId !== 'personnel' && viewId !== 'dashboard' && viewId !== 'personnel-overview') return;
|
||
// Admin can access all
|
||
}
|
||
|
||
document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
|
||
document.querySelectorAll('.nav-item').forEach(n => { n.classList.remove('active'); n.removeAttribute('aria-current'); });
|
||
|
||
const targetView = document.getElementById(viewId);
|
||
if (targetView) targetView.classList.add('active');
|
||
|
||
// Determine the main nav item to activate
|
||
let navId;
|
||
if (viewId.startsWith('personnel')) {
|
||
navId = viewId === 'personnel' && personnelCategory === 'contractors' ? 'nav-contractors' : 'nav-preview-personnel';
|
||
} else if (viewId === 'org-structure') {
|
||
navId = 'nav-org';
|
||
} else {
|
||
navId = 'nav-' + viewId;
|
||
}
|
||
|
||
const targetNav = document.getElementById(navId);
|
||
if (targetNav) { targetNav.classList.add('active'); targetNav.setAttribute('aria-current', 'page'); }
|
||
|
||
|
||
if (viewId === 'dashboard') renderDashboard();
|
||
if (viewId === 'personnel-overview') renderPersonnelOverview();
|
||
if (viewId === 'invoice') renderInvoice();
|
||
if (viewId === 'params') renderParams();
|
||
if (viewId === 'sales') renderSales();
|
||
if (viewId === 'artists') renderArtists();
|
||
if (viewId === 'coda') renderCoda();
|
||
if (viewId === 'group') renderGroup();
|
||
if (viewId === 'org-structure') renderOrgStructure();
|
||
if (viewId === 'plans') loadPlans().then(renderPlans);
|
||
if (viewId === 'permissions') permLoad();
|
||
if (viewId === 'simulate') { if (window.__simulateView) window.__simulateView.reload(); else window.__simulateView = PMScope.mount(document.getElementById('simulate-content'), { mode: 'simulate' }); }
|
||
document.querySelector('main').scrollTo({ top: 0, left: 0, behavior: 'instant' });
|
||
}
|
||
|
||
function showPersonnelView(dept, category = 'internal') {
|
||
personnelCategory = category;
|
||
if (dept === 'overview') {
|
||
showView('personnel-overview');
|
||
} else {
|
||
// Populate company and department filters
|
||
initOrgStructure();
|
||
populateCompanyFilter();
|
||
updateDeptFilter();
|
||
const deptFilterEl = document.getElementById('personnel-dept-filter');
|
||
deptFilterEl.value = [...deptFilterEl.options].some(option => option.value === dept) ? dept : 'all';
|
||
const label = category === 'contractors' ? '常態型外包' : '人員資料';
|
||
document.getElementById('personnel-view-title').innerText = `${label}(${dept === 'all' ? '全部門' : dept})`;
|
||
document.getElementById('personnel-source-note').textContent = category === 'contractors'
|
||
? '常態型外包不在 HR 系統內,在此獨立維護日薪、合約月份與部門/組別;新增、修改、刪除會自動儲存在本站。'
|
||
: `${globalParams.reportYear || 2027} HR 試算名單。姓名、職稱、部門/組別與薪資來自 HR;P/A、管理職及未辨識部/組可在此補齊。未完成 P/A 的人會列出,但不納入正式總額。`;
|
||
document.getElementById('personnel-add-button').textContent = category === 'contractors' ? '+ 新增常態型外包' : '+ 新增人員';
|
||
document.getElementById('personnel-search').value = '';
|
||
|
||
updateGroupFilter(); // Update group filter based on selected department
|
||
showView('personnel');
|
||
renderPersonnel();
|
||
}
|
||
}
|
||
|
||
|
||
function matchesCompany(p, companyFilter) {
|
||
if (companyFilter === 'all') return true;
|
||
if (companyFilter === '未指定') return !p.company;
|
||
return p.company === companyFilter;
|
||
}
|
||
|
||
function companyScopedData() {
|
||
const companyFilter = document.getElementById('personnel-company-filter')?.value || 'all';
|
||
const current = isSimMode ? simData : baseData;
|
||
return current.filter(p => matchesPersonnelCategory(p) && matchesCompany(p, companyFilter));
|
||
}
|
||
|
||
function populateCompanyFilter({ keepSelection = false } = {}) {
|
||
const companyFilterEl = document.getElementById('personnel-company-filter');
|
||
if (!companyFilterEl) return false;
|
||
const current = (isSimMode ? simData : baseData).filter(p => matchesPersonnelCategory(p));
|
||
const companies = [...new Set(current.map(p => p.company).filter(Boolean))].sort();
|
||
if (current.some(p => !p.company)) companies.push('未指定');
|
||
const existing = [...companyFilterEl.options].slice(1).map(option => option.value);
|
||
if (keepSelection && existing.join('\n') === companies.join('\n')) return false;
|
||
const selected = companyFilterEl.value;
|
||
companyFilterEl.replaceChildren(new Option('所有公司', 'all'),
|
||
...companies.map(name => new Option(name === '未指定' ? name : shortCompanyName(name), name)));
|
||
companyFilterEl.value = keepSelection && companies.includes(selected) ? selected : 'all';
|
||
return true;
|
||
}
|
||
|
||
function updateDeptFilter() {
|
||
initOrgStructure();
|
||
const deptFilterEl = document.getElementById('personnel-dept-filter');
|
||
const companyFilter = document.getElementById('personnel-company-filter')?.value || 'all';
|
||
const activeDepts = companyFilter === 'all'
|
||
? Object.keys(globalParams.orgStructure)
|
||
: [...new Set(companyScopedData().map(p => p.dept).filter(Boolean))];
|
||
deptFilterEl.replaceChildren(new Option('所有部門', 'all'),
|
||
...[...new Set(activeDepts.filter(Boolean))].sort().map(d => new Option(d, d)),
|
||
new Option('其他 (未定義)', '其他'));
|
||
deptFilterEl.value = 'all';
|
||
}
|
||
|
||
function updateGroupFilter() {
|
||
const deptFilterEl = document.getElementById('personnel-dept-filter');
|
||
const groupFilterEl = document.getElementById('personnel-group-filter');
|
||
const selectedDept = deptFilterEl.value;
|
||
const companySelected = (document.getElementById('personnel-company-filter')?.value || 'all') !== 'all';
|
||
|
||
let groupOptionsHtml = '<option value="all">所有組別</option>';
|
||
const collectedGroups = new Set(); // Track to avoid duplicates
|
||
|
||
if (selectedDept === 'all') {
|
||
// Show all groups from all departments (within the selected company)
|
||
const current = companyScopedData();
|
||
current.forEach(p => {
|
||
if (p.group) collectedGroups.add(p.group);
|
||
});
|
||
[...collectedGroups].sort().forEach(g => {
|
||
groupOptionsHtml += `<option value="${g}">${g}</option>`;
|
||
});
|
||
} else if (selectedDept === '其他') {
|
||
// Show groups for people in '其他' departments
|
||
const current = companyScopedData();
|
||
current.filter(p => !Object.keys(globalParams.orgStructure).includes(p.dept)).forEach(p => {
|
||
if (p.group) collectedGroups.add(p.group);
|
||
});
|
||
[...collectedGroups].sort().forEach(g => {
|
||
groupOptionsHtml += `<option value="${g}">${g}</option>`;
|
||
});
|
||
} else {
|
||
// Use orgStructure for specific department, or scan data if not defined
|
||
const targetDeptGroups = globalParams.orgStructure[selectedDept];
|
||
if (!companySelected && targetDeptGroups && targetDeptGroups.length > 0) {
|
||
targetDeptGroups.sort().forEach(g => {
|
||
collectedGroups.add(g);
|
||
groupOptionsHtml += `<option value="${g}">${g}</option>`;
|
||
});
|
||
} else {
|
||
// Fallback: scan data for groups in this specific department
|
||
const current = companyScopedData();
|
||
const pInDept = current.filter(p => p.dept === selectedDept);
|
||
[...new Set(pInDept.map(p => p.group || '未分組'))].sort().forEach(g => {
|
||
collectedGroups.add(g);
|
||
groupOptionsHtml += `<option value="${g}">${g}</option>`;
|
||
});
|
||
}
|
||
}
|
||
|
||
// Append 未分組 only if not already in the list
|
||
if (!collectedGroups.has('未分組')) {
|
||
groupOptionsHtml += `<option value="未分組">未分組</option>`;
|
||
}
|
||
|
||
groupFilterEl.innerHTML = groupOptionsHtml;
|
||
groupFilterEl.value = 'all'; // Reset group filter to 'all' when department changes
|
||
}
|
||
|
||
function renderCoda() {
|
||
initOrgStructure();
|
||
const current = isSimMode ? simData : baseData;
|
||
const container = document.getElementById('coda-content');
|
||
if (!container) return;
|
||
|
||
// --- 1. P-budget per dept (from Sales logic) ---
|
||
const targetDepts = Object.keys(globalParams.orgStructure);
|
||
const pBudgetByDept = {};
|
||
targetDepts.forEach(d => pBudgetByDept[d] = 0);
|
||
current.filter(p => p.role.startsWith('P') && targetDepts.includes(p.dept)).forEach(p => {
|
||
pBudgetByDept[p.dept] += codaCost(p);
|
||
});
|
||
|
||
|
||
// --- 3. Build per-dept A/O artist data (grouped) ---
|
||
|
||
// deptData: { dept -> { groups: { groupName -> [people] }, rawA, rawO } }
|
||
const deptData = {};
|
||
targetDepts.forEach(d => { deptData[d] = { rawA: 0, rawO: 0, groups: {} }; });
|
||
|
||
current.filter(p => targetDepts.includes(p.dept) && (p.role.startsWith('A') || p.role.startsWith('O'))).forEach(p => {
|
||
const d = p.dept;
|
||
const gName = p.group || '未分組';
|
||
if (!deptData[d].groups[gName]) deptData[d].groups[gName] = { people: [], rawA: 0, rawO: 0 };
|
||
const cost = codaCost(p);
|
||
if (p.role.startsWith('A')) { deptData[d].rawA += cost; deptData[d].groups[gName].rawA += cost; }
|
||
else { deptData[d].rawO += cost; deptData[d].groups[gName].rawO += cost; }
|
||
deptData[d].groups[gName].people.push(p);
|
||
});
|
||
|
||
// --- 4. Compute final dept budgets ---
|
||
// PARADIGM SHIFT: Outsource (O) is NO LONGER part of the CODA target
|
||
const ownCoda = {};
|
||
targetDepts.forEach(d => { ownCoda[d] = (pBudgetByDept[d] || 0) + deptData[d].rawA; });
|
||
const codaShare = codaShares(current, ownCoda);
|
||
let grandCoda = 0;
|
||
const codaRows = targetDepts.map(d => {
|
||
const pBudget = pBudgetByDept[d] || 0;
|
||
const aBudget = deptData[d].rawA;
|
||
const oBudget = deptData[d].rawO;
|
||
const sharedIn = codaShare.add[d] || 0;
|
||
const sharedOut = codaShare.out[d] || 0;
|
||
const totalCoda = ownCoda[d] + sharedIn - sharedOut;
|
||
grandCoda += totalCoda;
|
||
|
||
return { dept: d, pBudget, aBudget, oBudget, sharedIn, sharedOut, rawA: deptData[d].rawA, rawO: deptData[d].rawO, totalCoda, groups: deptData[d].groups };
|
||
});
|
||
|
||
// --- 5b. 各部門平均日工作 CODA(夢想創造+夢境現實;簡單平均;只給最高管理者看) ---
|
||
{
|
||
const avgCard = document.getElementById('coda-avg-card');
|
||
const avgUser = typeof getCurrentUser === 'function' ? getCurrentUser() : null;
|
||
const avgIsAdmin = !avgUser || avgUser.role === 'admin';
|
||
if (avgCard) avgCard.style.display = avgIsAdmin ? '' : 'none';
|
||
const avgEl = document.getElementById('coda-avg-daily');
|
||
if (avgEl && avgIsAdmin) {
|
||
const avgCompanyOf = deptCompanyMap(current);
|
||
const avgDays = globalParams.annualWorkDays || 255;
|
||
const avgVals = codaRows
|
||
.filter(r => ['夢想創造', '夢境現實'].includes(shortCompanyName(avgCompanyOf.get(r.dept) || '')) && r.totalCoda > 0)
|
||
.map(r => { const fte = extractDeptFTE(r.groups); return fte ? (r.totalCoda / avgDays) / fte : 0; })
|
||
.filter(v => v > 0);
|
||
const avgMean = avgVals.length ? avgVals.reduce((s, v) => s + v, 0) / avgVals.length : 0;
|
||
avgEl.innerHTML = `<div class='currency-wrap' style='--symbol-width: 50px; --symbol-gap: 1.5rem; min-width: 180px; width: 100%;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(avgMean)}</span></div>`;
|
||
}
|
||
}
|
||
|
||
// --- 6. Update grand total ---
|
||
document.getElementById('coda-grand-total').innerHTML = `<div class='currency-wrap' style='--symbol-width: 50px; --symbol-gap: 1.5rem; min-width: 220px; width: 100%;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(grandCoda)}</span></div>`;
|
||
|
||
// Helper: CODA sharing line under the P / A badges
|
||
function codaShareNote(row) {
|
||
if (row.sharedOut > 0) {
|
||
const r = codaShare.rules.find(x => x.fromDepts.includes(row.dept));
|
||
return `<div class="tag" style="margin-top:6px;" title="本部門 P+A 合計 ${PMI18n.cur(row.sharedOut)},依比例分攤">已分攤至 ${r ? r.to.map(escapeHtml).join('、') : '其他部門'}</div>`;
|
||
}
|
||
if (row.sharedIn > 0) {
|
||
const r = codaShare.rules.find(x => x.to.includes(row.dept));
|
||
const src = r ? [...r.fromDepts, ...r.noDeptPeople.map(p => p.name)].map(escapeHtml).join('、') : '';
|
||
return `<div class="tag" style="margin-top:6px;" title="分攤來源:${src}(依各部門自身 CODA 比例)">含分攤 ${PMI18n.cur(row.sharedIn)}</div>`;
|
||
}
|
||
return '';
|
||
}
|
||
|
||
// Helper: CODA breakdown badge row (fixed grid for alignment)
|
||
function budgetBadges(pBudget, aBudget, isSupport = false) {
|
||
return `
|
||
<div style="display:grid; grid-template-columns: 160px 1fr; gap: 4px 10px; align-items:center;">
|
||
<span style="font-size:0.78rem; color:var(--accent-secondary-text); background:color-mix(in srgb, var(--accent-secondary) 10%, transparent); padding:2px 10px; border-radius:99px; text-align:center; white-space:nowrap;">
|
||
P 預算
|
||
</span>
|
||
<span style="font-weight:700; color:${isSupport ? 'var(--text-dim)' : 'var(--accent-secondary)'}; text-align:right;">
|
||
${isSupport ? 'N/A(無業務P)' : `<div class='currency-wrap' style='--symbol-width: 40px; --symbol-gap: 0.5rem; min-width: 120px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(pBudget)}</span></div>`}
|
||
</span>
|
||
<span style="font-size:0.78rem; color:var(--accent-primary-text); background:color-mix(in srgb, var(--accent-primary) 10%, transparent); padding:2px 10px; border-radius:99px; text-align:center; white-space:nowrap;">
|
||
A 預算
|
||
</span>
|
||
<span style="font-weight:700; color:var(--accent-primary-text); text-align:right;"><div class='currency-wrap' style='--symbol-width: 40px; --symbol-gap: 0.5rem; min-width: 120px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(aBudget)}</span></div></span>
|
||
</div>`;
|
||
}
|
||
|
||
// Helper: build group + artist table for a dept
|
||
function buildArtistTable(deptName, groups, deptTotalCoda, deptAOraw, safeDeptId, visibleGroupsArray = null) {
|
||
let html = `<div id="coda-detail-${safeDeptId}" style="display:none; border-top:1px solid var(--border-glass); padding:1.5rem;"><div style="display:flex; flex-direction:column; gap:1rem;">`;
|
||
|
||
|
||
const { sortedGroups, totalCGLeadTax } = codaGroupsForDept(deptName, groups, deptTotalCoda);
|
||
|
||
sortedGroups.sort((a, b) => b.gRaw - a.gRaw).forEach(groupObj => {
|
||
const { gName, gData, gRaw, groupA, initialCoda, finalCoda, rdNote, groupFTE } = groupObj;
|
||
|
||
// Auth filter: skip rendering if not in visible list
|
||
if (visibleGroupsArray && !visibleGroupsArray.includes(gName)) return;
|
||
|
||
const gPctOfDept = deptAOraw === 0 ? 0 : (gRaw / deptAOraw * 100);
|
||
const safeGrp = (safeDeptId + '-' + gName).replace(/\s+/g, '-');
|
||
const annualWorkDays = globalParams.annualWorkDays || 255;
|
||
const managerReductionPct = globalParams.managerReductionPct !== undefined ? parseFloat(globalParams.managerReductionPct) : 0.6;
|
||
|
||
const groupAvgDailyCoda = groupFTE === 0 ? 0 : (finalCoda / annualWorkDays) / groupFTE;
|
||
|
||
// Manager Reduction Logic Pre-calculation
|
||
let totalManagerReductionPool = 0;
|
||
let nonManagerCostSum = 0;
|
||
|
||
// First pass: identify pure raw targets and manager reduced sums
|
||
const pRawCodaMap = new Map();
|
||
gData.people.forEach(p => {
|
||
const pCost = codaCost(p);
|
||
const isO = p.role.startsWith('O');
|
||
const isAManager = p.role.startsWith('A') && p.isManager;
|
||
|
||
let baseRawCoda = 0;
|
||
if (isO) {
|
||
baseRawCoda = 0;
|
||
} else {
|
||
baseRawCoda = groupA === 0 ? 0 : initialCoda * (pCost / groupA);
|
||
}
|
||
|
||
let targetRawCoda = baseRawCoda;
|
||
if (isAManager) {
|
||
const reduction = baseRawCoda * managerReductionPct;
|
||
totalManagerReductionPool += reduction;
|
||
targetRawCoda = baseRawCoda - reduction;
|
||
} else if (!isO && !isAManager) {
|
||
nonManagerCostSum += pCost;
|
||
}
|
||
|
||
pRawCodaMap.set(p, { baseRawCoda, targetRawCoda });
|
||
});
|
||
|
||
// Second pass: distribute the pool to non-managers
|
||
gData.people.forEach(p => {
|
||
const state = pRawCodaMap.get(p);
|
||
const isO = p.role.startsWith('O');
|
||
const isAManager = p.role.startsWith('A') && p.isManager;
|
||
|
||
if (!isO && !isAManager && nonManagerCostSum > 0) {
|
||
const pCost = codaCost(p);
|
||
const share = pCost / nonManagerCostSum;
|
||
state.targetRawCoda += totalManagerReductionPool * share;
|
||
}
|
||
});
|
||
|
||
html += `
|
||
<div style="background:var(--wash); border:1px solid var(--border-glass); border-radius:12px; overflow:hidden;">
|
||
<div onclick="toggleCodaGroup('${safeGrp}')" style="cursor:pointer; padding:0.75rem 1rem; display:flex; justify-content:space-between; align-items:center;" data-row-toggle>
|
||
<div style="display:flex; align-items:center; gap:1.5rem; flex-grow:1;">
|
||
<h3 style="margin:0; font-size:0.9rem; font-weight:500; color:var(--text-main); min-width:160px;" title="${escapeHtml(gName)}">${escapeHtml(shortGroupName(deptName, gName))}</h3>
|
||
<span style="font-size:0.78rem; color:var(--text-dim); background:var(--wash); padding:2px 8px; border-radius:99px;">${gData.people.length} 人</span>
|
||
<span class="tag" title="組別倍率=人薪倍率 × 組別最終 CODA ÷ 組內 A 成本">倍率 ${groupA > 0 ? `${(finalCoda / groupA * (globalParams.opMultiplier || 2)).toFixed(2)}x` : '—'}</span>
|
||
<div style="display:flex; flex-direction:column;">
|
||
<div style="display:flex; align-items:center; gap:10px;">
|
||
<span style="font-size:0.95rem; font-weight:500; color:var(--text-main);">CODA ${PMI18n.cur(finalCoda)}</span>
|
||
${rdNote ? `<span class="tag ${groupObj.isRD ? 'tag-rd' : 'tag-cg'}">${rdNote}</span>` : ''}
|
||
${(totalManagerReductionPool > 0 || totalCGLeadTax > 0) ? `<span class="tag">含主管及 CG Lead 承擔分攤</span>` : ''}
|
||
</div>
|
||
<span style="font-size:0.75rem; color:var(--text-dim);">佔部門總成本 ${formatPct(gPctOfDept)}%${window.IS_PUBLIC_VERSION ? '' : ` (組內 P+A: ${PMI18n.cur(groupA)} / O外包: ${PMI18n.cur(gData.rawO)})`}</span>
|
||
</div>
|
||
<div style="margin-left: auto; text-align:right; min-width:120px; display:flex; flex-direction:column;">
|
||
<span style="font-size:0.75rem; color:var(--text-dim); text-transform:uppercase;">平均日工作 CODA<span style="font-size:0.75rem;opacity:0.6;"> (不含O)</span></span>
|
||
<span style="font-size:0.9rem; font-weight:700; color:var(--text-main);">${PMI18n.cur(groupAvgDailyCoda)}</span>
|
||
</div>
|
||
</div>
|
||
<div id="coda-group-chevron-${safeGrp}" style="color:var(--text-dim); font-size:0.8rem; margin-left: 1rem;">▼</div>
|
||
</div>
|
||
<div id="coda-group-detail-${safeGrp}" style="display:none; padding:0 1rem 1rem 1rem;">
|
||
<table style="width:100%; table-layout:fixed; background:transparent; font-size:0.82rem;">
|
||
<colgroup>
|
||
<col style="width:90px"><col style="width:100px"><col style="width:60px">
|
||
<col style="width:65px"><col style="width:65px"><col style="min-width:130px; width:auto">
|
||
<col style="min-width:130px; width:auto"><col style="min-width:130px; width:auto">
|
||
</colgroup>
|
||
<thead>
|
||
<tr>
|
||
<th style="overflow:hidden;">姓名</th>
|
||
<th style="overflow:hidden;">職稱</th>
|
||
<th>職能</th>
|
||
<th class="num" style="white-space:nowrap;">總月份</th>
|
||
<th class="num" style="white-space:nowrap;">工作率</th>
|
||
<th class="num">${window.IS_PUBLIC_VERSION ? '組內佔比' : '年度總成本(組內佔比)'}</th>
|
||
<th class="num">應負責 CODA</th>
|
||
<th class="num">日工作 CODA</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
`;
|
||
|
||
gData.people.sort((a, b) => codaCost(b) - codaCost(a)).forEach(p => {
|
||
const pCost = codaCost(p);
|
||
const pPctInGroup = gRaw === 0 ? 0 : (pCost / gRaw * 100);
|
||
const isO = p.role.startsWith('O');
|
||
const isAManager = p.role.startsWith('A') && p.isManager;
|
||
|
||
const state = pRawCodaMap.get(p);
|
||
let pRawCoda = state ? state.targetRawCoda : 0;
|
||
|
||
// Apply RD proportional adjustment based on final target sum
|
||
const pCoda = initialCoda === 0 ? 0 : pRawCoda * (finalCoda / initialCoda);
|
||
|
||
// Calculate working days to derive Day Rate (Prorated)
|
||
const m1 = (p.h1Start && p.h1End) ? Math.max(0, parseInt(p.h1End) - parseInt(p.h1Start) + 1) : 0;
|
||
const m2 = (p.h2Start && p.h2End) ? Math.max(0, parseInt(p.h2End) - parseInt(p.h2Start) + 1) : 0;
|
||
const pDays = annualWorkDays * ((m1 + m2) / 12);
|
||
const pDailyCoda = isO ? 0 : (pDays > 0 ? (pCoda / pDays) : 0);
|
||
|
||
let codaNoteHtml = '';
|
||
if (isO) codaNoteHtml = '<span style="font-size:0.75rem;">[不負責業績]</span>';
|
||
else {
|
||
let mgrNote = '';
|
||
if (isAManager) mgrNote = `<span class="tag tag-warn" style="margin-right:6px;">主管承擔 −${formatPct(managerReductionPct * 100)}%</span>`;
|
||
codaNoteHtml = `${mgrNote}<div class='currency-wrap' style='--symbol-width: 35px; --symbol-gap: 0.5rem; min-width: 100px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(pCoda)}</span></div>`;
|
||
}
|
||
|
||
html += `
|
||
<tr>
|
||
<td style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="${p.name}">${p.name}</td>
|
||
<td style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="${p.title || ''}">${p.title || ''}</td>
|
||
<td><span class="role-pill ${isO ? 'role-o' : 'role-a'}" style="font-size:0.75rem;padding:2px 5px;">${p.role.split(' - ')[0]}</span></td>
|
||
<td class="num">${m1 + m2}</td>
|
||
<td class="num">${p.workRateUsed || 1}</td>
|
||
<td class='num'>${window.IS_PUBLIC_VERSION ? '' : `<div class='currency-wrap' style='--symbol-width: 35px; --symbol-gap: 0.5rem; min-width: 100px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(pCost)}</span></div> `}<span style="color:var(--text-dim);font-size:0.75rem;">(${formatPct(pPctInGroup)}%)</span></td>
|
||
<td class="num" style="color:${isO ? 'var(--text-muted)' : 'var(--text-main)'};">${codaNoteHtml}</td>
|
||
<td class="num" style="color:${isO ? 'var(--text-muted)' : 'var(--text-main)'};">${isO ? '<span style="font-size:0.75rem;">-</span>' : `<div class='currency-wrap' style='--symbol-width: 35px; --symbol-gap: 0.5rem; min-width: 100px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(pDailyCoda)}</span></div>`}</td>
|
||
</tr>`;
|
||
});
|
||
|
||
html += `</tbody></table></div></div>`;
|
||
});
|
||
|
||
html += `</div></div>`;
|
||
return html;
|
||
}
|
||
|
||
// Helper to compute Department FTE for accurate standard daily average
|
||
function extractDeptFTE(groups) {
|
||
return Object.values(groups).reduce((acc, g) => {
|
||
return acc + g.people.reduce((acc2, p) => {
|
||
if (isCostExcludedIntern(p)) return acc2;
|
||
const m1 = (p.h1Start && p.h1End) ? Math.max(0, parseInt(p.h1End) - parseInt(p.h1Start) + 1) : 0;
|
||
const m2 = (p.h2Start && p.h2End) ? Math.max(0, parseInt(p.h2End) - parseInt(p.h2Start) + 1) : 0;
|
||
return acc2 + ((m1 + m2) / 12);
|
||
}, 0);
|
||
}, 0);
|
||
}
|
||
|
||
// --- 7. Render dept cards ---
|
||
// Auth: resolve current user scope for content filtering
|
||
const _authUserCoda = typeof getCurrentUser === 'function' ? getCurrentUser() : null;
|
||
const _isAdminCoda = !_authUserCoda || _authUserCoda.role === 'admin';
|
||
|
||
const colors = ['var(--accent-primary)', 'var(--accent-secondary)', 'var(--accent-success)', 'var(--accent-warning)', 'var(--lime)'];
|
||
container.innerHTML = '';
|
||
|
||
// Privacy Hint for Managers
|
||
if (!_isAdminCoda) {
|
||
container.innerHTML = `
|
||
<div style="margin-bottom: 2rem; padding: 1rem 1.5rem; background: color-mix(in srgb, var(--accent-secondary) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent-secondary) 30%, transparent); border-radius: 12px; font-size: 0.88rem; color: var(--text-main);">
|
||
您目前以<strong>${_authUserCoda.role === 'dept_head' ? '部長' : '組長'}</strong>身份登入,以下僅顯示您所屬部門 (${_authUserCoda.dept || '—'}) 的成本組成與細節,全公司總 CODA 仍維持整體規模呈現。
|
||
</div>
|
||
`;
|
||
}
|
||
|
||
Object.keys(globalParams.orgStructure).forEach((deptName, i) => {
|
||
const row = codaRows.find(r => r.dept === deptName);
|
||
if (!row) return; // Skip if this department has no data
|
||
|
||
// Auth filter: non-admin users only see their authorized dept
|
||
if (!_isAdminCoda && _authUserCoda.dept && deptName !== _authUserCoda.dept) return;
|
||
|
||
const codaPct = grandCoda === 0 ? 0 : (row.totalCoda / grandCoda * 100);
|
||
const accentColor = 'var(--bar-strong)';
|
||
const safeDeptId = 'coda-dept-' + row.dept.replace(/\s+/g, '-');
|
||
const deptAOraw = row.rawA + row.rawO;
|
||
|
||
// Auth filter: group_head users only see their authorized group's artist data
|
||
let authorizedGroups = null;
|
||
if (!_isAdminCoda && _authUserCoda.role === 'group_head' && _authUserCoda.group) {
|
||
authorizedGroups = [_authUserCoda.group];
|
||
}
|
||
|
||
const deptFTE = extractDeptFTE(row.groups);
|
||
const annualWorkDays = globalParams.annualWorkDays || 255;
|
||
const deptAvgDailyCoda = deptFTE === 0 ? 0 : (row.totalCoda / annualWorkDays) / deptFTE;
|
||
|
||
container.innerHTML += `
|
||
<div class="card" style="margin-bottom:1.5rem; padding:0;">
|
||
<div onclick="toggleCodaDept('${safeDeptId}')" style="cursor:pointer; padding:1.5rem; display:flex; justify-content:space-between; align-items:center;" data-row-toggle>
|
||
<div style="flex-grow:1;">
|
||
<h2 class="dept-name" style="margin-bottom:0.4rem;">${row.dept}</h2>
|
||
<div style="display:flex; align-items:baseline; gap:1.5rem; flex-wrap:wrap;">
|
||
<div style="font-size:1.8rem; font-weight:400; color:var(--text-main);"><div class='currency-wrap' style='--symbol-width: 60px; --symbol-gap: 1.5rem; min-width: 250px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(row.totalCoda)}</span></div></div>
|
||
${row.oBudget > 0 ? `
|
||
<div class="tag tag-warn">
|
||
須另行負擔之外包成本: <strong>${PMI18n.cur(row.oBudget)}</strong>
|
||
</div>` : ''}
|
||
</div>
|
||
<div style="color:var(--text-dim); font-size:0.8rem; margin-top:0.4rem;">佔全公司 ${formatPct(codaPct)}% <span style="color:var(--text-main);" title="部門平均倍率=人薪倍率 × 部門 CODA ÷ 部門 A 成本(即各組倍率依 A 成本加權的平均)">平均倍率 ${row.aBudget > 0 && !row.sharedOut ? `${(row.totalCoda / row.aBudget * (globalParams.opMultiplier || 2)).toFixed(2)}x` : '—'}</span></div>
|
||
<div style="height:6px; background:var(--wash); border-radius:4px; overflow:hidden; margin-top:0.75rem; max-width:300px;">
|
||
<div style="width:${codaPct}%; height:100%; background:var(--bar-strong);"></div>
|
||
</div>
|
||
</div>
|
||
<div style="display:flex; align-items:center; gap:2rem;">
|
||
<div>
|
||
<div style="font-size:0.75rem; color:var(--text-dim); text-transform:uppercase; letter-spacing:1px; margin-bottom:0.5rem;">CODA 組成 (純內製 P+A)</div>
|
||
${budgetBadges(row.pBudget, row.aBudget)}
|
||
${codaShareNote(row)}
|
||
</div>
|
||
<div style="text-align:right;">
|
||
<div style="font-size:0.75rem; color:var(--text-dim); text-transform:uppercase; letter-spacing:1px; margin-bottom:0.5rem;">部門平均日工作 CODA</div>
|
||
<div style="font-size:1.1rem; font-weight:700; color:var(--text-main);"><div class='currency-wrap' style='--symbol-width: 45px; --symbol-gap: 1rem; min-width: 160px;'><span>${PMI18n.sym()}</span><span>${PMI18n.amt(deptAvgDailyCoda)}</span></div></div>
|
||
</div>
|
||
<div id="coda-chevron-${safeDeptId}" style="color:var(--text-muted); transition:transform 0.3s; margin-left: 0.5rem;">▼</div>
|
||
</div>
|
||
</div>
|
||
${buildArtistTable(row.dept, row.groups, row.totalCoda, deptAOraw, safeDeptId, authorizedGroups)}
|
||
</div>
|
||
`;
|
||
});
|
||
|
||
} // end renderCoda()
|
||
|
||
function toggleCodaDept(id) {
|
||
const detail = document.getElementById('coda-detail-' + id);
|
||
const chevron = document.getElementById('coda-chevron-' + id);
|
||
if (!detail) return;
|
||
const isOpen = detail.style.display !== 'none';
|
||
detail.style.display = isOpen ? 'none' : 'block';
|
||
if (chevron) { chevron.style.transform = isOpen ? 'rotate(0deg)' : 'rotate(180deg)'; chevron.style.color = isOpen ? 'var(--text-muted)' : 'var(--accent-primary)'; }
|
||
}
|
||
|
||
function toggleCodaGroup(id) {
|
||
const detail = document.getElementById('coda-group-detail-' + id);
|
||
const chevron = document.getElementById('coda-group-chevron-' + id);
|
||
if (!detail) return;
|
||
const isOpen = detail.style.display !== 'none';
|
||
detail.style.display = isOpen ? 'none' : 'block';
|
||
if (chevron) chevron.style.transform = isOpen ? 'rotate(0deg)' : 'rotate(180deg)';
|
||
}
|
||
|
||
// --- Regular contractors are saved on the server (not in HR, not in Git) ---
|
||
let contractorSignature = null;
|
||
let contractorSaveTimer = null;
|
||
|
||
|
||
// ---- 權限管理:原本是獨立的 /permissions 頁,搬進來變成一個區塊 ----
|
||
// 整包包在函式裡,只對外露出 perm 開頭的幾個名字,避免和看板既有的 state、filter、draw 撞名。
|
||
(function () {
|
||
let state = { people: [], grants: {}, denied: [], log: [] };
|
||
let filter = 'scoped';
|
||
let editing = null;
|
||
let message = {};
|
||
let logShown = 20;
|
||
|
||
const kindOf = (p) => {
|
||
const x = p.permission;
|
||
if (x.admin) return 'admin';
|
||
if (x.denied || state.denied.includes(p.employeeNumber)) return 'denied';
|
||
if (x.company) return 'company';
|
||
if (x.hr?.depts?.length) return 'dept';
|
||
if (x.hr?.groups?.length) return 'group';
|
||
if (state.grants[p.employeeNumber]) return 'manual';
|
||
return 'none';
|
||
};
|
||
const FILTERS = [
|
||
['scoped', '有權限', p => kindOf(p) !== 'none'],
|
||
['dept', '部長', p => kindOf(p) === 'dept'],
|
||
['group', '組長', p => kindOf(p) === 'group'],
|
||
['company', '全公司檢視', p => kindOf(p) === 'company'],
|
||
['manual', '有手動權限', p => Boolean(state.grants[p.employeeNumber])],
|
||
['denied', '暫不開放', p => kindOf(p) === 'denied'],
|
||
['all', '全部', () => true],
|
||
];
|
||
|
||
function chips(p) {
|
||
const x = p.permission;
|
||
if (x.admin) return '<span class="chip admin">最高管理者</span>';
|
||
if (x.denied) return '<span class="chip warn">暫不開放</span>';
|
||
const g = state.grants[p.employeeNumber] || {};
|
||
const out = [];
|
||
if (x.company) out.push(['manual', '全公司檢視']);
|
||
(x.hr?.depts || []).forEach(d => out.push(['hr', `部門 ${d}`]));
|
||
(x.hr?.groups || []).forEach(k => out.push(['hr', `組 ${k.split('|')[1]}`]));
|
||
(g.depts || []).forEach(d => out.push(['manual', `部門 ${d}`]));
|
||
(g.groups || []).forEach(k => out.push(['manual', `組 ${k.split('|')[1]}`]));
|
||
if (x.personDetail) out.push([x.hr?.depts?.length ? 'hr' : 'manual', '個人明細']);
|
||
if (x.simulate) out.push([x.hr?.depts?.length ? 'hr' : 'manual', '模擬']);
|
||
return out.length ? out.map(([c, t]) => `<span class="chip ${c}">${escapeHtml(t)}</span>`).join('') : '<span class="none">沒有權限</span>';
|
||
}
|
||
|
||
function options() {
|
||
const depts = [...new Set(state.people.map(p => p.dept).filter(Boolean))].sort((a, b) => a.localeCompare(b, 'zh-Hant'));
|
||
const groups = [...new Set(state.people.filter(p => p.dept && p.group).map(p => `${p.dept}|${p.group}`))].sort((a, b) => a.localeCompare(b, 'zh-Hant'));
|
||
return { depts, groups };
|
||
}
|
||
|
||
function editor(p) {
|
||
const g = state.grants[p.employeeNumber] || {};
|
||
const { depts, groups } = options();
|
||
const toggle = (name, label, hint, checked) => `<label class="toggle"><input type="checkbox" name="${name}" ${checked ? 'checked' : ''}><span>${label}<small>${hint}</small></span></label>`;
|
||
return `<div class="editor" id="perm-editor">
|
||
<div><h4>手動權限</h4><div class="toggles">
|
||
${toggle('company', '全公司檢視', '各部門、各組數字,不含個人薪資', g.company)}
|
||
${toggle('personDetail', '個人明細', '可看範圍內每個人的薪資與成本', g.personDetail)}
|
||
${toggle('simulate', '部門模擬', '可在看得到的部門做模擬試算', g.simulate)}
|
||
${toggle('denied', '暫不開放', '先不讓他看任何東西', state.denied.includes(p.employeeNumber))}
|
||
</div></div>
|
||
<div><h4>另外可以看的部門</h4><div class="pick">${depts.map(d => `<label><input type="checkbox" name="depts" value="${escapeHtml(d)}" ${(g.depts || []).includes(d) ? 'checked' : ''}>${escapeHtml(d)}</label>`).join('') || '<span class="none">沒有部門資料</span>'}</div></div>
|
||
<div><h4>另外可以看的組</h4><div class="pick">${groups.map(k => `<label><input type="checkbox" name="groups" value="${escapeHtml(k)}" ${(g.groups || []).includes(k) ? 'checked' : ''}>${escapeHtml(k.replace('|', ' · '))}</label>`).join('') || '<span class="none">沒有組資料</span>'}</div></div>
|
||
<div class="actions"><span class="status" role="status">${escapeHtml(message[p.employeeNumber] || '')}</span>
|
||
<button type="button" class="btn" onclick="permCancel()">取消</button>
|
||
<button type="button" class="btn primary" onclick="permSave('${escapeHtml(p.employeeNumber)}')">儲存</button></div>
|
||
</div>`;
|
||
}
|
||
|
||
function draw() {
|
||
const box = document.getElementById('perm-rows');
|
||
if (!box) return;
|
||
const q = (document.getElementById('perm-q').value || '').trim();
|
||
document.getElementById('perm-tabs').innerHTML = FILTERS.map(([key, label, test]) =>
|
||
`<button type="button" class="tab" aria-pressed="${filter === key}" onclick="permFilter('${key}')">${label}<span class="n">${state.people.filter(test).length}</span></button>`).join('');
|
||
const test = FILTERS.find(f => f[0] === filter)[2];
|
||
const rows = state.people.filter(test).filter(p => !q || [p.employeeNumber, p.name, p.dept, p.group].some(v => String(v || '').includes(q)));
|
||
box.innerHTML = rows.map(p => `<div class="row">
|
||
<div class="who"><b>${escapeHtml(p.name)}</b><span>${escapeHtml(p.employeeNumber)} ${escapeHtml(p.title)}</span></div>
|
||
<div class="where">${escapeHtml(p.dept || '—')}<br><span>${escapeHtml(p.group || '')}</span></div>
|
||
<div class="chips">${chips(p)}</div>
|
||
<div class="act">${p.permission.admin ? '' : `<button type="button" class="btn" onclick="permEdit('${escapeHtml(p.employeeNumber)}')" aria-expanded="${editing === p.employeeNumber}">${editing === p.employeeNumber ? '收起' : '調整'}</button>`}</div>
|
||
${editing === p.employeeNumber ? editor(p) : ''}
|
||
</div>`).join('') || '<div class="empty">沒有符合的人</div>';
|
||
}
|
||
|
||
function grantChips(entry) {
|
||
if (!entry) return [];
|
||
const out = [];
|
||
if (entry.denied) out.push(['warn', '暫不開放']);
|
||
const g = entry.grant || {};
|
||
if (g.company) out.push(['manual', '全公司檢視']);
|
||
(g.depts || []).forEach(d => out.push(['manual', `部門 ${d}`]));
|
||
(g.groups || []).forEach(k => out.push(['manual', `組 ${String(k).split('|')[1] || k}`]));
|
||
if (g.personDetail) out.push(['manual', '個人明細']);
|
||
if (g.simulate) out.push(['manual', '模擬']);
|
||
return out;
|
||
}
|
||
|
||
function drawLog() {
|
||
const box = document.getElementById('perm-log');
|
||
if (!box) return;
|
||
const log = state.log || [];
|
||
if (!log.length) { box.innerHTML = '<div class="empty">還沒有修改紀錄。</div>'; return; }
|
||
const names = new Map(state.people.map(p => [String(p.employeeNumber), p.name]));
|
||
const who = id => names.get(String(id)) ? `${escapeHtml(names.get(String(id)))}(${escapeHtml(id)})` : escapeHtml(id);
|
||
const chipHtml = (list, cls = '') => list.length ? list.map(([c, t]) => `<span class="chip ${c} ${cls}">${escapeHtml(t)}</span>`).join('') : '<span class="none">沒有手動權限</span>';
|
||
box.innerHTML = log.slice(0, logShown).map(e => {
|
||
const before = grantChips(e.before);
|
||
const after = grantChips(e.after);
|
||
const keys = list => new Set(list.map(([, t]) => t));
|
||
const a = keys(after);
|
||
const b = keys(before);
|
||
const removed = before.filter(([, t]) => !a.has(t));
|
||
const added = after.filter(([, t]) => !b.has(t));
|
||
const kept = after.filter(([, t]) => b.has(t));
|
||
const change = !removed.length && !added.length ? '<span class="none">沒有變更(重新儲存)</span>'
|
||
: `${removed.length ? `${chipHtml(removed, 'old')}<span class="arrow">→</span>` : ''}${added.length ? chipHtml(added) : '<span class="none">移除</span>'}${kept.length ? `<span class="none">(保留:${kept.map(([, t]) => escapeHtml(t)).join('、')})</span>` : ''}`;
|
||
return `<div class="log-row"><time datetime="${escapeHtml(e.at)}">${escapeHtml(new Date(e.at).toLocaleString('zh-TW', { hour12: false }))}</time>
|
||
<div><b>${who(e.employeeNumber)}</b></div>
|
||
<div class="change">${change}</div>
|
||
<div class="by">由 ${who(e.by)}</div></div>`;
|
||
}).join('') + (log.length > logShown ? `<div class="log-row" style="display:block;"><button type="button" class="btn" onclick="permMoreLog()">再顯示 ${Math.min(50, log.length - logShown)} 筆</button></div>` : '');
|
||
}
|
||
|
||
window.permFilter = (key) => { filter = key; draw(); };
|
||
window.permEdit = (id) => { editing = editing === id ? null : id; draw(); };
|
||
window.permCancel = () => { editing = null; draw(); };
|
||
window.permMoreLog = () => { logShown += 50; drawLog(); };
|
||
window.permDraw = draw;
|
||
|
||
window.permSave = async (id) => {
|
||
const box = document.getElementById('perm-editor');
|
||
const on = name => box.querySelector(`[name=${name}]`).checked;
|
||
const picked = name => [...box.querySelectorAll(`[name=${name}]:checked`)].map(i => i.value);
|
||
const grant = { company: on('company'), personDetail: on('personDetail'), simulate: on('simulate'), depts: picked('depts'), groups: picked('groups'), note: '權限頁設定' };
|
||
const empty = !grant.company && !grant.personDetail && !grant.simulate && !grant.depts.length && !grant.groups.length;
|
||
const response = await fetch('/api/permissions', { method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ employeeNumber: id, grant: empty ? null : grant, denied: on('denied') }) });
|
||
message[id] = response.ok ? '已儲存' : `儲存失敗(${response.status})`;
|
||
await window.permLoad();
|
||
};
|
||
|
||
window.permLoad = async () => {
|
||
const box = document.getElementById('perm-rows');
|
||
if (!box) return;
|
||
const response = await fetch('/api/permissions', { cache: 'no-store' });
|
||
if (!response.ok) { box.innerHTML = '<div class="empty">只有最高管理者可以管理權限。</div>'; return; }
|
||
state = await response.json();
|
||
drawLog();
|
||
if (state.preview && !state.people.length) { box.innerHTML = '<div class="empty">本機預覽沒有 HR 名單。</div>'; return; }
|
||
draw();
|
||
};
|
||
})();
|
||
|
||
// ---- 預排異動(預計離職、預計新進、預計轉調):只有最高管理者 ----
|
||
let planState = null;
|
||
const PLAN_STATUS = {
|
||
pending: ['等待 HR', 'var(--text-muted)'],
|
||
overdue: ['時間到了 HR 還沒改', 'var(--accent-danger)'],
|
||
conflict: ['HR 調到別的單位,請確認', 'var(--accent-warning)'],
|
||
manager_pending: ['部門已調,主管職還沒處理', 'var(--accent-warning)'],
|
||
};
|
||
const PLAN_REASON = {
|
||
hr_left: 'HR 名單上已經沒有這個人',
|
||
hr_leave_date: 'HR 已填離職日',
|
||
hr_joined: 'HR 名單已出現',
|
||
expired: '時間過了 HR 一直沒改,自動移除',
|
||
hr_transferred: 'HR 已經調到目標單位',
|
||
};
|
||
async function loadPlans() {
|
||
try {
|
||
const response = await fetch('/api/plans', { cache: 'no-store' });
|
||
if (!response.ok) { planState = null; return null; }
|
||
planState = await response.json();
|
||
} catch (error) { planState = null; }
|
||
updatePlanBanner();
|
||
return planState;
|
||
}
|
||
function updatePlanBanner() {
|
||
const overdue = planState?.status?.overdue || 0;
|
||
const conflicts = planState?.status?.conflicts || 0;
|
||
const managerPending = planState?.status?.managerPending || 0;
|
||
let note = document.getElementById('plan-overdue-banner');
|
||
if (!overdue && !conflicts && !managerPending) { if (note) note.remove(); return; }
|
||
if (!note) {
|
||
note = document.createElement('button');
|
||
note.id = 'plan-overdue-banner';
|
||
note.type = 'button';
|
||
note.onclick = () => showView('plans');
|
||
note.style.cssText = 'display:block;margin:.5rem 0;padding:.5rem .75rem;border-radius:10px;border:1px solid var(--accent-danger);background:none;color:var(--accent-danger);cursor:pointer;font-size:.85rem;text-align:left;';
|
||
document.getElementById('data-source-banner').after(note);
|
||
}
|
||
note.textContent = [overdue ? `有 ${overdue} 筆時間到了 HR 還沒更新,寬限期過後會自動移除` : '',
|
||
conflicts ? `有 ${conflicts} 筆 HR 調到別的單位,要你確認` : '',
|
||
managerPending ? `有 ${managerPending} 筆部門已經調了但主管職還沒處理` : ''].filter(Boolean).join(';');
|
||
note.textContent = `預排異動:${note.textContent} →`;
|
||
}
|
||
function planSummaryLine() {
|
||
const st = planState?.status;
|
||
const transfers = st?.transfers?.length || 0;
|
||
if (!st || (!st.departures.length && !st.hires.length && !transfers)) return '';
|
||
return `<div style="width:100%;font-size:.75rem;color:var(--accent-warning);">這次定錨包含預排異動:預計離職 ${st.departures.length} 位、預計新進 ${st.hires.length} 位、預計轉調 ${transfers} 位(在「預排異動」頁可以檢查)。</div>`;
|
||
}
|
||
function planStatusPill(status, autoRemoveAfter) {
|
||
const [label, color] = PLAN_STATUS[status] || [status, 'var(--text-muted)'];
|
||
const after = status === 'overdue' && autoRemoveAfter ? `<div style="font-size:.75rem;color:var(--text-dim);">${escapeHtml(autoRemoveAfter)} 之後自動移除</div>` : '';
|
||
return `<span style="font-size:.8rem;color:${color};">${escapeHtml(label)}</span>${after}`;
|
||
}
|
||
function planHistory(history) {
|
||
if (!history?.length) return '';
|
||
const cell = 'padding:.35rem .5rem;border-bottom:1px solid var(--border-color);text-align:left;';
|
||
return `<section class="card" style="padding:1.25rem;margin-top:1.5rem;">
|
||
<h2 style="font-size:1.1rem;margin:0 0 .25rem;">自動移除紀錄</h2>
|
||
<p style="font-size:.8rem;color:var(--text-dim);margin:0 0 .75rem;">HR 名單有結果之後,系統自動把預排移除,改用 HR 的資料(最近 30 筆)。</p>
|
||
<table style="width:100%;border-collapse:collapse;font-size:.85rem;">
|
||
<thead><tr><th style="${cell}">時間</th><th style="${cell}">類型</th><th style="${cell}">名稱</th><th style="${cell}">月份</th><th style="${cell}">原因</th></tr></thead>
|
||
<tbody>${history.map(h => `<tr>
|
||
<td style="${cell}">${escapeHtml(String(h.at || '').slice(0, 10))}</td>
|
||
<td style="${cell}">${h.kind === 'hire' ? '預計新進' : h.kind === 'transfer' ? '預計轉調' : '預計離職'}</td>
|
||
<td style="${cell}">${escapeHtml(h.label)}${h.matched ? `<div style="font-size:.75rem;color:var(--text-dim);">對到 ${escapeHtml(h.matched)}</div>` : ''}</td>
|
||
<td style="${cell}">${escapeHtml(h.month)}</td>
|
||
<td style="${cell}">${escapeHtml(PLAN_REASON[h.reason] || h.reason)}</td>
|
||
</tr>`).join('')}</tbody>
|
||
</table>
|
||
</section>`;
|
||
}
|
||
function renderPlans() {
|
||
const box = document.getElementById('plans-content');
|
||
if (!box) return;
|
||
if (!planState) { box.innerHTML = '<p style="color:var(--accent-danger);">預排異動讀取失敗,請重新整理。</p>'; return; }
|
||
const st = planState.status;
|
||
const hrPeople = baseData.filter(p => p.source === 'hr-sync').sort((a, b) => (a.dept || '').localeCompare(b.dept || '', 'zh-Hant') || (a.name || '').localeCompare(b.name || '', 'zh-Hant'));
|
||
const planned = new Set(planState.plans.departures.map(d => d.employeeNumber));
|
||
const moving = new Set((planState.plans.transfers || []).map(t => String(t.employeeNumber)));
|
||
const depts = [...new Set(baseData.filter(p => p.source !== 'planned' && p.dept).map(p => p.dept))].sort((a, b) => a.localeCompare(b, 'zh-Hant'));
|
||
const groups = [...new Set(baseData.filter(p => p.group).map(p => p.group))].sort();
|
||
const year = globalParams.reportYear || 2027;
|
||
const cell = 'padding:.45rem .5rem;border-bottom:1px solid var(--border-color);text-align:left;';
|
||
box.innerHTML = `
|
||
<section class="card" style="padding:1.25rem;margin-bottom:1.5rem;">
|
||
<h2 style="font-size:1.1rem;margin:0 0 .25rem;">預計離職</h2>
|
||
<p style="font-size:.8rem;color:var(--text-dim);margin:0 0 .75rem;">填「最後工作月份」。HR 名單上這個人不見了或填了離職日,系統會自動移除這一筆。在職月份會算到那個月為止;${year} 年 1 月前就走的,填 ${year - 1}-12(整年不算)。</p>
|
||
<table style="width:100%;border-collapse:collapse;font-size:.9rem;">
|
||
<thead><tr><th style="${cell}">姓名</th><th style="${cell}">部門/組</th><th style="${cell}">最後工作月份</th><th style="${cell}">備註</th><th style="${cell}">狀態</th><th style="${cell}"></th></tr></thead>
|
||
<tbody>${st.departures.length ? st.departures.map(d => `<tr>
|
||
<td style="${cell}">${escapeHtml(d.name || '(不在 HR 名單)')} <span style="color:var(--text-dim);font-size:.8rem;">${escapeHtml(d.employeeNumber)}</span></td>
|
||
<td style="${cell}">${escapeHtml([d.dept, shortGroupName(d.dept, d.group || '')].filter(Boolean).join(' / '))}</td>
|
||
<td style="${cell}">${escapeHtml(d.lastMonth)}</td>
|
||
<td style="${cell}">${escapeHtml(d.note)}</td>
|
||
<td style="${cell}">${planStatusPill(d.status, d.autoRemoveAfter)}</td>
|
||
<td style="${cell}"><button type="button" onclick="removePlan('departures','${escapeHtml(d.employeeNumber)}')" style="background:none;border:none;color:var(--accent-danger);cursor:pointer;">刪除</button></td>
|
||
</tr>`).join('') : `<tr><td colspan="6" style="${cell}color:var(--text-dim);">目前沒有預計離職。</td></tr>`}</tbody>
|
||
</table>
|
||
<div style="display:grid;grid-template-columns:minmax(220px,2fr) minmax(150px,1fr) minmax(200px,3fr) auto;gap:.5rem;align-items:center;margin-top:.75rem;">
|
||
<select id="plan-dep-person" aria-label="選擇人員">
|
||
<option value="">選擇人員…</option>
|
||
${hrPeople.filter(p => !planned.has(String(p.employeeNumber))).map(p => `<option value="${escapeHtml(p.employeeNumber)}">${escapeHtml(p.dept || '未歸部門')}|${escapeHtml(p.name)}(${escapeHtml(p.employeeNumber)})</option>`).join('')}
|
||
</select>
|
||
<input id="plan-dep-month" type="month" aria-label="最後工作月份" min="${year - 1}-12" max="${year}-12">
|
||
<input id="plan-dep-note" type="text" maxlength="200" placeholder="備註(只有你看得到)">
|
||
<button type="button" class="btn-primary" onclick="addDeparture()">+ 加入</button>
|
||
</div>
|
||
</section>
|
||
<section class="card" style="padding:1.25rem;">
|
||
<h2 style="font-size:1.1rem;margin:0 0 .25rem;">預計新進</h2>
|
||
<p style="font-size:.8rem;color:var(--text-dim);margin:0 0 .75rem;">名稱可以先寫職缺(例如「動畫師(2 月)」)。人到職、HR 名單出現同名或同部門、到職月份差不多的新人時,系統會自動移除這一筆,改用 HR 的資料。${year <= 2027 ? '2027 年的下半年(H2)跟其他人一樣先空白,下半年才開始的新進要等 H2 開放才會算進去。' : ''}</p>
|
||
<table style="width:100%;border-collapse:collapse;font-size:.9rem;">
|
||
<thead><tr><th style="${cell}">名稱</th><th style="${cell}">部門/組</th><th style="${cell}">職能</th><th style="${cell}">預估薪資</th><th style="${cell}">期間</th><th style="${cell}">備註</th><th style="${cell}">狀態</th><th style="${cell}"></th></tr></thead>
|
||
<tbody>${st.hires.length ? st.hires.map(h => `<tr>
|
||
<td style="${cell}">${escapeHtml(h.name)}${h.title ? `<div style="font-size:.75rem;color:var(--text-dim);">${escapeHtml(h.title)}</div>` : ''}</td>
|
||
<td style="${cell}">${escapeHtml([h.dept, shortGroupName(h.dept, h.group || '')].filter(Boolean).join(' / '))}</td>
|
||
<td style="${cell}">${escapeHtml(h.role.split(' - ')[0])}</td>
|
||
<td style="${cell}">${h.salaryType === 'hourly' ? '時薪 ' : '月薪 '}NT$ ${Number(h.amount).toLocaleString()}</td>
|
||
<td style="${cell}">${escapeHtml(h.startMonth)} 起${h.endMonth ? `,到 ${escapeHtml(h.endMonth)}` : ''}</td>
|
||
<td style="${cell}">${escapeHtml(h.note)}</td>
|
||
<td style="${cell}">${planStatusPill(h.status, h.autoRemoveAfter)}</td>
|
||
<td style="${cell}"><button type="button" onclick="removePlan('hires','${escapeHtml(h.id)}')" style="background:none;border:none;color:var(--accent-danger);cursor:pointer;">刪除</button></td>
|
||
</tr>`).join('') : `<tr><td colspan="8" style="${cell}color:var(--text-dim);">目前沒有預計新進。</td></tr>`}</tbody>
|
||
</table>
|
||
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:.5rem;margin-top:.75rem;">
|
||
<input id="plan-hire-name" type="text" maxlength="40" placeholder="名稱(例:動畫師 2 月)">
|
||
<input id="plan-hire-title" type="text" maxlength="80" placeholder="職稱(可不填)">
|
||
<select id="plan-hire-dept" aria-label="部門"><option value="">選擇部門…</option>${depts.map(d => `<option value="${escapeHtml(d)}">${escapeHtml(d)}</option>`).join('')}</select>
|
||
<input id="plan-hire-group" type="text" list="plan-group-list" maxlength="80" placeholder="組別(可不填)">
|
||
<datalist id="plan-group-list">${groups.map(g => `<option value="${escapeHtml(g)}">`).join('')}</datalist>
|
||
<select id="plan-hire-role" aria-label="職能"><option value="A - 藝術家">A 藝術家</option><option value="P - 製作">P 製作</option><option value="G - 營運支援">G 營運支援</option></select>
|
||
<select id="plan-hire-type" aria-label="薪資類型"><option value="monthly">月薪</option><option value="hourly">時薪</option></select>
|
||
<input id="plan-hire-amount" type="number" min="1" placeholder="預估薪資(NT$)">
|
||
<label style="font-size:.8rem;color:var(--text-dim);">開始月份<input id="plan-hire-start" type="month" min="${year}-01" max="${year}-12" style="width:100%;"></label>
|
||
<label style="font-size:.8rem;color:var(--text-dim);">結束月份(可不填)<input id="plan-hire-end" type="month" min="${year}-01" max="${year}-12" style="width:100%;"></label>
|
||
<input id="plan-hire-note" type="text" maxlength="200" placeholder="備註(只有你看得到)">
|
||
<button type="button" class="btn-primary" onclick="addHire()">+ 加入</button>
|
||
</div>
|
||
</section>
|
||
<section class="card" style="padding:1.25rem;margin-top:1.5rem;">
|
||
<h2 style="font-size:1.1rem;margin:0 0 .25rem;">預計轉調</h2>
|
||
<p style="font-size:.8rem;color:var(--text-dim);margin:0 0 .75rem;">填「生效月份」。${year} 年 1 月起就整年算新單位;生效月份在年度中間,成本會按月拆成兩段(前段原單位、後段新單位)。目標部門可以填 HR 還沒有的新部門。主管職預設轉調後卸任,可以指定原單位由誰接任,模擬就會照你設定的組織算。HR 把人調到目標單位、主管職也處理好之後,系統才會自動移除這一筆;只調了部門沒處理主管,會一直留著提醒;HR 要是調到別的地方,會標成「請確認」。主管職的設定只影響數字和模擬,不影響任何人在看板上看得到什麼,權限一律以 HR 為準。</p>
|
||
<table style="width:100%;border-collapse:collapse;font-size:.9rem;">
|
||
<thead><tr><th style="${cell}">姓名</th><th style="${cell}">HR 目前部門/組</th><th style="${cell}">調到</th><th style="${cell}">生效月份</th><th style="${cell}">主管職</th><th style="${cell}">備註</th><th style="${cell}">狀態</th><th style="${cell}"></th></tr></thead>
|
||
<tbody>${(st.transfers || []).length ? st.transfers.map(t => `<tr>
|
||
<td style="${cell}">${escapeHtml(t.name || '(不在 HR 名單)')} <span style="color:var(--text-dim);font-size:.8rem;">${escapeHtml(t.employeeNumber)}</span></td>
|
||
<td style="${cell}">${escapeHtml([t.dept, shortGroupName(t.dept, t.group || '')].filter(Boolean).join(' / ')) || '—'}</td>
|
||
<td style="${cell}">${escapeHtml([t.toDept, t.toGroup].filter(Boolean).join(' / '))}</td>
|
||
<td style="${cell}">${escapeHtml(t.effectiveMonth)}</td>
|
||
<td style="${cell}">${t.leads.length ? `${t.keepManager ? '保留' : '卸任'}(HR 目前:${escapeHtml(t.leads.join('、'))})` : t.keepManager ? '保留' : '—'}${t.successorEmployeeNumber ? `<div style="font-size:.75rem;color:var(--text-dim);">接任:${escapeHtml(t.successorName || t.successorEmployeeNumber)}${t.successorIsManager ? '' : '(HR 還沒設定)'}</div>` : ''}</td>
|
||
<td style="${cell}">${escapeHtml(t.note)}</td>
|
||
<td style="${cell}">${planStatusPill(t.status, t.autoRemoveAfter)}</td>
|
||
<td style="${cell}"><button type="button" onclick="removePlan('transfers','${escapeHtml(t.employeeNumber)}')" style="background:none;border:none;color:var(--accent-danger);cursor:pointer;">刪除</button></td>
|
||
</tr>`).join('') : `<tr><td colspan="8" style="${cell}color:var(--text-dim);">目前沒有預計轉調。</td></tr>`}</tbody>
|
||
</table>
|
||
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:.5rem;margin-top:.75rem;">
|
||
<select id="plan-tr-person" aria-label="選擇人員">
|
||
<option value="">選擇人員…</option>
|
||
${hrPeople.filter(p => !moving.has(String(p.employeeNumber))).map(p => `<option value="${escapeHtml(p.employeeNumber)}">${escapeHtml(p.dept || '未歸部門')}|${escapeHtml(p.name)}(${escapeHtml(p.employeeNumber)})</option>`).join('')}
|
||
</select>
|
||
<input id="plan-tr-dept" type="text" list="plan-dept-list" maxlength="80" placeholder="調到哪個部門">
|
||
<datalist id="plan-dept-list">${depts.map(d => `<option value="${escapeHtml(d)}">`).join('')}</datalist>
|
||
<input id="plan-tr-group" type="text" list="plan-group-list" maxlength="80" placeholder="組別(可不填)">
|
||
<label style="font-size:.8rem;color:var(--text-dim);">生效月份<input id="plan-tr-month" type="month" min="${year - 1}-01" max="${year + 1}-12" style="width:100%;"></label>
|
||
|
||
<select id="plan-tr-manager" aria-label="主管職"><option value="drop">轉調後卸任主管職</option><option value="keep">保留主管職</option></select>
|
||
<select id="plan-tr-successor" aria-label="原單位接任主管"><option value="">原單位接任主管…(可不填)</option>${hrPeople.map(p => `<option value="${escapeHtml(p.employeeNumber)}">${escapeHtml(p.dept || '未歸部門')}|${escapeHtml(p.name)}</option>`).join('')}</select>
|
||
<input id="plan-tr-note" type="text" maxlength="200" placeholder="備註(只有你看得到)">
|
||
<button type="button" class="btn-primary" onclick="addTransfer()">+ 加入</button>
|
||
</div>
|
||
</section>${planHistory(st.history)}`;
|
||
}
|
||
async function savePlans(next) {
|
||
try {
|
||
const response = await fetch('/api/plans', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(next) });
|
||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||
planState = await response.json();
|
||
updatePlanBanner();
|
||
await loadBootstrapData();
|
||
saveAndRefresh();
|
||
renderPlans();
|
||
showSaved();
|
||
} catch (error) {
|
||
console.error('Unable to save plans', error);
|
||
alert('預排異動儲存失敗,請檢查欄位後再試。');
|
||
}
|
||
}
|
||
function addDeparture() {
|
||
const employeeNumber = document.getElementById('plan-dep-person').value;
|
||
const lastMonth = document.getElementById('plan-dep-month').value;
|
||
if (!employeeNumber || !lastMonth) { alert('請選擇人員和最後工作月份。'); return; }
|
||
const plans = planState.plans;
|
||
savePlans({ ...plans, departures: [...plans.departures, { employeeNumber, lastMonth, note: document.getElementById('plan-dep-note').value }] });
|
||
}
|
||
function addHire() {
|
||
const value = id => document.getElementById(id).value;
|
||
const hire = {
|
||
id: 'h' + Date.now().toString(36), name: value('plan-hire-name').trim(), title: value('plan-hire-title'),
|
||
dept: value('plan-hire-dept'), group: value('plan-hire-group'), role: value('plan-hire-role'),
|
||
salaryType: value('plan-hire-type'), amount: Number(value('plan-hire-amount')),
|
||
startMonth: value('plan-hire-start'), endMonth: value('plan-hire-end'), note: value('plan-hire-note'),
|
||
};
|
||
if (!hire.name || !hire.dept || !(hire.amount > 0) || !hire.startMonth) { alert('請填名稱、部門、預估薪資和開始月份。'); return; }
|
||
if (hire.endMonth && hire.endMonth < hire.startMonth) { alert('結束月份不能早於開始月份。'); return; }
|
||
const plans = planState.plans;
|
||
savePlans({ ...plans, hires: [...plans.hires, hire] });
|
||
}
|
||
|
||
function addTransfer() {
|
||
const value = id => document.getElementById(id).value;
|
||
const employeeNumber = value('plan-tr-person');
|
||
const toDept = value('plan-tr-dept').trim();
|
||
const effectiveMonth = value('plan-tr-month');
|
||
if (!employeeNumber || !toDept || !effectiveMonth) { alert('請選擇人員,並填目標部門和生效月份。'); return; }
|
||
const person = baseData.find(p => String(p.employeeNumber) === employeeNumber);
|
||
const toGroup = value('plan-tr-group').trim();
|
||
if (person && person.dept === toDept && (person.group || '') === toGroup) { alert('這個人已經在目標單位了。'); return; }
|
||
const keepManager = value('plan-tr-manager') === 'keep';
|
||
const successorEmployeeNumber = value('plan-tr-successor');
|
||
const leads = (person?.supervisorOf || []).map(unit => unit.deptName).filter(Boolean);
|
||
if (leads.length && !keepManager && !successorEmployeeNumber
|
||
&& !confirm(`${person.name} 目前是 ${leads.join('、')} 的主管。轉調後這些單位會沒有主管,而且你還沒指定接任者。要繼續嗎?`)) return;
|
||
const plans = planState.plans;
|
||
savePlans({ ...plans, transfers: [...(plans.transfers || []),
|
||
{ employeeNumber, toDept, toGroup, fromDept: person?.dept || '', effectiveMonth,
|
||
keepManager, successorEmployeeNumber, note: value('plan-tr-note') }] });
|
||
}
|
||
function removePlan(kind, key) {
|
||
const plans = planState.plans;
|
||
const next = { ...plans, [kind]: (plans[kind] || []).filter(item => (kind === 'hires' ? item.id : item.employeeNumber) !== key) };
|
||
savePlans(next);
|
||
}
|
||
|
||
function contractorPayload() {
|
||
// 只存看板維護的常態型外包;HR 的工讀生(也算 O)不寫進外包清單。
|
||
return baseData.filter(p => (p.role || '').startsWith('O') && p.source !== 'hr-sync').map(p => ({
|
||
row: p.row, name: p.name, title: p.title, company: p.company, dept: p.dept, group: p.group,
|
||
dayrate: p.dayrate, h1Start: p.h1Start, h1End: p.h1End, h2Start: p.h2Start, h2End: p.h2End,
|
||
workRateUsed: p.workRateUsed,
|
||
}));
|
||
}
|
||
|
||
function scheduleContractorSave() {
|
||
if (isSimMode || contractorSignature === null) return;
|
||
const signature = JSON.stringify(contractorPayload());
|
||
if (signature === contractorSignature) return;
|
||
clearTimeout(contractorSaveTimer);
|
||
contractorSaveTimer = setTimeout(() => saveContractorsToServer(signature), 600);
|
||
}
|
||
|
||
async function saveContractorsToServer(signature) {
|
||
const banner = document.getElementById('data-source-banner');
|
||
try {
|
||
const response = await fetch('/api/cost-model/contractors', {
|
||
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ contractors: JSON.parse(signature) }),
|
||
});
|
||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||
contractorSignature = signature;
|
||
showSaved();
|
||
} catch (error) {
|
||
console.error('Unable to save contractors', error);
|
||
banner.textContent = '常態型外包儲存失敗,請重新整理後再試;剛才的外包修改尚未保存。';
|
||
banner.style.color = 'var(--accent-danger)';
|
||
}
|
||
}
|
||
|
||
// --- Board settings (RD / CG Lead flags, 核心參數) are saved on the server ---
|
||
const SETTINGS_PARAM_KEYS = ['opMultiplier', 'annualWorkDays', 'workingDays', 'utilizationP', 'utilizationA',
|
||
'invoiceWeightP', 'invoiceWeightA', 'invoiceWeightSurplus', 'targetAPRatio',
|
||
'externalProjectOutsourcing', 'employeeTripInvoices', 'grossMarginPct',
|
||
'rdReductionPct', 'pManagerReductionPct', 'pPCReductionPct', 'managerReductionPct', 'cgLeadReductionPct',
|
||
'contractorMultiplier', 'usdRate'];
|
||
let settingsSignature = null;
|
||
let settingsSaveTimer = null;
|
||
|
||
function settingsPayload() {
|
||
const params = {};
|
||
SETTINGS_PARAM_KEYS.forEach(key => {
|
||
if (globalParams[key] !== undefined && globalParams[key] !== null && globalParams[key] !== '') params[key] = Number(globalParams[key]);
|
||
});
|
||
const roles = globalParams.invoiceRoles || {};
|
||
return { rdGroups: [...(globalParams.rdGroups || [])], cgLeadGroups: [...(globalParams.cgLeadGroups || [])], params,
|
||
invoiceRoles: { companies: { ...(roles.companies || {}) }, depts: { ...(roles.depts || {}) } },
|
||
// 還沒有編輯介面,原樣送回去,才不會被其他設定的存檔洗掉。
|
||
...(Array.isArray(globalParams.codaShareRules) ? { codaShareRules: globalParams.codaShareRules } : {}) };
|
||
}
|
||
|
||
function scheduleSettingsSave() {
|
||
if (isSimMode || settingsSignature === null) return;
|
||
const signature = JSON.stringify(settingsPayload());
|
||
if (signature === settingsSignature) return;
|
||
clearTimeout(settingsSaveTimer);
|
||
settingsSaveTimer = setTimeout(() => saveSettingsToServer(signature), 600);
|
||
}
|
||
|
||
async function saveSettingsToServer(signature) {
|
||
try {
|
||
const response = await fetch('/api/cost-model/settings', {
|
||
method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: signature,
|
||
});
|
||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||
const result = await response.json().catch(() => ({}));
|
||
if (result.pending) {
|
||
// 已定錨:修改存成「下一次定錨才生效」,這半年的數字照舊,所以重新載入正式的數字。
|
||
const banner = document.getElementById('data-source-banner');
|
||
banner.textContent = '已定錨:剛才的參數修改會在下一次定錨才生效,這半年的數字照舊。';
|
||
banner.style.color = 'var(--accent-warning)';
|
||
setTimeout(() => location.reload(), 1500);
|
||
return;
|
||
}
|
||
settingsSignature = signature;
|
||
showSaved();
|
||
} catch (error) {
|
||
console.error('Unable to save board settings', error);
|
||
const banner = document.getElementById('data-source-banner');
|
||
banner.textContent = 'RD/CG 勾選或核心參數儲存失敗,請重新整理後再試;剛才的修改尚未保存。';
|
||
banner.style.color = 'var(--accent-danger)';
|
||
}
|
||
}
|
||
|
||
function saveAndRefresh() {
|
||
scheduleContractorSave();
|
||
scheduleSettingsSave();
|
||
globalParams.orgStructure = null; // Force rebuild with correct order and fresh data
|
||
renderDashboard();
|
||
renderPersonnel();
|
||
renderSales();
|
||
renderArtists();
|
||
renderCoda();
|
||
const activeView = document.querySelector('.view.active')?.id;
|
||
if (activeView === 'invoice') renderInvoice();
|
||
if (activeView === 'personnel-overview') renderPersonnelOverview();
|
||
if (activeView === 'group') renderGroup();
|
||
}
|
||
|
||
// --- INIT ---
|
||
// Initial boot handled by the preview-mode window.onload below.
|
||
// Temporary local preview identity. This is not authentication or access control.
|
||
function getCurrentUser() {
|
||
return { username: '本機預覽', role: 'admin', dept: '', group: '' };
|
||
}
|
||
|
||
function applyPreviewUI() {
|
||
document.getElementById('auth-avatar-initial').textContent = '預';
|
||
document.getElementById('auth-username-display').textContent = '確認登入狀態中';
|
||
document.getElementById('auth-role-display').textContent = '本機預覽';
|
||
}
|
||
|
||
async function applyLoginUI() {
|
||
try {
|
||
const response = await fetch('/api/auth/me', { cache: 'no-store', signal: AbortSignal.timeout(10000) });
|
||
if (response.status === 401) {
|
||
showLoginRequired();
|
||
return false;
|
||
}
|
||
if (!response.ok) throw new Error('無法確認登入狀態');
|
||
const user = await response.json();
|
||
document.getElementById('login-link').style.display = 'none';
|
||
if (user.employeeNumber === 'preview') {
|
||
document.getElementById('auth-username-display').textContent = '本機預覽';
|
||
document.getElementById('auth-role-display').textContent = '本機未啟用公司登入';
|
||
return true;
|
||
}
|
||
const name = user.name || user.employeeNumber;
|
||
document.getElementById('auth-avatar-initial').textContent = name.slice(0, 1);
|
||
document.getElementById('auth-username-display').textContent = name;
|
||
document.getElementById('auth-role-display').textContent = '公司帳號';
|
||
document.getElementById('auth-user-badge').title = '目前登入帳號';
|
||
document.getElementById('company-logout-form').style.display = '';
|
||
return true;
|
||
} catch (error) {
|
||
document.getElementById('auth-username-display').textContent = '登入狀態確認失敗';
|
||
document.getElementById('auth-role-display').textContent = '請重新整理或登入';
|
||
throw error;
|
||
}
|
||
}
|
||
|
||
function showLoginRequired() {
|
||
document.getElementById('auth-username-display').textContent = '尚未登入或登入已逾時';
|
||
document.getElementById('auth-role-display').textContent = '登入後即可載入資料';
|
||
document.getElementById('login-link').textContent = '重新登入';
|
||
document.getElementById('login-link').style.display = '';
|
||
document.getElementById('company-logout-form').style.display = 'none';
|
||
document.getElementById('data-source-banner').textContent = '登入已失效,請按左下角「重新登入」載入資料。';
|
||
}
|
||
|
||
// Revalidate when returning through the browser's back/forward cache.
|
||
window.addEventListener('pageshow', (event) => {
|
||
if (event.persisted) window.location.reload();
|
||
});
|
||
|
||
// --- API-backed preview boot ---
|
||
async function loadBootstrapData() {
|
||
const response = await fetch('/api/bootstrap', { cache: 'no-store', signal: AbortSignal.timeout(10000) });
|
||
if (response.status === 401) {
|
||
showLoginRequired();
|
||
return false;
|
||
}
|
||
const payload = await response.json().catch(() => ({}));
|
||
if (!response.ok) {
|
||
const labels = {
|
||
access_denied: '目前登入的公司帳號不在 LeadBoard 的允許名單內。',
|
||
hr_not_configured: '本站尚未收到平台提供的 HR Sync 執行期設定;因此沒有使用合成資料替代。',
|
||
hr_exchange_denied: '公司登入成功,但 HR Sync 未核准這個帳號的資料交換權限。',
|
||
hr_endpoint_forbidden: 'HR Sync 已連線,但拒絕目前要求的資料範圍。',
|
||
reauthentication_required: '公司登入已過期,請重新登入。',
|
||
hr_unavailable: 'HR Sync 暫時無法回應,請稍後重新整理。',
|
||
hr_target_unavailable: 'HR Sync 服務目前尚未可用。'
|
||
};
|
||
throw new Error(labels[payload.error] || `HR 試算資料讀取失敗(HTTP ${response.status})`);
|
||
}
|
||
if (!(payload.source === 'synthetic-demo' || /^hr-sync-\d{4}-planning$/.test(payload.source)) || !Array.isArray(payload.baseData) || !payload.globalParams) {
|
||
throw new Error('伺服器回傳格式不符。');
|
||
}
|
||
baseData = payload.baseData;
|
||
globalParams = payload.globalParams;
|
||
PMI18n.setRate(globalParams.usdRate || 30);
|
||
contractorSignature = JSON.stringify(contractorPayload());
|
||
settingsSignature = JSON.stringify(settingsPayload());
|
||
const banner = document.getElementById('data-source-banner');
|
||
if (/^hr-sync-\d{4}-planning$/.test(payload.source)) {
|
||
const summary = payload.summary || {};
|
||
banner.textContent = `${payload.reportYear || 2027} HR 試算|已轉入 ${summary.activeEmployees || 0} 位 HR 在職人員;${summary.needsReview || 0} 位待確認 P/A 或薪資,暫不納入正式總額。時薪先按每週 5 天、每天 8 小時計算;H1 預設為 1–6 月。常態型外包 ${summary.legacyContractors || 0} 位,在本站手動維護並儲存。`;
|
||
} else {
|
||
banner.textContent = '合成資料預覽|姓名、薪資與參數皆為虛構資料;修改只保留在目前頁面工作階段。';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
function setTheme(theme) {
|
||
document.documentElement.setAttribute('data-theme', theme);
|
||
try { localStorage.setItem('pmb-theme', theme); } catch (e) {}
|
||
syncThemeToggle();
|
||
}
|
||
|
||
function syncThemeToggle() {
|
||
const theme = document.documentElement.getAttribute('data-theme');
|
||
document.querySelectorAll('[data-theme-set]').forEach(b => b.setAttribute('aria-pressed', String(b.dataset.themeSet === theme)));
|
||
}
|
||
|
||
function bootApp() {
|
||
syncThemeToggle();
|
||
saveAndRefresh();
|
||
}
|
||
|
||
// 從網址帶進來的區塊(例如舊的 /permissions 會導成 /?view=permissions)。
|
||
function openViewFromUrl() {
|
||
const wanted = new URLSearchParams(location.search).get('view');
|
||
if (!wanted) return;
|
||
const target = document.getElementById(wanted);
|
||
if (target && target.classList.contains('view')) showView(wanted);
|
||
}
|
||
|
||
window.onload = async () => {
|
||
applyPreviewUI();
|
||
try {
|
||
if (!await applyLoginUI()) return;
|
||
if (!await loadBootstrapData()) return;
|
||
bootApp();
|
||
loadPlans();
|
||
openViewFromUrl();
|
||
} catch (error) {
|
||
console.error(error);
|
||
const banner = document.getElementById('data-source-banner');
|
||
banner.textContent = `無法載入預覽資料:${error.message}`;
|
||
banner.style.color = 'var(--accent-danger)';
|
||
}
|
||
};
|
||
|
||
</script>
|
||
<!-- ============ ADD PERSON MODAL ============ -->
|
||
<div id="add-person-modal" class="modal-backdrop" onclick="if(event.target===this)closeAddPersonModal()">
|
||
<div class="modal-box" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
||
<div class="modal-title" id="modal-title">新增人員</div>
|
||
|
||
<div class="modal-grid">
|
||
<!-- 姓名 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">姓名</div>
|
||
<input id="modal-name" class="modal-input" type="text" placeholder="請輸入姓名" />
|
||
</div>
|
||
<!-- 職稱 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">職稱</div>
|
||
<input id="modal-title-field" class="modal-input" type="text" placeholder="例:資深特效師" />
|
||
</div>
|
||
<!-- 部門 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">部門</div>
|
||
<select id="modal-dept" class="modal-input" onchange="addPersonModalUpdateGroups()">
|
||
</select>
|
||
</div>
|
||
<!-- 組別 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">組別</div>
|
||
<select id="modal-group" class="modal-input">
|
||
</select>
|
||
</div>
|
||
<!-- 職能角色 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">職能角色</div>
|
||
<select id="modal-role" class="modal-input" onchange="addPersonModalUpdateSalaryLabel()">
|
||
<option value="P - 製作人">P - 製作人</option>
|
||
<option value="P - 執行製作">P - 執行製作</option>
|
||
<option value="A - 藝術家" selected>A - 藝術家</option>
|
||
<option value="A - 特效師">A - 特效師</option>
|
||
<option value="A - 動畫師">A - 動畫師</option>
|
||
<option value="A - 剪輯">A - 剪輯</option>
|
||
<option value="A - 燈光">A - 燈光</option>
|
||
<option value="O - 外包">O - 外包</option>
|
||
</select>
|
||
</div>
|
||
<!-- 管理職 -->
|
||
<div class="modal-field" style="justify-content: flex-end;">
|
||
<div class="modal-label">屬性</div>
|
||
<label class="modal-checkbox-row">
|
||
<input type="checkbox" id="modal-is-manager" />
|
||
<span>管理職</span>
|
||
</label>
|
||
</div>
|
||
<!-- 薪資 -->
|
||
<div class="modal-field full-width">
|
||
<div class="modal-label" id="modal-salary-label">月薪</div>
|
||
<div class="modal-salary-wrapper">
|
||
<div class="modal-salary-prefix" id="modal-salary-prefix">NT$ / 月</div>
|
||
<input id="modal-salary" class="modal-salary-input" type="number" placeholder="例:40000" />
|
||
</div>
|
||
</div>
|
||
<!-- H1 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">H1 上半年合約期間</div>
|
||
<div class="modal-h-period">
|
||
<select id="modal-h1s" class="modal-input">
|
||
<option value="">— 無</option>
|
||
<option value="1">1月</option>
|
||
<option value="2">2月</option>
|
||
<option value="3">3月</option>
|
||
<option value="4">4月</option>
|
||
<option value="5">5月</option>
|
||
<option value="6">6月</option>
|
||
</select>
|
||
<span>→</span>
|
||
<select id="modal-h1e" class="modal-input">
|
||
<option value="">— 無</option>
|
||
<option value="1">1月</option>
|
||
<option value="2">2月</option>
|
||
<option value="3">3月</option>
|
||
<option value="4">4月</option>
|
||
<option value="5">5月</option>
|
||
<option value="6">6月</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<!-- H2 -->
|
||
<div class="modal-field">
|
||
<div class="modal-label">H2 下半年合約期間</div>
|
||
<div class="modal-h-period">
|
||
<select id="modal-h2s" class="modal-input">
|
||
<option value="">— 無</option>
|
||
<option value="7">7月</option>
|
||
<option value="8">8月</option>
|
||
<option value="9">9月</option>
|
||
<option value="10">10月</option>
|
||
<option value="11">11月</option>
|
||
<option value="12">12月</option>
|
||
</select>
|
||
<span>→</span>
|
||
<select id="modal-h2e" class="modal-input">
|
||
<option value="">— 無</option>
|
||
<option value="7">7月</option>
|
||
<option value="8">8月</option>
|
||
<option value="9">9月</option>
|
||
<option value="10">10月</option>
|
||
<option value="11">11月</option>
|
||
<option value="12">12月</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="modal-footer">
|
||
<button class="btn btn-outline" onclick="closeAddPersonModal()">取消</button>
|
||
<button class="btn btn-primary" onclick="confirmAddPerson()">✓ 確認新增</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</body>
|
||
|
||
</html>
|