24 lines
635 B
TypeScript
24 lines
635 B
TypeScript
import { prisma } from "./prisma"
|
|
|
|
export const generateNoPengajuanSurat = async () => {
|
|
const date = new Date()
|
|
const year = String(date.getFullYear()).slice(-2) // ambil 2 digit terakhir
|
|
const month = String(date.getMonth() + 1).padStart(2, "0")
|
|
const day = String(date.getDate()).padStart(2, "0")
|
|
|
|
const prefix = `PS-${day}${month}${year}`
|
|
|
|
const count = await prisma.pelayananAjuan.count({
|
|
where: {
|
|
noPengajuan: {
|
|
contains: prefix
|
|
}
|
|
}
|
|
})
|
|
|
|
// pastikan nomor urut selalu 3 digit
|
|
const number = String(count + 1).padStart(3, "0")
|
|
|
|
return `${prefix}-${number}`
|
|
}
|