v1.8.0: warehouse module (16 commits), docházka mzda model, leave_type=holiday removal, api.ts race fix
Highlights: - Warehouse module: receipts, issues, reservations, inventory, reports, dashboard, master data (categories, suppliers, locations), FIFO service, integration tests - Docházka: mzda PDF counting model (Odpracováno / Vč. svátků / Přesčas / Svátek / So/Ne / Noc) with Czech weekday names and decimal hours - AttendanceAdmin/AttendanceHistory KPI cards unified to mzda formula with fund bar colored by delta, badges for Práce/Dov/Nem/Sv/Nep - Remove leave_type=holiday entirely (auto-computed from Czech public holidays) - Allow multiple work shifts per day (overlap detection only) - Pre-flight refresh in api.ts eliminates spurious 401s on fresh page loads - Prisma: company_settings gets 6 nullable columns for warehouse numbering (PRI/VYD/INV prefixes, default patterns); migration seeds defaults
This commit is contained in:
@@ -518,6 +518,46 @@ export async function deleteOrder(id: number) {
|
||||
select: { id: true, created_at: true },
|
||||
});
|
||||
|
||||
// Guard: projects may have non-cascaded warehouse refs (sklad_issues,
|
||||
// sklad_reservations, attendance_project_logs all use project_id as a
|
||||
// non-nullable FK with no onDelete). Surface as 409 (resource conflict)
|
||||
// rather than letting Prisma throw P2003 -> 500.
|
||||
//
|
||||
// Only ACTIVE records count: a CANCELLED issue/restored batch or
|
||||
// CANCELLED reservation is audit-trail-only (cancelIssue() has already
|
||||
// restored the batch qty; cancelReservation() zeroes remaining_qty).
|
||||
// Attendance project logs are time-records — they always block, since
|
||||
// deleting the project would orphan the time record. The user must
|
||||
// re-assign the attendance log to a different project first.
|
||||
if (linkedProjects.length > 0) {
|
||||
const projectIds = linkedProjects.map((p) => p.id);
|
||||
const [activeIssuesCount, activeReservationsCount, attendanceLogCount] =
|
||||
await Promise.all([
|
||||
prisma.sklad_issues.count({
|
||||
where: {
|
||||
project_id: { in: projectIds },
|
||||
status: { not: "CANCELLED" },
|
||||
},
|
||||
}),
|
||||
prisma.sklad_reservations.count({
|
||||
where: {
|
||||
project_id: { in: projectIds },
|
||||
status: { not: "CANCELLED" },
|
||||
},
|
||||
}),
|
||||
prisma.attendance_project_logs.count({
|
||||
where: { project_id: { in: projectIds } },
|
||||
}),
|
||||
]);
|
||||
if (activeIssuesCount + activeReservationsCount + attendanceLogCount > 0) {
|
||||
return {
|
||||
error:
|
||||
"Nelze smazat objednávku, protože navázaný projekt má aktivní skladové výdeje, rezervace nebo docházkové záznamy. Zrušte je nebo přeřaďte docházku na jiný projekt.",
|
||||
status: 409,
|
||||
} as const;
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
// Clear quotation back-reference (matching PHP)
|
||||
await tx.quotations.updateMany({
|
||||
|
||||
Reference in New Issue
Block a user