Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be6809336a | ||
|
|
872d8f87c4 | ||
|
|
26827904db | ||
|
|
2cae35bd05 | ||
|
|
310a7c5e0d | ||
|
|
60be8331c1 | ||
|
|
8deec130dc | ||
|
|
bcb6d9df99 | ||
|
|
68abd5ccc8 | ||
|
|
cd553bbaea | ||
|
|
2f9a7c587c | ||
|
|
cfcab16149 | ||
|
|
1317c7297f | ||
|
|
3081b2a99b | ||
|
|
3e5a0813b0 | ||
|
|
65c11ba86e | ||
|
|
d440788d0d | ||
|
|
1c5c074fa1 | ||
|
|
d2d3292a73 | ||
|
|
a14500c7ab |
+74
-10
@@ -5,7 +5,7 @@ const archiver = require('archiver');
|
|||||||
const PDFDocument = require('pdfkit');
|
const PDFDocument = require('pdfkit');
|
||||||
const QRCode = require('qrcode');
|
const QRCode = require('qrcode');
|
||||||
const { pool, initializeDatabase } = require('./db');
|
const { pool, initializeDatabase } = require('./db');
|
||||||
const { normalizeInvoiceData } = require('./invoice-data');
|
const { isValidSignatureDataUrl, normalizeInvoiceData } = require('./invoice-data');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const sessionDurationMs = 1000 * 60 * 60 * 24 * 30;
|
const sessionDurationMs = 1000 * 60 * 60 * 24 * 30;
|
||||||
@@ -362,6 +362,43 @@ app.delete('/api/payment-presets/:id', requireAuth, async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/signature', requireAuth, async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const result = await pool.query('SELECT * FROM signature_profiles WHERE user_id = $1', [req.userId]);
|
||||||
|
res.json({ signature: result.rowCount ? result.rows[0].data_url : null });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.put('/api/signature', requireAuth, async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const dataUrl = req.body.dataUrl;
|
||||||
|
if (!isValidSignatureDataUrl(dataUrl)) {
|
||||||
|
res.status(400).json({ error: 'Podpis musí být platný obrázek JPG nebo PNG.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await pool.query(`
|
||||||
|
INSERT INTO signature_profiles (user_id, data_url)
|
||||||
|
VALUES ($1, $2)
|
||||||
|
ON CONFLICT (user_id) DO UPDATE SET data_url = EXCLUDED.data_url
|
||||||
|
RETURNING *
|
||||||
|
`, [req.userId, dataUrl]);
|
||||||
|
res.json({ signature: result.rows[0].data_url });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.delete('/api/signature', requireAuth, async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
await pool.query('DELETE FROM signature_profiles WHERE user_id = $1', [req.userId]);
|
||||||
|
res.status(204).end();
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const invoiceResponse = (row) => ({
|
const invoiceResponse = (row) => ({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
invoiceNumber: row.invoice_number,
|
invoiceNumber: row.invoice_number,
|
||||||
@@ -480,6 +517,20 @@ app.delete('/api/invoices', requireAuth, async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pdfText = (value) => String(value || 'Neuvedeno');
|
const pdfText = (value) => String(value || 'Neuvedeno');
|
||||||
|
const formatCzechDate = (value) => {
|
||||||
|
const date = new Date(`${value}T00:00:00`);
|
||||||
|
return Number.isNaN(date.getTime()) ? '' : date.toLocaleDateString('cs-CZ');
|
||||||
|
};
|
||||||
|
const toDateInputValue = (date) => date.toISOString().slice(0, 10);
|
||||||
|
const resolveIssueDate = (issueDate) => issueDate || toDateInputValue(new Date());
|
||||||
|
const resolveDueDate = (dueDate, issueDate) => {
|
||||||
|
if (dueDate) {
|
||||||
|
return dueDate;
|
||||||
|
}
|
||||||
|
const due = new Date(`${resolveIssueDate(issueDate)}T00:00:00`);
|
||||||
|
due.setDate(due.getDate() + 14);
|
||||||
|
return toDateInputValue(due);
|
||||||
|
};
|
||||||
const formatCzechNumber = (value) => Number(value || 0).toLocaleString('cs-CZ', {
|
const formatCzechNumber = (value) => Number(value || 0).toLocaleString('cs-CZ', {
|
||||||
minimumFractionDigits: 2,
|
minimumFractionDigits: 2,
|
||||||
maximumFractionDigits: 2
|
maximumFractionDigits: 2
|
||||||
@@ -554,13 +605,25 @@ const renderInvoicePdf = async (document, invoice) => {
|
|||||||
const partyWidth = (pageWidth - 24) / 2;
|
const partyWidth = (pageWidth - 24) / 2;
|
||||||
const customerX = document.page.margins.left + partyWidth + 24;
|
const customerX = document.page.margins.left + partyWidth + 24;
|
||||||
|
|
||||||
|
const issueDate = resolveIssueDate(data.issueDate);
|
||||||
|
const dueDate = resolveDueDate(data.dueDate, data.issueDate);
|
||||||
|
|
||||||
const headerY = document.y;
|
const headerY = document.y;
|
||||||
document.fillColor(navy).font(boldFont).fontSize(25).text('Faktura', document.page.margins.left, headerY);
|
document.fillColor(navy).font(boldFont).fontSize(25).text('Faktura', document.page.margins.left, headerY);
|
||||||
document.fillColor(navy).font(boldFont).fontSize(16).text(invoice.invoice_number, customerX, headerY, {
|
document.fillColor(navy).font(boldFont).fontSize(16).text(invoice.invoice_number, customerX, headerY, {
|
||||||
width: partyWidth,
|
width: partyWidth,
|
||||||
align: 'right'
|
align: 'right'
|
||||||
});
|
});
|
||||||
document.y = headerY + 40;
|
document.fillColor(bodyText).font(regularFont).fontSize(9)
|
||||||
|
.text(`Datum vystavení: ${formatCzechDate(issueDate)}`, customerX, headerY + 22, {
|
||||||
|
width: partyWidth,
|
||||||
|
align: 'right'
|
||||||
|
})
|
||||||
|
.text(`Datum splatnosti: ${formatCzechDate(dueDate)}`, customerX, headerY + 35, {
|
||||||
|
width: partyWidth,
|
||||||
|
align: 'right'
|
||||||
|
});
|
||||||
|
document.y = headerY + 52;
|
||||||
|
|
||||||
const partyTop = document.y;
|
const partyTop = document.y;
|
||||||
const drawParty = (x, title, profile, name) => {
|
const drawParty = (x, title, profile, name) => {
|
||||||
@@ -575,28 +638,29 @@ const renderInvoicePdf = async (document, invoice) => {
|
|||||||
|
|
||||||
const tableTop = document.y + 12;
|
const tableTop = document.y + 12;
|
||||||
const columns = [0, pageWidth * 0.52, pageWidth * 0.68, pageWidth * 0.82, pageWidth];
|
const columns = [0, pageWidth * 0.52, pageWidth * 0.68, pageWidth * 0.82, pageWidth];
|
||||||
const rowHeight = 25;
|
const headerRowHeight = 25;
|
||||||
document.rect(document.page.margins.left, tableTop, pageWidth, rowHeight).fill('#eef1f3');
|
const itemRowHeight = 22.5;
|
||||||
|
document.rect(document.page.margins.left, tableTop, pageWidth, headerRowHeight).fill('#eef1f3');
|
||||||
document.fillColor(navy).font(boldFont).fontSize(9);
|
document.fillColor(navy).font(boldFont).fontSize(9);
|
||||||
['Položka', 'Množství', 'MJ', 'Cena za MJ'].forEach((heading, index) => {
|
['Položka', 'Množství', 'MJ', 'Cena za MJ'].forEach((heading, index) => {
|
||||||
document.text(heading, document.page.margins.left + columns[index] + 6, tableTop + 8, {
|
document.text(heading, document.page.margins.left + columns[index] + 6, tableTop + 8, {
|
||||||
width: columns[index + 1] - columns[index] - 12
|
width: columns[index + 1] - columns[index] - 12
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
document.y = tableTop + rowHeight;
|
document.y = tableTop + headerRowHeight;
|
||||||
(data.items || []).forEach((item, index) => {
|
(data.items || []).forEach((item, index) => {
|
||||||
const rowTop = document.y;
|
const rowTop = document.y;
|
||||||
document.rect(document.page.margins.left, rowTop, pageWidth, rowHeight)
|
document.rect(document.page.margins.left, rowTop, pageWidth, itemRowHeight)
|
||||||
.fill(index % 2 ? lightBlue : warm);
|
.fill(index % 2 ? lightBlue : warm);
|
||||||
document.moveTo(document.page.margins.left, rowTop + rowHeight)
|
document.moveTo(document.page.margins.left, rowTop + itemRowHeight)
|
||||||
.lineTo(document.page.margins.left + pageWidth, rowTop + rowHeight)
|
.lineTo(document.page.margins.left + pageWidth, rowTop + itemRowHeight)
|
||||||
.strokeColor(line).lineWidth(0.7).stroke();
|
.strokeColor(line).lineWidth(0.7).stroke();
|
||||||
document.fillColor(bodyText).font(regularFont).fontSize(9);
|
document.fillColor(bodyText).font(regularFont).fontSize(9);
|
||||||
[pdfText(item.popis), formatCzechNumber(item.mnozstvi), pdfText(item.mernaJednotka), `${formatCzechNumber(item.cenaZaMj)} Kč`]
|
[pdfText(item.popis), formatCzechNumber(item.mnozstvi), pdfText(item.mernaJednotka), `${formatCzechNumber(item.cenaZaMj)} Kč`]
|
||||||
.forEach((value, columnIndex) => document.text(value, document.page.margins.left + columns[columnIndex] + 6, rowTop + 8, {
|
.forEach((value, columnIndex) => document.text(value, document.page.margins.left + columns[columnIndex] + 6, rowTop + 6, {
|
||||||
width: columns[columnIndex + 1] - columns[columnIndex] - 12
|
width: columns[columnIndex + 1] - columns[columnIndex] - 12
|
||||||
}));
|
}));
|
||||||
document.y = rowTop + rowHeight;
|
document.y = rowTop + itemRowHeight;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.y += 18;
|
document.y += 18;
|
||||||
|
|||||||
@@ -81,10 +81,30 @@ const initializeDatabase = () => {
|
|||||||
UNIQUE (user_id, name)
|
UNIQUE (user_id, name)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS signature_presets (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
data_url TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
UNIQUE (user_id, name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS signature_profiles (
|
||||||
|
user_id INTEGER PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
data_url TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
ALTER TABLE supplier_profiles ADD COLUMN IF NOT EXISTS nazev_spolecnosti TEXT NOT NULL DEFAULT '';
|
ALTER TABLE supplier_profiles ADD COLUMN IF NOT EXISTS nazev_spolecnosti TEXT NOT NULL DEFAULT '';
|
||||||
ALTER TABLE supplier_profiles ADD COLUMN IF NOT EXISTS typ_subjektu TEXT NOT NULL DEFAULT 'osoba';
|
ALTER TABLE supplier_profiles ADD COLUMN IF NOT EXISTS typ_subjektu TEXT NOT NULL DEFAULT 'osoba';
|
||||||
ALTER TABLE clients ADD COLUMN IF NOT EXISTS nazev_spolecnosti TEXT NOT NULL DEFAULT '';
|
ALTER TABLE clients ADD COLUMN IF NOT EXISTS nazev_spolecnosti TEXT NOT NULL DEFAULT '';
|
||||||
ALTER TABLE clients ADD COLUMN IF NOT EXISTS typ_subjektu TEXT NOT NULL DEFAULT 'osoba';
|
ALTER TABLE clients ADD COLUMN IF NOT EXISTS typ_subjektu TEXT NOT NULL DEFAULT 'osoba';
|
||||||
|
|
||||||
|
INSERT INTO signature_profiles (user_id, data_url)
|
||||||
|
SELECT DISTINCT ON (user_id) user_id, data_url
|
||||||
|
FROM signature_presets
|
||||||
|
ORDER BY user_id, created_at DESC
|
||||||
|
ON CONFLICT (user_id) DO NOTHING;
|
||||||
`).catch((error) => {
|
`).catch((error) => {
|
||||||
schemaPromise = undefined;
|
schemaPromise = undefined;
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
const SIGNATURE_DATA_URL_PATTERN = /^data:image\/(png|jpeg);base64,[A-Za-z0-9+/]+=*$/;
|
const SIGNATURE_DATA_URL_PATTERN = /^data:image\/(png|jpeg);base64,[A-Za-z0-9+/]+=*$/;
|
||||||
|
|
||||||
|
const isValidSignatureDataUrl = (value) => typeof value === 'string'
|
||||||
|
&& SIGNATURE_DATA_URL_PATTERN.test(value);
|
||||||
|
|
||||||
const normalizeInvoiceData = (data) => {
|
const normalizeInvoiceData = (data) => {
|
||||||
if (!data || !Array.isArray(data.items)) {
|
if (!data || !Array.isArray(data.items)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -18,7 +21,7 @@ const normalizeInvoiceData = (data) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signature = typeof data.signature === 'string' && SIGNATURE_DATA_URL_PATTERN.test(data.signature)
|
const signature = isValidSignatureDataUrl(data.signature)
|
||||||
? data.signature
|
? data.signature
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -32,4 +35,4 @@ const normalizeInvoiceData = (data) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { normalizeInvoiceData };
|
module.exports = { isValidSignatureDataUrl, normalizeInvoiceData };
|
||||||
|
|||||||
+20
-11
@@ -9,9 +9,14 @@
|
|||||||
<body>
|
<body>
|
||||||
<section id="auth-screen" aria-labelledby="auth-title">
|
<section id="auth-screen" aria-labelledby="auth-title">
|
||||||
<div class="auth-card">
|
<div class="auth-card">
|
||||||
<p class="eyebrow">FAKTUROVAČ</p>
|
<!--<p class="eyebrow">FAKTUROVAČ</p>-->
|
||||||
<h1 id="auth-title">Vaše faktury, bezpečně po ruce</h1>
|
<h1 id="auth-title">
|
||||||
<p class="auth-intro">Přihlaste se a mějte dodavatele i odběratele uložené ve svém účtu.</p>
|
<span>Fakturovač</span>
|
||||||
|
</h1>
|
||||||
|
<p class="auth-intro">
|
||||||
|
<span>Vaše faktury,</span>
|
||||||
|
<span>bezpečně po ruce.</span>
|
||||||
|
</p>
|
||||||
<form id="auth-form">
|
<form id="auth-form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="authEmail">E-mail</label>
|
<label for="authEmail">E-mail</label>
|
||||||
@@ -325,13 +330,13 @@
|
|||||||
|
|
||||||
<div class="due-date-group">
|
<div class="due-date-group">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dueDateOption">Datum splatnosti</label>
|
<label for="issueDate">Datum vystavení</label>
|
||||||
<select id="dueDateOption">
|
<input type="date" id="issueDate" name="issueDate" placeholder="Dnešní datum" />
|
||||||
<option value="14">14 dní</option>
|
</div>
|
||||||
<option value="30">30 dní</option>
|
<div class="form-group">
|
||||||
</select>
|
<label for="dueDate">Datum splatnosti</label>
|
||||||
|
<input type="date" id="dueDate" name="dueDate" placeholder="14 dní od vystavení" />
|
||||||
</div>
|
</div>
|
||||||
<output id="dueDateDisplay" class="due-date-display"></output>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -339,14 +344,18 @@
|
|||||||
<div class="form-group signature-group">
|
<div class="form-group signature-group">
|
||||||
<label for="signatureInput">Podpis (nepovinné)</label>
|
<label for="signatureInput">Podpis (nepovinné)</label>
|
||||||
<div id="signatureDropzone" class="signature-dropzone" tabindex="0" role="button" aria-label="Nahrát podpis kliknutím nebo přetažením souboru">
|
<div id="signatureDropzone" class="signature-dropzone" tabindex="0" role="button" aria-label="Nahrát podpis kliknutím nebo přetažením souboru">
|
||||||
<img id="signaturePreview" class="signature-preview" alt="Náhled podpisu" hidden />
|
<img id="signaturePreview" class="signature-preview" alt="Náhled podpisu" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" hidden />
|
||||||
<p id="signatureDropzoneText" class="signature-dropzone-text">Přetáhněte sem obrázek podpisu (420×210 px, JPG nebo PNG) nebo klikněte pro výběr souboru</p>
|
<p id="signatureDropzoneText" class="signature-dropzone-text">Přetáhněte sem obrázek podpisu (420×210 px, JPG nebo PNG) nebo klikněte pro výběr souboru</p>
|
||||||
<input type="file" id="signatureInput" accept="image/png,image/jpeg" hidden />
|
<input type="file" id="signatureInput" accept="image/png,image/jpeg" hidden />
|
||||||
</div>
|
</div>
|
||||||
<div class="signature-actions">
|
<div class="signature-actions">
|
||||||
<button type="button" id="removeSignatureButton" class="secondary-button" hidden>Odstranit podpis</button>
|
<button type="button" id="removeSignatureButton" class="secondary-button" hidden>Odstranit podpis</button>
|
||||||
</div>
|
</div>
|
||||||
<p id="signatureStatus" class="signature-status" role="status" aria-live="polite"></p>
|
<div class="saved-data-actions">
|
||||||
|
<button type="button" id="saveSignatureButton">Uložit podpis</button>
|
||||||
|
<button type="button" id="loadSignatureButton" class="secondary-button">Načíst uložený</button>
|
||||||
|
<span id="signatureStatus" class="signature-status" role="status" aria-live="polite"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+63
-14
@@ -46,8 +46,8 @@ const invoiceStartingNumberInput = document.getElementById("invoiceStartingNumbe
|
|||||||
const saveNumberingSettingsButton = document.getElementById("saveNumberingSettingsButton");
|
const saveNumberingSettingsButton = document.getElementById("saveNumberingSettingsButton");
|
||||||
const cancelNumberingSettingsButton = document.getElementById("cancelNumberingSettingsButton");
|
const cancelNumberingSettingsButton = document.getElementById("cancelNumberingSettingsButton");
|
||||||
const numberingSettingsStatus = document.getElementById("numberingSettingsStatus");
|
const numberingSettingsStatus = document.getElementById("numberingSettingsStatus");
|
||||||
const dueDateOption = document.getElementById("dueDateOption");
|
const issueDateInput = document.getElementById("issueDate");
|
||||||
const dueDateDisplay = document.getElementById("dueDateDisplay");
|
const dueDateInput = document.getElementById("dueDate");
|
||||||
const paymentPresetSelect = document.getElementById("paymentPresetSelect");
|
const paymentPresetSelect = document.getElementById("paymentPresetSelect");
|
||||||
const paymentPresetName = document.getElementById("paymentPresetName");
|
const paymentPresetName = document.getElementById("paymentPresetName");
|
||||||
const savePaymentPresetButton = document.getElementById("savePaymentPresetButton");
|
const savePaymentPresetButton = document.getElementById("savePaymentPresetButton");
|
||||||
@@ -57,6 +57,8 @@ const signaturePreview = document.getElementById("signaturePreview");
|
|||||||
const signatureDropzoneText = document.getElementById("signatureDropzoneText");
|
const signatureDropzoneText = document.getElementById("signatureDropzoneText");
|
||||||
const removeSignatureButton = document.getElementById("removeSignatureButton");
|
const removeSignatureButton = document.getElementById("removeSignatureButton");
|
||||||
const signatureStatus = document.getElementById("signatureStatus");
|
const signatureStatus = document.getElementById("signatureStatus");
|
||||||
|
const saveSignatureButton = document.getElementById("saveSignatureButton");
|
||||||
|
const loadSignatureButton = document.getElementById("loadSignatureButton");
|
||||||
const loadPaymentPresetButton = document.getElementById("loadPaymentPresetButton");
|
const loadPaymentPresetButton = document.getElementById("loadPaymentPresetButton");
|
||||||
const deletePaymentPresetButton = document.getElementById("deletePaymentPresetButton");
|
const deletePaymentPresetButton = document.getElementById("deletePaymentPresetButton");
|
||||||
|
|
||||||
@@ -99,12 +101,39 @@ const applySignaturePreview = (dataUrl) => {
|
|||||||
removeSignatureButton.hidden = false;
|
removeSignatureButton.hidden = false;
|
||||||
} else {
|
} else {
|
||||||
signaturePreview.hidden = true;
|
signaturePreview.hidden = true;
|
||||||
signaturePreview.src = "";
|
signaturePreview.removeAttribute("src");
|
||||||
signatureDropzoneText.hidden = false;
|
signatureDropzoneText.hidden = false;
|
||||||
removeSignatureButton.hidden = true;
|
removeSignatureButton.hidden = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveSignature = async () => {
|
||||||
|
if (!signatureDataUrl) {
|
||||||
|
setSignatureStatus("Nejprve nahrajte podpis.", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await apiRequest("/api/signature", {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify({ dataUrl: signatureDataUrl })
|
||||||
|
});
|
||||||
|
setSignatureStatus("Podpis byl uložen.");
|
||||||
|
} catch (error) {
|
||||||
|
setSignatureStatus(error.message, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadSignature = async () => {
|
||||||
|
const { signature } = await apiRequest("/api/signature");
|
||||||
|
if (signature) {
|
||||||
|
applySignaturePreview(signature);
|
||||||
|
setSignatureStatus("Uloženo na serveru");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
setSignatureStatus("Zatím není uložený podpis");
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
const readImageDimensions = (dataUrl) => new Promise((resolve, reject) => {
|
const readImageDimensions = (dataUrl) => new Promise((resolve, reject) => {
|
||||||
const image = new Image();
|
const image = new Image();
|
||||||
image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight });
|
image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight });
|
||||||
@@ -162,6 +191,15 @@ signatureInput.addEventListener("change", () => {
|
|||||||
handleSignatureFile(signatureInput.files[0]);
|
handleSignatureFile(signatureInput.files[0]);
|
||||||
signatureInput.value = "";
|
signatureInput.value = "";
|
||||||
});
|
});
|
||||||
|
saveSignatureButton.addEventListener("click", saveSignature);
|
||||||
|
loadSignatureButton.addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
await loadSignature();
|
||||||
|
setSignatureStatus("Podpis načten.");
|
||||||
|
} catch (error) {
|
||||||
|
setSignatureStatus(error.message, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
removeSignatureButton.addEventListener("click", (event) => {
|
removeSignatureButton.addEventListener("click", (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
applySignaturePreview(null);
|
applySignaturePreview(null);
|
||||||
@@ -207,17 +245,21 @@ const getClientLabel = (client) => [
|
|||||||
|
|
||||||
const formatCzechDate = (dateValue) => new Date(`${dateValue}T00:00:00`).toLocaleDateString("cs-CZ");
|
const formatCzechDate = (dateValue) => new Date(`${dateValue}T00:00:00`).toLocaleDateString("cs-CZ");
|
||||||
|
|
||||||
const getDueDays = () => Number.parseInt(dueDateOption.value, 10) || 14;
|
const toDateInputValue = (date) => [
|
||||||
|
date.getFullYear(),
|
||||||
|
String(date.getMonth() + 1).padStart(2, "0"),
|
||||||
|
String(date.getDate()).padStart(2, "0")
|
||||||
|
].join("-");
|
||||||
|
|
||||||
|
const getIssueDate = () => issueDateInput.value || toDateInputValue(new Date());
|
||||||
|
|
||||||
const getDueDate = () => {
|
const getDueDate = () => {
|
||||||
const dueDate = new Date();
|
if (dueDateInput.value) {
|
||||||
dueDate.setHours(0, 0, 0, 0);
|
return dueDateInput.value;
|
||||||
dueDate.setDate(dueDate.getDate() + getDueDays());
|
}
|
||||||
return dueDate.toISOString().slice(0, 10);
|
const dueDate = new Date(`${getIssueDate()}T00:00:00`);
|
||||||
};
|
dueDate.setDate(dueDate.getDate() + 14);
|
||||||
|
return toDateInputValue(dueDate);
|
||||||
const updateDueDate = () => {
|
|
||||||
dueDateDisplay.textContent = `Splatnost: ${formatCzechDate(getDueDate())}`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateClientTypeFields = () => {
|
const updateClientTypeFields = () => {
|
||||||
@@ -333,6 +375,8 @@ deletePaymentPresetButton.addEventListener("click", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const readInvoiceData = () => ({
|
const readInvoiceData = () => ({
|
||||||
|
issueDate: getIssueDate(),
|
||||||
|
dueDate: getDueDate(),
|
||||||
supplier: {
|
supplier: {
|
||||||
...readProfileFields("dodavatel"),
|
...readProfileFields("dodavatel"),
|
||||||
typSubjektu: supplierTypeSelect.value
|
typSubjektu: supplierTypeSelect.value
|
||||||
@@ -363,6 +407,8 @@ const clearInvoiceEditor = () => {
|
|||||||
currentInvoiceId = null;
|
currentInvoiceId = null;
|
||||||
invoiceNumberDisplay.textContent = "Nová faktura";
|
invoiceNumberDisplay.textContent = "Nová faktura";
|
||||||
invoiceSaveStatus.textContent = "";
|
invoiceSaveStatus.textContent = "";
|
||||||
|
issueDateInput.value = toDateInputValue(new Date());
|
||||||
|
dueDateInput.value = "";
|
||||||
writeProfileFields("odberatel", {});
|
writeProfileFields("odberatel", {});
|
||||||
clientSelect.value = "";
|
clientSelect.value = "";
|
||||||
clientTypeSelect.value = "osoba";
|
clientTypeSelect.value = "osoba";
|
||||||
@@ -384,6 +430,8 @@ const loadInvoiceIntoEditor = (invoice) => {
|
|||||||
currentInvoiceId = invoice.id;
|
currentInvoiceId = invoice.id;
|
||||||
invoiceNumberDisplay.textContent = invoice.invoiceNumber;
|
invoiceNumberDisplay.textContent = invoice.invoiceNumber;
|
||||||
invoiceSaveStatus.textContent = "";
|
invoiceSaveStatus.textContent = "";
|
||||||
|
issueDateInput.value = invoice.data.issueDate || "";
|
||||||
|
dueDateInput.value = invoice.data.dueDate || "";
|
||||||
writeProfileFields("dodavatel", invoice.data.supplier || {});
|
writeProfileFields("dodavatel", invoice.data.supplier || {});
|
||||||
supplierTypeSelect.value = invoice.data.supplier?.typSubjektu || "osoba";
|
supplierTypeSelect.value = invoice.data.supplier?.typSubjektu || "osoba";
|
||||||
updateSupplierTypeFields();
|
updateSupplierTypeFields();
|
||||||
@@ -435,8 +483,9 @@ const loadInvoices = async () => {
|
|||||||
renderInvoiceList();
|
renderInvoiceList();
|
||||||
};
|
};
|
||||||
|
|
||||||
const openNewInvoice = () => {
|
const openNewInvoice = async () => {
|
||||||
clearInvoiceEditor();
|
clearInvoiceEditor();
|
||||||
|
await loadSignature();
|
||||||
showInvoiceScreen("editor");
|
showInvoiceScreen("editor");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -623,7 +672,7 @@ deleteClientButton.addEventListener("click", async () => {
|
|||||||
const showInvoiceApp = async () => {
|
const showInvoiceApp = async () => {
|
||||||
authScreen.hidden = true;
|
authScreen.hidden = true;
|
||||||
document.getElementById("main-container").hidden = false;
|
document.getElementById("main-container").hidden = false;
|
||||||
await Promise.all([loadSupplier(), loadClients(), loadInvoices(), loadPaymentPresets(), loadNumberingSettings()]);
|
await Promise.all([loadSupplier(), loadClients(), loadInvoices(), loadPaymentPresets(), loadSignature(), loadNumberingSettings()]);
|
||||||
showInvoiceScreen("list");
|
showInvoiceScreen("list");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,19 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.auth-card {
|
.auth-card {
|
||||||
width: min(100%, 460px);
|
display: flex;
|
||||||
padding: clamp(1.75rem, 5vw, 3.5rem);
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
width: min(100%, 760px);
|
||||||
|
padding: clamp(1.75rem, 4vw, 3.25rem) clamp(1.75rem, 6vw, 4.5rem);
|
||||||
background: var(--paper);
|
background: var(--paper);
|
||||||
border: 1px solid rgba(24, 59, 86, 0.12);
|
border: 1px solid rgba(24, 59, 86, 0.12);
|
||||||
|
border-radius: 1rem;
|
||||||
box-shadow: var(--shadow);
|
box-shadow: var(--shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
.eyebrow {
|
.eyebrow {
|
||||||
|
align-self: flex-start;
|
||||||
margin: 0 0 0.75rem;
|
margin: 0 0 0.75rem;
|
||||||
color: var(--blue);
|
color: var(--blue);
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
@@ -52,12 +57,24 @@ body {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
color: var(--navy);
|
color: var(--navy);
|
||||||
font-family: Georgia, serif;
|
font-family: Georgia, serif;
|
||||||
font-size: clamp(2rem, 6vw, 3.4rem);
|
font-size: clamp(2rem, 5vw, 3.2rem);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
line-height: 1.05;
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-card h1 span {
|
||||||
|
display: block;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 420px) {
|
||||||
|
.auth-card h1 span {
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-intro {
|
.auth-intro {
|
||||||
|
max-width: 480px;
|
||||||
margin: 1.25rem 0 2rem;
|
margin: 1.25rem 0 2rem;
|
||||||
color: var(--muted-ink);
|
color: var(--muted-ink);
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
@@ -66,6 +83,7 @@ body {
|
|||||||
#auth-form {
|
#auth-form {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
|
width: min(100%, 420px);
|
||||||
}
|
}
|
||||||
|
|
||||||
#auth-form .form-group {
|
#auth-form .form-group {
|
||||||
@@ -74,18 +92,21 @@ body {
|
|||||||
|
|
||||||
#authSubmitButton {
|
#authSubmitButton {
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
|
min-height: 3rem;
|
||||||
padding: 0.8rem 1rem;
|
padding: 0.8rem 1rem;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: var(--navy);
|
background: var(--navy);
|
||||||
border: 0;
|
border: 0;
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.5rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
transition: background-color 160ms ease, transform 160ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
#authSubmitButton:hover:not(:disabled) {
|
#authSubmitButton:hover:not(:disabled) {
|
||||||
background: var(--blue);
|
background: var(--blue);
|
||||||
|
transform: translateY(-1px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-button {
|
.text-button {
|
||||||
@@ -99,6 +120,12 @@ body {
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-button:focus-visible,
|
||||||
|
#authSubmitButton:focus-visible {
|
||||||
|
outline: 3px solid rgba(43, 111, 143, 0.3);
|
||||||
|
outline-offset: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
.text-button:hover {
|
.text-button:hover {
|
||||||
color: var(--navy);
|
color: var(--navy);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { normalizeInvoiceData } = require('../src/invoice-data');
|
const { isValidSignatureDataUrl, normalizeInvoiceData } = require('../src/invoice-data');
|
||||||
|
|
||||||
describe('normalizeInvoiceData', () => {
|
describe('normalizeInvoiceData', () => {
|
||||||
test('calculates the total from validated line items', () => {
|
test('calculates the total from validated line items', () => {
|
||||||
@@ -49,4 +49,10 @@ describe('normalizeInvoiceData', () => {
|
|||||||
});
|
});
|
||||||
expect(withoutSignature.signature).toBeNull();
|
expect(withoutSignature.signature).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('validates only supported base64 signature image data URLs', () => {
|
||||||
|
expect(isValidSignatureDataUrl('data:image/jpeg;base64,aGVsbG8=')).toBe(true);
|
||||||
|
expect(isValidSignatureDataUrl('data:image/gif;base64,aGVsbG8=')).toBe(false);
|
||||||
|
expect(isValidSignatureDataUrl('data:image/png;base64,not valid')).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user