Update API PO for add-on PO
This commit is contained in:
parent
7acc2cf82c
commit
18daeb857b
|
|
@ -7,3 +7,6 @@
|
||||||
directory = /home/Log_service/
|
directory = /home/Log_service/
|
||||||
directory = /home/Log_service/
|
directory = /home/Log_service/
|
||||||
directory = /home/Log_service/
|
directory = /home/Log_service/
|
||||||
|
directory = /home/Log_service/
|
||||||
|
directory = /home/Log_service/
|
||||||
|
directory = /home/Log_service/
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import fs from "fs";
|
||||||
import type { HttpContextContract } from "@ioc:Adonis/Core/HttpContext";
|
import type { HttpContextContract } from "@ioc:Adonis/Core/HttpContext";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Env from "@ioc:Adonis/Core/Env";
|
import Env from "@ioc:Adonis/Core/Env";
|
||||||
|
import LogDetectFile from "App/Models/LogDetectFile";
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const BASE_URL = Env.get("BASE_URL_LOG");
|
const BASE_URL = Env.get("BASE_URL_LOG");
|
||||||
|
|
@ -23,34 +24,32 @@ export default class ErpsController {
|
||||||
const response = await axios.get(BASE_URL);
|
const response = await axios.get(BASE_URL);
|
||||||
// const responseAUTO = await axios.get(BASE_URL_AUTO);
|
// const responseAUTO = await axios.get(BASE_URL_AUTO);
|
||||||
console.log("check!!!!!!!!!!!!!!!!!!!!!")
|
console.log("check!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
|
||||||
let data1 = response.data
|
let data1 = response.data
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
|
.filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
|
||||||
// let data2 = responseAUTO.data
|
|
||||||
// .split("\n")
|
|
||||||
// .filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
|
|
||||||
|
|
||||||
const arrayLine = data1;
|
const arrayLine = data1;
|
||||||
|
|
||||||
// const arrayLineAUTO = data
|
arrayLine.map(async(u) => {
|
||||||
// .split("\n")
|
let fileName = u.slice(u.search("<a ") + 9, u.search("</a>")).split(">")[1];
|
||||||
// .filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
|
|
||||||
|
|
||||||
arrayLine.map((u) => {
|
|
||||||
let temp = u
|
|
||||||
.slice(u.search("<a ") + 9, u.search("</a>"))
|
|
||||||
.split(">")[1];
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
parseInt(temp?.split("-")[0]) >= from &&
|
parseInt(fileName?.split("-")[0]) >= parseInt(from) &&
|
||||||
parseInt(temp?.split("-")[0]) <= to
|
parseInt(fileName?.split("-")[0]) <= parseInt(to)
|
||||||
) {
|
) {
|
||||||
listLog.push(
|
listLog.push(
|
||||||
(BASE_URL + "/") +
|
(BASE_URL + "/") +
|
||||||
u.slice(u.search("<a ") + 9, u.search("</a>")).split(">")[1] +
|
fileName +
|
||||||
" "
|
" "
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const record = await LogDetectFile.firstOrCreate(
|
||||||
|
{ file_name: fileName },
|
||||||
|
{ file_name: fileName }
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(record.toJSON())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return listLog;
|
return listLog;
|
||||||
|
|
|
||||||
|
|
@ -533,12 +533,28 @@ Route.post("/api/po-email/packing-slip", async ({ request, response }) => {
|
||||||
doc.fontSize(13).font(loadFont('calibri-bold'))
|
doc.fontSize(13).font(loadFont('calibri-bold'))
|
||||||
.text('Ship To', leftMargin, detailsY)
|
.text('Ship To', leftMargin, detailsY)
|
||||||
|
|
||||||
doc.fontSize(11).font(loadFont('calibri-regular'))
|
|
||||||
if (inputData.shipTo.name) {
|
// === HÀM LOẠI TRÙNG ===
|
||||||
doc.text(inputData.shipTo.name, leftMargin, doc.y, { width: 280 })
|
function uniqueLines(lines) {
|
||||||
|
const seen = new Set();
|
||||||
|
return lines
|
||||||
|
.filter(
|
||||||
|
(line) =>
|
||||||
|
line &&
|
||||||
|
!seen.has(line.trim().toLowerCase()) &&
|
||||||
|
seen.add(line.trim().toLowerCase()),
|
||||||
|
)
|
||||||
|
.join("\n");
|
||||||
}
|
}
|
||||||
if (inputData.shipTo.address) {
|
|
||||||
doc.text(inputData.shipTo.address, leftMargin, doc.y, { width: 280 })
|
const shipToContent = uniqueLines([inputData.shipTo.name].concat(inputData.shipTo.address?.split("\n")))
|
||||||
|
|
||||||
|
doc.fontSize(11).font(loadFont('calibri-regular'))
|
||||||
|
// if (inputData.shipTo.name) {
|
||||||
|
// doc.text(inputData.shipTo.name, leftMargin, doc.y, { width: 280 })
|
||||||
|
// }
|
||||||
|
if (shipToContent) {
|
||||||
|
doc.text(shipToContent, leftMargin, doc.y, { width: 280 })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputData.shipTo.attn) {
|
if (inputData.shipTo.attn) {
|
||||||
|
|
@ -635,7 +651,7 @@ Route.post("/api/po-email/packing-slip", async ({ request, response }) => {
|
||||||
await new Promise(resolve => pdfStream.on('finish', resolve))
|
await new Promise(resolve => pdfStream.on('finish', resolve))
|
||||||
const buffer = pdfStream.getContents()
|
const buffer = pdfStream.getContents()
|
||||||
|
|
||||||
const fileName = `${data.po || 'PackingSlip'}_PackingSlip.pdf`
|
const fileName = `${data.po || ''}_PackingSlip.pdf`.replace(/[<>:"/\\|?*\x00-\x1F]/g, '_').trim()
|
||||||
const filePath = `/tmp/${fileName}`
|
const filePath = `/tmp/${fileName}`
|
||||||
fs.writeFileSync(filePath, buffer)
|
fs.writeFileSync(filePath, buffer)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue