diff --git a/src/controllers/04-invoice-controller.ts b/src/controllers/04-invoice-controller.ts index b1889c3..20dd91a 100644 --- a/src/controllers/04-invoice-controller.ts +++ b/src/controllers/04-invoice-controller.ts @@ -219,6 +219,16 @@ export class InvoiceController extends Controller { quotationStatus: "PaymentInProcess", }, }); + + await tx.notification.create({ + data: { + title: "ใบแจ้งหนี้ใหม่ / New Invoice", + detail: "รหัส / code : " + record.code, + registeredBranchId: record.registeredBranchId, + groupReceiver: { create: { name: "accountant" } }, + }, + }); + return await tx.invoice.create({ data: { quotationId: body.quotationId, diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index 16fdc20..e47a15c 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -679,6 +679,7 @@ export class QuotationController extends Controller { }, }, }, + productServiceList: true, }, where: { id: quotationId, isDebitNote: false }, }); @@ -850,7 +851,20 @@ export class QuotationController extends Controller { finalPrice: 0, }, ); - + const changed = list + ? record.productServiceList.some( + (lhs) => + !list?.find((rhs) => { + return ( + lhs.serviceId === rhs.serviceId && + lhs.workId === rhs.workId && + lhs.productId === rhs.productId && + lhs.discount === rhs.discount && + lhs.pricePerUnit === rhs.pricePerUnit + ); + }), + ) + : false; await Promise.all([ tx.service.updateMany({ where: { id: { in: ids.service }, status: Status.CREATED }, @@ -860,6 +874,16 @@ export class QuotationController extends Controller { where: { id: { in: ids.product }, status: Status.CREATED }, data: { status: Status.ACTIVE }, }), + changed && + tx.notification.create({ + data: { + title: "ใบเสนอราคามัการเปลี่ยนแปลง / Quotation Detail Changes", + detail: + "รหัส / code : " + record.code + " มีการเปลี่ยนแปลงของสินค้า / Product Updated", + registeredBranchId: record.registeredBranchId, + groupReceiver: { create: [{ name: "sale" }, { name: "head_of_sale" }] }, + }, + }), ]); return await tx.quotation.update({