|
|
|
@@ -0,0 +1,927 @@
|
|
|
|
|
/* Sygna DEMO mock — makes the static console fully clickable with NO backend.
|
|
|
|
|
*
|
|
|
|
|
* Loaded ONLY on the demo deployment: the Netlify build injects it before app.js when no
|
|
|
|
|
* SYGNA_BACKEND_URL is configured (see netlify/prepare.sh). It patches window.fetch, answers every
|
|
|
|
|
* /api/v1/* call from a seeded dataset kept in localStorage, and never ships in a real deployment
|
|
|
|
|
* — the Docker/Caddy build serves index.html without this <script>, so it cannot weaken a real
|
|
|
|
|
* backend.
|
|
|
|
|
*
|
|
|
|
|
* It is a SIMULATION of a small Polish firm, not a sandbox of the real thing. Reads are complete
|
|
|
|
|
* enough that every screen renders; a few writes (recording time, confirming a deadline, assigning
|
|
|
|
|
* post, marking notifications read) genuinely mutate the data, because a demo where nothing
|
|
|
|
|
* responds to a click teaches the wrong thing. Everything else answers with a plain "this is a
|
|
|
|
|
* demo" problem detail rather than pretending to have saved.
|
|
|
|
|
*
|
|
|
|
|
* The response SHAPES were captured from the running API rather than read off the schemas, so the
|
|
|
|
|
* console meets the same field names here that it meets in production.
|
|
|
|
|
*/
|
|
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
if (window.__sygnaDemo) return;
|
|
|
|
|
window.__sygnaDemo = true;
|
|
|
|
|
|
|
|
|
|
var API = '/api/v1';
|
|
|
|
|
var LS = 'sygna_demo_db_v1';
|
|
|
|
|
var SESS = 'sygna_demo_session';
|
|
|
|
|
var CURRENCY = 'PLN';
|
|
|
|
|
|
|
|
|
|
/* ── dates ──────────────────────────────────────────────────────────────────
|
|
|
|
|
* Everything is seeded relative to today, so the demo never looks abandoned: a deadline that was
|
|
|
|
|
* "in 3 days" in March must not still say so in September. The store is re-seeded once it drifts
|
|
|
|
|
* more than a fortnight from the day it was written — short-lived edits survive, a stale dataset
|
|
|
|
|
* does not. */
|
|
|
|
|
function day(offset) {
|
|
|
|
|
var d = new Date();
|
|
|
|
|
d.setHours(12, 0, 0, 0);
|
|
|
|
|
d.setDate(d.getDate() + (offset || 0));
|
|
|
|
|
return d.toISOString().slice(0, 10);
|
|
|
|
|
}
|
|
|
|
|
function stamp(offsetDays, hour) {
|
|
|
|
|
var d = new Date();
|
|
|
|
|
d.setDate(d.getDate() + (offsetDays || 0));
|
|
|
|
|
d.setHours(hour == null ? 9 : hour, 15, 0, 0);
|
|
|
|
|
return d.toISOString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var USERS = [
|
|
|
|
|
{ id: 'u-admin', email: 'demo@sygna.example', full_name: 'Maria Wiśniewska', is_admin: true, is_active: true },
|
|
|
|
|
{ id: 'u-piotr', email: 'p.zielinski@sygna.example', full_name: 'Piotr Zieliński', is_admin: false, is_active: true },
|
|
|
|
|
{ id: 'u-ola', email: 'a.dabrowska@sygna.example', full_name: 'Aleksandra Dąbrowska', is_admin: false, is_active: true }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/* ── the firm ───────────────────────────────────────────────────────────── */
|
|
|
|
|
function seed() {
|
|
|
|
|
var parties = [
|
|
|
|
|
{ id: 'p-kowalski', kind: 'person', name: 'Jan Kowalski', nip: null, pesel: '78050612345', krs: null,
|
|
|
|
|
regon: null, email: 'j.kowalski@example.com', phone: '+48 601 234 567',
|
|
|
|
|
address: 'ul. Piękna 14/3, 00-549 Warszawa', edoreczenia_address: null, is_pep: false,
|
|
|
|
|
risk_rating: 'low', notes: null },
|
|
|
|
|
{ id: 'p-wodociagi', kind: 'organisation', name: 'Wodociągi Miejskie sp. z o.o.', nip: '5252445566',
|
|
|
|
|
pesel: null, krs: '0000123456', regon: '146112233', email: 'sekretariat@wodociagi.example',
|
|
|
|
|
phone: '+48 22 555 10 10', address: 'ul. Kanałowa 2, 00-001 Warszawa',
|
|
|
|
|
edoreczenia_address: null, is_pep: false, risk_rating: 'low', notes: null },
|
|
|
|
|
{ id: 'p-acme', kind: 'organisation', name: 'ACME Polska S.A.', nip: '7010101010', pesel: null,
|
|
|
|
|
krs: '0000998877', regon: '380011223', email: 'legal@acme.example', phone: '+48 22 100 20 30',
|
|
|
|
|
address: 'al. Jerozolimskie 100, 02-001 Warszawa', edoreczenia_address: null, is_pep: false,
|
|
|
|
|
risk_rating: 'medium', notes: 'Stały klient — obsługa korporacyjna od 2021 r.' },
|
|
|
|
|
{ id: 'p-nowak', kind: 'person', name: 'Anna Nowak', nip: null, pesel: '85112298765', krs: null,
|
|
|
|
|
regon: null, email: 'a.nowak@example.com', phone: '+48 502 987 654',
|
|
|
|
|
address: 'ul. Lipowa 7, 31-002 Kraków', edoreczenia_address: null, is_pep: false,
|
|
|
|
|
risk_rating: 'low', notes: null },
|
|
|
|
|
{ id: 'p-skarb', kind: 'organisation', name: 'Skarb Państwa — Prezydent m.st. Warszawy', nip: null,
|
|
|
|
|
pesel: null, krs: null, regon: null, email: null, phone: null,
|
|
|
|
|
address: 'pl. Bankowy 3/5, 00-950 Warszawa', edoreczenia_address: null, is_pep: false,
|
|
|
|
|
risk_rating: 'low', notes: null }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var containers = [
|
|
|
|
|
{ id: 'n-kancelaria', parent_id: null, kind: 'workspace', name: 'Kancelaria', slug: 'kancelaria',
|
|
|
|
|
path: '/kancelaria' },
|
|
|
|
|
{ id: 'n-proces', parent_id: 'n-kancelaria', kind: 'group', name: 'Dział procesowy',
|
|
|
|
|
slug: 'dzial-procesowy', path: '/kancelaria/dzial-procesowy' },
|
|
|
|
|
{ id: 'n-korpo', parent_id: 'n-kancelaria', kind: 'group', name: 'Dział korporacyjny',
|
|
|
|
|
slug: 'dzial-korporacyjny', path: '/kancelaria/dzial-korporacyjny' }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function matter(o) {
|
|
|
|
|
return Object.assign({
|
|
|
|
|
document_node_id: null, description: null, practice_area: null, status: 'open',
|
|
|
|
|
responsible_lawyer_id: 'u-admin', originating_lawyer_id: 'u-admin', closed_at: null,
|
|
|
|
|
fee_type: 'hourly', default_rate_minor: null, rate_card_id: null, fee_cap_minor: null,
|
|
|
|
|
currency: CURRENCY, value_in_dispute: null, court: null, court_department: null,
|
|
|
|
|
case_signature: null, instance: null, case_file_url: null
|
|
|
|
|
}, o);
|
|
|
|
|
}
|
|
|
|
|
var matters = [
|
|
|
|
|
matter({ id: 'm-1', node_id: 'n-m1', reference: '2026/0001',
|
|
|
|
|
name: 'Kowalski przeciwko Wodociągom Miejskim', client_party_id: 'p-kowalski',
|
|
|
|
|
client_name: 'Jan Kowalski', practice_area: 'Postępowanie cywilne', opened_at: day(-124),
|
|
|
|
|
value_in_dispute: 8640000, court: 'Sąd Rejonowy dla Warszawy-Śródmieścia',
|
|
|
|
|
court_department: 'I Wydział Cywilny', case_signature: 'I C 412/26', instance: 1,
|
|
|
|
|
description: 'Zalanie lokalu wskutek awarii sieci wodociągowej. Odszkodowanie i zadośćuczynienie.' }),
|
|
|
|
|
matter({ id: 'm-2', node_id: 'n-m2', reference: '2026/0002',
|
|
|
|
|
name: 'ACME Polska — stała obsługa korporacyjna', client_party_id: 'p-acme',
|
|
|
|
|
client_name: 'ACME Polska S.A.', practice_area: 'Prawo spółek', opened_at: day(-210),
|
|
|
|
|
fee_type: 'retainer', default_rate_minor: 55000 }),
|
|
|
|
|
matter({ id: 'm-3', node_id: 'n-m3', reference: '2026/0003', name: 'Nowak — dział spadku',
|
|
|
|
|
client_party_id: 'p-nowak', client_name: 'Anna Nowak', practice_area: 'Prawo spadkowe',
|
|
|
|
|
opened_at: day(-38), fee_type: 'flat', fee_cap_minor: 900000,
|
|
|
|
|
court: 'Sąd Rejonowy dla Krakowa-Podgórza', court_department: 'I Wydział Cywilny' })
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var matterParties = {
|
|
|
|
|
'm-1': [
|
|
|
|
|
{ id: 'mp-1', party_id: 'p-kowalski', party_name: 'Jan Kowalski', party_kind: 'person',
|
|
|
|
|
role: 'client', is_adverse: false, note: null },
|
|
|
|
|
{ id: 'mp-2', party_id: 'p-wodociagi', party_name: 'Wodociągi Miejskie sp. z o.o.',
|
|
|
|
|
party_kind: 'organisation', role: 'opponent', is_adverse: true, note: null }
|
|
|
|
|
],
|
|
|
|
|
'm-2': [
|
|
|
|
|
{ id: 'mp-3', party_id: 'p-acme', party_name: 'ACME Polska S.A.', party_kind: 'organisation',
|
|
|
|
|
role: 'client', is_adverse: false, note: null }
|
|
|
|
|
],
|
|
|
|
|
'm-3': [
|
|
|
|
|
{ id: 'mp-4', party_id: 'p-nowak', party_name: 'Anna Nowak', party_kind: 'person',
|
|
|
|
|
role: 'client', is_adverse: false, note: null },
|
|
|
|
|
{ id: 'mp-5', party_id: 'p-skarb', party_name: 'Skarb Państwa — Prezydent m.st. Warszawy',
|
|
|
|
|
party_kind: 'organisation', role: 'intervener', is_adverse: false, note: null }
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function deadline(o) {
|
|
|
|
|
return Object.assign({
|
|
|
|
|
kind: 'procedural', source: 'court', owner_id: 'u-admin', created_by_id: 'u-piotr',
|
|
|
|
|
confirmed_by_id: 'u-admin', confirmed_at: stamp(-6), completed_at: null, notes: null
|
|
|
|
|
}, o);
|
|
|
|
|
}
|
|
|
|
|
var deadlines = [
|
|
|
|
|
deadline({ id: 'd-1', matter_id: 'm-1', title: 'Odpowiedź na sprzeciw', due_date: day(-2),
|
|
|
|
|
basis: 'Doręczenie ' + day(-16) + ' + 14 dni (art. 205(2) § 1 k.p.c.)',
|
|
|
|
|
matter_reference: '2026/0001', matter_name: 'Kowalski przeciwko Wodociągom Miejskim' }),
|
|
|
|
|
deadline({ id: 'd-2', matter_id: 'm-1', title: 'Rozprawa — I C 412/26', due_date: day(9),
|
|
|
|
|
kind: 'hearing', basis: 'Zawiadomienie sądu z dnia ' + day(-20),
|
|
|
|
|
matter_reference: '2026/0001', matter_name: 'Kowalski przeciwko Wodociągom Miejskim' }),
|
|
|
|
|
deadline({ id: 'd-3', matter_id: 'm-3', title: 'Uzupełnienie braków formalnych wniosku',
|
|
|
|
|
due_date: day(3), confirmed_by_id: null, confirmed_at: null,
|
|
|
|
|
basis: 'Zarządzenie z dnia ' + day(-4) + ' + 7 dni',
|
|
|
|
|
matter_reference: '2026/0003', matter_name: 'Nowak — dział spadku' }),
|
|
|
|
|
deadline({ id: 'd-4', matter_id: 'm-2', title: 'Zgłoszenie zmiany w KRS', due_date: day(17),
|
|
|
|
|
kind: 'contractual', source: 'contract',
|
|
|
|
|
basis: 'Uchwała zgromadzenia + 7 dni (art. 22 ustawy o KRS)',
|
|
|
|
|
matter_reference: '2026/0002', matter_name: 'ACME Polska — stała obsługa korporacyjna' }),
|
|
|
|
|
deadline({ id: 'd-5', matter_id: 'm-1', title: 'Przedawnienie roszczenia', due_date: day(46),
|
|
|
|
|
kind: 'limitation', source: 'statute',
|
|
|
|
|
basis: 'Art. 442(1) § 1 k.c. — 3 lata od dowiedzenia się o szkodzie',
|
|
|
|
|
matter_reference: '2026/0001', matter_name: 'Kowalski przeciwko Wodociągom Miejskim' })
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var correspondence = [
|
|
|
|
|
{ id: 'c-1', channel: 'edoreczenia', direction: 'incoming', status: 'unassigned',
|
|
|
|
|
subject: 'Zobowiązanie do złożenia pisma przygotowawczego',
|
|
|
|
|
sender: 'Sąd Rejonowy dla Warszawy-Śródmieścia', recipient: 'Kancelaria', note: null,
|
|
|
|
|
legal_service_date: day(-3), received_at: stamp(-3, 8), sent_at: null,
|
|
|
|
|
external_ref: 'DOR/2026/88121', document_path: null, matter_id: null, matter_reference: null,
|
|
|
|
|
matter_name: null, created_at: stamp(-3, 8) },
|
|
|
|
|
{ id: 'c-2', channel: 'post', direction: 'incoming', status: 'unassigned',
|
|
|
|
|
subject: 'Pismo Wodociągów Miejskich — propozycja ugody',
|
|
|
|
|
sender: 'Wodociągi Miejskie sp. z o.o.', recipient: 'Kancelaria',
|
|
|
|
|
note: 'Koperta bez potwierdzenia odbioru — datę doręczenia trzeba ustalić.',
|
|
|
|
|
legal_service_date: null, received_at: stamp(-1, 11), sent_at: null, external_ref: null,
|
|
|
|
|
document_path: null, matter_id: null, matter_reference: null, matter_name: null,
|
|
|
|
|
created_at: stamp(-1, 11) },
|
|
|
|
|
{ id: 'c-3', channel: 'court_portal', direction: 'incoming', status: 'assigned',
|
|
|
|
|
subject: 'Odpis sprzeciwu od nakazu zapłaty',
|
|
|
|
|
sender: 'Sąd Rejonowy dla Warszawy-Śródmieścia', recipient: 'Kancelaria', note: null,
|
|
|
|
|
legal_service_date: day(-16), received_at: stamp(-16, 9), sent_at: null,
|
|
|
|
|
external_ref: 'PI/2026/4471', document_path: null, matter_id: 'm-1',
|
|
|
|
|
matter_reference: '2026/0001', matter_name: 'Kowalski przeciwko Wodociągom Miejskim',
|
|
|
|
|
created_at: stamp(-16, 9) }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Field names follow `schemas.time_out`: `author` (not user_name) and `invoiced` (not
|
|
|
|
|
// billed). The console reads both straight through, and a wrong name renders as blank.
|
|
|
|
|
function entry(id, matterId, userId, author, dayOffset, minutes, rate, narrative, ref, name, invoiced) {
|
|
|
|
|
return { id: id, matter_id: matterId, user_id: userId, author: author,
|
|
|
|
|
matter_reference: ref, matter_name: name, work_date: day(dayOffset), minutes: minutes,
|
|
|
|
|
hours: Math.round((minutes / 60) * 100) / 100, narrative: narrative, activity_code: null,
|
|
|
|
|
billable: true, rate_minor: rate, write_off_minutes: 0,
|
|
|
|
|
amount_minor: Math.floor((minutes / 60) * rate), invoiced: !!invoiced };
|
|
|
|
|
}
|
|
|
|
|
var time = [
|
|
|
|
|
entry('t-1', 'm-1', 'u-admin', 'Maria Wiśniewska', -2, 150, 65000,
|
|
|
|
|
'Analiza sprzeciwu, research orzecznictwa SN na tle art. 435 k.c.',
|
|
|
|
|
'2026/0001', 'Kowalski przeciwko Wodociągom Miejskim'),
|
|
|
|
|
entry('t-2', 'm-1', 'u-piotr', 'Piotr Zieliński', -1, 90, 45000,
|
|
|
|
|
'Projekt pisma przygotowawczego.',
|
|
|
|
|
'2026/0001', 'Kowalski przeciwko Wodociągom Miejskim'),
|
|
|
|
|
entry('t-3', 'm-2', 'u-admin', 'Maria Wiśniewska', -5, 60, 55000,
|
|
|
|
|
'Uchwała zgromadzenia wspólników — opiniowanie.',
|
|
|
|
|
'2026/0002', 'ACME Polska — stała obsługa korporacyjna', true),
|
|
|
|
|
entry('t-4', 'm-3', 'u-ola', 'Aleksandra Dąbrowska', -4, 210, 35000,
|
|
|
|
|
'Wniosek o dział spadku — przygotowanie i załączniki.',
|
|
|
|
|
'2026/0003', 'Nowak — dział spadku')
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var expenses = [
|
|
|
|
|
{ id: 'e-1', matter_id: 'm-1', kind: 'court_fee', description: 'Opłata od pozwu',
|
|
|
|
|
spent_on: day(-120), amount_minor: 432000, vat_rate: 0, recharge: true, billed: false,
|
|
|
|
|
supplier: 'Sąd Rejonowy dla Warszawy-Śródmieścia' },
|
|
|
|
|
{ id: 'e-2', matter_id: 'm-1', kind: 'stamp_duty', description: 'Opłata skarbowa od pełnomocnictwa',
|
|
|
|
|
spent_on: day(-120), amount_minor: 1700, vat_rate: 0, recharge: true, billed: false,
|
|
|
|
|
supplier: 'Urząd Miasta Warszawy' }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var invoices = [
|
|
|
|
|
{ id: 'i-1', matter_id: 'm-2', number: 'FV 2026/08/014', kind: 'invoice', status: 'issued',
|
|
|
|
|
issued_on: day(-28), due_on: day(-14), net_minor: 55000, vat_minor: 12650,
|
|
|
|
|
gross_minor: 67650, paid_minor: 67650, currency: CURRENCY, client_name: 'ACME Polska S.A.',
|
|
|
|
|
matter_reference: '2026/0002', note: null },
|
|
|
|
|
{ id: 'i-2', matter_id: 'm-1', number: null, kind: 'invoice', status: 'draft',
|
|
|
|
|
issued_on: null, due_on: null, net_minor: 230000, vat_minor: 52900, gross_minor: 282900,
|
|
|
|
|
paid_minor: 0, currency: CURRENCY, client_name: 'Jan Kowalski',
|
|
|
|
|
matter_reference: '2026/0001', note: null }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var conflicts = [
|
|
|
|
|
{ id: 'k-1', subject: 'Jan Kowalski', adverse_names: ['Wodociągi Miejskie sp. z o.o.'],
|
|
|
|
|
hit_count: 0, hits: [], outcome: 'clear', decision_note: 'Brak trafień — automatycznie.',
|
|
|
|
|
lead_id: null, matter_id: 'm-1', created_at: stamp(-125), decided_at: stamp(-125),
|
|
|
|
|
decided_by_id: 'u-admin' },
|
|
|
|
|
{ id: 'k-2', subject: 'Przedsiębiorstwo Budowlane Nowak i Syn',
|
|
|
|
|
adverse_names: ['ACME Polska S.A.'], hit_count: 2, outcome: 'pending', decision_note: null,
|
|
|
|
|
lead_id: null, matter_id: null, created_at: stamp(-2), decided_at: null, decided_by_id: null,
|
|
|
|
|
hits: [
|
|
|
|
|
{ kind: 'known_party', party_id: 'p-nowak', party_name: 'Anna Nowak', matched_name: 'Nowak',
|
|
|
|
|
score: 0.6, severity: 1, role: null, is_adverse: null, matter_id: null, matter_name: null,
|
|
|
|
|
matter_reference: null, matter_status: null },
|
|
|
|
|
{ kind: 'matter_party', party_id: 'p-acme', party_name: 'ACME Polska S.A.',
|
|
|
|
|
matched_name: 'ACME Polska S.A.', score: 1.0, severity: 3, role: 'client',
|
|
|
|
|
is_adverse: false, matter_id: 'm-2',
|
|
|
|
|
matter_name: 'ACME Polska — stała obsługa korporacyjna', matter_reference: '2026/0002',
|
|
|
|
|
matter_status: 'open' }
|
|
|
|
|
] }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var notifications = [
|
|
|
|
|
{ id: 'no-1', kind: 'deadline_overdue', title: 'Termin minął: Odpowiedź na sprzeciw',
|
|
|
|
|
body: '2026/0001 — termin upłynął 2 dni temu.', link: '#/matters/m-1?tab=deadlines',
|
|
|
|
|
read: false, created_at: stamp(-2, 7) },
|
|
|
|
|
{ id: 'no-2', kind: 'service_date_missing',
|
|
|
|
|
title: 'Brak daty doręczenia: Pismo Wodociągów Miejskich',
|
|
|
|
|
body: 'post — bez daty doręczenia nie ma od czego liczyć terminu.', link: '#/inbox',
|
|
|
|
|
read: false, created_at: stamp(-1, 11) },
|
|
|
|
|
{ id: 'no-3', kind: 'deadline_unconfirmed',
|
|
|
|
|
title: 'Do potwierdzenia: Uzupełnienie braków formalnych wniosku',
|
|
|
|
|
body: '2026/0003 — termin sądowy wymaga potwierdzenia przez drugą osobę.',
|
|
|
|
|
link: '#/matters/m-3?tab=deadlines', read: false, created_at: stamp(-4, 16) },
|
|
|
|
|
{ id: 'no-4', kind: 'conflict_pending', title: 'Konflikt do rozstrzygnięcia',
|
|
|
|
|
body: 'Przedsiębiorstwo Budowlane Nowak i Syn — 2 trafienia.', link: '#/intake',
|
|
|
|
|
read: true, created_at: stamp(-2, 9) }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var aml = {
|
|
|
|
|
'm-2': {
|
|
|
|
|
// Field names follow `schemas.aml_out` exactly — `risk`, not `risk_rating`, and
|
|
|
|
|
// `risk_score`, not `score`. The console reads them straight through.
|
|
|
|
|
current: { id: 'a-1', status: 'approved', in_scope: true, scope_note: null,
|
|
|
|
|
risk: 'medium', risk_score: 3, measure: 'standard', factors: ['long_standing_client'],
|
|
|
|
|
measures_note: 'Weryfikacja KRS i beneficjentów rzeczywistych; dokumenty w aktach sprawy.',
|
|
|
|
|
purpose_note: 'Bieżąca obsługa korporacyjna — uchwały, umowy, zmiany w KRS.',
|
|
|
|
|
source_of_funds: 'Przychody z działalności operacyjnej spółki.',
|
|
|
|
|
ubo_established: true, ubo_note: null, pep: false, pep_note: null,
|
|
|
|
|
assessed_by_id: 'u-admin', approved_by_id: 'u-admin', approved_at: stamp(-199),
|
|
|
|
|
next_review_on: day(165), retain_until: day(1800), created_at: stamp(-200) },
|
|
|
|
|
history: []
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
seeded_on: day(0), users: USERS, parties: parties, containers: containers, matters: matters,
|
|
|
|
|
matter_parties: matterParties, deadlines: deadlines, correspondence: correspondence,
|
|
|
|
|
time: time, expenses: expenses, invoices: invoices, conflicts: conflicts,
|
|
|
|
|
notifications: notifications, aml: aml,
|
|
|
|
|
// Ethical walls are what Sygna is built around, so the demo shows one rather than an
|
|
|
|
|
// empty list: Piotr is screened off the ACME retainer while he acts on the other side.
|
|
|
|
|
walls: { 'm-2': [{ user_id: 'u-piotr', user_name: 'Piotr Zieliński', mode: 'deny',
|
|
|
|
|
reason: 'Prowadzi sprawę przeciwko spółce z grupy ACME — bariera informacyjna.',
|
|
|
|
|
created_at: stamp(-60) }] },
|
|
|
|
|
access: { direct: [
|
|
|
|
|
{ user_id: 'u-admin', name: 'Maria Wiśniewska', email: 'demo@sygna.example',
|
|
|
|
|
role: 'manager', from: null },
|
|
|
|
|
{ user_id: 'u-ola', name: 'Aleksandra Dąbrowska', email: 'a.dabrowska@sygna.example',
|
|
|
|
|
role: 'editor', from: null }
|
|
|
|
|
], inherited: [
|
|
|
|
|
{ user_id: 'u-piotr', name: 'Piotr Zieliński', email: 'p.zielinski@sygna.example',
|
|
|
|
|
role: 'editor', from: 'Kancelaria' }
|
|
|
|
|
], groups: [] },
|
|
|
|
|
settings: {
|
|
|
|
|
firm_name: 'Kancelaria Adwokacka Wiśniewska i Wspólnicy', practice_mode: 'law_firm',
|
|
|
|
|
default_rate_minor: 65000, currency: CURRENCY, deadline_horizon_days: 14,
|
|
|
|
|
target_hours_per_day: 6.0, email_detail: 'minimal',
|
|
|
|
|
firm_address: 'ul. Próżna 9/4, 00-107 Warszawa', firm_nip: '5251234567',
|
|
|
|
|
firm_bank_account: 'PL61 1090 1014 0000 0712 1981 2874',
|
|
|
|
|
firm_email: 'kancelaria@sygna.example', firm_phone: '+48 22 828 00 00',
|
|
|
|
|
invoice_payment_days: 14, backup_enabled: false, backup_interval: 'daily', backup_retention: 7
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── store ──────────────────────────────────────────────────────────────── */
|
|
|
|
|
var db = null;
|
|
|
|
|
function load() {
|
|
|
|
|
if (db) return db;
|
|
|
|
|
try {
|
|
|
|
|
var raw = localStorage.getItem(LS);
|
|
|
|
|
if (raw) {
|
|
|
|
|
var parsed = JSON.parse(raw);
|
|
|
|
|
var age = (Date.parse(day(0)) - Date.parse(parsed.seeded_on || '1970-01-01')) / 86400000;
|
|
|
|
|
if (age >= 0 && age <= 14) { db = parsed; return db; }
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { /* private mode, cleared storage — fall through to a fresh seed */ }
|
|
|
|
|
db = seed();
|
|
|
|
|
save();
|
|
|
|
|
return db;
|
|
|
|
|
}
|
|
|
|
|
function save() {
|
|
|
|
|
try { localStorage.setItem(LS, JSON.stringify(db)); } catch (e) { /* nothing to do */ }
|
|
|
|
|
}
|
|
|
|
|
window.sygnaDemoReset = function () {
|
|
|
|
|
try { localStorage.removeItem(LS); localStorage.removeItem(SESS); } catch (e) {}
|
|
|
|
|
db = null;
|
|
|
|
|
location.reload();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function signedIn() {
|
|
|
|
|
try { return localStorage.getItem(SESS) === '1'; } catch (e) { return false; }
|
|
|
|
|
}
|
|
|
|
|
function setSignedIn(on) {
|
|
|
|
|
try { if (on) localStorage.setItem(SESS, '1'); else localStorage.removeItem(SESS); } catch (e) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── helpers ────────────────────────────────────────────────────────────── */
|
|
|
|
|
function byId(list, id) {
|
|
|
|
|
for (var i = 0; i < list.length; i++) if (list[i].id === id) return list[i];
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
function daysLeft(iso) { return Math.round((Date.parse(iso) - Date.parse(day(0))) / 86400000); }
|
|
|
|
|
function withDeadlineState(d) {
|
|
|
|
|
var left = daysLeft(d.due_date);
|
|
|
|
|
return Object.assign({}, d, { days_left: left, overdue: left < 0 && !d.completed_at });
|
|
|
|
|
}
|
|
|
|
|
function fold(s) {
|
|
|
|
|
return (s || '').toLowerCase()
|
|
|
|
|
.replace(/ą/g, 'a').replace(/ć/g, 'c').replace(/ę/g, 'e').replace(/ł/g, 'l').replace(/ń/g, 'n')
|
|
|
|
|
.replace(/ó/g, 'o').replace(/ś/g, 's').replace(/ź/g, 'z').replace(/ż/g, 'z');
|
|
|
|
|
}
|
|
|
|
|
function unbilledMinor(d, matterId) {
|
|
|
|
|
var total = 0;
|
|
|
|
|
d.time.forEach(function (t) {
|
|
|
|
|
if (t.matter_id === matterId && t.billable && !t.invoiced) total += t.amount_minor;
|
|
|
|
|
});
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
/* The console sends what the user typed. The API accepts 90, "90m", "1.5", "1:30", "1h30"
|
|
|
|
|
(services/timelog.parse_duration), so the demo has to understand the same — otherwise a
|
|
|
|
|
perfectly ordinary "1:30" silently becomes six minutes. */
|
|
|
|
|
function parseDuration(value) {
|
|
|
|
|
if (value == null || value === '') return 0;
|
|
|
|
|
if (typeof value === 'number') return Math.round(value);
|
|
|
|
|
var text = String(value).trim().toLowerCase().replace(',', '.');
|
|
|
|
|
var m = /^(\d+):(\d{1,2})$/.exec(text); // 1:30
|
|
|
|
|
if (m) return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
|
|
|
|
|
m = /^(\d+)h\s*(\d+)m?$/.exec(text); // 1h30
|
|
|
|
|
if (m) return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
|
|
|
|
|
m = /^(\d+(?:\.\d+)?)h$/.exec(text); // 1h, 1.5h
|
|
|
|
|
if (m) return Math.round(parseFloat(m[1]) * 60);
|
|
|
|
|
m = /^(\d+)m$/.exec(text); // 90m
|
|
|
|
|
if (m) return parseInt(m[1], 10);
|
|
|
|
|
if (/^\d+$/.test(text)) return parseInt(text, 10); // 90 (minutes)
|
|
|
|
|
if (/^\d+\.\d+$/.test(text)) return Math.round(parseFloat(text) * 60); // 1.5 (hours)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
function problem(status, detail) {
|
|
|
|
|
return { body: { type: 'about:blank', title: 'Demo', status: status, detail: detail }, status: status };
|
|
|
|
|
}
|
|
|
|
|
var DEMO_WRITE = problem(400,
|
|
|
|
|
'To jest wersja demonstracyjna — dane są tylko w tej przeglądarce, więc tej operacji nie zapisuję. ' +
|
|
|
|
|
'Pełna instalacja Sygny robi to naprawdę.');
|
|
|
|
|
|
|
|
|
|
/* ── routes ─────────────────────────────────────────────────────────────── */
|
|
|
|
|
var routes = [];
|
|
|
|
|
function on(method, pattern, handler) {
|
|
|
|
|
routes.push({ method: method, pattern: pattern, handler: handler });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
on('POST', /^\/auth\/login$/, function () {
|
|
|
|
|
setSignedIn(true);
|
|
|
|
|
return { token: 'demo-token', user: load().users[0] };
|
|
|
|
|
});
|
|
|
|
|
on('POST', /^\/auth\/logout$/, function () { setSignedIn(false); return { ok: true }; });
|
|
|
|
|
on('GET', /^\/auth\/me$/, function () {
|
|
|
|
|
if (!signedIn()) return problem(401, 'Nie zalogowano.');
|
|
|
|
|
return load().users[0];
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/auth\/tokens$/, function () {
|
|
|
|
|
return { items: [], enabled: true, default_idle_days: 30 };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/config$/, function () {
|
|
|
|
|
var s = load().settings;
|
|
|
|
|
return { firm_name: s.firm_name, practice_mode: s.practice_mode, bills_clients: true,
|
|
|
|
|
currency: s.currency, email_configured: false };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/shell$/, function () {
|
|
|
|
|
return { apps: [{ key: 'sygna', name: 'Sygna', role: 'Sprawy, terminy, czas pracy',
|
|
|
|
|
url: null, current: true }], embed: false };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/users$/, function () { return load().users; });
|
|
|
|
|
on('GET', /^\/tree\/containers$/, function () { return load().containers; });
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/dashboard$/, function () {
|
|
|
|
|
var d = load();
|
|
|
|
|
var live = d.deadlines.map(withDeadlineState).filter(function (x) { return !x.completed_at; });
|
|
|
|
|
var due = live.filter(function (x) { return x.days_left <= d.settings.deadline_horizon_days; });
|
|
|
|
|
var week = day(-7), mine = 0;
|
|
|
|
|
d.time.forEach(function (t) { if (t.user_id === 'u-admin' && t.work_date >= week) mine += t.minutes; });
|
|
|
|
|
return {
|
|
|
|
|
cards: {
|
|
|
|
|
deadlines_due: due.length,
|
|
|
|
|
deadlines_overdue: live.filter(function (x) { return x.overdue; }).length,
|
|
|
|
|
deadlines_unconfirmed: live.filter(function (x) { return !x.confirmed_at; }).length,
|
|
|
|
|
open_matters: d.matters.filter(function (m) { return m.status === 'open'; }).length,
|
|
|
|
|
my_matters: d.matters.filter(function (m) { return m.responsible_lawyer_id === 'u-admin'; }).length,
|
|
|
|
|
minutes_this_week: mine,
|
|
|
|
|
pending_conflicts: d.conflicts.filter(function (c) { return c.outcome === 'pending'; }).length,
|
|
|
|
|
open_leads: 0,
|
|
|
|
|
inbox: d.correspondence.filter(function (c) { return c.status === 'unassigned'; }).length,
|
|
|
|
|
undated_service: d.correspondence.filter(function (c) { return !c.legal_service_date; }).length,
|
|
|
|
|
horizon_days: d.settings.deadline_horizon_days
|
|
|
|
|
},
|
|
|
|
|
deadlines: due.sort(function (a, b) { return a.due_date < b.due_date ? -1 : 1; }),
|
|
|
|
|
unconfirmed: live.filter(function (x) { return !x.confirmed_at; })
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/matters$/, function (m, body, url) {
|
|
|
|
|
var d = load(), status = url.searchParams.get('status'), q = fold(url.searchParams.get('q') || '');
|
|
|
|
|
return d.matters.filter(function (x) {
|
|
|
|
|
if (status && x.status !== status) return false;
|
|
|
|
|
if (q && fold(x.name + ' ' + x.reference + ' ' + x.client_name).indexOf(q) < 0) return false;
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)$/, function (m) {
|
|
|
|
|
var d = load(), matter = byId(d.matters, m[1]);
|
|
|
|
|
if (!matter) return problem(404, 'Nie znaleziono.');
|
|
|
|
|
var mins = 0, billable = 0;
|
|
|
|
|
d.time.forEach(function (t) {
|
|
|
|
|
if (t.matter_id !== matter.id) return;
|
|
|
|
|
mins += t.minutes;
|
|
|
|
|
if (t.billable) billable += t.minutes;
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
matter: Object.assign({ role: 'manager' }, matter),
|
|
|
|
|
parties: d.matter_parties[matter.id] || [],
|
|
|
|
|
breadcrumb: [{ id: 'n-kancelaria', name: 'Kancelaria', kind: 'workspace' },
|
|
|
|
|
{ id: matter.node_id, name: matter.name, kind: 'matter' }],
|
|
|
|
|
totals: { total_minutes: mins, billable_minutes: billable,
|
|
|
|
|
unbilled_minor: unbilledMinor(d, matter.id) },
|
|
|
|
|
galena_enabled: false, galena_embed: false
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/time$/, function (m) {
|
|
|
|
|
var d = load(), entries = d.time.filter(function (t) { return t.matter_id === m[1]; });
|
|
|
|
|
var mins = 0, billable = 0;
|
|
|
|
|
entries.forEach(function (t) { mins += t.minutes; if (t.billable) billable += t.minutes; });
|
|
|
|
|
return { entries: entries, totals: { total_minutes: mins, billable_minutes: billable,
|
|
|
|
|
unbilled_minor: unbilledMinor(d, m[1]) } };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/deadlines$/, function (m) {
|
|
|
|
|
return load().deadlines.filter(function (x) { return x.matter_id === m[1]; }).map(withDeadlineState);
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/correspondence$/, function (m) {
|
|
|
|
|
return load().correspondence.filter(function (c) { return c.matter_id === m[1]; });
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/expenses$/, function (m) {
|
|
|
|
|
return load().expenses.filter(function (e) { return e.matter_id === m[1]; });
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/events$/, function () { return []; });
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/walls$/, function (m) {
|
|
|
|
|
return (load().walls || {})[m[1]] || [];
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/nodes\/([^/]+)\/access$/, function () {
|
|
|
|
|
return load().access || { direct: [], inherited: [], groups: [] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/billing$/, function (m) {
|
|
|
|
|
var d = load(), invoices = d.invoices.filter(function (i) { return i.matter_id === m[1]; });
|
|
|
|
|
var billed = 0, paid = 0, expenses = 0, entries = 0, mins = 0, expenseRows = 0;
|
|
|
|
|
invoices.forEach(function (i) {
|
|
|
|
|
if (i.status === 'issued' || i.status === 'paid') { billed += i.net_minor; paid += i.paid_minor; }
|
|
|
|
|
});
|
|
|
|
|
d.expenses.forEach(function (e) {
|
|
|
|
|
if (e.matter_id === m[1] && !e.billed) { expenses += e.amount_minor; expenseRows += 1; }
|
|
|
|
|
});
|
|
|
|
|
d.time.forEach(function (t) {
|
|
|
|
|
if (t.matter_id === m[1] && t.billable && !t.invoiced) { entries += 1; mins += t.minutes; }
|
|
|
|
|
});
|
|
|
|
|
var wip = unbilledMinor(d, m[1]);
|
|
|
|
|
return {
|
|
|
|
|
financials: { wip_minor: wip, wip_minutes: mins, unbilled_expenses_minor: expenses,
|
|
|
|
|
billed_minor: billed, paid_minor: paid, outstanding_minor: billed - paid, deposit_minor: 0,
|
|
|
|
|
invoice_count: invoices.length },
|
|
|
|
|
invoices: invoices,
|
|
|
|
|
unbilled: { minutes: mins, time_minor: wip, expenses_minor: expenses, entries: entries,
|
|
|
|
|
expense_rows: expenseRows }
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/deposit$/, function () {
|
|
|
|
|
return { balance_minor: 0, currency: CURRENCY, movements: [] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/rates$/, function () {
|
|
|
|
|
var rates = [65000, 45000, 35000];
|
|
|
|
|
return { on_date: day(0), currency: CURRENCY,
|
|
|
|
|
mine: { rate_minor: 65000, source: 'firm_card',
|
|
|
|
|
label: 'cennik kancelarii „Cennik kancelarii 2026” (stopień: partner)', card_id: 'rc-1' },
|
|
|
|
|
everyone: load().users.map(function (u, i) {
|
|
|
|
|
return { user_id: u.id, name: u.full_name, rate_minor: rates[i] || 35000,
|
|
|
|
|
source: 'firm_card', label: 'cennik kancelarii „Cennik kancelarii 2026”' };
|
|
|
|
|
}) };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/fees$/, function (m) {
|
|
|
|
|
var matter = byId(load().matters, m[1]);
|
|
|
|
|
if (!matter || !matter.value_in_dispute) {
|
|
|
|
|
return problem(409,
|
|
|
|
|
'Ta sprawa nie ma podanej wartości przedmiotu sporu — bez niej nie ma od czego liczyć opłaty.');
|
|
|
|
|
}
|
|
|
|
|
return { type: 'civil', title: 'Opłata stosunkowa od pozwu', status: 'ok',
|
|
|
|
|
detail: { value_in_dispute: matter.value_in_dispute, fee_minor: 432000,
|
|
|
|
|
basis: 'art. 13 ust. 1 u.k.s.c. — 5% wartości przedmiotu sporu, zaokrąglone w górę do pełnego złotego',
|
|
|
|
|
schedule_version: '2026-01-01',
|
|
|
|
|
verify_note: 'Zebrane z tekstów ustaw — przed użyciem sprawdź z adwokatem.' } };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/aml$/, function (m) {
|
|
|
|
|
return load().aml[m[1]] || { current: null, history: [] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/matters\/([^/]+)\/aml\/ubo$/, function (m) {
|
|
|
|
|
var matter = byId(load().matters, m[1]);
|
|
|
|
|
return { client_id: matter ? matter.client_party_id : null,
|
|
|
|
|
client_name: matter ? matter.client_name : null, items: [] };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/parties$/, function (m, body, url) {
|
|
|
|
|
var q = fold(url.searchParams.get('q') || '');
|
|
|
|
|
return load().parties.filter(function (p) { return !q || fold(p.name).indexOf(q) >= 0; });
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/parties\/([^/]+)$/, function (m) {
|
|
|
|
|
var d = load(), party = byId(d.parties, m[1]);
|
|
|
|
|
if (!party) return problem(404, 'Nie znaleziono.');
|
|
|
|
|
return { party: party, aliases: [], links: [],
|
|
|
|
|
matters: d.matters.filter(function (x) { return x.client_party_id === party.id; }) };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/deadlines$/, function (m, body, url) {
|
|
|
|
|
var days = parseInt(url.searchParams.get('days') || '60', 10);
|
|
|
|
|
return load().deadlines.map(withDeadlineState)
|
|
|
|
|
.filter(function (x) { return !x.completed_at && x.days_left <= days; })
|
|
|
|
|
.sort(function (a, b) { return a.due_date < b.due_date ? -1 : 1; });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/calendar$/, function (m, body, url) {
|
|
|
|
|
var d = load();
|
|
|
|
|
var now = new Date();
|
|
|
|
|
var year = parseInt(url.searchParams.get('year') || now.getFullYear(), 10);
|
|
|
|
|
var month = parseInt(url.searchParams.get('month') || (now.getMonth() + 1), 10);
|
|
|
|
|
var first = new Date(Date.UTC(year, month - 1, 1));
|
|
|
|
|
var start = new Date(first);
|
|
|
|
|
start.setUTCDate(1 - ((first.getUTCDay() + 6) % 7)); // the grid starts on Monday
|
|
|
|
|
var last = new Date(Date.UTC(year, month, 0));
|
|
|
|
|
var end = new Date(last);
|
|
|
|
|
end.setUTCDate(last.getUTCDate() + (6 - ((last.getUTCDay() + 6) % 7)));
|
|
|
|
|
var days = {}, counts = { deadlines: 0, events: 0 };
|
|
|
|
|
d.deadlines.map(withDeadlineState).forEach(function (x) {
|
|
|
|
|
var matter = byId(d.matters, x.matter_id);
|
|
|
|
|
var entry = { kind: 'deadline', id: x.id, date: x.due_date, title: x.title,
|
|
|
|
|
deadline_kind: x.kind, source: x.source, confirmed: !!x.confirmed_at,
|
|
|
|
|
done: !!x.completed_at, overdue: x.overdue, matter_id: x.matter_id,
|
|
|
|
|
matter_reference: matter ? matter.reference : null,
|
|
|
|
|
matter_name: matter ? matter.name : null };
|
|
|
|
|
// The calendar EXPLAINS art. 115 k.c.; it never rewrites the recorded date.
|
|
|
|
|
var when = new Date(x.due_date + 'T12:00:00');
|
|
|
|
|
if (when.getDay() === 0 || when.getDay() === 6) {
|
|
|
|
|
var moved = new Date(when);
|
|
|
|
|
while (moved.getDay() === 0 || moved.getDay() === 6) moved.setDate(moved.getDate() + 1);
|
|
|
|
|
entry.moves_to = moved.toISOString().slice(0, 10);
|
|
|
|
|
entry.moves_note = 'sobota/niedziela — termin upływa w najbliższy dzień roboczy (art. 115 k.c.)';
|
|
|
|
|
}
|
|
|
|
|
(days[x.due_date] = days[x.due_date] || []).push(entry);
|
|
|
|
|
counts.deadlines += 1;
|
|
|
|
|
});
|
|
|
|
|
var MONTHS = ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień',
|
|
|
|
|
'Wrzesień', 'Październik', 'Listopad', 'Grudzień'];
|
|
|
|
|
return { year: year, month: month, label: MONTHS[month - 1] + ' ' + year,
|
|
|
|
|
start: start.toISOString().slice(0, 10), end: end.toISOString().slice(0, 10), today: day(0),
|
|
|
|
|
weekdays: ['pon', 'wt', 'śr', 'czw', 'pt', 'sob', 'niedz'], holidays: [], days: days,
|
|
|
|
|
counts: counts };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/correspondence\/inbox$/, function () {
|
|
|
|
|
var d = load();
|
|
|
|
|
var items = d.correspondence.filter(function (c) { return c.status === 'unassigned'; });
|
|
|
|
|
var undated = d.correspondence.filter(function (c) { return !c.legal_service_date; });
|
|
|
|
|
return { items: items, items_total: items.length, undated: undated,
|
|
|
|
|
undated_total: undated.length, limit: 50 };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/correspondence\/([^/]+)$/, function (m) {
|
|
|
|
|
return byId(load().correspondence, m[1]) || problem(404, 'Nie znaleziono.');
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/leads$/, function () { return []; });
|
|
|
|
|
on('GET', /^\/conflicts$/, function () { return load().conflicts; });
|
|
|
|
|
on('GET', /^\/conflicts\/([^/]+)$/, function (m) {
|
|
|
|
|
return byId(load().conflicts, m[1]) || problem(404, 'Nie znaleziono.');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/time\/mine$/, function () {
|
|
|
|
|
var entries = load().time.filter(function (t) { return t.user_id === 'u-admin'; });
|
|
|
|
|
var total = 0;
|
|
|
|
|
entries.forEach(function (t) { total += t.minutes; });
|
|
|
|
|
return { date_from: day(-30), date_to: day(0), total_minutes: total, entries: entries };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/notifications$/, function () {
|
|
|
|
|
var d = load();
|
|
|
|
|
return { unread: d.notifications.filter(function (n) { return !n.read; }).length,
|
|
|
|
|
items: d.notifications };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/notifications\/unread$/, function () {
|
|
|
|
|
return { unread: load().notifications.filter(function (n) { return !n.read; }).length };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/notifications\/prefs$/, function () {
|
|
|
|
|
return { inapp: true, webpush: false, email: false };
|
|
|
|
|
});
|
|
|
|
|
on('POST', /^\/notifications\/read$/, function () {
|
|
|
|
|
var d = load();
|
|
|
|
|
d.notifications.forEach(function (n) { n.read = true; });
|
|
|
|
|
save();
|
|
|
|
|
return { unread: 0 };
|
|
|
|
|
});
|
|
|
|
|
on('POST', /^\/notifications\/([^/]+)\/read$/, function (m) {
|
|
|
|
|
var d = load(), n = byId(d.notifications, m[1]);
|
|
|
|
|
if (n) { n.read = true; save(); }
|
|
|
|
|
return { unread: d.notifications.filter(function (x) { return !x.read; }).length };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/search$/, function (m, body, url) {
|
|
|
|
|
var d = load(), raw = url.searchParams.get('q') || '', q = fold(raw);
|
|
|
|
|
if (q.length < 2) return { query: raw, groups: [], total: 0, min_query: 2 };
|
|
|
|
|
var groups = [];
|
|
|
|
|
function group(kind, items) {
|
|
|
|
|
if (items.length) groups.push({ kind: kind, total: items.length, truncated: false, items: items });
|
|
|
|
|
}
|
|
|
|
|
group('matter', d.matters.filter(function (x) {
|
|
|
|
|
return fold(x.name + ' ' + x.reference + ' ' + x.client_name).indexOf(q) >= 0;
|
|
|
|
|
}).map(function (x) {
|
|
|
|
|
return { kind: 'matter', id: x.id, title: x.reference + ' — ' + x.name,
|
|
|
|
|
subtitle: x.client_name, status: x.status, date: x.opened_at, matter_id: x.id,
|
|
|
|
|
matter_reference: x.reference, score: 1 };
|
|
|
|
|
}));
|
|
|
|
|
group('party', d.parties.filter(function (p) {
|
|
|
|
|
return fold(p.name).indexOf(q) >= 0;
|
|
|
|
|
}).map(function (p) {
|
|
|
|
|
return { kind: 'party', id: p.id, title: p.name,
|
|
|
|
|
subtitle: p.nip ? 'NIP ' + p.nip : p.email, status: null, date: null, matter_id: null,
|
|
|
|
|
matter_reference: null, score: 1 };
|
|
|
|
|
}));
|
|
|
|
|
group('deadline', d.deadlines.filter(function (x) {
|
|
|
|
|
return fold(x.title + ' ' + (x.basis || '')).indexOf(q) >= 0;
|
|
|
|
|
}).map(function (x) {
|
|
|
|
|
return { kind: 'deadline', id: x.id, title: x.title, subtitle: x.matter_reference,
|
|
|
|
|
status: null, date: x.due_date, matter_id: x.matter_id,
|
|
|
|
|
matter_reference: x.matter_reference, score: 1 };
|
|
|
|
|
}));
|
|
|
|
|
var total = 0;
|
|
|
|
|
groups.forEach(function (g) { total += g.total; });
|
|
|
|
|
return { query: raw, groups: groups, total: total, min_query: 2 };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/billing\/summary$/, function () {
|
|
|
|
|
var d = load(), wip = 0, outstanding = 0;
|
|
|
|
|
d.matters.forEach(function (x) { wip += unbilledMinor(d, x.id); });
|
|
|
|
|
d.invoices.forEach(function (i) {
|
|
|
|
|
if (i.status === 'issued') outstanding += i.gross_minor - i.paid_minor;
|
|
|
|
|
});
|
|
|
|
|
// `matters` is a COUNT, not a list — the dashboard prints it as "N spraw". Caught by the
|
|
|
|
|
// console rendering "[object Object],[object Object]" rather than by anything in this file.
|
|
|
|
|
return { wip_minor: wip, outstanding_minor: outstanding, overdue_minor: 0, deposits_minor: 0,
|
|
|
|
|
matters: d.matters.filter(function (x) { return unbilledMinor(d, x.id) > 0; }).length };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on('GET', /^\/reports$/, function (m, body, url) {
|
|
|
|
|
var d = load(), standard = 0, unbilled = 0, billed = 0;
|
|
|
|
|
d.time.forEach(function (t) {
|
|
|
|
|
if (!t.billable) return;
|
|
|
|
|
standard += t.amount_minor;
|
|
|
|
|
if (t.invoiced) billed += t.amount_minor; else unbilled += t.amount_minor;
|
|
|
|
|
});
|
|
|
|
|
var workingDays = 21;
|
|
|
|
|
var target = workingDays * 60 * d.settings.target_hours_per_day;
|
|
|
|
|
return {
|
|
|
|
|
date_from: url.searchParams.get('date_from'), date_to: url.searchParams.get('date_to'),
|
|
|
|
|
realisation: { standard_minor: standard, written_off_minor: 0, billable_minor: standard,
|
|
|
|
|
billed_minor: billed, unbilled_minor: unbilled, write_off_rate: 0.0,
|
|
|
|
|
billing_realisation: standard ? Math.round((billed / standard) * 10000) / 10000 : 0.0,
|
|
|
|
|
invoiced_net_minor: 55000, collected_net_minor: 55000, collection_realisation: 1.0 },
|
|
|
|
|
utilisation: { working_days: workingDays, target_hours_per_day: d.settings.target_hours_per_day,
|
|
|
|
|
target_minutes: target,
|
|
|
|
|
people: d.users.map(function (u) {
|
|
|
|
|
var mins = 0;
|
|
|
|
|
d.time.forEach(function (t) { if (t.user_id === u.id) mins += t.minutes; });
|
|
|
|
|
return { user_id: u.id, name: u.full_name, recorded_minutes: mins, billable_minutes: mins,
|
|
|
|
|
target_minutes: target, utilisation: Math.round((mins / target) * 10000) / 10000 };
|
|
|
|
|
}) },
|
|
|
|
|
lock_up: { wip_minor: unbilled, outstanding_minor: 0, billed_net_minor: billed,
|
|
|
|
|
period_days: 365, wip_days: 31, debtor_days: 0, lock_up_days: 31 },
|
|
|
|
|
aged_debt: { buckets: { current: 0, d1_30: 0, d31_60: 0, d61_90: 0, d90_plus: 0 },
|
|
|
|
|
total_minor: 0, invoices: [] },
|
|
|
|
|
// Every cost rate is present in the demo, but profitability still reports `incomplete`
|
|
|
|
|
// wherever a matter has uncosted time — a flattering zero is the thing it must never show.
|
|
|
|
|
profitability: d.matters.map(function (x) {
|
|
|
|
|
return { matter_id: x.id, reference: x.reference, name: x.name, billed_minor: 0,
|
|
|
|
|
cost_of_time_minor: 0, unrecharged_expenses_minor: 0, margin_minor: 0,
|
|
|
|
|
margin_rate: null, incomplete: true };
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* ── admin ──────────────────────────────────────────────────────────────── */
|
|
|
|
|
on('GET', /^\/admin\/settings$/, function () { return load().settings; });
|
|
|
|
|
on('GET', /^\/admin\/email$/, function () {
|
|
|
|
|
return { configured: false, host: '', port: 587, sender: '', starttls: true, ssl: false,
|
|
|
|
|
detail: 'minimal', pending: 0 };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/admin\/integrations$/, function () {
|
|
|
|
|
return { galena_console_url: null, galena_casefile_parent_id: null, integrations: [
|
|
|
|
|
{ name: 'galena', title: 'Galena — akta spraw', phase: 1, status: 'off', configured: false,
|
|
|
|
|
detail: 'Sprawy są zakładane bez akt; konsola mówi o tym wprost.', probeable: true,
|
|
|
|
|
settings: 'GALENA_BASE_URL' },
|
|
|
|
|
{ name: 'email', title: 'Poczta (SMTP) — powiadomienia', phase: 1, status: 'off',
|
|
|
|
|
configured: false, detail: 'Powiadomienia zostają w aplikacji — czysty brak działania, nie błąd.',
|
|
|
|
|
probeable: true, settings: 'SMTP_HOST' },
|
|
|
|
|
{ name: 'registers', title: 'Rejestry — KRS i Biała lista VAT', phase: 1, status: 'ready',
|
|
|
|
|
configured: true, detail: 'Publiczne API, bez konfiguracji.', probeable: false, settings: '' },
|
|
|
|
|
{ name: 'edoreczenia', title: 'e-Doręczenia', phase: 2, status: 'planned', configured: false,
|
|
|
|
|
detail: 'Czeka na dostęp do środowiska testowego.', probeable: false, settings: '' },
|
|
|
|
|
{ name: 'ksef', title: 'KSeF 2.0 — faktury ustrukturyzowane', phase: 2, status: 'planned',
|
|
|
|
|
configured: false, detail: 'Czeka na dostęp do środowiska testowego.', probeable: false,
|
|
|
|
|
settings: '' },
|
|
|
|
|
{ name: 'portal-informacyjny', title: 'Portal Informacyjny sądów', phase: 4, status: 'planned',
|
|
|
|
|
configured: false, detail: 'Brak publicznego API.', probeable: false, settings: '' }
|
|
|
|
|
] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/admin\/backup$/, function () {
|
|
|
|
|
return { config: { enabled: false, interval: 'daily', retention: 7 }, backups: [],
|
|
|
|
|
intervals: ['daily', 'hourly', 'weekly'] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/templates$/, function () {
|
|
|
|
|
return { items: [],
|
|
|
|
|
known_placeholders: ['klient', 'klient_dop', 'sprawa', 'sygnatura', 'kancelaria'],
|
|
|
|
|
max_bytes: 5242880 };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/document-templates$/, function () {
|
|
|
|
|
return { templates: [
|
|
|
|
|
{ id: 'pelnomocnictwo', name: 'Pełnomocnictwo procesowe',
|
|
|
|
|
basis: 'art. 87 § 1 k.p.c. — pełnomocnikiem może być adwokat lub radca prawny',
|
|
|
|
|
needs_opponent: false },
|
|
|
|
|
{ id: 'wezwanie_do_zaplaty', name: 'Wezwanie do zapłaty',
|
|
|
|
|
basis: 'art. 455 k.c. — świadczenie bezterminowe staje się wymagalne po wezwaniu',
|
|
|
|
|
needs_opponent: true },
|
|
|
|
|
{ id: 'pozew_o_zaplate', name: 'Pozew o zapłatę',
|
|
|
|
|
basis: 'art. 187 k.p.c. — wymogi pozwu', needs_opponent: true }
|
|
|
|
|
] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/rate-cards$/, function () {
|
|
|
|
|
return [{ id: 'rc-1', name: 'Cennik kancelarii 2026', currency: CURRENCY, client_party_id: null,
|
|
|
|
|
client_name: null, scope: 'firm', valid_from: day(-250), valid_to: null, is_default: true,
|
|
|
|
|
note: null, entries: [
|
|
|
|
|
{ id: 'rce-1', user_id: null, seniority: 'partner', rate_minor: 65000, label: 'Partner' },
|
|
|
|
|
{ id: 'rce-2', user_id: null, seniority: 'associate', rate_minor: 45000, label: 'Adwokat' },
|
|
|
|
|
{ id: 'rce-3', user_id: null, seniority: 'trainee', rate_minor: 35000, label: 'Aplikant' }
|
|
|
|
|
] }];
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/lawyer-profiles$/, function () {
|
|
|
|
|
var seniority = ['partner', 'associate', 'trainee'], cost = [28000, 18000, 12000];
|
|
|
|
|
return load().users.map(function (u, i) {
|
|
|
|
|
return { user_id: u.id, name: u.full_name, seniority: seniority[i] || 'other',
|
|
|
|
|
bar_number: 'WAW/Adw/' + (1000 + i),
|
|
|
|
|
bar_chamber: 'Okręgowa Rada Adwokacka w Warszawie',
|
|
|
|
|
oc_policy_number: 'OC/2026/' + (500 + i), oc_valid_to: day(200),
|
|
|
|
|
cost_rate_minor: cost[i] || null };
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/aml\/factors$/, function () {
|
|
|
|
|
return { schedule_version: '2026-01-01',
|
|
|
|
|
verify_note: 'Zebrane z tekstu ustawy — przed użyciem sprawdź z adwokatem.',
|
|
|
|
|
factors: [
|
|
|
|
|
{ key: 'pep', points: 4, label: 'Osoba zajmująca eksponowane stanowisko polityczne (PEP)',
|
|
|
|
|
basis: 'art. 46 — wymaga środków wzmożonych i akceptacji kadry kierowniczej wyższego szczebla' },
|
|
|
|
|
{ key: 'high_risk_country', points: 4,
|
|
|
|
|
label: 'Powiązanie z państwem trzecim wysokiego ryzyka', basis: 'art. 44 ust. 2' },
|
|
|
|
|
{ key: 'cash_intensive', points: 2, label: 'Działalność gotówkowa', basis: 'art. 43 ust. 2' },
|
|
|
|
|
{ key: 'complex_structure', points: 2, label: 'Złożona struktura własnościowa',
|
|
|
|
|
basis: 'art. 43 ust. 2 pkt 3' },
|
|
|
|
|
{ key: 'long_standing_client', points: -1, label: 'Klient od lat, znany kancelarii',
|
|
|
|
|
basis: 'art. 43 ust. 3' }
|
|
|
|
|
] };
|
|
|
|
|
});
|
|
|
|
|
on('GET', /^\/fees\/options$/, function () {
|
|
|
|
|
return { proceedings: [{ key: 'civil', label: 'Cywilne — opłata stosunkowa' },
|
|
|
|
|
{ key: 'civil_flat', label: 'Cywilne — opłata stała' }],
|
|
|
|
|
stages: [{ key: 'first_instance', label: 'I instancja' }, { key: 'appeal', label: 'Apelacja' }],
|
|
|
|
|
max_multiplier: 6, schedule_version: '2026-01-01',
|
|
|
|
|
verify_note: 'Zebrane z tekstów ustaw — przed użyciem sprawdź z adwokatem.',
|
|
|
|
|
sources: ['u.k.s.c.', 'rozporządzenie o opłatach za czynności adwokackie'] };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* ── the few writes that make a demo feel real ───────────────────────────── */
|
|
|
|
|
on('POST', /^\/matters\/([^/]+)\/time$/, function (m, body) {
|
|
|
|
|
var d = load(), matter = byId(d.matters, m[1]);
|
|
|
|
|
if (!matter) return problem(404, 'Nie znaleziono.');
|
|
|
|
|
body = body || {};
|
|
|
|
|
var raw = parseDuration(body.duration);
|
|
|
|
|
if (!raw) return problem(400, 'Nie rozumiem tego czasu. Spróbuj 90, 1:30, 1,5h albo 90m.');
|
|
|
|
|
var minutes = Math.ceil(raw / 6) * 6; // 6-minute units, rounded UP
|
|
|
|
|
var rate = 65000;
|
|
|
|
|
var row = { id: 't-' + Date.now(), matter_id: matter.id, user_id: 'u-admin',
|
|
|
|
|
author: 'Maria Wiśniewska', matter_reference: matter.reference, matter_name: matter.name,
|
|
|
|
|
work_date: body.work_date || day(0), minutes: minutes,
|
|
|
|
|
hours: Math.round((minutes / 60) * 100) / 100, narrative: body.narrative || null,
|
|
|
|
|
activity_code: null, billable: body.billable !== false, rate_minor: rate,
|
|
|
|
|
write_off_minutes: 0,
|
|
|
|
|
amount_minor: Math.floor((minutes / 60) * rate), // the amount rounds DOWN, for the client
|
|
|
|
|
invoiced: false };
|
|
|
|
|
d.time.unshift(row);
|
|
|
|
|
save();
|
|
|
|
|
return row;
|
|
|
|
|
});
|
|
|
|
|
on('POST', /^\/deadlines\/([^/]+)\/confirm$/, function (m) {
|
|
|
|
|
var d = load(), x = byId(d.deadlines, m[1]);
|
|
|
|
|
if (!x) return problem(404, 'Nie znaleziono.');
|
|
|
|
|
if (x.created_by_id === 'u-admin' && (x.source === 'statute' || x.source === 'court')) {
|
|
|
|
|
return problem(409,
|
|
|
|
|
'Terminu sądowego nie potwierdza jego autor — kontrola dwóch par oczu wykonana przez jedną parę to teatr.');
|
|
|
|
|
}
|
|
|
|
|
x.confirmed_at = new Date().toISOString();
|
|
|
|
|
x.confirmed_by_id = 'u-admin';
|
|
|
|
|
save();
|
|
|
|
|
return withDeadlineState(x);
|
|
|
|
|
});
|
|
|
|
|
on('POST', /^\/correspondence\/([^/]+)\/assign$/, function (m, body) {
|
|
|
|
|
var d = load(), c = byId(d.correspondence, m[1]);
|
|
|
|
|
var matter = byId(d.matters, body && body.matter_id);
|
|
|
|
|
if (!c || !matter) return problem(404, 'Nie znaleziono.');
|
|
|
|
|
c.matter_id = matter.id;
|
|
|
|
|
c.matter_reference = matter.reference;
|
|
|
|
|
c.matter_name = matter.name;
|
|
|
|
|
c.status = 'assigned';
|
|
|
|
|
save();
|
|
|
|
|
return c;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* ── dispatch ───────────────────────────────────────────────────────────── */
|
|
|
|
|
function respond(value) {
|
|
|
|
|
var status = 200, payload = value;
|
|
|
|
|
if (value && value.body && value.status) { status = value.status; payload = value.body; }
|
|
|
|
|
return new Response(JSON.stringify(payload === undefined ? null : payload),
|
|
|
|
|
{ status: status, headers: { 'Content-Type': 'application/json' } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var realFetch = window.fetch.bind(window);
|
|
|
|
|
window.fetch = function (input, init) {
|
|
|
|
|
var href = typeof input === 'string' ? input : (input && input.url) || '';
|
|
|
|
|
if (href.indexOf(API) < 0) return realFetch(input, init);
|
|
|
|
|
var url = new URL(href, location.origin);
|
|
|
|
|
var path = url.pathname.slice(url.pathname.indexOf(API) + API.length) || '/';
|
|
|
|
|
var method = ((init && init.method) || (input && input.method) || 'GET').toUpperCase();
|
|
|
|
|
var body = null;
|
|
|
|
|
try { if (init && init.body) body = JSON.parse(init.body); } catch (e) { body = null; }
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < routes.length; i++) {
|
|
|
|
|
if (routes[i].method !== method) continue;
|
|
|
|
|
var match = routes[i].pattern.exec(path);
|
|
|
|
|
if (!match) continue;
|
|
|
|
|
if (path !== '/auth/login' && path !== '/auth/me' && !signedIn()) {
|
|
|
|
|
return Promise.resolve(respond(problem(401, 'Nie zalogowano.')));
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
return Promise.resolve(respond(routes[i].handler(match, body, url)));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return Promise.resolve(respond(problem(500, 'Demo: ' + e.message)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Anything unhandled is a write the demo will not pretend to have saved.
|
|
|
|
|
return Promise.resolve(respond(method === 'GET'
|
|
|
|
|
? problem(404, 'Ten ekran nie ma danych w wersji demonstracyjnej.')
|
|
|
|
|
: DEMO_WRITE));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ── an honest, visible label ────────────────────────────────────────────── */
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
var sub = document.querySelector('#login .lsub');
|
|
|
|
|
if (sub) sub.textContent = 'System zarządzania kancelarią — wersja demonstracyjna';
|
|
|
|
|
var email = document.getElementById('email');
|
|
|
|
|
var password = document.getElementById('password');
|
|
|
|
|
if (email && !email.value) email.value = 'demo@sygna.example';
|
|
|
|
|
if (password && !password.value) password.value = 'demo';
|
|
|
|
|
var form = document.getElementById('loginForm');
|
|
|
|
|
if (form && !document.getElementById('demoNote')) {
|
|
|
|
|
var note = document.createElement('div');
|
|
|
|
|
note.id = 'demoNote';
|
|
|
|
|
note.className = 'tiny faint';
|
|
|
|
|
note.style.marginTop = '12px';
|
|
|
|
|
note.style.textAlign = 'center';
|
|
|
|
|
note.textContent = 'Dane są wymyślone i zostają w tej przeglądarce. Dowolne hasło otwiera demo.';
|
|
|
|
|
form.appendChild(note);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.info('Sygna demo mock active — no backend. window.sygnaDemoReset() wipes the data.');
|
|
|
|
|
})();
|