Prevent duplicate invoice number reservations
This commit is contained in:
@@ -5,7 +5,7 @@ import bwipjs from "bwip-js"
|
|||||||
import Sharp from "sharp"
|
import Sharp from "sharp"
|
||||||
|
|
||||||
import { tenants } from "../../db/schema"
|
import { tenants } from "../../db/schema"
|
||||||
import { eq } from "drizzle-orm"
|
import { eq, sql } from "drizzle-orm"
|
||||||
|
|
||||||
export const useNextNumberRangeNumber = async (
|
export const useNextNumberRangeNumber = async (
|
||||||
server: FastifyInstance,
|
server: FastifyInstance,
|
||||||
@@ -19,7 +19,12 @@ export const useNextNumberRangeNumber = async (
|
|||||||
cancellationInvoices: "invoices",
|
cancellationInvoices: "invoices",
|
||||||
}
|
}
|
||||||
|
|
||||||
const [tenant] = await server.db
|
return server.db.transaction(async (tx) => {
|
||||||
|
// Serialisiert Nummernvergaben dieses Mandanten auch ueber mehrere
|
||||||
|
// Backend-Prozesse hinweg, bis die Transaktion abgeschlossen ist.
|
||||||
|
await tx.execute(sql`select pg_advisory_xact_lock(${tenantId})`)
|
||||||
|
|
||||||
|
const [tenant] = await tx
|
||||||
.select()
|
.select()
|
||||||
.from(tenants)
|
.from(tenants)
|
||||||
.where(eq(tenants.id, tenantId))
|
.where(eq(tenants.id, tenantId))
|
||||||
@@ -54,12 +59,13 @@ export const useNextNumberRangeNumber = async (
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
await server.db
|
await tx
|
||||||
.update(tenants)
|
.update(tenants)
|
||||||
.set({ numberRanges: updatedRanges })
|
.set({ numberRanges: updatedRanges })
|
||||||
.where(eq(tenants.id, tenantId))
|
.where(eq(tenants.id, tenantId))
|
||||||
|
|
||||||
return { usedNumber }
|
return { usedNumber }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function encodeBase64ToNiimbot(base64Png: string, printDirection: "top" | "left" = "top") {
|
export async function encodeBase64ToNiimbot(base64Png: string, printDirection: "top" | "left" = "top") {
|
||||||
|
|||||||
@@ -1761,7 +1761,7 @@ const saveDocument = async (state, resetup = false) => {
|
|||||||
itemInfo.value.state = state
|
itemInfo.value.state = state
|
||||||
normalizeCustomSurchargePercentage()
|
normalizeCustomSurchargePercentage()
|
||||||
|
|
||||||
if (state !== "Entwurf") {
|
if (state !== "Entwurf" && !itemInfo.value.documentNumber) {
|
||||||
console.log("???")
|
console.log("???")
|
||||||
|
|
||||||
const type = itemInfo.value.type
|
const type = itemInfo.value.type
|
||||||
|
|||||||
Reference in New Issue
Block a user