UI changes for collapsing and header bcg

This commit is contained in:
marijo 2026-06-09 11:35:21 +00:00
parent 71aeb691df
commit 996acdef92
4 changed files with 106 additions and 48 deletions

20
api.php
View file

@ -117,11 +117,17 @@ function migrate(PDO $db): void
source TEXT NOT NULL DEFAULT 'auto',
status TEXT NOT NULL DEFAULT 'planned',
allow_unpaid INTEGER NOT NULL DEFAULT 0,
non_working_days REAL NOT NULL DEFAULT 0,
note TEXT NOT NULL DEFAULT '',
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
)");
$columns = array_column($db->query('PRAGMA table_info(entries)')->fetchAll(), 'name');
if (!in_array('non_working_days', $columns, true)) {
$db->exec('ALTER TABLE entries ADD COLUMN non_working_days REAL NOT NULL DEFAULT 0');
}
$db->exec("CREATE TABLE IF NOT EXISTS monthly_corrections (
year INTEGER NOT NULL,
month INTEGER NOT NULL,
@ -293,7 +299,7 @@ function save_flex_override(PDO $db, int $year, int $month, mixed $value): void
function get_entries(PDO $db): array
{
return $db->query('SELECT id, title, start_date, end_date, source, status, allow_unpaid, note
return $db->query('SELECT id, title, start_date, end_date, source, status, allow_unpaid, non_working_days, note
FROM entries ORDER BY start_date, end_date, id')->fetchAll();
}
@ -305,7 +311,8 @@ function save_entry(PDO $db, array $entry, ?int $id = null): int
$source = (string)($entry['source'] ?? 'auto');
$status = (string)($entry['status'] ?? 'planned');
$allowUnpaid = !empty($entry['allow_unpaid']) ? 1 : 0;
$note = trim((string)($entry['note'] ?? ''));
$nonWorkingDays = (float)($entry['non_working_days'] ?? 0);
$note = trim((string)($entry['note'] ?? ''));
if ($title === '') {
fail('Title is required', 400);
@ -319,6 +326,9 @@ function save_entry(PDO $db, array $entry, ?int $id = null): int
if (!in_array($source, ['auto', 'vacation', 'feriefridag', 'flex', 'unpaid'], true)) {
fail('Invalid source', 400);
}
if ($nonWorkingDays < 0 || fmod($nonWorkingDays * 2, 1.0) !== 0.0) {
fail('Additional non-working days must be in steps of 0.5', 400);
}
if ($status === 'confirmed') {
$status = 'approved';
}
@ -333,13 +343,14 @@ function save_entry(PDO $db, array $entry, ?int $id = null): int
':source' => $source,
':status' => $status,
':allow_unpaid' => $allowUnpaid,
':non_working_days' => $nonWorkingDays,
':note' => $note,
];
if ($id === null) {
$stmt = $db->prepare('INSERT INTO entries
(title, start_date, end_date, source, status, allow_unpaid, note)
VALUES (:title, :start_date, :end_date, :source, :status, :allow_unpaid, :note)');
(title, start_date, end_date, source, status, allow_unpaid, non_working_days, note)
VALUES (:title, :start_date, :end_date, :source, :status, :allow_unpaid, :non_working_days, :note)');
$stmt->execute($params);
return (int)$db->lastInsertId();
}
@ -352,6 +363,7 @@ function save_entry(PDO $db, array $entry, ?int $id = null): int
source = :source,
status = :status,
allow_unpaid = :allow_unpaid,
non_working_days = :non_working_days,
note = :note,
updated_at = CURRENT_TIMESTAMP
WHERE id = :id');