Ausgangsbelegliste schlank laden
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 50s
Build and Push Docker Images / build-frontend (push) Successful in 1m23s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-docs (push) Successful in 22s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 50s
Build and Push Docker Images / build-frontend (push) Successful in 1m23s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-docs (push) Successful in 22s
This commit is contained in:
@@ -11,7 +11,14 @@ import {
|
|||||||
sql,
|
sql,
|
||||||
} from "drizzle-orm"
|
} from "drizzle-orm"
|
||||||
|
|
||||||
import { authProfiles, costcentres, customers, entitybankaccounts } from "../../../db/schema";
|
import {
|
||||||
|
authProfiles,
|
||||||
|
costcentres,
|
||||||
|
createddocuments,
|
||||||
|
customers,
|
||||||
|
entitybankaccounts,
|
||||||
|
statementallocations,
|
||||||
|
} from "../../../db/schema";
|
||||||
import { resourceConfig } from "../../utils/resource.config";
|
import { resourceConfig } from "../../utils/resource.config";
|
||||||
import { useNextNumberRangeNumber } from "../../utils/functions";
|
import { useNextNumberRangeNumber } from "../../utils/functions";
|
||||||
import { getHistoryEntityLabel, insertHistoryItem } from "../../utils/history";
|
import { getHistoryEntityLabel, insertHistoryItem } from "../../utils/history";
|
||||||
@@ -495,6 +502,97 @@ async function validateOutgoingSepaMandatePayload(
|
|||||||
|
|
||||||
export default async function resourceRoutes(server: FastifyInstance) {
|
export default async function resourceRoutes(server: FastifyInstance) {
|
||||||
|
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
// CREATED DOCUMENT LIST
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
server.get("/resource/createddocuments/list", async (req, reply) => {
|
||||||
|
try {
|
||||||
|
const tenantId = req.user?.tenant_id
|
||||||
|
if (!tenantId) {
|
||||||
|
return reply.code(400).send({ error: "No tenant selected" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const portalCustomerId = await getPortalCustomerId(server, req)
|
||||||
|
let whereCond: any = eq(createddocuments.tenant, tenantId)
|
||||||
|
whereCond = applyResourceWhereFilters("createddocuments", createddocuments, whereCond)
|
||||||
|
whereCond = applyPortalScope(
|
||||||
|
"createddocuments",
|
||||||
|
createddocuments,
|
||||||
|
whereCond,
|
||||||
|
portalCustomerId
|
||||||
|
)
|
||||||
|
|
||||||
|
const documentRows = await server.db
|
||||||
|
.select({
|
||||||
|
id: createddocuments.id,
|
||||||
|
createdAt: createddocuments.createdAt,
|
||||||
|
type: createddocuments.type,
|
||||||
|
documentNumber: createddocuments.documentNumber,
|
||||||
|
documentDate: createddocuments.documentDate,
|
||||||
|
state: createddocuments.state,
|
||||||
|
rows: createddocuments.rows,
|
||||||
|
paymentDays: createddocuments.paymentDays,
|
||||||
|
linkedDocumentId: createddocuments.createddocument,
|
||||||
|
usedAdvanceInvoices: createddocuments.usedAdvanceInvoices,
|
||||||
|
archived: createddocuments.archived,
|
||||||
|
customerId: customers.id,
|
||||||
|
customerName: customers.name,
|
||||||
|
})
|
||||||
|
.from(createddocuments)
|
||||||
|
.leftJoin(customers, eq(createddocuments.customer, customers.id))
|
||||||
|
.where(whereCond)
|
||||||
|
.orderBy(asc(createddocuments.documentNumber))
|
||||||
|
|
||||||
|
if (documentRows.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const documentIds = documentRows.map((document) => document.id)
|
||||||
|
const allocationRows = await server.db
|
||||||
|
.select({
|
||||||
|
id: statementallocations.id,
|
||||||
|
createddocument: statementallocations.createddocument,
|
||||||
|
amount: statementallocations.amount,
|
||||||
|
})
|
||||||
|
.from(statementallocations)
|
||||||
|
.where(and(
|
||||||
|
eq(statementallocations.tenant, tenantId),
|
||||||
|
inArray(statementallocations.createddocument, documentIds)
|
||||||
|
))
|
||||||
|
|
||||||
|
const allocationsByDocument = new Map<number, typeof allocationRows>()
|
||||||
|
for (const allocation of allocationRows) {
|
||||||
|
if (allocation.createddocument === null) continue
|
||||||
|
const allocations = allocationsByDocument.get(allocation.createddocument) || []
|
||||||
|
allocations.push(allocation)
|
||||||
|
allocationsByDocument.set(allocation.createddocument, allocations)
|
||||||
|
}
|
||||||
|
|
||||||
|
return documentRows.map((document) => ({
|
||||||
|
id: document.id,
|
||||||
|
createdAt: document.createdAt,
|
||||||
|
type: document.type,
|
||||||
|
documentNumber: document.documentNumber,
|
||||||
|
documentDate: document.documentDate,
|
||||||
|
state: document.state,
|
||||||
|
rows: document.rows || [],
|
||||||
|
paymentDays: document.paymentDays,
|
||||||
|
createddocument: document.linkedDocumentId
|
||||||
|
? { id: document.linkedDocumentId }
|
||||||
|
: null,
|
||||||
|
usedAdvanceInvoices: document.usedAdvanceInvoices || [],
|
||||||
|
archived: document.archived,
|
||||||
|
customer: document.customerId
|
||||||
|
? { id: document.customerId, name: document.customerName }
|
||||||
|
: null,
|
||||||
|
statementallocations: allocationsByDocument.get(document.id) || [],
|
||||||
|
}))
|
||||||
|
} catch (err) {
|
||||||
|
server.log.error({ err }, "Failed to load created document list")
|
||||||
|
return reply.code(500).send({ error: "Internal Server Error" })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// LIST
|
// LIST
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|||||||
@@ -204,7 +204,9 @@ defineShortcuts({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
items.value = (await useEntities("createddocuments").select("*, customer(id,name), statementallocations(id,amount),linkedDocument(*)", "documentNumber", true, true))
|
items.value = await useNuxtApp().$api('/api/resource/createddocuments/list', {
|
||||||
|
method: 'GET'
|
||||||
|
}) || []
|
||||||
}
|
}
|
||||||
|
|
||||||
setupPage()
|
setupPage()
|
||||||
|
|||||||
Reference in New Issue
Block a user