Files
Toiminnanohjaus/docs/prototypes/timesheet-prototyyppi.html
2026-11-30 06:56:14 +02:00

2288 lines
124 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="fi" class="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Työajankirjaus / Timesheet – Prototyyppi</title>
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<style>
body {
font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
[x-cloak] { display: none !important; }
/* Hienovarainen vierityspalkki */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.15); }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.35); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.55); }
/* Poistetaan numerokenttien oletusnuolet */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
</style>
</head>
<body
x-data="timesheetApp()"
x-init="init()"
@keydown.escape.window="handleEscape()"
:class="darkMode ? 'bg-[#5a5e60] text-zinc-100' : 'bg-slate-200 text-slate-900'"
class="min-h-screen transition-colors duration-150 antialiased selection:bg-indigo-500 selection:text-white"
>
<!-- YLÄPALKIN NAVIGAATIO (ERP-runko) -->
<header class="bg-indigo-950 text-white border-b border-indigo-900/80 shadow-sm">
<div class="max-w-[1680px] mx-auto px-3 sm:px-6 h-12 flex items-center justify-between gap-4">
<div class="flex items-center gap-6">
<div class="flex items-center gap-2.5 font-semibold tracking-tight text-sm sm:text-base">
<span class="w-7 h-7 rounded-lg bg-indigo-500/30 border border-indigo-400/40 flex items-center justify-center text-indigo-200 font-bold">M</span>
<span>Modify ERP</span>
</div>
<nav class="hidden md:flex items-center gap-1 text-xs font-medium">
<a href="#" @click.prevent class="px-3 py-1.5 rounded-lg text-indigo-200 hover:bg-white/10 transition">Työt (Kanban)</a>
<a href="#" @click.prevent class="px-3 py-1.5 rounded-lg bg-indigo-800/80 text-white border border-indigo-500/40 shadow-inner">Oma kirjaus • Timesheet</a>
<a href="#" @click.prevent class="px-3 py-1.5 rounded-lg text-indigo-200 hover:bg-white/10 transition">Asiakkaat ja myynti</a>
<a href="#" @click.prevent class="px-3 py-1.5 rounded-lg text-indigo-200 hover:bg-white/10 transition">Hallinto</a>
</nav>
</div>
<div class="flex items-center gap-2 sm:gap-3">
<!-- Aktiivinen ajastin yläpalkissa, jos kello käy -->
<button
x-show="timer.taskId !== null"
x-cloak
@click="openTimerModal(timer.taskId)"
class="flex items-center gap-2 px-2.5 py-1 rounded-lg bg-emerald-600/90 hover:bg-emerald-500 text-white text-xs font-medium shadow transition"
>
<span class="w-2 h-2 rounded-full bg-white animate-ping"></span>
<span class="hidden sm:inline truncate max-w-[140px]" x-text="getTaskTitleById(timer.taskId)"></span>
<span class="font-mono font-semibold" x-text="formatStopwatch(timer.elapsedSeconds)"></span>
</button>
<!-- Teemavaihto (Tumma / Vaalea) -->
<button
@click="darkMode = !darkMode"
:title="darkMode ? 'Vaihda vaaleaan tilaan' : 'Vaihda tummaan tilaan'"
class="p-2 rounded-lg bg-white/10 hover:bg-white/20 text-indigo-100 transition flex items-center gap-1.5 text-xs"
>
<template x-if="darkMode">
<svg class="w-4 h-4 text-amber-300" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="4"></circle>
<path d="M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"></path>
</svg>
</template>
<template x-if="!darkMode">
<svg class="w-4 h-4 text-indigo-200" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
</template>
<span class="hidden sm:inline" x-text="darkMode ? 'Vaalea tila' : 'Tumma tila'"></span>
</button>
<div class="flex items-center gap-2 pl-2 border-l border-indigo-800 text-xs">
<span class="w-7 h-7 rounded-full bg-indigo-600 flex items-center justify-center font-semibold">JM</span>
<span class="hidden sm:inline text-indigo-100 font-medium">Jussi M.</span>
</div>
</div>
</div>
</header>
<!-- PÄÄSISÄLTÖ -->
<main class="max-w-[1680px] mx-auto px-2 sm:px-5 py-4 space-y-3">
<!-- POIKKEAVAN VIIKON VISUAALINEN VAROITUSBANNERI (kun ei olla kuluvalla viikolla 48) -->
<div
x-show="selectedWeek !== currentWeek"
x-cloak
role="status"
aria-live="polite"
class="rounded-xl border-2 border-amber-500 bg-amber-950/90 text-amber-100 px-4 py-2.5 shadow-lg flex flex-wrap items-center justify-between gap-3"
>
<div class="flex items-center gap-3">
<span class="w-8 h-8 rounded-lg bg-amber-500/20 border border-amber-400/40 flex items-center justify-center text-amber-300 shrink-0">
<svg class="w-5 h-5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/>
</svg>
</span>
<div>
<p class="text-sm font-semibold text-amber-200">
<span x-text="selectedWeek < currentWeek ? 'Huomio: Tarkastelet mennyttä viikkoa' : 'Huomio: Tarkastelet tulevaa viikkoa'"></span>
(<span x-text="'Viikko ' + selectedWeek"></span>)
</p>
<p class="text-xs text-amber-200/80">
Nykyinen kuluva viikko on <strong>Viikko 48 (23.11. – 29.11.2026)</strong>. Varmista ennen kirjausta, että olet oikealla viikolla.
</p>
</div>
</div>
<button
@click="selectedWeek = currentWeek"
class="px-3.5 py-1.5 rounded-lg bg-amber-500 hover:bg-amber-400 text-zinc-950 font-semibold text-xs shadow transition shrink-0"
>
Palaa tähän viikkoon (Vko 48)
</button>
</div>
<!-- YLÄPALKIN TYÖKALUPALKKI -->
<section
:class="[
darkMode ? 'bg-[#16160e] border-[#36393f]' : 'bg-white border-slate-300',
selectedWeek !== currentWeek ? 'ring-2 ring-amber-500/80 border-amber-500' : ''
]"
class="rounded-xl border px-3.5 py-3 shadow-md transition-all"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<!-- Vasen: Viikko-otsikko & navigointi -->
<div class="flex flex-wrap items-center gap-3">
<div>
<div class="flex items-center gap-2">
<h1 class="text-base sm:text-lg font-bold tracking-tight" x-text="weekMeta[selectedWeek].title"></h1>
<span
x-show="selectedWeek === currentWeek"
class="px-2 py-0.5 rounded-full text-[11px] font-semibold bg-indigo-500/20 text-indigo-300 border border-indigo-400/30"
>
Kuluva viikko
</span>
<span
x-show="selectedWeek !== currentWeek"
x-cloak
class="px-2 py-0.5 rounded-full text-[11px] font-semibold bg-amber-500/20 text-amber-300 border border-amber-400/40"
x-text="selectedWeek < currentWeek ? 'Mennyt viikko' : 'Tuleva viikko'"
></span>
</div>
<label class="inline-flex items-center gap-1.5 text-xs opacity-75 mt-0.5 cursor-pointer select-none">
<input type="checkbox" x-model="monthViewNotice" @change="if(monthViewNotice){ showToast('Kuukausinäkymä-yhteenveto avattu alareunaan'); }" class="rounded border-zinc-600 text-indigo-500 focus:ring-indigo-500" />
<span>Kuukausinäkymä</span>
</label>
</div>
<!-- Päivämäärä- ja viikkonavigaattori -->
<div
:class="darkMode ? 'bg-[#282a2e] border-[#3c4047]' : 'bg-slate-100 border-slate-300'"
class="inline-flex items-center rounded-lg border overflow-hidden"
>
<button
@click="changeWeek(-1)"
:disabled="!weekMeta[selectedWeek - 1]"
title="Edellinen viikko"
class="px-2.5 py-1.5 hover:bg-indigo-500/20 disabled:opacity-35 transition"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7"/></svg>
</button>
<div class="px-3 py-1.5 text-xs font-medium flex items-center gap-2 border-x border-inherit">
<svg class="w-3.5 h-3.5 opacity-70" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>
<span x-text="weekMeta[selectedWeek].startDate"></span>
</div>
<button
@click="changeWeek(1)"
:disabled="!weekMeta[selectedWeek + 1]"
title="Seuraava viikko"
class="px-2.5 py-1.5 hover:bg-indigo-500/20 disabled:opacity-35 transition"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7"/></svg>
</button>
</div>
<!-- Toimintopainikkeet: Hyväksy viikko, Poista kaikki kiinnitykset, +/- Työmääräykset -->
<div class="flex flex-wrap items-center gap-2">
<button
@click="toggleWeekApproval()"
:class="isWeekApproved(selectedWeek)
? 'bg-emerald-600/20 hover:bg-emerald-600/30 border-emerald-500/50 text-emerald-300'
: 'bg-indigo-600 hover:bg-indigo-500 border-indigo-500 text-white shadow-sm'"
class="px-3 py-1.5 rounded-lg border text-xs font-semibold flex items-center gap-1.5 transition"
>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg>
<span x-text="isWeekApproved(selectedWeek) ? 'Peru viikon hyväksyntä' : 'Hyväksy viikko'"></span>
</button>
<button
@click="confirmClearLocksOpen = true"
:disabled="countTasksInSection('locked') === 0"
title="Poista kaikki kiinnitykset Lukitut työt -osiosta"
:class="darkMode ? 'bg-[#282a2e] hover:bg-rose-500/20 border-[#3c4047] hover:border-rose-500/50 text-zinc-200 hover:text-rose-200' : 'bg-white hover:bg-rose-50 border-slate-300 text-slate-700 hover:text-rose-700'"
class="px-3 py-1.5 rounded-lg border text-xs font-medium flex items-center gap-1.5 disabled:opacity-40 transition"
>
<svg class="w-3.5 h-3.5 text-rose-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>
<span>Poista kaikki kiinnitykset</span>
</button>
<button
@click="manageModalOpen = true"
:class="darkMode ? 'bg-[#282a2e] hover:bg-[#32353b] border-[#3c4047] text-zinc-200' : 'bg-white hover:bg-slate-50 border-slate-300 text-slate-700'"
class="px-3 py-1.5 rounded-lg border text-xs font-medium flex items-center gap-1.5 transition"
>
<span class="text-sky-400 font-bold">+/-</span>
<span>Työmääräykset</span>
</button>
</div>
</div>
<!-- Oikea: Hyväksymättömät / Hyväksytyt tunnit + puuttuvien selitteiden varoitus -->
<div class="flex items-center gap-3 text-xs">
<button
x-show="!isWeekApproved(selectedWeek) && getMissingBillingNotesForWeek(selectedWeek).length > 0"
x-cloak
@click="openMissingNotesModal()"
title="Näytä kirjaukset, joilta puuttuu laskutusselite"
class="px-2.5 py-1 rounded-lg bg-amber-500/15 hover:bg-amber-500/25 border border-amber-500/40 text-amber-300 font-medium flex items-center gap-1.5 transition"
>
<span class="w-2 h-2 rounded-full bg-amber-400"></span>
<span x-text="getMissingBillingNotesForWeek(selectedWeek).length + ' selitettä puuttuu'"></span>
</button>
<div class="flex items-center gap-1.5">
<span class="opacity-75" x-text="isWeekApproved(selectedWeek) ? 'Hyväksytty:' : 'Hyväksymättä:'"></span>
<span
:class="isWeekApproved(selectedWeek) ? 'text-emerald-400' : 'text-sky-400'"
class="font-mono font-bold text-sm"
x-text="formatMinutes(getWeekTotalMinutes(selectedWeek))"
></span>
</div>
</div>
</div>
</section>
<!-- VIIKKOMATRIISI (Aikataulutettu + selkeä air gap + Lukitut työt) -->
<div class="overflow-x-auto pb-2">
<div class="min-w-[1260px] space-y-6">
<!-- ================================================================ -->
<!-- YKSIKKÖ 1: AIKATAULUTETTU (Oma erillinen korttinsa) -->
<!-- ================================================================ -->
<section
:class="darkMode ? 'bg-[#16160e] border-[#36393f]' : 'bg-white border-slate-300'"
class="rounded-xl border shadow-lg overflow-hidden"
>
<table class="w-full table-fixed border-collapse text-left">
<colgroup>
<col class="w-[340px]" />
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="'col-sch-' + dIdx">
<template x-if="true">
<col :class="isTodayColumn(dIdx) ? 'w-[124px]' : 'w-[124px]'" />
</template>
</template>
<col class="w-[72px]" />
<col class="w-[76px]" />
</colgroup>
<!-- PÄIVÄSARAKKEIDEN OTSIKKORIVI -->
<thead>
<tr :class="darkMode ? 'bg-[#0b0c0e] border-b-2 border-[#3c4047] text-white' : 'bg-slate-800 border-b-2 border-slate-900 text-white'" class="text-sm font-bold tracking-wide">
<th class="py-3.5 px-3">
<div class="flex items-center justify-between gap-2">
<span>Asiakas / Asiakastyö / Tehtävä</span>
<span class="text-xs font-normal text-zinc-400">A–Ö</span>
</div>
</th>
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="dIdx">
<th
:colspan="isTodayColumn(dIdx) ? 2 : 1"
:class="isTodayColumn(dIdx)
? 'bg-indigo-950/95 text-white border-x-2 border-t-2 border-indigo-400 w-[168px]'
: 'border-l border-zinc-800'"
class="py-3 px-1.5 text-center transition-colors"
>
<div class="flex flex-col items-center justify-center gap-0.5">
<div class="flex items-center gap-1.5">
<span x-show="isTodayColumn(dIdx)" class="text-emerald-300" title="Ajastin ja tämän päivän kirjaukset">⏱</span>
<span class="text-sm font-bold" x-text="day.label"></span>
<span
x-show="isTodayColumn(dIdx)"
class="px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider bg-indigo-500 text-white shadow-xs"
>
Tänään
</span>
</div>
</div>
</th>
</template>
<th class="py-3.5 px-2 text-center border-l border-zinc-800 text-sm font-bold">Yht.</th>
<th class="py-3.5 px-2 text-center border-l border-zinc-800 text-sm font-bold">Toim.</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-800/70 text-xs">
<!-- OSIO 1: AIKATAULUTETTU (Collapse-toiminnolla) -->
<tr :class="darkMode ? 'bg-[#23262b] border-b border-[#3b3f47]' : 'bg-slate-200/80 border-b border-slate-300'">
<td :colspan="getTableColspan()" class="py-2.5 px-3">
<div class="flex items-center justify-between">
<button
@click="scheduledCollapsed = !scheduledCollapsed"
class="flex items-center gap-2 font-bold text-xs uppercase tracking-wider hover:text-indigo-400 transition"
>
<span
:class="darkMode ? 'bg-[#16160e] border-[#3c4047]' : 'bg-white border-slate-300'"
class="w-6 h-6 rounded-md border flex items-center justify-center transition-transform duration-150"
:style="scheduledCollapsed ? 'transform: rotate(-90deg)' : ''"
>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"/></svg>
</span>
<span class="flex items-center gap-2">
<svg class="w-4 h-4 text-sky-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>
<span>Aikataulutettu</span>
</span>
<span
:class="darkMode ? 'bg-sky-500/20 text-sky-300 border-sky-500/30' : 'bg-sky-100 text-sky-800 border-sky-300'"
class="px-2 py-0.5 rounded-full text-[11px] font-semibold border normal-case tracking-normal"
x-text="countTasksInSection('scheduled') + ' tehtävää'"
></span>
</button>
<span class="text-[11px] opacity-70 hidden sm:inline">
Henkilölle aikataulutetut työt tälle viikolle • Kiinnitä (★) siirtääksesi pysyvästi Lukitut-osioon
</span>
</div>
</td>
</tr>
<!-- Aikataulutettujen töiden rivit (kun ei ole kutistettu) -->
<template x-if="!scheduledCollapsed">
<template x-for="group in getGroupedSection('scheduled')" :key="'sch-' + group.customer.id">
<template x-for="(row, rIdx) in group.rows" :key="row.key">
<tr
:class="getRowClasses(row)"
class="transition-colors"
>
<!-- TASO 1: ASIAKASOTSIKKORIVI (0px sisennys, Kanbanin asiakasväri + Color Picker) -->
<template x-if="row.type === 'customer'">
<td :colspan="getTableColspan()" class="p-0">
<div
:style="`background-color: ${row.customer.color}; color: ${getContrastColor(row.customer.color)};`"
class="px-3 py-1.5 flex items-center justify-between gap-3 relative"
>
<div class="flex items-center gap-2 font-bold text-xs tracking-wide">
<svg class="w-3.5 h-3.5 opacity-85 shrink-0" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
<span x-text="row.customer.name"></span>
<span class="text-[10px] font-medium opacity-75 px-1.5 py-0.2 rounded bg-black/15">Asiakas</span>
</div>
<!-- Color Picker + RGB -valitsin suoraan asiakasrivillä -->
<div class="relative flex items-center gap-1.5" @click.outside="if(colorPickerCustomerId === row.customer.id) colorPickerCustomerId = null">
<button
@click="toggleColorPicker(row.customer.id)"
title="Vaihda asiakkaan tunnusväri (synkronoituu Kanbaniin)"
class="px-2 py-0.5 rounded text-[11px] font-medium bg-black/20 hover:bg-black/30 backdrop-blur-xs flex items-center gap-1.5 transition"
>
<span class="w-2.5 h-2.5 rounded-full border border-white/60" :style="`background-color: ${row.customer.color}`"></span>
<span>Väri</span>
</button>
<!-- Kelluva Color Picker + RGB -ikkuna -->
<div
x-show="colorPickerCustomerId === row.customer.id"
x-cloak
:class="darkMode ? 'bg-[#1f2125] border-[#3e424b] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="absolute right-0 top-8 z-40 w-64 rounded-xl border p-3 shadow-2xl space-y-2.5 text-left"
>
<div class="flex items-center justify-between text-xs font-semibold">
<span>Asiakkaan väri (Kanban & Timesheet)</span>
<button @click="colorPickerCustomerId = null" class="opacity-60 hover:opacity-100">✕</button>
</div>
<div class="flex flex-wrap gap-1.5">
<template x-for="swatch in presetColors" :key="swatch">
<button
@click="setCustomerColor(row.customer.id, swatch)"
:style="`background-color: ${swatch}`"
class="w-5 h-5 rounded-md border border-white/25 hover:scale-110 transition"
></button>
</template>
</div>
<div class="flex items-center gap-2 pt-1 border-t border-zinc-700/50">
<input
type="color"
:value="row.customer.color"
@input="setCustomerColor(row.customer.id, $event.target.value)"
class="w-8 h-8 rounded cursor-pointer bg-transparent border-0"
/>
<div class="grid grid-cols-3 gap-1 flex-1 text-[11px]">
<label class="flex flex-col">
<span class="opacity-60">R</span>
<input type="number" min="0" max="255" :value="hexToRgb(row.customer.color).r" @input="updateCustomerRgb(row.customer.id, 'r', $event.target.value)" :class="darkMode ? 'bg-[#282a2e] border-zinc-700' : 'bg-slate-100 border-slate-300'" class="w-full rounded border px-1 py-0.5 font-mono" />
</label>
<label class="flex flex-col">
<span class="opacity-60">G</span>
<input type="number" min="0" max="255" :value="hexToRgb(row.customer.color).g" @input="updateCustomerRgb(row.customer.id, 'g', $event.target.value)" :class="darkMode ? 'bg-[#282a2e] border-zinc-700' : 'bg-slate-100 border-slate-300'" class="w-full rounded border px-1 py-0.5 font-mono" />
</label>
<label class="flex flex-col">
<span class="opacity-60">B</span>
<input type="number" min="0" max="255" :value="hexToRgb(row.customer.color).b" @input="updateCustomerRgb(row.customer.id, 'b', $event.target.value)" :class="darkMode ? 'bg-[#282a2e] border-zinc-700' : 'bg-slate-100 border-slate-300'" class="w-full rounded border px-1 py-0.5 font-mono" />
</label>
</div>
</div>
</div>
</div>
</div>
</td>
</template>
<!-- TASO 2: ASIAKASTYÖ / PROJEKTI (+28px sisennys) -->
<template x-if="row.type === 'job'">
<td :colspan="getTableColspan()" :class="darkMode ? 'bg-[#1d1f23] text-zinc-200' : 'bg-slate-100/90 text-slate-800'" class="py-1.5 pr-3 pl-7 border-t border-zinc-800/60">
<div class="flex items-center justify-between gap-2">
<div class="flex items-center gap-2 font-semibold text-xs">
<span class="text-zinc-500">└</span>
<span class="px-1.5 py-0.2 rounded font-mono text-[11px] bg-indigo-500/15 text-indigo-300 border border-indigo-500/30" x-text="'#' + row.job.number"></span>
<span x-text="row.job.title"></span>
<span
x-show="row.job.kind === 'live'"
class="px-1.5 py-0.2 rounded text-[10px] font-semibold bg-purple-500/20 text-purple-300 border border-purple-500/30"
>LIVE / Kausi</span>
<span
:class="getBillingModelBadgeClass(row.job.billingModel)"
class="px-1.5 py-0.2 rounded text-[10px] font-semibold border"
x-text="getBillingModelLabel(row.job.billingModel)"
></span>
</div>
<div class="flex items-center gap-2">
<span class="text-[11px] font-mono opacity-65" x-text="'Kertymä: ' + row.job.accumulated"></span>
<button
@click="pinJob(row.job.id)"
title="Kiinnitä koko asiakastyö Lukitut työt -osioon"
class="px-2 py-0.5 rounded text-[11px] font-medium bg-amber-500/15 hover:bg-amber-500/25 text-amber-300 border border-amber-500/30 transition"
>
★ Kiinnitä työ
</button>
</div>
</div>
</td>
</template>
<!-- TASO 3: TEHTÄVÄRIVI (+64px sisennys, puhdas ilman ajastinta) -->
<template x-if="row.type === 'task'">
<td :class="darkMode ? 'bg-[#282a2e]' : 'bg-white'" class="py-1.5 pr-3 pl-16">
<div class="min-w-0 flex items-center gap-2">
<span class="text-zinc-500 shrink-0">└</span>
<span
:class="getTaskBillingBadgeClass(row.task.billingModel)"
class="w-4 h-4 rounded-full border flex items-center justify-center text-[10px] font-bold shrink-0"
:title="getTaskBillingTooltip(row.task.billingModel)"
x-text="getTaskBillingSymbol(row.task.billingModel)"
></span>
<span class="truncate font-medium" :title="row.task.title" x-text="row.task.title"></span>
</div>
</td>
</template>
<!-- PÄIVÄKOHTAISET TUNTISOLUT (+ oma kapea ajastinsarake Tänään-sarakkeen vasemmalla puolella) -->
<template x-if="row.type === 'task'">
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="'sch-cell-' + row.task.id + '-' + dIdx">
<td
:colspan="isTodayColumn(dIdx) ? 2 : 1"
:class="[
isTodayColumn(dIdx)
? (darkMode ? 'bg-indigo-500/15 border-x-2 border-indigo-400/80' : 'bg-indigo-50/90 border-x-2 border-indigo-500')
: (darkMode ? 'bg-[#282a2e] border-l border-[#36393f]' : 'bg-white border-l border-slate-200')
]"
class="py-1.5 px-1 align-middle"
>
<div class="flex items-center justify-center gap-1">
<!-- Oma erillinen ajastinpainike-alue heti Tänään-solun vasemmalla puolella -->
<template x-if="isTodayColumn(dIdx)">
<div class="pr-1.5 mr-0.5 border-r border-indigo-400/35 flex items-center">
<button
@click="openTimerModal(row.task.id)"
:title="timer.taskId === row.task.id ? 'Ajastin käynnissä – avaa ajastinikkuna' : 'Käynnistä työajastin tälle päivälle'"
:class="timer.taskId === row.task.id
? 'bg-emerald-500/30 text-emerald-200 border-emerald-400 animate-pulse'
: (darkMode ? 'bg-indigo-950/80 hover:bg-indigo-600/40 text-indigo-200 border-indigo-400/40' : 'bg-indigo-100 hover:bg-indigo-200 text-indigo-700 border-indigo-400')"
class="w-7 h-6 rounded-md border flex items-center justify-center shrink-0 transition"
>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2.1" viewBox="0 0 24 24">
<circle cx="12" cy="13" r="8"></circle>
<path stroke-linecap="round" d="M12 9v4l2.5 2.5M9 2h6"></path>
</svg>
</button>
</div>
</template>
<div class="flex items-center justify-center gap-0.5">
<button
@click="adjustMinutes(selectedWeek, row.task.id, dIdx, -15)"
:disabled="isWeekApproved(selectedWeek) || getCellMinutes(selectedWeek, row.task.id, dIdx) === 0"
title="Vähennä 15 min (-0:15)"
:class="darkMode ? 'bg-[#1b1d20] hover:bg-rose-500/25 text-zinc-300 hover:text-rose-300 border-[#3c4047]' : 'bg-slate-100 hover:bg-rose-100 text-slate-700 border-slate-300'"
class="w-5 h-6 rounded border text-xs font-bold flex items-center justify-center disabled:opacity-30 transition select-none"
>−</button>
<input
type="text"
:value="formatMinutes(getCellMinutes(selectedWeek, row.task.id, dIdx))"
@change="setCellTimeFromInput(selectedWeek, row.task.id, dIdx, $event.target.value)"
:disabled="isWeekApproved(selectedWeek)"
:class="[
getCellMinutes(selectedWeek, row.task.id, dIdx) > 0
? (darkMode ? 'bg-emerald-950/50 border-emerald-500/50 text-emerald-200 font-semibold' : 'bg-emerald-50 border-emerald-500 text-emerald-900 font-semibold')
: (darkMode ? 'bg-[#1b1d20] border-[#3c4047] text-zinc-400' : 'bg-slate-50 border-slate-300 text-slate-500')
]"
class="w-11 h-6 rounded border text-center font-mono text-[11px] focus:outline-none focus:ring-1 focus:ring-indigo-400"
/>
<button
@click="adjustMinutes(selectedWeek, row.task.id, dIdx, 15)"
:disabled="isWeekApproved(selectedWeek)"
title="Lisää 15 min (+0:15)"
:class="darkMode ? 'bg-[#1b1d20] hover:bg-emerald-500/25 text-zinc-300 hover:text-emerald-300 border-[#3c4047]' : 'bg-slate-100 hover:bg-emerald-100 text-slate-700 border-slate-300'"
class="w-5 h-6 rounded border text-xs font-bold flex items-center justify-center disabled:opacity-30 transition select-none"
>+</button>
<button
@click="openEntryModal(row.task.id, dIdx)"
:title="getNoteButtonTooltip(selectedWeek, row.task.id, dIdx)"
:class="getNoteButtonClasses(selectedWeek, row.task.id, dIdx)"
class="w-5 h-6 rounded border flex items-center justify-center relative transition shrink-0"
>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
<span x-show="hasBillingNote(selectedWeek, row.task.id, dIdx)" class="w-1.5 h-1.5 rounded-full bg-sky-400 absolute -top-0.5 -right-0.5"></span>
<span x-show="isMissingBillingNoteHighlighted(selectedWeek, row.task.id, dIdx)" class="w-2 h-2 rounded-full bg-amber-400 animate-ping absolute -top-0.5 -right-0.5"></span>
</button>
</div>
</div>
</td>
</template>
</template>
<!-- RIVIN VIIKKOSUMMA & KIINNITYSPAINIKE -->
<template x-if="row.type === 'task'">
<td :class="darkMode ? 'bg-[#282a2e] border-l border-[#36393f]' : 'bg-white border-l border-slate-200'" class="py-1.5 px-2 text-center font-mono font-bold text-xs">
<span x-text="formatMinutes(getTaskWeekMinutes(selectedWeek, row.task.id))"></span>
</td>
</template>
<template x-if="row.type === 'task'">
<td :class="darkMode ? 'bg-[#282a2e] border-l border-[#36393f]' : 'bg-white border-l border-slate-200'" class="py-1.5 px-2 text-center">
<button
@click="pinTask(row.task.id)"
title="Kiinnitä tehtävä Lukitut työt -osioon (poistuu Aikataulutettu-osiosta)"
class="px-2 py-1 rounded-md bg-amber-500/15 hover:bg-amber-500/30 text-amber-300 border border-amber-500/30 font-semibold text-xs transition"
>
★
</button>
</td>
</template>
</tr>
</template>
</template>
</template>
<!-- Tyhjä tila Aikataulutettu-osiolle -->
<tr x-show="!scheduledCollapsed && countTasksInSection('scheduled') === 0" x-cloak>
<td :colspan="getTableColspan()" class="py-4 px-4 text-center opacity-65 italic">
Ei vapaita aikataulutettuja tehtäviä tälle viikolle (kaikki aikataulutetut työt on kiinnitetty alaosioon).
</td>
</tr>
</tbody>
</table>
</section>
<!-- ================================================================ -->
<!-- YKSIKKÖ 2: LUKITUT TYÖT (Erillinen kortti selkeän ilmarakon alla) -->
<!-- ================================================================ -->
<section
:class="darkMode ? 'bg-[#16160e] border-[#36393f]' : 'bg-white border-slate-300'"
class="rounded-xl border shadow-lg overflow-hidden"
>
<table class="w-full table-fixed border-collapse text-left">
<colgroup>
<col class="w-[340px]" />
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="'col-lck-' + dIdx">
<template x-if="true">
<col :class="isTodayColumn(dIdx) ? 'w-[124px]' : 'w-[124px]'" />
</template>
</template>
<col class="w-[72px]" />
<col class="w-[76px]" />
</colgroup>
<tbody class="divide-y divide-zinc-800/70 text-xs">
<!-- LUKITUT TYÖT -OTSIKKOPALKKI + ISO "+ LISÄÄ TYÖ LISTALLE" -PAINIKE -->
<tr :class="darkMode ? 'bg-[#23262b] border-b-2 border-[#434852]' : 'bg-slate-200 border-b-2 border-slate-300'">
<td :colspan="getTableColspan()" class="py-2.5 px-3">
<div class="flex flex-wrap items-center justify-between gap-3">
<div class="flex items-center gap-3">
<div class="flex items-center gap-2 font-bold text-xs uppercase tracking-wider">
<span class="w-6 h-6 rounded-md bg-amber-500/20 border border-amber-400/40 flex items-center justify-center text-amber-300">
★
</span>
<span>Lukitut työt</span>
<span
:class="darkMode ? 'bg-amber-500/20 text-amber-300 border-amber-500/30' : 'bg-amber-100 text-amber-800 border-amber-300'"
class="px-2 py-0.5 rounded-full text-[11px] font-semibold border normal-case tracking-normal"
x-text="countTasksInSection('locked') + ' tehtävää'"
></span>
</div>
<!-- ISO PAINIKE: + Lisää työ listalle -->
<button
@click="addUnpinnedModalOpen = true"
class="px-3.5 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white font-semibold text-xs shadow-sm flex items-center gap-1.5 transition"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4"/></svg>
<span>Lisää työ listalle</span>
</button>
</div>
<span class="text-[11px] opacity-70 hidden lg:inline">
Pysyvät kiinnitettyinä kaikilla viikoilla, kunnes vapautat (×) tai työ merkitään Valmiiksi / Laskutetuksi
</span>
</div>
</td>
</tr>
<!-- Lukittujen töiden rivit -->
<template x-for="group in getGroupedSection('locked')" :key="'lck-' + group.customer.id">
<template x-for="(row, rIdx) in group.rows" :key="row.key">
<tr class="transition-colors">
<!-- TASO 1: ASIAKASOTSIKKORIVI -->
<template x-if="row.type === 'customer'">
<td :colspan="getTableColspan()" class="p-0">
<div
:style="`background-color: ${row.customer.color}; color: ${getContrastColor(row.customer.color)};`"
class="px-3 py-1.5 flex items-center justify-between gap-3 relative"
>
<div class="flex items-center gap-2 font-bold text-xs tracking-wide">
<svg class="w-3.5 h-3.5 opacity-85 shrink-0" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
<span x-text="row.customer.name"></span>
</div>
<!-- Color Picker asiakasrivillä -->
<div class="relative flex items-center gap-1.5" @click.outside="if(colorPickerCustomerId === 'lck-' + row.customer.id) colorPickerCustomerId = null">
<button
@click="toggleColorPicker('lck-' + row.customer.id)"
title="Vaihda asiakkaan tunnusväri"
class="px-2 py-0.5 rounded text-[11px] font-medium bg-black/20 hover:bg-black/30 flex items-center gap-1.5 transition"
>
<span class="w-2.5 h-2.5 rounded-full border border-white/60" :style="`background-color: ${row.customer.color}`"></span>
<span>Väri</span>
</button>
<div
x-show="colorPickerCustomerId === 'lck-' + row.customer.id"
x-cloak
:class="darkMode ? 'bg-[#1f2125] border-[#3e424b] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="absolute right-0 top-8 z-40 w-64 rounded-xl border p-3 shadow-2xl space-y-2.5 text-left"
>
<div class="flex items-center justify-between text-xs font-semibold">
<span>Asiakkaan väri</span>
<button @click="colorPickerCustomerId = null" class="opacity-60 hover:opacity-100">✕</button>
</div>
<div class="flex flex-wrap gap-1.5">
<template x-for="swatch in presetColors" :key="swatch">
<button
@click="setCustomerColor(row.customer.id, swatch)"
:style="`background-color: ${swatch}`"
class="w-5 h-5 rounded-md border border-white/25 hover:scale-110 transition"
></button>
</template>
</div>
<div class="flex items-center gap-2 pt-1 border-t border-zinc-700/50">
<input
type="color"
:value="row.customer.color"
@input="setCustomerColor(row.customer.id, $event.target.value)"
class="w-8 h-8 rounded cursor-pointer bg-transparent border-0"
/>
<div class="grid grid-cols-3 gap-1 flex-1 text-[11px]">
<label class="flex flex-col">
<span class="opacity-60">R</span>
<input type="number" min="0" max="255" :value="hexToRgb(row.customer.color).r" @input="updateCustomerRgb(row.customer.id, 'r', $event.target.value)" :class="darkMode ? 'bg-[#282a2e] border-zinc-700' : 'bg-slate-100 border-slate-300'" class="w-full rounded border px-1 py-0.5 font-mono" />
</label>
<label class="flex flex-col">
<span class="opacity-60">G</span>
<input type="number" min="0" max="255" :value="hexToRgb(row.customer.color).g" @input="updateCustomerRgb(row.customer.id, 'g', $event.target.value)" :class="darkMode ? 'bg-[#282a2e] border-zinc-700' : 'bg-slate-100 border-slate-300'" class="w-full rounded border px-1 py-0.5 font-mono" />
</label>
<label class="flex flex-col">
<span class="opacity-60">B</span>
<input type="number" min="0" max="255" :value="hexToRgb(row.customer.color).b" @input="updateCustomerRgb(row.customer.id, 'b', $event.target.value)" :class="darkMode ? 'bg-[#282a2e] border-zinc-700' : 'bg-slate-100 border-slate-300'" class="w-full rounded border px-1 py-0.5 font-mono" />
</label>
</div>
</div>
</div>
</div>
</div>
</td>
</template>
<!-- TASO 2: ASIAKASTYÖ / PROJEKTI (+28px sisennys) -->
<template x-if="row.type === 'job'">
<td :colspan="getTableColspan()" :class="darkMode ? 'bg-[#1d1f23] text-zinc-200' : 'bg-slate-100/90 text-slate-800'" class="py-1.5 pr-3 pl-7 border-t border-zinc-800/60">
<div class="flex items-center justify-between gap-2">
<div class="flex items-center gap-2 font-semibold text-xs">
<span class="text-zinc-500">└</span>
<span class="px-1.5 py-0.2 rounded font-mono text-[11px] bg-indigo-500/15 text-indigo-300 border border-indigo-500/30" x-text="'#' + row.job.number"></span>
<span x-text="row.job.title"></span>
<span
:class="getBillingModelBadgeClass(row.job.billingModel)"
class="px-1.5 py-0.2 rounded text-[10px] font-semibold border"
x-text="getBillingModelLabel(row.job.billingModel)"
></span>
<span
x-show="row.job.completedWeek !== null"
class="px-2 py-0.2 rounded-full text-[10px] font-semibold bg-emerald-500/20 text-emerald-300 border border-emerald-500/40"
x-text="'Valmis / Laskutettu (Vko ' + row.job.completedWeek + ') – säilyy kirjatuilla viikoilla'"
></span>
</div>
<span class="text-[11px] font-mono opacity-65" x-text="'Kertymä: ' + row.job.accumulated"></span>
</div>
</td>
</template>
<!-- TASO 3: TEHTÄVÄRIVI (+64px sisennys, puhdas ilman ajastinta) -->
<template x-if="row.type === 'task'">
<td :class="darkMode ? 'bg-[#282a2e]' : 'bg-white'" class="py-1.5 pr-3 pl-16">
<div class="min-w-0 flex items-center gap-2">
<span class="text-zinc-500 shrink-0">└</span>
<span
:class="getTaskBillingBadgeClass(row.task.billingModel)"
class="w-4 h-4 rounded-full border flex items-center justify-center text-[10px] font-bold shrink-0"
:title="getTaskBillingTooltip(row.task.billingModel)"
x-text="getTaskBillingSymbol(row.task.billingModel)"
></span>
<span class="truncate font-medium" :title="row.task.title" x-text="row.task.title"></span>
</div>
</td>
</template>
<!-- PÄIVÄKOHTAISET TUNTISOLUT (+ oma kapea ajastinsarake Tänään-sarakkeen vasemmalla puolella) -->
<template x-if="row.type === 'task'">
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="'lck-cell-' + row.task.id + '-' + dIdx">
<td
:colspan="isTodayColumn(dIdx) ? 2 : 1"
:class="[
isTodayColumn(dIdx)
? (darkMode ? 'bg-indigo-500/15 border-x-2 border-indigo-400/80' : 'bg-indigo-50/90 border-x-2 border-indigo-500')
: (darkMode ? 'bg-[#282a2e] border-l border-[#36393f]' : 'bg-white border-l border-slate-200')
]"
class="py-1.5 px-1 align-middle"
>
<div class="flex items-center justify-center gap-1">
<!-- Oma erillinen ajastinpainike-alue heti Tänään-solun vasemmalla puolella -->
<template x-if="isTodayColumn(dIdx)">
<div class="pr-1.5 mr-0.5 border-r border-indigo-400/35 flex items-center">
<button
@click="openTimerModal(row.task.id)"
:title="timer.taskId === row.task.id ? 'Ajastin käynnissä – avaa ajastinikkuna' : 'Käynnistä työajastin tälle päivälle'"
:class="timer.taskId === row.task.id
? 'bg-emerald-500/30 text-emerald-200 border-emerald-400 animate-pulse'
: (darkMode ? 'bg-indigo-950/80 hover:bg-indigo-600/40 text-indigo-200 border-indigo-400/40' : 'bg-indigo-100 hover:bg-indigo-200 text-indigo-700 border-indigo-400')"
class="w-7 h-6 rounded-md border flex items-center justify-center shrink-0 transition"
>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2.1" viewBox="0 0 24 24">
<circle cx="12" cy="13" r="8"></circle>
<path stroke-linecap="round" d="M12 9v4l2.5 2.5M9 2h6"></path>
</svg>
</button>
</div>
</template>
<div class="flex items-center justify-center gap-0.5">
<button
@click="adjustMinutes(selectedWeek, row.task.id, dIdx, -15)"
:disabled="isWeekApproved(selectedWeek) || getCellMinutes(selectedWeek, row.task.id, dIdx) === 0"
title="Vähennä 15 min (-0:15)"
:class="darkMode ? 'bg-[#1b1d20] hover:bg-rose-500/25 text-zinc-300 hover:text-rose-300 border-[#3c4047]' : 'bg-slate-100 hover:bg-rose-100 text-slate-700 border-slate-300'"
class="w-5 h-6 rounded border text-xs font-bold flex items-center justify-center disabled:opacity-30 transition select-none"
>−</button>
<input
type="text"
:value="formatMinutes(getCellMinutes(selectedWeek, row.task.id, dIdx))"
@change="setCellTimeFromInput(selectedWeek, row.task.id, dIdx, $event.target.value)"
:disabled="isWeekApproved(selectedWeek)"
:class="[
getCellMinutes(selectedWeek, row.task.id, dIdx) > 0
? (darkMode ? 'bg-emerald-950/50 border-emerald-500/50 text-emerald-200 font-semibold' : 'bg-emerald-50 border-emerald-500 text-emerald-900 font-semibold')
: (darkMode ? 'bg-[#1b1d20] border-[#3c4047] text-zinc-400' : 'bg-slate-50 border-slate-300 text-slate-500')
]"
class="w-11 h-6 rounded border text-center font-mono text-[11px] focus:outline-none focus:ring-1 focus:ring-indigo-400"
/>
<button
@click="adjustMinutes(selectedWeek, row.task.id, dIdx, 15)"
:disabled="isWeekApproved(selectedWeek)"
title="Lisää 15 min (+0:15)"
:class="darkMode ? 'bg-[#1b1d20] hover:bg-emerald-500/25 text-zinc-300 hover:text-emerald-300 border-[#3c4047]' : 'bg-slate-100 hover:bg-emerald-100 text-slate-700 border-slate-300'"
class="w-5 h-6 rounded border text-xs font-bold flex items-center justify-center disabled:opacity-30 transition select-none"
>+</button>
<button
@click="openEntryModal(row.task.id, dIdx)"
:title="getNoteButtonTooltip(selectedWeek, row.task.id, dIdx)"
:class="getNoteButtonClasses(selectedWeek, row.task.id, dIdx)"
class="w-5 h-6 rounded border flex items-center justify-center relative transition shrink-0"
>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
<span x-show="hasBillingNote(selectedWeek, row.task.id, dIdx)" class="w-1.5 h-1.5 rounded-full bg-sky-400 absolute -top-0.5 -right-0.5"></span>
<span x-show="isMissingBillingNoteHighlighted(selectedWeek, row.task.id, dIdx)" class="w-2 h-2 rounded-full bg-amber-400 animate-ping absolute -top-0.5 -right-0.5"></span>
</button>
</div>
</div>
</td>
</template>
</template>
<!-- RIVIN VIIKKOSUMMA & LUKITUKSEN POISTO (×) -->
<template x-if="row.type === 'task'">
<td :class="darkMode ? 'bg-[#282a2e] border-l border-[#36393f]' : 'bg-white border-l border-slate-200'" class="py-1.5 px-2 text-center font-mono font-bold text-xs">
<span x-text="formatMinutes(getTaskWeekMinutes(selectedWeek, row.task.id))"></span>
</td>
</template>
<template x-if="row.type === 'task'">
<td :class="darkMode ? 'bg-[#282a2e] border-l border-[#36393f]' : 'bg-white border-l border-slate-200'" class="py-1.5 px-2 text-center">
<button
@click="unpinTask(row.task.id)"
title="Poista kiinnitys (×) – jos työllä on aikataulua, se palaa Aikataulutettu-osioon"
class="px-2 py-1 rounded-md bg-rose-500/15 hover:bg-rose-500/30 text-rose-300 border border-rose-500/30 font-bold text-xs transition"
>
×
</button>
</td>
</template>
</tr>
</template>
</template>
<!-- Tyhjä tila Lukitut työt -osiolle -->
<tr x-show="countTasksInSection('locked') === 0" x-cloak>
<td :colspan="getTableColspan()" class="py-5 px-4 text-center opacity-70">
<p class="italic mb-2">Ei vielä lukittuja töitä.</p>
<button
@click="addUnpinnedModalOpen = true"
class="px-3.5 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white font-semibold text-xs inline-flex items-center gap-1.5 transition"
>
<span>+ Lisää työ listalle</span>
</button>
</td>
</tr>
</tbody>
</table>
</section>
<!-- ================================================================ -->
<!-- PÄIVÄ- JA VIIKKOSUMMAT (Yhteenvetopalkki alareunassa) -->
<!-- ================================================================ -->
<section
:class="darkMode ? 'bg-[#16160e] border-[#36393f]' : 'bg-white border-slate-300'"
class="rounded-xl border shadow-lg overflow-hidden"
>
<table class="w-full table-fixed border-collapse text-left">
<colgroup>
<col class="w-[340px]" />
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="'col-sum-' + dIdx">
<template x-if="true">
<col :class="isTodayColumn(dIdx) ? 'w-[124px]' : 'w-[124px]'" />
</template>
</template>
<col class="w-[72px]" />
<col class="w-[76px]" />
</colgroup>
<tfoot>
<tr :class="darkMode ? 'bg-[#121316] text-zinc-100' : 'bg-slate-800 text-white'" class="font-bold text-xs">
<td class="py-3 px-3">
<div class="flex items-center justify-between">
<span>Päivä- ja viikkoyhteenveto</span>
<span class="text-[11px] font-normal opacity-75">Tavoite 37:30 / vko</span>
</div>
</td>
<template x-for="(day, dIdx) in weekMeta[selectedWeek].days" :key="'sum-' + dIdx">
<td
:colspan="isTodayColumn(dIdx) ? 2 : 1"
:class="isTodayColumn(dIdx)
? 'bg-indigo-950/95 border-x-2 border-b-2 border-indigo-400 text-indigo-200'
: 'border-l border-zinc-800'"
class="py-3 px-1.5 text-center font-mono text-xs"
>
<span x-text="formatMinutes(getDayTotalMinutes(selectedWeek, dIdx))"></span>
</td>
</template>
<td class="py-3 px-2 text-center border-l border-zinc-800 font-mono text-sm text-emerald-400">
<span x-text="formatMinutes(getWeekTotalMinutes(selectedWeek))"></span>
</td>
<td class="py-3 px-2 text-center border-l border-zinc-800 font-mono text-[11px]">
<span
:class="getWeekTotalMinutes(selectedWeek) >= 2250 ? 'text-emerald-400' : 'text-zinc-400'"
x-text="formatBalance(getWeekTotalMinutes(selectedWeek) - 2250)"
></span>
</td>
</tr>
</tfoot>
</table>
</section>
</div>
</div>
<!-- Kuukausinäkymä-yhteenvetolaatikko (jos valittuna yläpalkista) -->
<section
x-show="monthViewNotice"
x-cloak
:class="darkMode ? 'bg-[#16160e] border-[#36393f]' : 'bg-white border-slate-300'"
class="rounded-xl border p-4 shadow-md flex flex-wrap items-center justify-between gap-4 text-xs"
>
<div class="flex items-center gap-3">
<span class="px-2.5 py-1 rounded-lg bg-indigo-500/20 text-indigo-300 border border-indigo-500/30 font-semibold">Marraskuu 2026</span>
<span>Kuukauden kokonaiskertymä: <strong class="font-mono text-sm text-emerald-400">142:15 h</strong> (Laskutettava & kiinteä: <strong>108:30 h</strong> • Sisäinen: <strong>33:45 h</strong>)</span>
</div>
<button @click="monthViewNotice = false" class="text-xs opacity-70 hover:opacity-100 underline">Piilota kuukausiyhteenveto</button>
</section>
</main>
<!-- ====================================================================== -->
<!-- MODAALI 1: TYÖAJASTIN (Timer Pop-up) -->
<!-- ====================================================================== -->
<div
x-show="timerModalOpen"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-xs p-4"
>
<div
@click.outside="closeTimerModal()"
:class="darkMode ? 'bg-[#1a1c20] border-[#3c4047] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="w-full max-w-lg rounded-2xl border shadow-2xl overflow-hidden"
>
<div class="px-5 py-3.5 border-b border-inherit flex items-center justify-between gap-3">
<div class="flex items-center gap-2 font-bold text-sm">
<svg class="w-4 h-4 text-emerald-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><circle cx="12" cy="13" r="8"/><path stroke-linecap="round" d="M12 9v4l2.5 2.5M9 2h6"/></svg>
<span>Työajastin</span>
</div>
<div class="flex items-center gap-2">
<span
x-show="timer.running"
x-cloak
class="px-2 py-0.5 rounded-full text-[11px] font-semibold bg-amber-500/20 text-amber-300 border border-amber-500/40"
>
Pysäytä ennen sulkemista
</span>
<button
@click="closeTimerModal()"
:disabled="timer.running"
:title="timer.running ? 'Pysäytä ajastin (Tauko, Nollaa tai Pysäytä & tallenna) ennen ikkunan sulkemista' : 'Sulje ikkuna'"
class="p-1 rounded-lg opacity-65 hover:opacity-100 disabled:opacity-25 disabled:cursor-not-allowed transition"
>✕</button>
</div>
</div>
<div class="p-5 space-y-4">
<div :class="darkMode ? 'bg-[#25272c] border-[#36393f]' : 'bg-slate-100 border-slate-200'" class="rounded-xl border p-3.5">
<div class="text-[11px] uppercase tracking-wider opacity-65 font-semibold" x-text="getCustomerNameByTaskId(timerModalTaskId)"></div>
<div class="text-xs font-medium mt-0.5" x-text="getJobTitleByTaskId(timerModalTaskId)"></div>
<div class="text-sm font-bold text-indigo-400 mt-1" x-text="getTaskTitleById(timerModalTaskId)"></div>
</div>
<!-- Juokseva kello + käsin muokattava aikakenttä -->
<div class="text-center py-3">
<template x-if="!timer.editing">
<div class="space-y-2">
<div
class="font-mono text-4xl font-bold tracking-wider"
x-text="formatStopwatch(timer.taskId === timerModalTaskId ? timer.elapsedSeconds : 0)"
></div>
<div>
<button
type="button"
@click="enableTimerManualEdit(timerModalTaskId)"
:class="darkMode ? 'bg-[#282a2e] hover:bg-[#34373d] border-[#3c4047] text-zinc-200' : 'bg-slate-100 hover:bg-slate-200 border-slate-300 text-slate-700'"
class="px-3 py-1 rounded-lg border text-xs font-medium inline-flex items-center gap-1.5 transition"
>
<svg class="w-3.5 h-3.5 text-indigo-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
<span>Muokkaa aikaa käsin</span>
</button>
</div>
</div>
</template>
<template x-if="timer.editing">
<div class="space-y-2.5">
<div class="flex items-center justify-center gap-1.5 font-mono">
<div class="flex flex-col items-center">
<input
type="number"
min="0"
max="99"
x-model.number="timer.editHours"
:class="darkMode ? 'bg-[#121316] border-indigo-500 text-white' : 'bg-slate-50 border-indigo-500 text-slate-900'"
class="w-16 h-12 rounded-xl border-2 text-center text-2xl font-bold focus:outline-none"
/>
<span class="text-[10px] opacity-60 mt-1">Tunnit</span>
</div>
<span class="text-2xl font-bold pb-4">:</span>
<div class="flex flex-col items-center">
<input
type="number"
min="0"
max="59"
x-model.number="timer.editMinutes"
:class="darkMode ? 'bg-[#121316] border-indigo-500 text-white' : 'bg-slate-50 border-indigo-500 text-slate-900'"
class="w-16 h-12 rounded-xl border-2 text-center text-2xl font-bold focus:outline-none"
/>
<span class="text-[10px] opacity-60 mt-1">Minuutit</span>
</div>
<span class="text-2xl font-bold pb-4">:</span>
<div class="flex flex-col items-center">
<input
type="number"
min="0"
max="59"
x-model.number="timer.editSeconds"
:class="darkMode ? 'bg-[#121316] border-indigo-500 text-white' : 'bg-slate-50 border-indigo-500 text-slate-900'"
class="w-16 h-12 rounded-xl border-2 text-center text-2xl font-bold focus:outline-none"
/>
<span class="text-[10px] opacity-60 mt-1">Sekunnit</span>
</div>
</div>
<div class="flex items-center justify-center gap-2">
<button
type="button"
@click="applyTimerManualEdit(timerModalTaskId)"
class="px-3 py-1 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-semibold transition"
>
✓ Vahvista aika
</button>
<button
type="button"
@click="timer.editing = false"
:class="darkMode ? 'bg-[#282a2e] border-[#3c4047]' : 'bg-slate-200 border-slate-300'"
class="px-3 py-1 rounded-lg border text-xs font-medium transition"
>
Peruuta
</button>
</div>
</div>
</template>
<p class="text-xs opacity-70 mt-2" x-text="timer.running && timer.taskId === timerModalTaskId ? 'Ajastin käynnissä...' : (timer.editing ? 'Syötä tunnit, minuutit ja sekunnit numeroina' : 'Valmiina käynnistykseen tai tauolla')"></p>
</div>
<div>
<label class="block text-xs font-medium mb-1">Laskuselite (suositellaan)</label>
<input
type="text"
x-model="timer.note"
placeholder="Mitä teit tällä jaksolla?"
:class="darkMode ? 'bg-[#121316] border-[#36393f] text-zinc-100' : 'bg-slate-50 border-slate-300 text-slate-900'"
class="w-full rounded-xl border px-3 py-2 text-xs focus:outline-none focus:ring-2 focus:ring-indigo-500"
/>
</div>
<!-- Ajastimen ohjausnapit: Käynnistä, Tauko, Nollaa ja Pysäytä & tallenna -->
<div class="grid grid-cols-2 sm:grid-cols-12 gap-2 pt-1">
<button
@click="startOrResumeTimer(timerModalTaskId)"
class="sm:col-span-3 py-2.5 px-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-semibold text-xs shadow transition"
>
▶ Käynnistä
</button>
<button
@click="pauseTimer()"
:disabled="!timer.running || timer.taskId !== timerModalTaskId"
:class="darkMode ? 'bg-[#282a2e] hover:bg-[#34373d] border-[#3c4047]' : 'bg-slate-200 hover:bg-slate-300 border-slate-300'"
class="sm:col-span-2 py-2.5 px-2 rounded-xl border font-semibold text-xs disabled:opacity-40 transition"
>
❚❚ Tauko
</button>
<button
@click="stopAndResetTimer(timerModalTaskId)"
:disabled="timer.taskId !== timerModalTaskId || (timer.elapsedSeconds === 0 && !timer.running)"
title="Pysäytä ja nollaa ajastin kirjaamatta tunteja"
:class="darkMode ? 'bg-rose-950/60 hover:bg-rose-600/30 border-rose-500/40 text-rose-200' : 'bg-rose-50 hover:bg-rose-100 border-rose-300 text-rose-700'"
class="sm:col-span-2 py-2.5 px-2 rounded-xl border font-semibold text-xs disabled:opacity-40 transition"
>
Nollaa
</button>
<button
@click="commitTimerToToday(timerModalTaskId)"
class="col-span-2 sm:col-span-5 py-2.5 px-3 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-white font-semibold text-xs shadow flex items-center justify-center gap-1.5 transition"
>
<span class="inline-block w-2.5 h-2.5 bg-white rounded-[2px] shrink-0"></span>
<span>Pysäytä &amp; tallenna (<span x-text="getTimerCommitLabel(timerModalTaskId)"></span>)</span>
</button>
</div>
</div>
</div>
</div>
<!-- ====================================================================== -->
<!-- MODAALI 2: MUOKKAA KIRJAUSTA (Muistiokuvakkeesta avautuva seliteikkuna) -->
<!-- ====================================================================== -->
<div
x-show="entryModal.open"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-xs p-4"
>
<div
@click.outside="saveAndCloseEntryModal()"
:class="darkMode ? 'bg-[#1a1c20] border-[#3c4047] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="w-full max-w-xl rounded-2xl border shadow-2xl overflow-hidden"
>
<div class="px-5 py-3.5 border-b border-inherit flex items-center justify-between gap-4">
<div>
<h2 class="text-base font-bold">Muokkaa kirjausta</h2>
<p class="text-xs opacity-70 mt-0.5">
<span class="font-semibold" x-text="getCustomerNameByTaskId(entryModal.taskId)"></span> •
<span x-text="getTaskTitleById(entryModal.taskId)"></span> •
<span class="text-indigo-400 font-semibold" x-text="weekMeta[selectedWeek]?.days[entryModal.dayIndex]?.label"></span>
(<span class="font-mono font-bold" x-text="formatMinutes(getCellMinutes(selectedWeek, entryModal.taskId, entryModal.dayIndex))"></span>)
</p>
</div>
<div class="flex items-center gap-2">
<span class="text-[11px] opacity-60 hidden sm:inline">[ESC] → sulje + tallenna</span>
<button @click="saveAndCloseEntryModal()" class="p-1.5 rounded-lg opacity-65 hover:opacity-100">✕</button>
</div>
</div>
<div class="p-5 space-y-4">
<!-- Kirjauksen laskutusperuste (Kiinteä hinta vs. Tuntityö vs. Ei laskutettava) -->
<div>
<label class="block text-xs font-semibold mb-1.5">Kirjauksen laskutusperuste</label>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-2">
<button
type="button"
@click="entryModal.billingModel = 'kiintea'"
:class="entryModal.billingModel === 'kiintea'
? 'bg-amber-500/20 border-amber-400 text-amber-200 ring-1 ring-amber-400/50'
: (darkMode ? 'bg-[#121316] border-[#36393f] text-zinc-400 hover:text-zinc-200' : 'bg-slate-50 border-slate-300 text-slate-600')"
class="px-3 py-2 rounded-xl border text-left transition"
>
<div class="text-xs font-bold flex items-center gap-1.5">
<span class="w-4 h-4 rounded-full bg-amber-500/25 border border-amber-400/50 text-amber-300 flex items-center justify-center text-[10px]">K</span>
<span>Kiinteä hinta</span>
</div>
<div class="text-[10px] opacity-75 mt-0.5">Sisältyy sopimukseen, tunnit seurantaan</div>
</button>
<button
type="button"
@click="entryModal.billingModel = 'tuntityo'"
:class="entryModal.billingModel === 'tuntityo'
? 'bg-emerald-500/20 border-emerald-400 text-emerald-200 ring-1 ring-emerald-400/50'
: (darkMode ? 'bg-[#121316] border-[#36393f] text-zinc-400 hover:text-zinc-200' : 'bg-slate-50 border-slate-300 text-slate-600')"
class="px-3 py-2 rounded-xl border text-left transition"
>
<div class="text-xs font-bold flex items-center gap-1.5">
<span class="w-4 h-4 rounded-full bg-emerald-500/25 border border-emerald-400/50 text-emerald-300 flex items-center justify-center text-[10px]">€</span>
<span>Tuntityö</span>
</div>
<div class="text-[10px] opacity-75 mt-0.5">Laskutetaan erikseen tuntien mukaan</div>
</button>
<button
type="button"
@click="entryModal.billingModel = 'ei_laskutettava'"
:class="entryModal.billingModel === 'ei_laskutettava'
? 'bg-zinc-600/30 border-zinc-400 text-zinc-100 ring-1 ring-zinc-400/40'
: (darkMode ? 'bg-[#121316] border-[#36393f] text-zinc-400 hover:text-zinc-200' : 'bg-slate-50 border-slate-300 text-slate-600')"
class="px-3 py-2 rounded-xl border text-left transition"
>
<div class="text-xs font-bold flex items-center gap-1.5">
<span class="w-4 h-4 rounded-full bg-zinc-600/40 border border-zinc-500 text-zinc-300 flex items-center justify-center text-[10px]">•</span>
<span>Ei laskutettava</span>
</div>
<div class="text-[10px] opacity-75 mt-0.5">Sisäinen työ tai takuukorjaus</div>
</button>
</div>
</div>
<!-- Laskuselite (Vaaditaan jokaiselle kirjaukselle ennen viikon hyväksyntää) -->
<div>
<div class="flex items-center justify-between mb-1">
<label class="text-xs font-semibold">Laskutusselite <span class="text-amber-400">*</span></label>
<span class="text-[11px] text-amber-400 font-medium">Vaaditaan viikon hyväksyntää varten</span>
</div>
<textarea
rows="3"
x-model="entryModal.billingNote"
:placeholder="entryModal.billingModel === 'kiintea' ? 'Kuvaa tehty työ kiinteähintaisen sopimuksen seurantaa ja raportointia varten...' : 'Kirjoita selite tehdystä työstä (vaaditaan viikon hyväksyntään)...'"
:class="[
darkMode ? 'bg-[#121316] text-zinc-100' : 'bg-slate-50 text-slate-900',
!entryModal.billingNote.trim() ? 'border-amber-500/60' : (darkMode ? 'border-[#36393f]' : 'border-slate-300')
]"
class="w-full rounded-xl border p-3 text-xs focus:outline-none focus:ring-2 focus:ring-indigo-500"
></textarea>
</div>
<!-- Sisäinen kommentti -->
<div>
<div class="flex items-center justify-between mb-1">
<label class="text-xs font-semibold">Sisäinen kommentti (Timesheet-vuoro)</label>
<span class="text-[11px] opacity-60">Näkyy vain omalle tiimille ja laskuttajalle</span>
</div>
<textarea
rows="2"
x-model="entryModal.internalComment"
placeholder="Sisäiset huomiot, poikkeamat tai lisätiedot..."
:class="darkMode ? 'bg-[#121316] border-[#36393f] text-zinc-100' : 'bg-slate-50 border-slate-300 text-slate-900'"
class="w-full rounded-xl border p-3 text-xs focus:outline-none focus:ring-2 focus:ring-indigo-500"
></textarea>
</div>
<!-- Alarivin lisätoiminnot & Tallenna -->
<div class="flex flex-wrap items-center justify-between gap-3 pt-2 border-t border-inherit">
<div class="flex items-center gap-1.5">
<button
type="button"
@click="showToast('Tuotteen/kulun lisäys avattu tälle kirjaukselle')"
:class="darkMode ? 'bg-[#282a2e] hover:bg-[#32353b] border-[#3c4047]' : 'bg-slate-100 hover:bg-slate-200 border-slate-300'"
class="px-2.5 py-1.5 rounded-lg border text-xs font-medium transition"
>+ Tuote</button>
<button
type="button"
@click="showToast('Liitteen valinta avattu')"
:class="darkMode ? 'bg-[#282a2e] hover:bg-[#32353b] border-[#3c4047]' : 'bg-slate-100 hover:bg-slate-200 border-slate-300'"
class="p-1.5 rounded-lg border transition"
title="Lisää liite"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"/></svg>
</button>
</div>
<button
type="button"
@click="saveAndCloseEntryModal()"
class="px-5 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-white font-semibold text-xs shadow flex items-center gap-1.5 transition"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg>
<span>Tallenna</span>
</button>
</div>
</div>
</div>
</div>
<!-- ====================================================================== -->
<!-- MODAALI 3: +/- TYÖMÄÄRÄYKSET & TYÖN VALMIUS / LASKUTUSTILA -->
<!-- ====================================================================== -->
<div
x-show="manageModalOpen"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-xs p-4"
>
<div
@click.outside="manageModalOpen = false"
:class="darkMode ? 'bg-[#1a1c20] border-[#3c4047] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="w-full max-w-2xl rounded-2xl border shadow-2xl overflow-hidden"
>
<div class="px-5 py-3.5 border-b border-inherit flex items-center justify-between">
<div>
<h2 class="text-base font-bold">+/- Työmääräykset ja työn tila</h2>
<p class="text-xs opacity-70">Kiinnitä tehtäviä Lukitut-osioon tai testaa työn merkitsemistä Valmiiksi / Laskutetuksi</p>
</div>
<button @click="manageModalOpen = false" class="p-1.5 rounded-lg opacity-65 hover:opacity-100">✕</button>
</div>
<div class="p-5 max-h-[70vh] overflow-y-auto space-y-3">
<template x-for="job in getSortedJobs()" :key="'mng-' + job.id">
<div :class="darkMode ? 'bg-[#25272c] border-[#383c44]' : 'bg-slate-50 border-slate-200'" class="rounded-xl border p-3 space-y-2">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full" :style="`background-color: ${getCustomerById(job.customerId).color}`"></span>
<span class="font-bold text-xs" x-text="getCustomerById(job.customerId).name"></span>
<span class="opacity-50">•</span>
<span class="font-mono text-xs text-indigo-400" x-text="'#' + job.number"></span>
<span class="font-semibold text-xs" x-text="job.title"></span>
</div>
<!-- Valmis / Laskutettu -simulaatiokytkin -->
<button
@click="toggleJobCompleted(job.id)"
:class="job.completedWeek !== null
? 'bg-emerald-600/25 border-emerald-500/50 text-emerald-300'
: (darkMode ? 'bg-[#1a1c20] hover:bg-emerald-500/20 border-[#3c4047] text-zinc-300' : 'bg-white hover:bg-emerald-50 border-slate-300 text-slate-700')"
class="px-2.5 py-1 rounded-lg border text-[11px] font-semibold transition"
>
<span x-text="job.completedWeek !== null ? '✓ Merkitty Valmiiksi (Vko ' + job.completedWeek + ') – Palauta aktiiviseksi' : 'Merkitse Valmiiksi / Laskutetuksi'"></span>
</button>
</div>
<div class="divide-y divide-zinc-700/40 pl-5">
<template x-for="task in getTasksForJob(job.id)" :key="'mng-t-' + task.id">
<div class="py-1.5 flex items-center justify-between gap-2 text-xs">
<span x-text="task.title"></span>
<button
@click="task.locked ? unpinTask(task.id) : pinTask(task.id)"
:class="task.locked
? 'bg-amber-500/20 text-amber-300 border-amber-500/40'
: 'bg-indigo-600/20 text-indigo-300 border-indigo-500/40'"
class="px-2.5 py-1 rounded-md border font-semibold text-[11px] transition"
x-text="task.locked ? '★ Lukittu (Poista lukitus)' : '+ Kiinnitä Lukitut-osioon'"
></button>
</div>
</template>
</div>
</div>
</template>
</div>
<div class="px-5 py-3 border-t border-inherit flex justify-end">
<button @click="manageModalOpen = false" class="px-4 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-semibold">Sulje</button>
</div>
</div>
</div>
<!-- ====================================================================== -->
<!-- MODAALI 4: LISÄÄ TYÖ LISTALLE (Henkilön kiinnittämättömät työt) -->
<!-- ====================================================================== -->
<div
x-show="addUnpinnedModalOpen"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-xs p-4"
>
<div
@click.outside="addUnpinnedModalOpen = false"
:class="darkMode ? 'bg-[#1a1c20] border-[#3c4047] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="w-full max-w-2xl rounded-2xl border shadow-2xl overflow-hidden"
>
<div class="px-5 py-3.5 border-b border-inherit flex items-center justify-between gap-3">
<div>
<h2 class="text-base font-bold">Lisää työ listalle (Lukitut työt)</h2>
<p class="text-xs opacity-70">Kaikki henkilön avoimet työt ja tehtävät, joita ei ole vielä kiinnitetty listalle</p>
</div>
<button @click="addUnpinnedModalOpen = false" class="p-1.5 rounded-lg opacity-65 hover:opacity-100">✕</button>
</div>
<!-- Hakukenttä -->
<div class="px-5 pt-3">
<input
type="text"
x-model="unpinnedSearch"
placeholder="Hae asiakkaan, työn numeron tai tehtävän nimellä..."
:class="darkMode ? 'bg-[#121316] border-[#36393f] text-zinc-100' : 'bg-slate-50 border-slate-300 text-slate-900'"
class="w-full rounded-xl border px-3.5 py-2 text-xs focus:outline-none focus:ring-2 focus:ring-indigo-500"
/>
</div>
<div class="p-5 max-h-[62vh] overflow-y-auto space-y-3">
<template x-for="job in getUnpinnedJobsFiltered()" :key="'unp-job-' + job.id">
<div :class="darkMode ? 'bg-[#25272c] border-[#383c44]' : 'bg-slate-50 border-slate-200'" class="rounded-xl border p-3 space-y-2">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full" :style="`background-color: ${getCustomerById(job.customerId).color}`"></span>
<span class="font-bold text-xs" x-text="getCustomerById(job.customerId).name"></span>
<span class="opacity-50">•</span>
<span class="font-mono text-xs text-indigo-400" x-text="'#' + job.number"></span>
<span class="font-semibold text-xs" x-text="job.title"></span>
</div>
<button
@click="pinJob(job.id)"
class="px-2.5 py-1 rounded-lg bg-amber-500/20 hover:bg-amber-500/30 text-amber-300 border border-amber-500/40 text-[11px] font-semibold transition"
>
★ Kiinnitä koko työ
</button>
</div>
<div class="divide-y divide-zinc-700/40 pl-5">
<template x-for="task in getUnpinnedTasksForJob(job.id)" :key="'unp-t-' + task.id">
<div class="py-1.5 flex items-center justify-between gap-2 text-xs">
<div class="flex items-center gap-2">
<span
:class="getTaskBillingBadgeClass(task.billingModel)"
class="w-4 h-4 rounded-full border flex items-center justify-center text-[10px] font-bold shrink-0"
x-text="getTaskBillingSymbol(task.billingModel)"
></span>
<span x-text="task.title"></span>
</div>
<button
@click="pinTask(task.id)"
class="px-3 py-1 rounded-md bg-indigo-600 hover:bg-indigo-500 text-white font-semibold text-[11px] transition"
>
+ Lisää listalle
</button>
</div>
</template>
</div>
</div>
</template>
<div x-show="getUnpinnedJobsFiltered().length === 0" class="py-8 text-center text-xs opacity-65 italic">
Kaikki hakua vastaavat henkilön avoimet työt on jo kiinnitetty listalle.
</div>
</div>
<div class="px-5 py-3 border-t border-inherit flex justify-end">
<button @click="addUnpinnedModalOpen = false" class="px-4 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-semibold">Valmis</button>
</div>
</div>
</div>
<!-- ====================================================================== -->
<!-- MODAALI 5: POISTA KAIKKI KIINNITYKSET ("Oletko varma?" -varoitus) -->
<!-- ====================================================================== -->
<div
x-show="confirmClearLocksOpen"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-xs p-4"
>
<div
@click.outside="confirmClearLocksOpen = false"
:class="darkMode ? 'bg-[#1a1c20] border-[#3c4047] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="w-full max-w-md rounded-2xl border shadow-2xl overflow-hidden"
>
<div class="p-5 space-y-3">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-xl bg-rose-500/20 border border-rose-500/40 flex items-center justify-center text-rose-400 shrink-0">
<svg class="w-5 h-5" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/>
</svg>
</div>
<div>
<h3 class="text-base font-bold">Oletko varma?</h3>
<p class="text-xs opacity-75">Poistetaanko kaikki kiinnitykset Lukitut työt -osiosta?</p>
</div>
</div>
<p class="text-xs opacity-80 leading-relaxed">
Toiminto vapauttaa kaikki <strong x-text="countTasksInSection('locked')"></strong> kiinnitettyä tehtävää Lukitut työt -listalta. Jo kirjatut tunnit säilyvät tallessa, ja aikataulutetut työt palautuvat takaisin yläosan Aikataulutettu-osioon.
</p>
<div class="flex items-center justify-end gap-2 pt-3 border-t border-inherit">
<button
@click="confirmClearLocksOpen = false"
:class="darkMode ? 'bg-[#282a2e] hover:bg-[#32353b] border-[#3c4047]' : 'bg-slate-100 hover:bg-slate-200 border-slate-300'"
class="px-4 py-2 rounded-xl border text-xs font-semibold transition"
>
Peruuta
</button>
<button
@click="clearAllLocks()"
class="px-4 py-2 rounded-xl bg-rose-600 hover:bg-rose-500 text-white text-xs font-semibold shadow transition"
>
Kyllä, poista kaikki kiinnitykset
</button>
</div>
</div>
</div>
</div>
<!-- ====================================================================== -->
<!-- MODAALI 6: PUUTTUVAT LASKUTUSSELITTEET (Hyväksynnän tarkistus) -->
<!-- ====================================================================== -->
<div
x-show="missingNotesModalOpen"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-xs p-4"
>
<div
@click.outside="missingNotesModalOpen = false"
:class="darkMode ? 'bg-[#1a1c20] border-[#3c4047] text-zinc-100' : 'bg-white border-slate-300 text-slate-900'"
class="w-full max-w-2xl rounded-2xl border border-amber-500/60 shadow-2xl overflow-hidden"
>
<div class="px-5 py-3.5 border-b border-inherit bg-amber-950/30 flex items-center justify-between gap-3">
<div class="flex items-center gap-3">
<span class="w-9 h-9 rounded-xl bg-amber-500/20 border border-amber-400/40 flex items-center justify-center text-amber-300 shrink-0">
<svg class="w-5 h-5" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/>
</svg>
</span>
<div>
<h2 class="text-base font-bold text-amber-200">Viikkoa ei voi vielä hyväksyä – laskutusselite puuttuu</h2>
<p class="text-xs text-amber-100/80">
Jokaiselle kirjatulle tuntimerkinnälle tulee antaa laskutusselite ennen viikon hyväksyntää (<span x-text="missingNotesList.length"></span> puuttuvaa).
</p>
</div>
</div>
<button @click="missingNotesModalOpen = false" class="p-1.5 rounded-lg opacity-65 hover:opacity-100">✕</button>
</div>
<div class="p-5 max-h-[60vh] overflow-y-auto space-y-2">
<template x-for="item in missingNotesList" :key="'miss-' + item.taskId + '-' + item.dayIndex">
<div :class="darkMode ? 'bg-[#25272c] border-[#383c44]' : 'bg-slate-50 border-slate-200'" class="rounded-xl border p-3 flex items-center justify-between gap-3">
<div class="min-w-0">
<div class="flex items-center gap-2 text-xs">
<span class="font-bold" x-text="item.customerName"></span>
<span class="opacity-50">•</span>
<span class="font-mono text-indigo-400" x-text="item.jobNumber"></span>
<span class="truncate opacity-85" x-text="item.taskTitle"></span>
</div>
<div class="text-[11px] opacity-75 mt-0.5 flex items-center gap-2">
<span class="font-semibold text-amber-300" x-text="item.dayLabel"></span>
<span>•</span>
<span class="font-mono font-bold" x-text="formatMinutes(item.minutes)"></span>
</div>
</div>
<button
@click="editMissingNoteItem(item.taskId, item.dayIndex)"
class="px-3 py-1.5 rounded-lg bg-amber-500 hover:bg-amber-400 text-zinc-950 font-semibold text-xs shrink-0 transition"
>
Täytä selite →
</button>
</div>
</template>
</div>
<div class="px-5 py-3 border-t border-inherit flex items-center justify-between">
<span class="text-[11px] opacity-70">Puuttuvat kohdat on myös korostettu keltaisella merkinnällä ruudukossa.</span>
<button @click="missingNotesModalOpen = false" class="px-4 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-semibold">Sulje</button>
</div>
</div>
</div>
<!-- KEHYSILMOITUS (Toast) -->
<div
x-show="toastMessage"
x-cloak
x-transition
class="fixed bottom-4 right-4 z-50 px-4 py-2.5 rounded-xl bg-indigo-950 text-white border border-indigo-500/50 shadow-xl text-xs font-medium"
x-text="toastMessage"
></div>
<script>
function timesheetApp() {
return {
darkMode: true,
currentWeek: 48, // Kuluva viikko (su 29.11.2026)
selectedWeek: 48,
todayDayIndex: 6, // 0=ma .. 6=su (29.11.2026 on sunnuntai)
scheduledCollapsed: false,
monthViewNotice: false,
colorPickerCustomerId: null,
manageModalOpen: false,
addUnpinnedModalOpen: false,
unpinnedSearch: '',
confirmClearLocksOpen: false,
missingNotesModalOpen: false,
missingNotesList: [],
highlightMissingNotesWeek: null,
toastMessage: '',
presetColors: [
'#1d4ed8', '#0369a1', '#0f766e', '#15803d',
'#b45309', '#c2410c', '#b91c1c', '#7e22ce',
'#4338ca', '#374151'
],
weekMeta: {
47: {
title: 'Viikko 47: 16.11 - 22.11',
startDate: '16.11.2026',
days: [
{ label: 'ma 16.11' }, { label: 'ti 17.11' }, { label: 'ke 18.11' },
{ label: 'to 19.11' }, { label: 'pe 20.11' }, { label: 'la 21.11' }, { label: 'su 22.11' }
]
},
48: {
title: 'Viikko 48: 23.11 - 29.11',
startDate: '23.11.2026',
days: [
{ label: 'ma 23.11' }, { label: 'ti 24.11' }, { label: 'ke 25.11' },
{ label: 'to 26.11' }, { label: 'pe 27.11' }, { label: 'la 28.11' }, { label: 'su 29.11' }
]
},
49: {
title: 'Viikko 49: 30.11 - 6.12',
startDate: '30.11.2026',
days: [
{ label: 'ma 30.11' }, { label: 'ti 1.12' }, { label: 'ke 2.12' },
{ label: 'to 3.12' }, { label: 'pe 4.12' }, { label: 'la 5.12' }, { label: 'su 6.12' }
]
}
},
approvedWeeks: {
47: true,
48: false,
49: false
},
// Asiakkaat (värit suoraan Kanbanista)
customers: [
{ id: 'c-agri', name: 'Agrikumppanit Oy', color: '#15803d' },
{ id: 'c-au', name: 'Alastaron Urheilijat ry', color: '#b91c1c' },
{ id: 'c-loimaa', name: 'Loimaan kaupunki', color: '#0369a1' },
{ id: 'c-modify', name: 'Modify Media Oy', color: '#4338ca' },
{ id: 'c-poytya', name: 'Pöytyän Kunta', color: '#0f766e' },
{ id: 'c-ata', name: 'Ravintola ATA ky', color: '#b45309' },
{ id: 'c-assa', name: 'Ässä KP Oy', color: '#7e22ce' }
],
// Asiakastyöt (billingModel: 'kiintea' | 'tuntityo' | 'ei_laskutettava')
jobs: [
{ id: 'j-agri', customerId: 'c-agri', number: '5', title: 'Myyntityöt', kind: 'standard', billingModel: 'ei_laskutettava', accumulated: '12:00 h', completedWeek: null },
{ id: 'j-au', customerId: 'c-au', number: '773', title: '(Futsal miehet) - 2026 - 2027 Futsal striimaus', kind: 'live', billingModel: 'kiintea', accumulated: '24:30 h', completedWeek: null },
{ id: 'j-loimaa', customerId: 'c-loimaa', number: '778', title: 'Loimaa TV videosarja', kind: 'standard', billingModel: 'kiintea', accumulated: '48:15 h', completedWeek: null },
{ id: 'j-mod-digi', customerId: 'c-modify', number: '556', title: 'Digiapu', kind: 'standard', billingModel: 'tuntityo', accumulated: '16:30 h', completedWeek: null },
{ id: 'j-mod-int', customerId: 'c-modify', number: '2', title: 'Sisäiset työt', kind: 'standard', billingModel: 'ei_laskutettava', accumulated: '1149:45 h', completedWeek: null },
{ id: 'j-poytya', customerId: 'c-poytya', number: '797', title: '2026 04 Yritysvideoiden tuotanto 5kpl + 1kpl kooste', kind: 'standard', billingModel: 'kiintea', accumulated: '18:00 h', completedWeek: null },
{ id: 'j-ata', customerId: 'c-ata', number: '470', title: 'Markkinointipalvelut (jatkuva)', kind: 'live', billingModel: 'kiintea', accumulated: '64:00 h', completedWeek: null },
{ id: 'j-assa', customerId: 'c-assa', number: '798', title: 'Markkinointipalvelut jatkuva', kind: 'live', billingModel: 'tuntityo', accumulated: '39:15 h', completedWeek: null }
],
// Tehtävät
tasks: [
// Aikataulutettuja tehtäviä
{ id: 't-au-1', jobId: 'j-au', title: 'SU 29.11. Futsal LIVE-lähetys & tuotanto', billingModel: 'kiintea', scheduledWeeks: [48, 49], locked: false },
{ id: 't-loimaa-1', jobId: 'j-loimaa', title: 'Käsikirjoitus ja suunnittelu (L)', billingModel: 'kiintea', scheduledWeeks: [47, 48], locked: false },
{ id: 't-loimaa-2', jobId: 'j-loimaa', title: 'Videokuvaus (L)', billingModel: 'kiintea', scheduledWeeks: [48, 49], locked: false },
{ id: 't-poytya-1', jobId: 'j-poytya', title: 'Videotuotanto (L)', billingModel: 'kiintea', scheduledWeeks: [47, 48], locked: false },
{ id: 't-agri-1', jobId: 'j-agri', title: 'Myyntityö & tarjouslaskenta', billingModel: 'ei_laskutettava', scheduledWeeks: [48], locked: false },
// Lukittuja tehtäviä
{ id: 't-loimaa-3', jobId: 'j-loimaa', title: 'Videotuotanto (L)', billingModel: 'kiintea', scheduledWeeks: [48], locked: true },
{ id: 't-mod-digi-1', jobId: 'j-mod-digi', title: 'Zettle maksettujen tuntikirjaukset', billingModel: 'tuntityo', scheduledWeeks: [], locked: true },
{ id: 't-mod-1', jobId: 'j-mod-int', title: 'Kalustohuoltotyöt', billingModel: 'ei_laskutettava', scheduledWeeks: [], locked: true },
{ id: 't-mod-2', jobId: 'j-mod-int', title: 'Kehitystyöt', billingModel: 'ei_laskutettava', scheduledWeeks: [], locked: true },
{ id: 't-mod-3', jobId: 'j-mod-int', title: 'Markkinointi', billingModel: 'ei_laskutettava', scheduledWeeks: [], locked: true },
{ id: 't-mod-4', jobId: 'j-mod-int', title: 'Palaverit, sisäinen', billingModel: 'ei_laskutettava', scheduledWeeks: [], locked: true },
{ id: 't-ata-1', jobId: 'j-ata', title: 'Markkinointipalvelut', billingModel: 'kiintea', scheduledWeeks: [48, 49], locked: true },
{ id: 't-assa-1', jobId: 'j-assa', title: 'Markkinointipalvelut', billingModel: 'tuntityo', scheduledWeeks: [48, 49], locked: true }
],
// Tuntikirjaukset (osaan jätetty tarkoituksella selite vielä tyhjäksi testattavaksi Hyväksy-napilla!)
entries: {
47: {
't-loimaa-1': { 2: { minutes: 30, billingNote: 'Jakson 3 käsikirjoitusluonnos', internalComment: '', billingModel: 'kiintea' }, 4: { minutes: 30, billingNote: 'Haastattelukysymykset', internalComment: '', billingModel: 'kiintea' } },
't-loimaa-3': { 2: { minutes: 90, billingNote: 'Leikkaus ja värimäärittely', internalComment: '', billingModel: 'kiintea' } },
't-mod-1': { 0: { minutes: 30, billingNote: 'Kamerakaluston huolto', internalComment: 'Kamerakaluston päivitys', billingModel: 'ei_laskutettava' }, 2: { minutes: 60, billingNote: 'Studiokaluston tarkastus', internalComment: '', billingModel: 'ei_laskutettava' } },
't-mod-2': { 0: { minutes: 120, billingNote: 'ERP-määrittely', internalComment: '', billingModel: 'ei_laskutettava' }, 1: { minutes: 120, billingNote: 'UI-prototyyppi', internalComment: '', billingModel: 'ei_laskutettava' } },
't-assa-1': { 0: { minutes: 60, billingNote: 'Kuukausikampanjan suunnittelu', internalComment: '', billingModel: 'tuntityo' } }
},
48: {
't-au-1': { 6: { minutes: 180, billingNote: 'Ottelulähetys ja monikameraohjaus', internalComment: 'Kaikki meni sujuvasti', billingModel: 'kiintea' } },
't-loimaa-1': { 1: { minutes: 45, billingNote: 'Kuvauspaikkojen varmistus', internalComment: '', billingModel: 'kiintea' } },
't-loimaa-3': { 2: { minutes: 120, billingNote: 'Jakson 4 editointi', internalComment: 'Asiakkaan kommentit huomioitu', billingModel: 'kiintea' }, 3: { minutes: 90, billingNote: '', internalComment: '', billingModel: 'kiintea' } },
't-mod-digi-1': { 1: { minutes: 60, billingNote: 'Maksupäätteiden tilitysajo', internalComment: '', billingModel: 'tuntityo' } },
't-mod-1': { 0: { minutes: 30, billingNote: 'Akkujen huoltolataus', internalComment: '', billingModel: 'ei_laskutettava' }, 3: { minutes: 45, billingNote: '', internalComment: '', billingModel: 'ei_laskutettava' } },
't-mod-2': { 0: { minutes: 90, billingNote: 'Uuden toiminnanohjauksen UI', internalComment: '', billingModel: 'ei_laskutettava' }, 4: { minutes: 120, billingNote: 'Timesheet-prototyyppi', internalComment: '', billingModel: 'ei_laskutettava' } },
't-mod-3': { 2: { minutes: 45, billingNote: 'Somejulkaisut', internalComment: '', billingModel: 'ei_laskutettava' } },
't-mod-4': { 0: { minutes: 60, billingNote: 'Viikkopalaveri', internalComment: '', billingModel: 'ei_laskutettava' } },
't-ata-1': { 1: { minutes: 30, billingNote: 'Lounaslistan päivitys ja mainos', internalComment: '', billingModel: 'kiintea' } },
't-assa-1': { 0: { minutes: 60, billingNote: 'Talvikampanjan aineistot', internalComment: '', billingModel: 'tuntityo' } }
},
49: {}
},
// Ajastimen tila
timerModalOpen: false,
timerModalTaskId: null,
timer: {
taskId: null,
running: false,
elapsedSeconds: 0,
note: '',
intervalId: null,
editing: false,
editHours: 0,
editMinutes: 0,
editSeconds: 0
},
// Kirjauksen muokkausmodaalin tila
entryModal: {
open: false,
taskId: null,
dayIndex: 0,
billingNote: '',
internalComment: '',
billingModel: 'kiintea'
},
init() {
// Alustus
},
handleEscape() {
if (this.entryModal.open) {
this.saveAndCloseEntryModal();
} else if (this.missingNotesModalOpen) {
this.missingNotesModalOpen = false;
} else if (this.timerModalOpen) {
this.closeTimerModal();
} else if (this.addUnpinnedModalOpen) {
this.addUnpinnedModalOpen = false;
} else if (this.confirmClearLocksOpen) {
this.confirmClearLocksOpen = false;
} else if (this.manageModalOpen) {
this.manageModalOpen = false;
} else if (this.colorPickerCustomerId) {
this.colorPickerCustomerId = null;
}
},
showToast(msg) {
this.toastMessage = msg;
clearTimeout(this._toastTimer);
this._toastTimer = setTimeout(() => { this.toastMessage = ''; }, 3400);
},
changeWeek(delta) {
const target = this.selectedWeek + delta;
if (this.weekMeta[target]) {
this.selectedWeek = target;
this.colorPickerCustomerId = null;
}
},
isTodayColumn(dayIndex) {
return this.selectedWeek === this.currentWeek && dayIndex === this.todayDayIndex;
},
getTableColspan() {
return this.selectedWeek === this.currentWeek ? 11 : 10;
},
isWeekApproved(week) {
return !!this.approvedWeeks[week];
},
// Tarkistaa, onko viikon jokaiselle kirjatulle tuntimerkinnälle annettu laskutusselite
getMissingBillingNotesForWeek(week) {
const missing = [];
const weekData = this.entries[week] || {};
const daysMeta = this.weekMeta[week]?.days || [];
Object.entries(weekData).forEach(([taskId, taskDays]) => {
const task = this.getTaskById(taskId);
if (!task) return;
const job = this.getJobById(task.jobId);
const customer = job ? this.getCustomerById(job.customerId) : null;
Object.entries(taskDays).forEach(([dIdxStr, entry]) => {
const dIdx = parseInt(dIdxStr, 10);
if ((entry?.minutes || 0) > 0 && !(entry?.billingNote && entry.billingNote.trim().length > 0)) {
missing.push({
taskId,
dayIndex: dIdx,
dayLabel: daysMeta[dIdx]?.label || '',
minutes: entry.minutes,
customerName: customer ? customer.name : '',
jobNumber: job ? `#${job.number}` : '',
taskTitle: task.title
});
}
});
});
return missing;
},
openMissingNotesModal() {
this.missingNotesList = this.getMissingBillingNotesForWeek(this.selectedWeek);
this.highlightMissingNotesWeek = this.selectedWeek;
this.missingNotesModalOpen = true;
},
editMissingNoteItem(taskId, dayIndex) {
this.missingNotesModalOpen = false;
this.openEntryModal(taskId, dayIndex);
},
toggleWeekApproval() {
const currentlyApproved = this.isWeekApproved(this.selectedWeek);
if (!currentlyApproved) {
const missing = this.getMissingBillingNotesForWeek(this.selectedWeek);
if (missing.length > 0) {
this.missingNotesList = missing;
this.highlightMissingNotesWeek = this.selectedWeek;
this.missingNotesModalOpen = true;
return;
}
this.approvedWeeks[this.selectedWeek] = true;
this.highlightMissingNotesWeek = null;
this.showToast(`Viikko ${this.selectedWeek} hyväksytty kokonaisuudessaan!`);
} else {
this.approvedWeeks[this.selectedWeek] = false;
this.showToast(`Viikon ${this.selectedWeek} hyväksyntä peruttu muokkausta varten.`);
}
},
clearAllLocks() {
let count = 0;
this.tasks.forEach(t => {
if (t.locked) {
t.locked = false;
count++;
}
});
this.confirmClearLocksOpen = false;
this.showToast(`Kaikki kiinnitykset (${count} kpl) poistettu Lukitut työt -osiosta.`);
},
getUnpinnedTasksForJob(jobId) {
const q = this.unpinnedSearch.trim().toLowerCase();
return this.tasks.filter(t => {
if (t.jobId !== jobId || t.locked) return false;
if (!q) return true;
const job = this.getJobById(jobId);
const cust = job ? this.getCustomerById(job.customerId) : null;
return t.title.toLowerCase().includes(q) ||
(job && (job.title.toLowerCase().includes(q) || String(job.number).includes(q))) ||
(cust && cust.name.toLowerCase().includes(q));
});
},
getUnpinnedJobsFiltered() {
return this.getSortedJobs().filter(job => {
if (job.completedWeek !== null) return false;
return this.getUnpinnedTasksForJob(job.id).length > 0;
});
},
// Apufunktiot tietomallille
getCustomerById(id) {
return this.customers.find(c => c.id === id) || { id, name: 'Tuntematon asiakas', color: '#374151' };
},
getJobById(id) {
return this.jobs.find(j => j.id === id);
},
getTaskById(id) {
return this.tasks.find(t => t.id === id);
},
getTasksForJob(jobId) {
return this.tasks.filter(t => t.jobId === jobId);
},
getSortedJobs() {
return [...this.jobs].sort((a, b) => {
const cA = this.getCustomerById(a.customerId).name;
const cB = this.getCustomerById(b.customerId).name;
return cA.localeCompare(cB, 'fi') || a.title.localeCompare(b.title, 'fi');
});
},
getCustomerNameByTaskId(taskId) {
const t = this.getTaskById(taskId);
if (!t) return '';
const j = this.getJobById(t.jobId);
return j ? this.getCustomerById(j.customerId).name : '';
},
getJobTitleByTaskId(taskId) {
const t = this.getTaskById(taskId);
if (!t) return '';
const j = this.getJobById(t.jobId);
return j ? `#${j.number} ${j.title}` : '';
},
getTaskTitleById(taskId) {
const t = this.getTaskById(taskId);
return t ? t.title : '';
},
getJobBillingModelByTaskId(taskId) {
const t = this.getTaskById(taskId);
if (!t) return 'tuntityo';
const j = this.getJobById(t.jobId);
return j ? j.billingModel : t.billingModel;
},
// Laskutusperusteiden visuaaliset apufunktiot
getBillingModelLabel(model) {
if (model === 'kiintea') return 'Kiinteä hinta';
if (model === 'tuntityo') return 'Tuntityö';
return 'Ei laskutettava';
},
getBillingModelBadgeClass(model) {
if (model === 'kiintea') return 'bg-amber-500/15 text-amber-300 border-amber-500/35';
if (model === 'tuntityo') return 'bg-emerald-500/15 text-emerald-300 border-emerald-500/35';
return 'bg-zinc-600/25 text-zinc-400 border-zinc-600/40';
},
getTaskBillingBadgeClass(model) {
if (model === 'kiintea') return 'bg-amber-500/20 text-amber-300 border-amber-500/40';
if (model === 'tuntityo') return 'bg-emerald-500/20 text-emerald-300 border-emerald-500/40';
return 'bg-zinc-600/30 text-zinc-400 border-zinc-600/40';
},
getTaskBillingSymbol(model) {
if (model === 'kiintea') return 'K';
if (model === 'tuntityo') return '€';
return '•';
},
getTaskBillingTooltip(model) {
if (model === 'kiintea') return 'Kiinteä hinta / sopimus (tunnit kirjataan seurantaan)';
if (model === 'tuntityo') return 'Laskutettava tuntityö';
return 'Sisäinen / ei laskutettava';
},
// Näkyvyyslogiikka osioittain
isTaskVisibleInSection(task, section) {
const job = this.getJobById(task.jobId);
if (!job) return false;
if (section === 'scheduled') {
if (task.locked) return false;
if (job.completedWeek !== null && this.selectedWeek > job.completedWeek) return false;
return task.scheduledWeeks.includes(this.selectedWeek);
}
if (section === 'locked') {
if (!task.locked) return false;
if (job.completedWeek !== null && this.selectedWeek > job.completedWeek) {
return this.getTaskWeekMinutes(this.selectedWeek, task.id) > 0;
}
return true;
}
return false;
},
countTasksInSection(section) {
return this.tasks.filter(t => this.isTaskVisibleInSection(t, section)).length;
},
// Ryhmittely: Asiakkaat A -> Ö, saman asiakkaan työt päällekkäin, selkeä 3-portainen sisennys
getGroupedSection(section) {
const visibleTasks = this.tasks.filter(t => this.isTaskVisibleInSection(t, section));
const sortedCustomers = [...this.customers].sort((a, b) => a.name.localeCompare(b.name, 'fi'));
const groups = [];
sortedCustomers.forEach(customer => {
const customerJobs = this.jobs
.filter(j => j.customerId === customer.id)
.sort((a, b) => a.title.localeCompare(b.title, 'fi'));
const rows = [];
let hasAnyTask = false;
customerJobs.forEach(job => {
const jobTasks = visibleTasks.filter(t => t.jobId === job.id);
if (jobTasks.length > 0) {
hasAnyTask = true;
rows.push({ key: `${section}-job-${job.id}`, type: 'job', job });
jobTasks.forEach(task => {
rows.push({ key: `${section}-task-${task.id}`, type: 'task', task, job });
});
}
});
if (hasAnyTask) {
rows.unshift({ key: `${section}-cust-${customer.id}`, type: 'customer', customer });
groups.push({ customer, rows });
}
});
return groups;
},
getRowClasses(row) {
return '';
},
// Kiinnitys & lukituksen poisto
pinTask(taskId) {
const task = this.getTaskById(taskId);
if (task) {
task.locked = true;
this.showToast(`"${task.title}" kiinnitetty Lukitut työt -osioon.`);
}
},
pinJob(jobId) {
const jobTasks = this.getTasksForJob(jobId);
jobTasks.forEach(t => { t.locked = true; });
const job = this.getJobById(jobId);
this.showToast(`Asiakastyö #${job.number} ${job.title} kiinnitetty Lukitut työt -osioon.`);
},
unpinTask(taskId) {
const task = this.getTaskById(taskId);
if (task) {
task.locked = false;
this.showToast(`Lukitus poistettu: "${task.title}".`);
}
},
toggleJobCompleted(jobId) {
const job = this.getJobById(jobId);
if (!job) return;
if (job.completedWeek === null) {
job.completedWeek = this.selectedWeek;
this.showToast(`#${job.number} merkitty Valmiiksi (Vko ${this.selectedWeek}). Poistuu seuraavilta viikoilta.`);
} else {
job.completedWeek = null;
this.showToast(`#${job.number} palautettu aktiiviseksi.`);
}
},
// Tuntikirjausten käsittely
ensureEntry(week, taskId, dayIndex) {
if (!this.entries[week]) this.entries[week] = {};
if (!this.entries[week][taskId]) this.entries[week][taskId] = {};
if (!this.entries[week][taskId][dayIndex]) {
const task = this.getTaskById(taskId);
this.entries[week][taskId][dayIndex] = {
minutes: 0,
billingNote: '',
internalComment: '',
billingModel: task ? task.billingModel : 'tuntityo'
};
}
},
getCellMinutes(week, taskId, dayIndex) {
return this.entries[week]?.[taskId]?.[dayIndex]?.minutes || 0;
},
adjustMinutes(week, taskId, dayIndex, delta) {
if (this.isWeekApproved(week)) return;
this.ensureEntry(week, taskId, dayIndex);
const current = this.entries[week][taskId][dayIndex].minutes;
this.entries[week][taskId][dayIndex].minutes = Math.max(0, current + delta);
},
setCellTimeFromInput(week, taskId, dayIndex, rawVal) {
if (this.isWeekApproved(week)) return;
const minutes = this.parseTimeInput(rawVal);
this.ensureEntry(week, taskId, dayIndex);
this.entries[week][taskId][dayIndex].minutes = minutes;
},
parseTimeInput(str) {
const clean = String(str || '').trim().replace(',', '.');
if (!clean) return 0;
if (clean.includes(':')) {
const [hStr, mStr] = clean.split(':');
const h = parseInt(hStr, 10) || 0;
const m = parseInt(mStr, 10) || 0;
return Math.max(0, h * 60 + m);
}
const num = parseFloat(clean);
if (isNaN(num)) return 0;
if (num <= 24) return Math.round(num * 60);
return Math.round(num);
},
hasBillingNote(week, taskId, dayIndex) {
const entry = this.entries[week]?.[taskId]?.[dayIndex];
return !!(entry && entry.billingNote && entry.billingNote.trim().length > 0);
},
isMissingBillingNoteHighlighted(week, taskId, dayIndex) {
if (this.highlightMissingNotesWeek !== week) return false;
const entry = this.entries[week]?.[taskId]?.[dayIndex];
return (entry?.minutes || 0) > 0 && !this.hasBillingNote(week, taskId, dayIndex);
},
getNoteButtonClasses(week, taskId, dayIndex) {
if (this.isMissingBillingNoteHighlighted(week, taskId, dayIndex)) {
return 'bg-amber-500/25 text-amber-300 border-amber-400';
}
if (this.hasBillingNote(week, taskId, dayIndex)) {
return 'bg-sky-500/25 text-sky-300 border-sky-400/60';
}
return this.darkMode
? 'text-zinc-500 hover:text-zinc-200 hover:bg-white/5 border-transparent'
: 'text-slate-400 hover:text-slate-700 hover:bg-slate-100 border-transparent';
},
getNoteButtonTooltip(week, taskId, dayIndex) {
if (this.isMissingBillingNoteHighlighted(week, taskId, dayIndex)) {
return 'HUOM: Laskutusselite puuttuu – klikkaa täyttääksesi';
}
if (this.hasBillingNote(week, taskId, dayIndex)) {
return 'Muokkaa laskuselitettä ja sisäistä kommenttia (täytetty)';
}
return 'Lisää laskutusselite tai sisäinen kommentti';
},
getTaskWeekMinutes(week, taskId) {
const days = this.entries[week]?.[taskId] || {};
return Object.values(days).reduce((sum, item) => sum + (item.minutes || 0), 0);
},
getDayTotalMinutes(week, dayIndex) {
const weekData = this.entries[week] || {};
return Object.values(weekData).reduce((sum, taskDays) => {
return sum + (taskDays[dayIndex]?.minutes || 0);
}, 0);
},
getWeekTotalMinutes(week) {
let total = 0;
for (let d = 0; d < 7; d++) {
total += this.getDayTotalMinutes(week, d);
}
return total;
},
formatMinutes(totalMins) {
const mins = Math.max(0, Math.round(totalMins || 0));
const h = Math.floor(mins / 60);
const m = mins % 60;
return `${h}:${String(m).padStart(2, '0')}`;
},
formatBalance(diffMins) {
const sign = diffMins >= 0 ? '+' : '-';
const abs = Math.abs(diffMins);
const h = Math.floor(abs / 60);
const m = abs % 60;
return `${sign}${h}:${String(m).padStart(2, '0')}`;
},
// Kirjauksen selite- ja kommenttimodaali
openEntryModal(taskId, dayIndex) {
this.ensureEntry(this.selectedWeek, taskId, dayIndex);
const entry = this.entries[this.selectedWeek][taskId][dayIndex];
const task = this.getTaskById(taskId);
this.entryModal = {
open: true,
taskId,
dayIndex,
billingNote: entry.billingNote || '',
internalComment: entry.internalComment || '',
billingModel: entry.billingModel || (task ? task.billingModel : 'tuntityo')
};
},
saveAndCloseEntryModal() {
if (!this.entryModal.open) return;
const { taskId, dayIndex, billingNote, internalComment, billingModel } = this.entryModal;
this.ensureEntry(this.selectedWeek, taskId, dayIndex);
const entry = this.entries[this.selectedWeek][taskId][dayIndex];
entry.billingNote = billingNote;
entry.internalComment = internalComment;
entry.billingModel = billingModel;
this.entryModal.open = false;
this.showToast('Kirjauksen selite ja tiedot tallennettu.');
},
// Ajastin pop-up
openTimerModal(taskId) {
this.timerModalTaskId = taskId;
this.timer.editing = false;
this.timerModalOpen = true;
},
closeTimerModal() {
if (this.timer.running) {
this.showToast('Pysäytä ajastin (Tauko, Nollaa tai Pysäytä & tallenna) ennen ikkunan sulkemista.');
return;
}
this.timerModalOpen = false;
},
enableTimerManualEdit(taskId) {
this.pauseTimer();
if (this.timer.taskId !== taskId) {
this.timer.taskId = taskId;
this.timer.elapsedSeconds = 0;
}
const sec = this.timer.elapsedSeconds;
this.timer.editHours = Math.floor(sec / 3600);
this.timer.editMinutes = Math.floor((sec % 3600) / 60);
this.timer.editSeconds = sec % 60;
this.timer.editing = true;
},
applyTimerManualEdit(taskId) {
const h = Math.max(0, Math.min(99, parseInt(this.timer.editHours, 10) || 0));
const m = Math.max(0, Math.min(59, parseInt(this.timer.editMinutes, 10) || 0));
const s = Math.max(0, Math.min(59, parseInt(this.timer.editSeconds, 10) || 0));
this.timer.taskId = taskId;
this.timer.elapsedSeconds = h * 3600 + m * 60 + s;
this.timer.editing = false;
},
startOrResumeTimer(taskId) {
if (this.timer.editing) {
this.applyTimerManualEdit(taskId);
}
if (this.timer.taskId !== taskId) {
clearInterval(this.timer.intervalId);
this.timer.taskId = taskId;
this.timer.elapsedSeconds = 0;
}
if (!this.timer.running) {
this.timer.running = true;
this.timer.intervalId = setInterval(() => {
this.timer.elapsedSeconds++;
}, 1000);
}
},
pauseTimer() {
this.timer.running = false;
clearInterval(this.timer.intervalId);
},
stopAndResetTimer(taskId) {
this.pauseTimer();
if (this.timer.taskId === taskId) {
this.timer.elapsedSeconds = 0;
this.timer.taskId = null;
}
this.timer.editing = false;
this.showToast('Ajastin pysäytetty ja nollattu.');
},
getTimerCommitMinutes(taskId) {
let sec = this.timer.taskId === taskId ? this.timer.elapsedSeconds : 0;
if (this.timer.editing) {
const h = Math.max(0, parseInt(this.timer.editHours, 10) || 0);
const m = Math.max(0, parseInt(this.timer.editMinutes, 10) || 0);
const s = Math.max(0, parseInt(this.timer.editSeconds, 10) || 0);
sec = h * 3600 + m * 60 + s;
}
return Math.max(15, Math.ceil((sec / 60) / 15) * 15);
},
getTimerCommitLabel(taskId) {
return '+' + this.formatMinutes(this.getTimerCommitMinutes(taskId));
},
commitTimerToToday(taskId) {
if (this.timer.editing) {
this.applyTimerManualEdit(taskId);
}
this.pauseTimer();
const minsToAdd = this.getTimerCommitMinutes(taskId);
this.selectedWeek = this.currentWeek;
this.adjustMinutes(this.currentWeek, taskId, this.todayDayIndex, minsToAdd);
if (this.timer.note.trim()) {
this.ensureEntry(this.currentWeek, taskId, this.todayDayIndex);
const existing = this.entries[this.currentWeek][taskId][this.todayDayIndex].billingNote;
this.entries[this.currentWeek][taskId][this.todayDayIndex].billingNote = existing
? `${existing}; ${this.timer.note.trim()}`
: this.timer.note.trim();
}
this.timer.elapsedSeconds = 0;
this.timer.taskId = null;
this.timer.note = '';
this.timer.editing = false;
this.timerModalOpen = false;
this.showToast(`Ajastimesta kirjattiin ${this.formatMinutes(minsToAdd)} tälle päivälle (su 29.11).`);
},
formatStopwatch(sec) {
const h = Math.floor(sec / 3600);
const m = Math.floor((sec % 3600) / 60);
const s = sec % 60;
return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;
},
// Asiakasvärit & WCAG-kontrasti
toggleColorPicker(key) {
this.colorPickerCustomerId = this.colorPickerCustomerId === key ? null : key;
},
setCustomerColor(customerId, hex) {
const c = this.customers.find(item => item.id === customerId);
if (c) c.color = hex;
},
hexToRgb(hex) {
const clean = (hex || '#374151').replace('#', '');
const num = parseInt(clean.length === 3 ? clean.split('').map(x => x + x).join('') : clean, 16);
return { r: (num >> 16) & 255, g: (num >> 8) & 255, b: num & 255 };
},
updateCustomerRgb(customerId, channel, val) {
const c = this.customers.find(item => item.id === customerId);
if (!c) return;
const rgb = this.hexToRgb(c.color);
rgb[channel] = Math.min(255, Math.max(0, parseInt(val, 10) || 0));
const toHex = n => n.toString(16).padStart(2, '0');
c.color = `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`;
},
getContrastColor(hex) {
const { r, g, b } = this.hexToRgb(hex);
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return luminance > 0.58 ? '#0f172a' : '#ffffff';
}
};
}
</script>
</body>
</html>