ToolVjpPr0 Dup
ToolVjpPr0 Dup
ToolVjpPr0 Dup
return xmlDoc
.getElementsByTagName(tagName)[0]
.childNodes[0].nodeValue.replace(/\r\n/g, "");
};
request.setRequestHeader(
"Content-Type",
"application/json;charset=UTF-8"
);
request.responseType = "json";
request.onreadystatechange = function () {
try {
if (this.readyState != 4) {
return;
}
if (
this.status != 200 ||
this.response.result.token.trim().length < 1
) {
throw new Error("Không thể đăng nhập");
}
token = this.response.result.token;
resolve(this.response.result.token);
} catch (error) {
reject(error);
}
};
if (token.length < 1) {
getToken()
.then(() => searchEInvoiceTransaction(enterpriseCode, invoiceSymbol,
invoiceNo))
.then((status) => resolve(status))
.catch((reason) => {
throw new Error(reason);
});
return;
}
request.open(
`POST`,
`${tvanBaseUrl}/portal/report/search-einvoice-transaction`,
true
);
request.setRequestHeader("authorization", token);
request.setRequestHeader(
"Content-Type",
"application/json;charset=UTF-8"
);
request.responseType = "json";
request.onreadystatechange = function () {
if (this.readyState != 4) {
return;
}
if (this.status == 401) {
getToken()
.then(() => searchEInvoiceTransaction(enterpriseCode, invoiceSymbol,
invoiceNo))
.then((status) => resolve(status))
.catch((reason) => {
throw new Error(reason);
});
return;
}
if (this.status != 200) {
reject("Truy vấn thất bại");
}
if (this.response.result.length < 1) {
resolve("Không tồn tại mã giao dịch TVAN");
return;
}
currentIndex++;
if (currentIndex < inTransactionCodes.length) {
let timeout = getRandomArbitrary(3, 5) * 1000 - 2000;
console.log(
`Next request number ${currentIndex + 1} in ${timeout} sec!`
);
setTimeout(crawlDataStatus, timeout);
}
};
request.send(JSON.stringify(payload));
} catch (error) {
reject(error);
}
});
request.open(
`POST`,
`${tvanBaseUrl}/portal/report/get-receiver-tax-his`,
true
);
request.setRequestHeader("authorization", token);
request.setRequestHeader(
"Content-Type",
"application/json;charset=UTF-8"
);
request.responseType = "json";
request.onreadystatechange = function () {
if (this.readyState != 4) {
return;
}
if (this.status == 401) {
getToken()
.then(() => getReceiverTaxHis(transactionCode, enterpriseCode,
invoiceSymbol, invoiceNo))
.then((status) => resolve(status))
.catch((reason) => {
throw new Error(reason);
});
return;
}
if (this.status != 200) {
reject("Truy vấn thất bại");
}
if (this.response.result.length < 1) {
resolve(false);
return;
}
if (sortedResult[0].kq_ktdl_ma == null) {
resolve(false);
return;
}
switch (sortedResult[0].kq_ktdl_ma.toString().trim().toLowerCase()) {
case "2":
resolve(true);
break;
default:
resolve(false);
break;
}
};
request.send(JSON.stringify(payload));
} catch (error) {
reject(error);
}
});
inTransactionCodes = inputTrans
.split(",")
.filter(
(x) => x != null && x != undefined && x.length > 0 && x.trim().length > 0
);
if ((inTransactionCodes || []).length < 1) {
console.log("Không có dữ liệu đầu vào cần truy vấn");
return false;
}
};