fix: restore archive downloads and task report context
Some checks failed
ERP CI/CD Pipeline / test (push) Has been cancelled
ERP CI/CD Pipeline / Deploy (server git pull + compose) (push) Has been cancelled

Restore the monthly fleet archive task and routes so generated ZIP downloads work again. Also populate service report DOCX headers from the selected task/work-order context and cover the direct and archived export flows with regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
mariomitte
2026-08-06 20:37:30 +02:00
parent ed71bf500f
commit 925cd25d98
5 changed files with 196 additions and 207 deletions

View File

@@ -1,10 +1,8 @@
import { useEffect, useMemo, useState } from 'preact/hooks';
import { getStatusLabel } from '../../stores/taskStore';
import {
downloadMonthlyServiceTasksArchive,
downloadMonthlyCostsReport,
downloadMonthlyServiserReport,
downloadMonthlyWorkOrdersArchive,
fetchMonthlyCostInvoices,
fetchMonthlyServicerEntries,
upsertMonthlyServicerEntry,
@@ -91,9 +89,6 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
const [manualEntryDraft, setManualEntryDraft] = useState(null);
const [manualEntryError, setManualEntryError] = useState('');
const [savingManualEntry, setSavingManualEntry] = useState(false);
const [bulkDownloadOpen, setBulkDownloadOpen] = useState(false);
const [downloadingAllTasks, setDownloadingAllTasks] = useState(false);
const [downloadingAllWorkOrders, setDownloadingAllWorkOrders] = useState(false);
const reportOpen = reportType !== null;
const panelWidth = reportOpen ? 920 : 300;
@@ -346,9 +341,6 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
function toggleReport(type) {
setReportType((prev) => (prev === type ? null : type));
setManualEntryTarget(null);
if (type !== 'servicer') {
setBulkDownloadOpen(false);
}
}
async function handleDownload() {
@@ -365,28 +357,6 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
}
}
async function handleDownloadAllTasksArchive() {
if (downloadingAllTasks) return;
setDownloadingAllTasks(true);
try {
await downloadMonthlyServiceTasksArchive(viewYear, viewMonth + 1);
setBulkDownloadOpen(false);
} finally {
setDownloadingAllTasks(false);
}
}
async function handleDownloadAllWorkOrdersArchive() {
if (downloadingAllWorkOrders) return;
setDownloadingAllWorkOrders(true);
try {
await downloadMonthlyWorkOrdersArchive(viewYear, viewMonth + 1);
setBulkDownloadOpen(false);
} finally {
setDownloadingAllWorkOrders(false);
}
}
function handleServicerRowClick(row) {
if (!row?.clickable) return;
setManualEntryTarget(row);
@@ -661,17 +631,8 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
disabled={downloading}
className="rounded-md bg-indigo-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-indigo-700 disabled:opacity-60"
>
{downloading ? 'Preuzimanje...' : reportType === 'servicer' ? 'Preuzmi mjesečni izvještaj' : 'Preuzmi DOCX'}
{downloading ? 'Preuzimanje...' : 'Preuzmi DOCX'}
</button>
{reportType === 'servicer' && (
<button
type="button"
onClick={() => setBulkDownloadOpen(true)}
className="ml-2 rounded-md border border-border-hairline px-3 py-1.5 text-xs font-medium text-text-main hover:bg-canvas-deep"
>
Preuzmi sve
</button>
)}
</div>
<p className="border-b border-border-hairline bg-canvas-deep px-4 py-1.5 text-[11px] text-text-muted">
@@ -864,48 +825,6 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
</div>
</div>
)}
{bulkDownloadOpen && reportType === 'servicer' && (
<div className="absolute inset-0 z-20 flex items-center justify-center bg-black/30 px-4">
<div className="w-full max-w-md rounded-xl border border-border-hairline bg-canvas-elevated p-4 shadow-2xl">
<div className="flex items-center justify-between gap-3">
<div>
<h3 className="text-sm font-semibold text-text-main">Preuzmi sve</h3>
<p className="mt-1 text-xs text-text-muted">
{MONTH_NAMES[viewMonth]} {viewYear}
</p>
</div>
<button
type="button"
onClick={() => setBulkDownloadOpen(false)}
className="rounded p-1 text-text-muted hover:bg-canvas-deep"
aria-label="Zatvori"
>
x
</button>
</div>
<div className="mt-4 grid gap-2">
<button
type="button"
disabled={downloadingAllTasks || downloadingAllWorkOrders}
onClick={handleDownloadAllTasksArchive}
className="rounded-lg border border-border-hairline px-3 py-2 text-left text-sm hover:bg-indigo-50 disabled:opacity-60"
>
{downloadingAllTasks ? 'Generiranje...' : 'Preuzmi sve pojedinačne servisne taskove (SN)'}
</button>
<button
type="button"
disabled={downloadingAllTasks || downloadingAllWorkOrders}
onClick={handleDownloadAllWorkOrdersArchive}
className="rounded-lg border border-border-hairline px-3 py-2 text-left text-sm hover:bg-indigo-50 disabled:opacity-60"
>
{downloadingAllWorkOrders ? 'Generiranje...' : 'Preuzmi sve putne naloge + račune (PN)'}
</button>
</div>
</div>
</div>
)}
</div>
)}
</LeftSlideDrawer>