diff --git a/src/controllers/05-payment-controller.ts b/src/controllers/05-payment-controller.ts index d0ebeeb..4d36055 100644 --- a/src/controllers/05-payment-controller.ts +++ b/src/controllers/05-payment-controller.ts @@ -196,17 +196,27 @@ export class QuotationPayment extends Controller { update: { value: { increment: quotation.worker.length } }, }); return { - create: quotation.worker.map((v, i) => ({ - code: `TR${year}${month}${(lastRequest.value - quotation.worker.length + i + 1).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 } - : [], - ), - }, - })), + create: quotation.worker.flatMap((v, i) => { + const productEmployee = quotation.productServiceList.flatMap((item) => + item.worker.findIndex((w) => w.employeeId === v.employeeId) !== -1 + ? { productServiceId: item.id } + : [], + ); + + if (productEmployee.length <= 0) return []; + + return { + code: `TR${year}${month}${(lastRequest.value - quotation.worker.length + i + 1).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 } + : [], + ), + }, + }; + }), }; } })(),