Merge branch 'fix/line-alert' into develop
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
This commit is contained in:
commit
c34af75bad
2 changed files with 295 additions and 39 deletions
|
|
@ -321,6 +321,14 @@ export class RequestDataController extends Controller {
|
||||||
@Route("/api/v1/request-data/{requestDataId}")
|
@Route("/api/v1/request-data/{requestDataId}")
|
||||||
@Tags("Request List")
|
@Tags("Request List")
|
||||||
export class RequestDataActionController extends Controller {
|
export class RequestDataActionController extends Controller {
|
||||||
|
async #getLineToken() {
|
||||||
|
if (!process.env.LINE_MESSAGING_API_TOKEN) {
|
||||||
|
console.warn("Line Webhook Activated but LINE_MESSAGING_API_TOKEN not set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.env.LINE_MESSAGING_API_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
@Post("reject-request-cancel")
|
@Post("reject-request-cancel")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async rejectRequestCancel(
|
async rejectRequestCancel(
|
||||||
|
|
@ -395,6 +403,17 @@ export class RequestDataActionController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
include: {
|
||||||
|
quotation: {
|
||||||
|
include: {
|
||||||
|
customerBranch: {
|
||||||
|
include: {
|
||||||
|
customer: { include: { branch: { where: { userId: { not: null } } } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result) throw notFoundError("Request Data");
|
if (!result) throw notFoundError("Request Data");
|
||||||
|
|
@ -454,6 +473,49 @@ export class RequestDataActionController extends Controller {
|
||||||
data: { taskOrderStatus: TaskStatus.Canceled },
|
data: { taskOrderStatus: TaskStatus.Canceled },
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const token = await this.#getLineToken();
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
const textHead = "JWS ALERT:";
|
||||||
|
|
||||||
|
const textAlert = "ขอแจ้งให้ทราบว่าใบเสนอราคา";
|
||||||
|
const textAlert2 = "ได้ดำเนินการยกเลิกเรียบร้อยแล้ว";
|
||||||
|
const textAlert3 = "หากต้องการข้อมูลเพิ่มเติม กรุณาแจ้งให้ฝ่ายที่เกี่ยวข้องทราบ 🙏";
|
||||||
|
let finalTextWork = "";
|
||||||
|
let textData = "";
|
||||||
|
|
||||||
|
let dataCustomerId: string[] = [];
|
||||||
|
let dataUserId: string[] = [];
|
||||||
|
|
||||||
|
result.quotation.customerBranch.customer.branch.forEach((item) => {
|
||||||
|
if (!dataCustomerId?.includes(item.id) && item.userId) {
|
||||||
|
dataCustomerId.push(item.id);
|
||||||
|
dataUserId.push(item.userId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
finalTextWork = `เลขที่ใบเสนอราคา: ${result.code} ${result.quotation.workName}`;
|
||||||
|
|
||||||
|
textData = `${textHead}\n\n${textAlert}\n${finalTextWork}\n${textAlert2}\n\n${textAlert3}`;
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
to: dataUserId,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: textData,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
await fetch("https://api.line.me/v2/bot/message/multicast", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -674,6 +736,19 @@ export class RequestDataActionController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||||
|
include: {
|
||||||
|
customerBranch: {
|
||||||
|
include: {
|
||||||
|
customer: {
|
||||||
|
include: {
|
||||||
|
branch: {
|
||||||
|
where: { userId: { not: null } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
await tx.notification.createMany({
|
await tx.notification.createMany({
|
||||||
|
|
@ -683,6 +758,56 @@ export class RequestDataActionController extends Controller {
|
||||||
receiverId: v.createdByUserId,
|
receiverId: v.createdByUserId,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const token = await this.#getLineToken();
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
const textHead = "JWS ALERT:";
|
||||||
|
|
||||||
|
const textAlert = "ขอแจ้งให้ทราบว่าใบเสนอราคา";
|
||||||
|
const textAlert2 = "ได้ดำเนินการเสร็จสิ้นทุกกระบวนการเรียบร้อยแล้ว";
|
||||||
|
const textAlert3 = "หากต้องการข้อมูลเพิ่มเติม กรุณาแจ้งให้ฝ่ายที่เกี่ยวข้องทราบ 🙏";
|
||||||
|
let finalTextWork = "";
|
||||||
|
let textData = "";
|
||||||
|
|
||||||
|
let dataCustomerId: string[] = [];
|
||||||
|
let textWorkList: string[] = [];
|
||||||
|
let dataUserId: string[] = [];
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
res.forEach((data, index) => {
|
||||||
|
data.customerBranch.customer.branch.forEach((item) => {
|
||||||
|
if (!dataCustomerId?.includes(item.id) && item.userId) {
|
||||||
|
dataCustomerId.push(item.id);
|
||||||
|
dataUserId.push(item.userId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
textWorkList.push(`${index + 1}. เลขที่ใบเสนอราคา ${data.code} ${data.workName}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
finalTextWork = textWorkList.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
textData = `${textHead}\n\n${textAlert}\n${finalTextWork}\n${textAlert2}\n\n${textAlert3}`;
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
to: dataUserId,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: textData,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
await fetch("https://api.line.me/v2/bot/message/multicast", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// dataRecord.push(record);
|
// dataRecord.push(record);
|
||||||
return data;
|
return data;
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,14 @@ type CreditNoteUpdate = {
|
||||||
@Route("api/v1/credit-note")
|
@Route("api/v1/credit-note")
|
||||||
@Tags("Credit Note")
|
@Tags("Credit Note")
|
||||||
export class CreditNoteController extends Controller {
|
export class CreditNoteController extends Controller {
|
||||||
|
async #getLineToken() {
|
||||||
|
if (!process.env.LINE_MESSAGING_API_TOKEN) {
|
||||||
|
console.warn("Line Webhook Activated but LINE_MESSAGING_API_TOKEN not set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.env.LINE_MESSAGING_API_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
@Get("stats")
|
@Get("stats")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async getCreditNoteStats(@Request() req: RequestWithUser, @Query() quotationId?: string) {
|
async getCreditNoteStats(@Request() req: RequestWithUser, @Query() quotationId?: string) {
|
||||||
|
|
@ -366,33 +374,90 @@ export class CreditNoteController extends Controller {
|
||||||
update: { value: { increment: 1 } },
|
update: { value: { increment: 1 } },
|
||||||
});
|
});
|
||||||
|
|
||||||
return await prisma.creditNote.create({
|
return await prisma.creditNote
|
||||||
include: {
|
.create({
|
||||||
requestWork: {
|
include: {
|
||||||
include: {
|
requestWork: {
|
||||||
request: true,
|
include: {
|
||||||
|
request: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
quotation: {
|
||||||
|
include: {
|
||||||
|
customerBranch: {
|
||||||
|
include: {
|
||||||
|
customer: { include: { branch: { where: { userId: { not: null } } } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
quotation: true,
|
data: {
|
||||||
},
|
reason: body.reason,
|
||||||
data: {
|
detail: body.detail,
|
||||||
reason: body.reason,
|
remark: body.remark,
|
||||||
detail: body.detail,
|
paybackType: body.paybackType,
|
||||||
remark: body.remark,
|
paybackBank: body.paybackBank,
|
||||||
paybackType: body.paybackType,
|
paybackAccount: body.paybackAccount,
|
||||||
paybackBank: body.paybackBank,
|
paybackAccountName: body.paybackAccountName,
|
||||||
paybackAccount: body.paybackAccount,
|
code: `CN${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${last.value.toString().padStart(6, "0")}`,
|
||||||
paybackAccountName: body.paybackAccountName,
|
value,
|
||||||
code: `CN${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${last.value.toString().padStart(6, "0")}`,
|
requestWork: {
|
||||||
value,
|
connect: body.requestWorkId.map((v) => ({
|
||||||
requestWork: {
|
id: v,
|
||||||
connect: body.requestWorkId.map((v) => ({
|
})),
|
||||||
id: v,
|
},
|
||||||
})),
|
quotationId: body.quotationId,
|
||||||
},
|
},
|
||||||
quotationId: body.quotationId,
|
})
|
||||||
},
|
.then(async (res) => {
|
||||||
});
|
const token = await this.#getLineToken();
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
const textHead = "JWS ALERT:";
|
||||||
|
|
||||||
|
const textAlert = "ขอแจ้งให้ทราบว่าใบลดหนี้";
|
||||||
|
const textAlert2 = "ได้ถูกสร้างขึ้นเรียบร้อยแล้ว";
|
||||||
|
const textAlert3 =
|
||||||
|
"หากท่านต้องการข้อมูลเพิ่มเติมหรือมีข้อสงสัยประการใด โปรดแจ้งให้ฝ่ายที่เกี่ยวข้องทราบ ทางเรายินดีให้ความช่วยเหลืออย่างเต็มที่ 🙏";
|
||||||
|
let finalTextWork = "";
|
||||||
|
let textData = "";
|
||||||
|
|
||||||
|
let dataCustomerId: string[] = [];
|
||||||
|
let textWorkList: string[] = [];
|
||||||
|
let dataUserId: string[] = [];
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
res.quotation.customerBranch.customer.branch.forEach((item) => {
|
||||||
|
if (!dataCustomerId?.includes(item.id) && item.userId) {
|
||||||
|
dataCustomerId.push(item.id);
|
||||||
|
dataUserId.push(item.userId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
finalTextWork = `จำนวนเงิน ${res.value.toFixed(2)} บาท `;
|
||||||
|
}
|
||||||
|
|
||||||
|
textData = `${textHead}\n\n${textAlert}\n${finalTextWork}${textAlert2}\n\n${textAlert3}`;
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
to: dataUserId,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: textData,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
await fetch("https://api.line.me/v2/bot/message/multicast", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||||
);
|
);
|
||||||
|
|
@ -573,6 +638,14 @@ export class CreditNoteActionController extends Controller {
|
||||||
return creditNoteData;
|
return creditNoteData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #getLineToken() {
|
||||||
|
if (!process.env.LINE_MESSAGING_API_TOKEN) {
|
||||||
|
console.warn("Line Webhook Activated but LINE_MESSAGING_API_TOKEN not set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.env.LINE_MESSAGING_API_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
@Post("accept")
|
@Post("accept")
|
||||||
@Security("keycloak", MANAGE_ROLES)
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async acceptCreditNote(@Request() req: RequestWithUser, @Path() creditNoteId: string) {
|
async acceptCreditNote(@Request() req: RequestWithUser, @Path() creditNoteId: string) {
|
||||||
|
|
@ -591,23 +664,81 @@ export class CreditNoteActionController extends Controller {
|
||||||
@Body() body: { paybackStatus: PaybackStatus },
|
@Body() body: { paybackStatus: PaybackStatus },
|
||||||
) {
|
) {
|
||||||
await this.#checkPermission(req.user, creditNoteId);
|
await this.#checkPermission(req.user, creditNoteId);
|
||||||
return await prisma.creditNote.update({
|
return await prisma.creditNote
|
||||||
where: { id: creditNoteId },
|
.update({
|
||||||
include: {
|
where: { id: creditNoteId },
|
||||||
requestWork: {
|
include: {
|
||||||
include: {
|
requestWork: {
|
||||||
request: true,
|
include: {
|
||||||
|
request: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
quotation: {
|
||||||
|
include: {
|
||||||
|
customerBranch: {
|
||||||
|
include: {
|
||||||
|
customer: { include: { branch: { where: { userId: { not: null } } } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
quotation: true,
|
data: {
|
||||||
},
|
creditNoteStatus:
|
||||||
data: {
|
body.paybackStatus === PaybackStatus.Done ? CreditNoteStatus.Success : undefined,
|
||||||
creditNoteStatus:
|
paybackStatus: body.paybackStatus,
|
||||||
body.paybackStatus === PaybackStatus.Done ? CreditNoteStatus.Success : undefined,
|
paybackDate: body.paybackStatus === PaybackStatus.Done ? new Date() : undefined,
|
||||||
paybackStatus: body.paybackStatus,
|
},
|
||||||
paybackDate: body.paybackStatus === PaybackStatus.Done ? new Date() : undefined,
|
})
|
||||||
},
|
.then(async (res) => {
|
||||||
});
|
const token = await this.#getLineToken();
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
const textHead = "JWS ALERT:";
|
||||||
|
|
||||||
|
const textAlert = "ทางเราขอแจ้งให้ทราบว่าการดำเนินการคืนเงินสำหรับใบลดหนี้";
|
||||||
|
const textAlert2 = "ได้รับการอนุมัติและเสร็จสมบูรณ์เรียบร้อยแล้ว";
|
||||||
|
const textAlert3 =
|
||||||
|
"หากท่านต้องการข้อมูลเพิ่มเติมหรือมีข้อสงสัยประการใด โปรดแจ้งให้ฝ่ายที่เกี่ยวข้องทราบ ทางเรายินดีให้ความช่วยเหลืออย่างเต็มที่ 🙏";
|
||||||
|
let finalTextWork = "";
|
||||||
|
let textData = "";
|
||||||
|
|
||||||
|
let dataCustomerId: string[] = [];
|
||||||
|
let textWorkList: string[] = [];
|
||||||
|
let dataUserId: string[] = [];
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
res.quotation.customerBranch.customer.branch.forEach((item) => {
|
||||||
|
if (!dataCustomerId?.includes(item.id) && item.userId) {
|
||||||
|
dataCustomerId.push(item.id);
|
||||||
|
dataUserId.push(item.userId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
finalTextWork = `จำนวนเงิน ${res.value.toFixed(2)} บาท `;
|
||||||
|
}
|
||||||
|
|
||||||
|
textData = `${textHead}\n\n${textAlert}\n${finalTextWork}${textAlert2}\n\n${textAlert3}`;
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
to: dataUserId,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: textData,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
body.paybackStatus === PaybackStatus.Done
|
||||||
|
? await fetch("https://api.line.me/v2/bot/message/multicast", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue