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 {
|
model RequestData {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
|
|
||||||
|
code String
|
||||||
|
|
||||||
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
|
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
|
||||||
employeeId String
|
employeeId String
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export class QuotationPayment extends Controller {
|
||||||
const year = `${current.getFullYear()}`.slice(-2).padStart(2, "0");
|
const year = `${current.getFullYear()}`.slice(-2).padStart(2, "0");
|
||||||
const month = `${current.getMonth() + 1}`.padStart(2, "0");
|
const month = `${current.getMonth() + 1}`.padStart(2, "0");
|
||||||
|
|
||||||
const last =
|
const lastReceipt =
|
||||||
body.paymentStatus === "PaymentSuccess" && record.paymentStatus !== "PaymentSuccess"
|
body.paymentStatus === "PaymentSuccess" && record.paymentStatus !== "PaymentSuccess"
|
||||||
? await tx.runningNo.upsert({
|
? await tx.runningNo.upsert({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -154,7 +154,9 @@ export class QuotationPayment extends Controller {
|
||||||
where: { id: paymentId, invoice: { quotationId: quotation.id } },
|
where: { id: paymentId, invoice: { quotationId: quotation.id } },
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...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
|
paymentSum._sum.amount || 0 >= quotation.finalPrice
|
||||||
? "PaymentSuccess"
|
? "PaymentSuccess"
|
||||||
: "PaymentInProcess",
|
: "PaymentInProcess",
|
||||||
requestData:
|
requestData: await (async () => {
|
||||||
body.paymentStatus === "PaymentSuccess" &&
|
if (
|
||||||
(paymentSum._sum.amount || 0) - payment.amount <= 0
|
body.paymentStatus === "PaymentSuccess" &&
|
||||||
? {
|
(paymentSum._sum.amount || 0) - payment.amount <= 0
|
||||||
create: quotation.worker.map((v) => ({
|
) {
|
||||||
employeeId: v.employeeId,
|
const lastRequest = await tx.runningNo.upsert({
|
||||||
requestWork: {
|
where: {
|
||||||
create: quotation.productServiceList.flatMap((item) =>
|
key: `REQUEST_${year}${month}`,
|
||||||
item.worker.findIndex((w) => w.employeeId === v.employeeId) !== -1
|
},
|
||||||
? { productServiceId: item.id }
|
create: {
|
||||||
: [],
|
key: `REQUEST_${year}${month}`,
|
||||||
),
|
value: 1,
|
||||||
},
|
},
|
||||||
})),
|
update: { value: { increment: 1 } },
|
||||||
}
|
});
|
||||||
: undefined,
|
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