mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 22:26:27 +00:00
Update load balance
This commit is contained in:
@@ -19,14 +19,6 @@ const postingInvoice = async (req, res) => {
|
||||
// time
|
||||
let invoiceDate = moment('2022-06-25').subtract(1, "days").format("YYYY-MM-DD");
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} Generating invoice ${invoiceDate}`
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.info(`${uniqueCode} Start Transaction`);
|
||||
|
||||
let invoice = [];
|
||||
|
||||
await knex.transaction(async trx => {
|
||||
@@ -36,7 +28,7 @@ const postingInvoice = async (req, res) => {
|
||||
invoice = await model.generateInvoice(invoiceDate, trx)
|
||||
|
||||
winston.logger.info(`${uniqueCode} result payment.sp_payment_req_topup_online ${JSON.stringify(invoice)}`);
|
||||
|
||||
|
||||
if(invoice){
|
||||
for (const key in invoice) {
|
||||
|
||||
@@ -50,17 +42,9 @@ const postingInvoice = async (req, res) => {
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
result = {
|
||||
code: "200",
|
||||
message: "Succes posting",
|
||||
data: invoice,
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
if (invoice[0].c_invoice_no) {
|
||||
if(invoice){
|
||||
|
||||
winston.logger.info(`${uniqueCode} preparing posting FB70 to SAP`);
|
||||
|
||||
@@ -71,22 +55,34 @@ const postingInvoice = async (req, res) => {
|
||||
password: "12345678"
|
||||
}
|
||||
|
||||
invoice.forEach( async function (item) {
|
||||
for (const key in invoice) {
|
||||
|
||||
winston.logger.info(`${uniqueCode} REQUEST posting ${item.c_invoice_no} to SAP`);
|
||||
winston.logger.info(`${uniqueCode} REQUEST posting ${invoice[key].c_invoice_no} to SAP`);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/xml',
|
||||
'Authorization': 'Basic' + base64.encode(credential.username + ":" + credential.password)
|
||||
},
|
||||
body: xmlRequest
|
||||
});
|
||||
// const response = await fetch(url, {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'text/xml',
|
||||
// 'Authorization': 'Basic' + base64.encode(credential.username + ":" + credential.password)
|
||||
// },
|
||||
// body: xmlRequest
|
||||
// });
|
||||
|
||||
const soap = await response.text();
|
||||
|
||||
winston.logger.info(`${uniqueCode} RESPONSE posting ${item.c_invoice_no} to SAP : ${soap}`);
|
||||
// const soap = await response.text();
|
||||
const soap = `<SOAP:Envelope
|
||||
xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
|
||||
<SOAP:Header/>
|
||||
<SOAP:Body>
|
||||
<ns0:ZFMCMS_FI_001.Response
|
||||
xmlns:ns0='urn:sap-com:document:sap:rfc:functions'>
|
||||
<E_MATDOCUMENTYEAR>2021</E_MATDOCUMENTYEAR>
|
||||
<E_MATERIALDOCUMENT>4905741245</E_MATERIALDOCUMENT>
|
||||
<C_T_RETURN/>
|
||||
</ns0:ZFMCMS_FI_001.Response>
|
||||
</SOAP:Body>
|
||||
</SOAP:Envelope>`
|
||||
|
||||
winston.logger.info(`${uniqueCode} RESPONSE posting ${invoice[key].c_invoice_no} to SAP : ${soap}`);
|
||||
|
||||
let resSAP = {
|
||||
E_MATDOCUMENTYEAR: '',
|
||||
@@ -107,22 +103,31 @@ const postingInvoice = async (req, res) => {
|
||||
|
||||
if (soapBody.$) delete soapBody.$
|
||||
|
||||
resSAP.E_MATDOCUMENTYEAR = soapBody['ZKCIMM_CMS02.Response']['E_MATDOCUMENTYEAR']
|
||||
resSAP.E_MATERIALDOCUMENT = soapBody['ZKCIMM_CMS02.Response']['E_MATERIALDOCUMENT']
|
||||
resSAP.E_MATDOCUMENTYEAR = soapBody['ZFMCMS_FI_001.Response']['E_MATDOCUMENTYEAR']
|
||||
resSAP.E_MATERIALDOCUMENT = soapBody['ZFMCMS_FI_001.Response']['E_MATERIALDOCUMENT']
|
||||
|
||||
if (!Array.isArray(soapBody['ZKCIMM_CMS02.Response']['C_T_RETURN']['item'])) {
|
||||
resSAP.ITEM.push(soapBody['ZKCIMM_CMS02.Response']['C_T_RETURN']['item'])
|
||||
if (!Array.isArray(soapBody['ZFMCMS_FI_001.Response']['C_T_RETURN']['item'])) {
|
||||
resSAP.ITEM.push(soapBody['ZFMCMS_FI_001.Response']['C_T_RETURN']['item'])
|
||||
} else {
|
||||
resSAP.ITEM = soapBody['ZKCIMM_CMS02.Response']['C_T_RETURN']['item']
|
||||
resSAP.ITEM = soapBody['ZFMCMS_FI_001.Response']['C_T_RETURN']['item']
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// UPDATE CMS
|
||||
|
||||
});
|
||||
|
||||
winston.logger.info(`${uniqueCode} UPDATE resposn FB70 to CMS ${JSON.stringify(resSAP)}`);
|
||||
const cms = await model.setReturnSAP(invoice[key], resSAP, trx)
|
||||
winston.logger.info(`${uniqueCode} SUKSES UPDATE resposn FB70 to CMS ${JSON.stringify(resSAP)}`);
|
||||
};
|
||||
}
|
||||
})
|
||||
result = {
|
||||
code: "200",
|
||||
message: "Succes posting",
|
||||
data: invoice,
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
} catch (error) {
|
||||
// create log
|
||||
|
||||
Reference in New Issue
Block a user