feat: update service report exports and calendar bulk downloads
Align service-record PDF/DOCX generation with task-level data and naming. - Use Task.service_report_note as report note source - Use Task.scheduled_date for service-record dates - Rename per-task exports to MT...SN... format - Add monthly SN/PN ZIP download endpoints with 7-day retention - Add calendar 'Preuzmi sve' modal with both bulk download actions - Prefill work-hours day/date from scheduled_date for empty tables - Remove duplicate note table and clean extra DOCX page breaks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { useEffect, useMemo, useState } from 'preact/hooks';
|
||||
import { getStatusLabel } from '../../stores/taskStore';
|
||||
import {
|
||||
downloadMonthlyServiceTasksArchive,
|
||||
downloadMonthlyCostsReport,
|
||||
downloadMonthlyServiserReport,
|
||||
downloadMonthlyWorkOrdersArchive,
|
||||
fetchMonthlyCostInvoices,
|
||||
fetchMonthlyServicerEntries,
|
||||
upsertMonthlyServicerEntry,
|
||||
@@ -89,6 +91,9 @@ 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;
|
||||
@@ -341,6 +346,9 @@ 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() {
|
||||
@@ -357,6 +365,28 @@ 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);
|
||||
@@ -631,8 +661,17 @@ 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...' : 'Preuzmi DOCX'}
|
||||
{downloading ? 'Preuzimanje...' : reportType === 'servicer' ? 'Preuzmi mjesečni izvještaj' : '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">
|
||||
@@ -825,6 +864,48 @@ 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>
|
||||
|
||||
Reference in New Issue
Block a user