feat: add code gen to credit note
This commit is contained in:
parent
16ceabe3df
commit
b9b6745bb6
2 changed files with 41 additions and 21 deletions
|
|
@ -1582,6 +1582,8 @@ enum CreditNoteStatus {
|
|||
model CreditNote {
|
||||
id String @id @default(cuid())
|
||||
|
||||
code String
|
||||
|
||||
creditNoteStatus CreditNoteStatus @default(Pending)
|
||||
|
||||
value Float @default(0)
|
||||
|
|
|
|||
|
|
@ -261,29 +261,47 @@ export class CreditNoteController extends Controller {
|
|||
return a + c.productService.product.price;
|
||||
}, 0);
|
||||
|
||||
const record = await prisma.creditNote.create({
|
||||
include: {
|
||||
requestWork: {
|
||||
include: {
|
||||
request: true,
|
||||
},
|
||||
},
|
||||
quotation: true,
|
||||
},
|
||||
data: {
|
||||
value,
|
||||
requestWork: {
|
||||
connect: body.requestWorkId.map((v) => ({
|
||||
id: v,
|
||||
})),
|
||||
},
|
||||
quotationId: body.quotationId,
|
||||
},
|
||||
});
|
||||
|
||||
this.setStatus(HttpStatus.CREATED);
|
||||
|
||||
return record;
|
||||
return await prisma.$transaction(
|
||||
async (tx) => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const currentMonth = new Date().getMonth() + 1;
|
||||
|
||||
const last = await tx.runningNo.upsert({
|
||||
where: {
|
||||
key: `CREDIT_NOTE_${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}`,
|
||||
},
|
||||
create: {
|
||||
key: `CREDIT_NOTE_${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}`,
|
||||
value: 1,
|
||||
},
|
||||
update: { value: { increment: 1 } },
|
||||
});
|
||||
|
||||
return await prisma.creditNote.create({
|
||||
include: {
|
||||
requestWork: {
|
||||
include: {
|
||||
request: true,
|
||||
},
|
||||
},
|
||||
quotation: true,
|
||||
},
|
||||
data: {
|
||||
code: `CN${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${last.value.toString().padStart(6, "0")}`,
|
||||
value,
|
||||
requestWork: {
|
||||
connect: body.requestWorkId.map((v) => ({
|
||||
id: v,
|
||||
})),
|
||||
},
|
||||
quotationId: body.quotationId,
|
||||
},
|
||||
});
|
||||
},
|
||||
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||
);
|
||||
}
|
||||
|
||||
@Put("{creditNoteId}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue