feat: add code gen to request data
This commit is contained in:
parent
766f9b4af5
commit
c1ac3845ce
2 changed files with 36 additions and 18 deletions
|
|
@ -1393,6 +1393,8 @@ enum RequestDataStatus {
|
|||
model RequestData {
|
||||
id String @id @default(cuid())
|
||||
|
||||
code String
|
||||
|
||||
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
|
||||
employeeId String
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ export class QuotationPayment extends Controller {
|
|||
const year = `${current.getFullYear()}`.slice(-2).padStart(2, "0");
|
||||
const month = `${current.getMonth() + 1}`.padStart(2, "0");
|
||||
|
||||
const last =
|
||||
const lastReceipt =
|
||||
body.paymentStatus === "PaymentSuccess" && record.paymentStatus !== "PaymentSuccess"
|
||||
? await tx.runningNo.upsert({
|
||||
where: {
|
||||
|
|
@ -154,7 +154,9 @@ export class QuotationPayment extends Controller {
|
|||
where: { id: paymentId, invoice: { quotationId: quotation.id } },
|
||||
data: {
|
||||
...body,
|
||||
code: last ? `RE${year}${month}${last.value.toString().padStart(6, "0")}` : undefined,
|
||||
code: lastReceipt
|
||||
? `RE${year}${month}${lastReceipt.value.toString().padStart(6, "0")}`
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -175,22 +177,36 @@ export class QuotationPayment extends Controller {
|
|||
paymentSum._sum.amount || 0 >= quotation.finalPrice
|
||||
? "PaymentSuccess"
|
||||
: "PaymentInProcess",
|
||||
requestData:
|
||||
body.paymentStatus === "PaymentSuccess" &&
|
||||
(paymentSum._sum.amount || 0) - payment.amount <= 0
|
||||
? {
|
||||
create: quotation.worker.map((v) => ({
|
||||
employeeId: v.employeeId,
|
||||
requestWork: {
|
||||
create: quotation.productServiceList.flatMap((item) =>
|
||||
item.worker.findIndex((w) => w.employeeId === v.employeeId) !== -1
|
||||
? { productServiceId: item.id }
|
||||
: [],
|
||||
),
|
||||
},
|
||||
})),
|
||||
}
|
||||
: undefined,
|
||||
requestData: await (async () => {
|
||||
if (
|
||||
body.paymentStatus === "PaymentSuccess" &&
|
||||
(paymentSum._sum.amount || 0) - payment.amount <= 0
|
||||
) {
|
||||
const lastRequest = await tx.runningNo.upsert({
|
||||
where: {
|
||||
key: `REQUEST_${year}${month}`,
|
||||
},
|
||||
create: {
|
||||
key: `REQUEST_${year}${month}`,
|
||||
value: 1,
|
||||
},
|
||||
update: { value: { increment: 1 } },
|
||||
});
|
||||
return {
|
||||
create: quotation.worker.map((v) => ({
|
||||
code: `TR${year}${month}${lastRequest.value.toString().padStart(6, "0")}`,
|
||||
employeeId: v.employeeId,
|
||||
requestWork: {
|
||||
create: quotation.productServiceList.flatMap((item) =>
|
||||
item.worker.findIndex((w) => w.employeeId === v.employeeId) !== -1
|
||||
? { productServiceId: item.id }
|
||||
: [],
|
||||
),
|
||||
},
|
||||
})),
|
||||
};
|
||||
}
|
||||
})(),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue