Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6eb743a1bf | ||
|
|
5882a957ad | ||
|
|
f4d2c30493 | ||
|
|
3848ab47df | ||
|
|
84657b9610 | ||
|
|
2bcf9a2f02 |
@@ -0,0 +1,85 @@
|
|||||||
|
name: CI/CD
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: app
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '22'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: app/package-lock.json
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: npm test
|
||||||
|
|
||||||
|
build-and-push:
|
||||||
|
name: Build and push image (dev)
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract image metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=dev
|
||||||
|
type=sha,prefix=dev-
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./app
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Summary
|
||||||
|
run: |
|
||||||
|
echo "### Dev image published :rocket:" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo '```' >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "${{ steps.meta.outputs.tags }}" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo '```' >> "$GITHUB_STEP_SUMMARY"
|
||||||
@@ -20,3 +20,31 @@ docker compose up --build
|
|||||||
Then open `http://localhost:3001` and create an account. PostgreSQL data is kept
|
Then open `http://localhost:3001` and create an account. PostgreSQL data is kept
|
||||||
in the `postgres-data` Docker volume, so it survives app and container restarts.
|
in the `postgres-data` Docker volume, so it survives app and container restarts.
|
||||||
To remove the database as well, run `docker compose down -v`.
|
To remove the database as well, run `docker compose down -v`.
|
||||||
|
|
||||||
|
## CI/CD
|
||||||
|
|
||||||
|
On every push to `main`, GitHub Actions (`.github/workflows/ci-cd.yml`) runs the
|
||||||
|
test suite, then builds and publishes a dev image to the GitHub Container
|
||||||
|
Registry:
|
||||||
|
|
||||||
|
```
|
||||||
|
ghcr.io/odweta/fakturovac:dev
|
||||||
|
```
|
||||||
|
|
||||||
|
A commit-pinned tag (`ghcr.io/odweta/fakturovac:dev-<short-sha>`) is published
|
||||||
|
alongside `:dev` for traceability. Pull requests only run the test job.
|
||||||
|
|
||||||
|
To pull and run the latest dev image in a testing environment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker login ghcr.io -u <your-github-username> # only needed if the package is private
|
||||||
|
docker pull ghcr.io/odweta/fakturovac:dev
|
||||||
|
docker run -d -p 3001:3001 \
|
||||||
|
-e DATABASE_URL=postgres://fakturovac:fakturovac@<db-host>:5432/fakturovac \
|
||||||
|
-e NODE_ENV=production \
|
||||||
|
ghcr.io/odweta/fakturovac:dev
|
||||||
|
```
|
||||||
|
|
||||||
|
The package's visibility (public/private) is managed under the repository's
|
||||||
|
**Packages** settings on GitHub; no extra secrets are required since the
|
||||||
|
workflow authenticates with the built-in `GITHUB_TOKEN`.
|
||||||
+37
-2
@@ -227,6 +227,33 @@ app.put('/api/supplier', requireAuth, async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/settings', requireAuth, async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const result = await pool.query('SELECT invoice_starting_number FROM user_settings WHERE user_id = $1', [req.userId]);
|
||||||
|
res.json({ settings: { invoiceStartingNumber: result.rowCount ? result.rows[0].invoice_starting_number : 1 } });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.put('/api/settings', requireAuth, async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const invoiceStartingNumber = Number.parseInt(req.body.invoiceStartingNumber, 10);
|
||||||
|
if (!Number.isInteger(invoiceStartingNumber) || invoiceStartingNumber < 1) {
|
||||||
|
res.status(400).json({ error: 'Počáteční číslo faktury musí být kladné celé číslo.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await pool.query(`
|
||||||
|
INSERT INTO user_settings (user_id, invoice_starting_number) VALUES ($1, $2)
|
||||||
|
ON CONFLICT (user_id) DO UPDATE SET invoice_starting_number = EXCLUDED.invoice_starting_number
|
||||||
|
RETURNING invoice_starting_number
|
||||||
|
`, [req.userId, invoiceStartingNumber]);
|
||||||
|
res.json({ settings: { invoiceStartingNumber: result.rows[0].invoice_starting_number } });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/api/clients', requireAuth, async (req, res, next) => {
|
app.get('/api/clients', requireAuth, async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const result = await pool.query('SELECT * FROM clients WHERE user_id = $1 ORDER BY created_at, id', [req.userId]);
|
const result = await pool.query('SELECT * FROM clients WHERE user_id = $1 ORDER BY created_at, id', [req.userId]);
|
||||||
@@ -376,13 +403,21 @@ app.post('/api/invoices', requireAuth, async (req, res, next) => {
|
|||||||
|
|
||||||
const invoiceYear = new Date().getFullYear();
|
const invoiceYear = new Date().getFullYear();
|
||||||
await client.query('BEGIN');
|
await client.query('BEGIN');
|
||||||
|
const settingsResult = await client.query(
|
||||||
|
'SELECT invoice_starting_number FROM user_settings WHERE user_id = $1',
|
||||||
|
[req.userId]
|
||||||
|
);
|
||||||
|
const invoiceStartingNumber = settingsResult.rowCount ? settingsResult.rows[0].invoice_starting_number : 1;
|
||||||
await client.query(`
|
await client.query(`
|
||||||
INSERT INTO invoice_counters (user_id, invoice_year, last_number)
|
INSERT INTO invoice_counters (user_id, invoice_year, last_number)
|
||||||
SELECT $1, $2, COALESCE(MAX((substring(invoice_number FROM '^F-[0-9]{4}-([0-9]+)$'))::integer), 0)
|
SELECT $1, $2, GREATEST(
|
||||||
|
COALESCE(MAX((substring(invoice_number FROM '^F-[0-9]{4}-([0-9]+)$'))::integer), 0),
|
||||||
|
$4 - 1
|
||||||
|
)
|
||||||
FROM invoices
|
FROM invoices
|
||||||
WHERE user_id = $1 AND invoice_number LIKE $3
|
WHERE user_id = $1 AND invoice_number LIKE $3
|
||||||
ON CONFLICT (user_id, invoice_year) DO NOTHING
|
ON CONFLICT (user_id, invoice_year) DO NOTHING
|
||||||
`, [req.userId, invoiceYear, `F-${invoiceYear}-%`]);
|
`, [req.userId, invoiceYear, `F-${invoiceYear}-%`, invoiceStartingNumber]);
|
||||||
const counterResult = await client.query(`
|
const counterResult = await client.query(`
|
||||||
UPDATE invoice_counters
|
UPDATE invoice_counters
|
||||||
SET last_number = last_number + 1
|
SET last_number = last_number + 1
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ const initializeDatabase = () => {
|
|||||||
PRIMARY KEY (user_id, invoice_year)
|
PRIMARY KEY (user_id, invoice_year)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_settings (
|
||||||
|
user_id INTEGER PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
invoice_starting_number INTEGER NOT NULL DEFAULT 1 CHECK (invoice_starting_number > 0)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS payment_presets (
|
CREATE TABLE IF NOT EXISTS payment_presets (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
|||||||
@@ -65,11 +65,28 @@
|
|||||||
<summary><span class="account-mark" aria-hidden="true"></span><span id="navEmail" class="signed-in-email"></span></summary>
|
<summary><span class="account-mark" aria-hidden="true"></span><span id="navEmail" class="signed-in-email"></span></summary>
|
||||||
<div class="nav-menu-content account-menu-content">
|
<div class="nav-menu-content account-menu-content">
|
||||||
<button type="button" id="passwordButton" class="text-button">Změnit heslo</button>
|
<button type="button" id="passwordButton" class="text-button">Změnit heslo</button>
|
||||||
|
<button type="button" id="numberingSettingsButton" class="text-button">Číslování faktur</button>
|
||||||
<button type="button" id="logoutButton" class="text-button">Odhlásit se</button>
|
<button type="button" id="logoutButton" class="text-button">Odhlásit se</button>
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
<section id="numberingSettingsPanel" class="password-panel" hidden>
|
||||||
|
<div id="numberingSettingsForm">
|
||||||
|
<h3>Číslování faktur</h3>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="invoiceStartingNumber">Počáteční číslo faktury (pro aktuální rok)</label>
|
||||||
|
<input id="invoiceStartingNumber" type="number" min="1" step="1" placeholder="1" />
|
||||||
|
<p class="field-hint">Určuje, od jakého čísla se budou generovat nové faktury v roce, kdy zatím žádnou nemáte. Výchozí hodnota je 1.</p>
|
||||||
|
</div>
|
||||||
|
<div class="saved-data-actions">
|
||||||
|
<button type="button" id="saveNumberingSettingsButton">Uložit</button>
|
||||||
|
<button type="button" id="cancelNumberingSettingsButton" class="secondary-button">Zrušit</button>
|
||||||
|
<span id="numberingSettingsStatus" role="status" aria-live="polite"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section id="passwordPanel" class="password-panel" hidden>
|
<section id="passwordPanel" class="password-panel" hidden>
|
||||||
<div id="passwordForm">
|
<div id="passwordForm">
|
||||||
<h3>Změnit heslo</h3>
|
<h3>Změnit heslo</h3>
|
||||||
@@ -312,13 +329,8 @@
|
|||||||
<select id="dueDateOption">
|
<select id="dueDateOption">
|
||||||
<option value="14">14 dní</option>
|
<option value="14">14 dní</option>
|
||||||
<option value="30">30 dní</option>
|
<option value="30">30 dní</option>
|
||||||
<option value="custom">Vlastní počet dní</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group custom-due-days-group" hidden>
|
|
||||||
<label for="customDueDays">Počet dní</label>
|
|
||||||
<input id="customDueDays" type="number" min="1" step="1" value="14" />
|
|
||||||
</div>
|
|
||||||
<output id="dueDateDisplay" class="due-date-display"></output>
|
<output id="dueDateDisplay" class="due-date-display"></output>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -40,9 +40,13 @@ const passwordForm = document.getElementById("passwordForm");
|
|||||||
const savePasswordButton = document.getElementById("savePasswordButton");
|
const savePasswordButton = document.getElementById("savePasswordButton");
|
||||||
const cancelPasswordButton = document.getElementById("cancelPasswordButton");
|
const cancelPasswordButton = document.getElementById("cancelPasswordButton");
|
||||||
const passwordStatus = document.getElementById("passwordStatus");
|
const passwordStatus = document.getElementById("passwordStatus");
|
||||||
|
const numberingSettingsButton = document.getElementById("numberingSettingsButton");
|
||||||
|
const numberingSettingsPanel = document.getElementById("numberingSettingsPanel");
|
||||||
|
const invoiceStartingNumberInput = document.getElementById("invoiceStartingNumber");
|
||||||
|
const saveNumberingSettingsButton = document.getElementById("saveNumberingSettingsButton");
|
||||||
|
const cancelNumberingSettingsButton = document.getElementById("cancelNumberingSettingsButton");
|
||||||
|
const numberingSettingsStatus = document.getElementById("numberingSettingsStatus");
|
||||||
const dueDateOption = document.getElementById("dueDateOption");
|
const dueDateOption = document.getElementById("dueDateOption");
|
||||||
const customDueDays = document.getElementById("customDueDays");
|
|
||||||
const customDueDaysGroup = document.querySelector(".custom-due-days-group");
|
|
||||||
const dueDateDisplay = document.getElementById("dueDateDisplay");
|
const dueDateDisplay = document.getElementById("dueDateDisplay");
|
||||||
const paymentPresetSelect = document.getElementById("paymentPresetSelect");
|
const paymentPresetSelect = document.getElementById("paymentPresetSelect");
|
||||||
const paymentPresetName = document.getElementById("paymentPresetName");
|
const paymentPresetName = document.getElementById("paymentPresetName");
|
||||||
@@ -110,9 +114,7 @@ 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 = () => dueDateOption.value === "custom"
|
const getDueDays = () => Number.parseInt(dueDateOption.value, 10) || 14;
|
||||||
? Math.max(1, Number.parseInt(customDueDays.value, 10) || 14)
|
|
||||||
: Number.parseInt(dueDateOption.value, 10);
|
|
||||||
|
|
||||||
const getDueDate = () => {
|
const getDueDate = () => {
|
||||||
const dueDate = new Date();
|
const dueDate = new Date();
|
||||||
@@ -122,7 +124,6 @@ const getDueDate = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateDueDate = () => {
|
const updateDueDate = () => {
|
||||||
customDueDaysGroup.hidden = dueDateOption.value !== "custom";
|
|
||||||
dueDateDisplay.textContent = `Splatnost: ${formatCzechDate(getDueDate())}`;
|
dueDateDisplay.textContent = `Splatnost: ${formatCzechDate(getDueDate())}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -524,10 +525,27 @@ 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()]);
|
await Promise.all([loadSupplier(), loadClients(), loadInvoices(), loadPaymentPresets(), loadNumberingSettings()]);
|
||||||
showInvoiceScreen("list");
|
showInvoiceScreen("list");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadNumberingSettings = async () => {
|
||||||
|
try {
|
||||||
|
const { settings } = await apiRequest("/api/settings");
|
||||||
|
invoiceStartingNumberInput.value = settings.invoiceStartingNumber;
|
||||||
|
invoiceStartingNumberInput.placeholder = String(settings.invoiceStartingNumber);
|
||||||
|
} catch {
|
||||||
|
// Keep the placeholder default if settings cannot be loaded.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const showNumberingSettingsPanel = (visible) => {
|
||||||
|
numberingSettingsPanel.hidden = !visible;
|
||||||
|
if (!visible) {
|
||||||
|
numberingSettingsStatus.textContent = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const showPasswordPanel = (visible) => {
|
const showPasswordPanel = (visible) => {
|
||||||
passwordPanel.hidden = !visible;
|
passwordPanel.hidden = !visible;
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
@@ -580,6 +598,24 @@ logoutButton.addEventListener("click", async () => {
|
|||||||
passwordButton.addEventListener("click", () => showPasswordPanel(passwordPanel.hidden));
|
passwordButton.addEventListener("click", () => showPasswordPanel(passwordPanel.hidden));
|
||||||
cancelPasswordButton.addEventListener("click", () => showPasswordPanel(false));
|
cancelPasswordButton.addEventListener("click", () => showPasswordPanel(false));
|
||||||
|
|
||||||
|
numberingSettingsButton.addEventListener("click", () => showNumberingSettingsPanel(numberingSettingsPanel.hidden));
|
||||||
|
cancelNumberingSettingsButton.addEventListener("click", () => showNumberingSettingsPanel(false));
|
||||||
|
|
||||||
|
saveNumberingSettingsButton.addEventListener("click", async () => {
|
||||||
|
numberingSettingsStatus.textContent = "";
|
||||||
|
const invoiceStartingNumber = Number.parseInt(invoiceStartingNumberInput.value, 10) || 1;
|
||||||
|
try {
|
||||||
|
const { settings } = await apiRequest("/api/settings", {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify({ invoiceStartingNumber })
|
||||||
|
});
|
||||||
|
invoiceStartingNumberInput.value = settings.invoiceStartingNumber;
|
||||||
|
numberingSettingsStatus.textContent = "Uloženo";
|
||||||
|
} catch (error) {
|
||||||
|
numberingSettingsStatus.textContent = error.message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
savePasswordButton.addEventListener("click", async () => {
|
savePasswordButton.addEventListener("click", async () => {
|
||||||
passwordStatus.textContent = "";
|
passwordStatus.textContent = "";
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -595,6 +595,12 @@ body {
|
|||||||
outline-offset: 1px;
|
outline-offset: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-hint {
|
||||||
|
margin: 0.35rem 0 0;
|
||||||
|
color: var(--muted-ink);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
.form-group output {
|
.form-group output {
|
||||||
min-height: 1.5rem;
|
min-height: 1.5rem;
|
||||||
padding: 0.25rem 0;
|
padding: 0.25rem 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user