Fix monthly PDF export to include only the selected month

The month dropdown carried only the month (e.g. "07") while the year was
a separate select; the export required month AND year, so a month-only
selection fell through to exporting every application. Encode the year in
the month option value ("YYYY-MM"), parse it client-side to always send
the exact month+year, and harden /api/export so a month can never fall
through to "export all".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 16:39:46 +02:00
co-authored by Claude Opus 4.8
parent 0b44f61410
commit 05357acddb
3 changed files with 22 additions and 5 deletions
+15 -3
View File
@@ -251,9 +251,21 @@ function openPdfExportModal() {
function generatePDF(event) { function generatePDF(event) {
event.preventDefault(); event.preventDefault();
const month = document.getElementById('pdfMonth').value; // The month option encodes its year ("YYYY-MM"), so a chosen month always
const year = document.getElementById('pdfYear').value; // exports exactly that month of that year, regardless of the year select.
const monthRaw = document.getElementById('pdfMonth').value;
let year = document.getElementById('pdfYear').value;
let month = '';
if (monthRaw) {
if (monthRaw.indexOf('-') !== -1) {
const parts = monthRaw.split('-');
year = parts[0];
month = parts[1];
} else {
month = monthRaw;
}
}
// Fetch data for PDF // Fetch data for PDF
let url = '/api/export?'; let url = '/api/export?';
const params = []; const params = [];
+5
View File
@@ -849,6 +849,11 @@ initializeDatabase().then(() => {
if (month && year) { if (month && year) {
query = 'SELECT * FROM bewerbungen WHERE strftime("%m", datum) = ? AND strftime("%Y", datum) = ? ORDER BY datum DESC'; query = 'SELECT * FROM bewerbungen WHERE strftime("%m", datum) = ? AND strftime("%Y", datum) = ? ORDER BY datum DESC';
params.push(month.padStart(2, '0'), year); params.push(month.padStart(2, '0'), year);
} else if (month) {
// A month without a year must still restrict the export to that month —
// never fall through to exporting every application.
query = 'SELECT * FROM bewerbungen WHERE strftime("%m", datum) = ? ORDER BY datum DESC';
params.push(month.padStart(2, '0'));
} else if (year) { } else if (year) {
query = 'SELECT * FROM bewerbungen WHERE strftime("%Y", datum) = ? ORDER BY datum DESC'; query = 'SELECT * FROM bewerbungen WHERE strftime("%Y", datum) = ? ORDER BY datum DESC';
params.push(year); params.push(year);
+2 -2
View File
@@ -568,11 +568,11 @@
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-800 dark:text-white"> class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-800 dark:text-white">
<option value="">-- Alle Monate --</option> <option value="">-- Alle Monate --</option>
<% availableMonths.forEach(m => { %> <% availableMonths.forEach(m => { %>
<option value="<%= m.month %>"><%= m.month %> - <%= m.year %></option> <option value="<%= m.year %>-<%= m.month %>"><%= m.month %> - <%= m.year %></option>
<% }); %> <% }); %>
</select> </select>
</div> </div>
<div> <div>
<label for="pdfYear" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"> <label for="pdfYear" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Jahr Jahr