diff --git a/index.html b/index.html
index 324885d..0a98f1f 100644
--- a/index.html
+++ b/index.html
@@ -105,7 +105,7 @@
Osoite ↕ |
Kaupunki ↕ |
Nopeus ↕ |
- Hinta/kk ↕ |
+ Hinta/kk ↕ |
Sopimus ↕ |
Toiminnot |
diff --git a/script.js b/script.js
index cd29256..feab1dc 100644
--- a/script.js
+++ b/script.js
@@ -347,15 +347,14 @@ function renderTable() {
const c = r.customer, l = r.liittyma;
const isFirst = c.id !== prevId;
prevId = c.id;
- const sopimus = l.sopimuskausi ? l.sopimuskausi + ' kk' : '';
- const alkupvm = l.alkupvm ? ' (' + esc(l.alkupvm) + ')' : '';
+ const sopimusStr = contractRemaining(l.sopimuskausi, l.alkupvm);
return `
| ${isFirst ? '' + esc(c.yritys) + '' : '↳'} |
${esc(l.asennusosoite)}${l.postinumero ? ', ' + esc(l.postinumero) : ''} |
${esc(l.kaupunki)} |
${esc(l.liittymanopeus)} |
${formatPrice(l.hinta)} |
- ${sopimus}${alkupvm} |
+ ${sopimusStr} |
${isFirst ? `` : ''} |
`;
}).join('');
@@ -426,6 +425,36 @@ function setTrivia(id, value, sub) {
}
function setText(id, value) { const el = document.getElementById(id); if (el) el.textContent = value; }
function formatPrice(val) { return parseFloat(val || 0).toFixed(2).replace('.', ',') + ' €'; }
+
+function contractRemaining(sopimuskausi, alkupvm) {
+ if (!sopimuskausi) return '';
+ const months = parseInt(sopimuskausi);
+ if (!months || !alkupvm) return months + ' kk';
+ const start = new Date(alkupvm);
+ if (isNaN(start.getTime())) return months + ' kk';
+ const end = new Date(start);
+ end.setMonth(end.getMonth() + months);
+ const now = new Date();
+ const diffMs = end - now;
+ if (diffMs <= 0) return `${months} kk (päättynyt)`;
+ const remainMonths = Math.ceil(diffMs / (1000 * 60 * 60 * 24 * 30.44));
+ return `${months} kk (${remainMonths} kk jäljellä)`;
+}
+
+// Hintojen näyttö/piilotus
+(function() {
+ const toggle = document.getElementById('toggle-prices');
+ if (!toggle) return;
+ // Oletuksena piilossa
+ document.getElementById('customer-table')?.classList.add('prices-hidden');
+ toggle.addEventListener('change', () => {
+ document.getElementById('customer-table')?.classList.toggle('prices-hidden', !toggle.checked);
+ // Blurraa myös asiakaskortin hinnat
+ document.querySelectorAll('.customer-detail-card').forEach(el => {
+ el.classList.toggle('prices-hidden', !toggle.checked);
+ });
+ });
+})();
function esc(str) { if (!str) return ''; const d = document.createElement('div'); d.textContent = str; return d.innerHTML; }
function timeAgo(dateStr) {
@@ -486,7 +515,7 @@ function showDetail(id) {
Nopeus
${detailVal(l.liittymanopeus)}
Hinta / kk
${formatPrice(l.hinta)}
- Sopimuskausi
${l.sopimuskausi ? l.sopimuskausi + ' kk' : '-'}
+ Sopimuskausi
${contractRemaining(l.sopimuskausi, l.alkupvm) || '-'}
Alkaen
${detailVal(l.alkupvm)}
Laite
${detailVal(l.laite)}
@@ -504,7 +533,7 @@ function showDetail(id) {
Y-tunnus
${detailVal(c.ytunnus)}
Liittymät (${liittymat.length})
${liittymatHtml}
- ${liittymat.length > 1 ? `
Yhteensä: ${formatPrice(totalH)}/kk
` : ''}
+ ${liittymat.length > 1 ? `
${formatPrice(totalH)}/kk
` : ''}
Yhteystiedot
Yhteyshenkilö
${detailVal(c.yhteyshenkilö)}
@@ -528,6 +557,9 @@ function showDetail(id) {
`;
+ // Synkronoi prices-hidden tila detail-modaliin
+ const pricesHidden = document.getElementById('customer-table')?.classList.contains('prices-hidden');
+ detailModal.querySelector('.modal-content')?.classList.toggle('prices-hidden', !!pricesHidden);
detailModal.style.display = 'flex';
loadFiles(id);
document.getElementById('file-upload-input').addEventListener('change', async function () {
diff --git a/style.css b/style.css
index 896e93c..e5b8abd 100644
--- a/style.css
+++ b/style.css
@@ -420,6 +420,11 @@ tbody td {
font-weight: 700;
color: var(--primary-color);
}
+.prices-hidden .price-cell {
+ filter: blur(6px);
+ user-select: none;
+ transition: filter 0.2s;
+}
.actions-cell {
white-space: nowrap;