|
|
|
@ -8,6 +8,7 @@ export const TYPE_PREFIX: Record<string, string> = {
|
|
|
|
export function nextDocNo(db: DB, docType: string, fy: string): string {
|
|
|
|
export function nextDocNo(db: DB, docType: string, fy: string): string {
|
|
|
|
const prefix = `${TYPE_PREFIX[docType]}/${fy.slice(2)}`
|
|
|
|
const prefix = `${TYPE_PREFIX[docType]}/${fy.slice(2)}`
|
|
|
|
db.prepare(
|
|
|
|
db.prepare(
|
|
|
|
|
|
|
|
// Portability quirk: ON CONFLICT upsert is SQLite/Postgres dialect (standard SQL has MERGE).
|
|
|
|
`INSERT INTO doc_series (doc_type, fy, prefix, next_seq) VALUES (?, ?, ?, 1)
|
|
|
|
`INSERT INTO doc_series (doc_type, fy, prefix, next_seq) VALUES (?, ?, ?, 1)
|
|
|
|
ON CONFLICT (doc_type, fy) DO NOTHING`,
|
|
|
|
ON CONFLICT (doc_type, fy) DO NOTHING`,
|
|
|
|
).run(docType, fy, prefix)
|
|
|
|
).run(docType, fy, prefix)
|
|
|
|
@ -21,6 +22,7 @@ export function nextDocNo(db: DB, docType: string, fy: string): string {
|
|
|
|
export function seedSeries(db: DB, docType: string, fy: string, lastUsedSeq: number): void {
|
|
|
|
export function seedSeries(db: DB, docType: string, fy: string, lastUsedSeq: number): void {
|
|
|
|
const prefix = `${TYPE_PREFIX[docType]}/${fy.slice(2)}`
|
|
|
|
const prefix = `${TYPE_PREFIX[docType]}/${fy.slice(2)}`
|
|
|
|
db.prepare(
|
|
|
|
db.prepare(
|
|
|
|
|
|
|
|
// Portability quirk: ON CONFLICT upsert is SQLite/Postgres dialect (standard SQL has MERGE).
|
|
|
|
`INSERT INTO doc_series (doc_type, fy, prefix, next_seq) VALUES (?, ?, ?, ?)
|
|
|
|
`INSERT INTO doc_series (doc_type, fy, prefix, next_seq) VALUES (?, ?, ?, ?)
|
|
|
|
ON CONFLICT (doc_type, fy) DO UPDATE SET next_seq = excluded.next_seq`,
|
|
|
|
ON CONFLICT (doc_type, fy) DO UPDATE SET next_seq = excluded.next_seq`,
|
|
|
|
).run(docType, fy, prefix, lastUsedSeq + 1)
|
|
|
|
).run(docType, fy, prefix, lastUsedSeq + 1)
|
|
|
|
|