mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 12:46:28 +00:00
Merge branch 'nuranggi' of https://github.com/mohamadihsan/topuponline
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
const helper = require("../../helpers/helper");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const model = require("./invoice.model");
|
||||
const moment = require("moment");
|
||||
const xml2js = require('xml2js');
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
|
||||
moment.locale("id");
|
||||
|
||||
var result = {};
|
||||
var uniqueCode;
|
||||
|
||||
// POSTING INVOICE
|
||||
const postingInvoice = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = await helper.getUniqueCode();
|
||||
|
||||
// time
|
||||
let invoiceDate = moment('2022-06-25').subtract(1, "days").format("YYYY-MM-DD");
|
||||
|
||||
let invoice = [];
|
||||
|
||||
await knex.transaction(async trx => {
|
||||
|
||||
winston.logger.info(`${uniqueCode} execute payment.sp_payment_req_topup_online`);
|
||||
|
||||
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) {
|
||||
|
||||
winston.logger.info(`${uniqueCode} insert posting et ${JSON.stringify(invoice[key])}`)
|
||||
|
||||
let postingEt = await model.insertPostingEt(invoice[key], trx)
|
||||
|
||||
winston.logger.info(`${uniqueCode} success insert posting : ${postingEt}`)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(invoice){
|
||||
|
||||
winston.logger.info(`${uniqueCode} preparing posting FB70 to SAP`);
|
||||
|
||||
const url = 'http://piqas.kereta-api.co.id:51500/XISOAPAdapter/MessageServlet?senderParty=&senderService=KCI_ETICKETING_2&receiverParty=&receiverService=&interface=SI_KCI_CMS_FI01&interfaceNamespace=urn:Posting_ETicketing_2'
|
||||
|
||||
const credential = {
|
||||
username: "basisxiqas",
|
||||
password: "12345678"
|
||||
}
|
||||
|
||||
for (const key in invoice) {
|
||||
|
||||
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 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: '',
|
||||
E_MATERIALDOCUMENT: '',
|
||||
ITEM: [],
|
||||
}
|
||||
|
||||
xml2js.parseString(soap, {
|
||||
explicitArray: false,
|
||||
tagNameProcessors: [xml2js.processors.stripPrefix]
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
winston.logger.error(`${uniqueCode} ERROR parsing XML : ${err}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let soapBody = result.Envelope.Body;
|
||||
|
||||
if (soapBody.$) delete soapBody.$
|
||||
|
||||
resSAP.E_MATDOCUMENTYEAR = soapBody['ZFMCMS_FI_001.Response']['E_MATDOCUMENTYEAR']
|
||||
resSAP.E_MATERIALDOCUMENT = soapBody['ZFMCMS_FI_001.Response']['E_MATERIALDOCUMENT']
|
||||
|
||||
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['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
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
return res.status(200).json({
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
postingInvoice,
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||
const generateInvoice = (invoiceDate, trx) => {
|
||||
|
||||
let result = trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}')`))
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
const insertPostingEt = (invoice, trx) => {
|
||||
console.log("invoice : ", invoice)
|
||||
let type = ['S', 'H']
|
||||
let et = []
|
||||
let posting_et = []
|
||||
type.forEach((item, index) => {
|
||||
let data = {
|
||||
file_name: invoice.file_name,
|
||||
tcode: invoice.tcode,
|
||||
reversal: invoice.reversal,
|
||||
doc_type: invoice.doc_type,
|
||||
fiscal_year: invoice.fisc_year,
|
||||
posting_date: invoice.posting_date,
|
||||
doc_date: invoice.doc_date,
|
||||
no_dok: invoice.c_invoice_no,
|
||||
reference: invoice.c_invoice_no,
|
||||
amount: invoice.amount,
|
||||
ba: invoice.ba,
|
||||
indeks: (index+1),
|
||||
totalidx: type.length,
|
||||
doc_header_text: `POSTING INVOICE CMS ${invoice.c_invoice_no} - ${invoice.doc_header_text}`,
|
||||
}
|
||||
|
||||
if(item == 'H'){
|
||||
data = {...data, ...{
|
||||
text: `DEBIT INVOICE CMS ${invoice.c_invoice_no} - ${invoice.doc_header_text}`,
|
||||
debit_kredit: item,
|
||||
account: invoice.c_account_topup,
|
||||
}}
|
||||
}else{
|
||||
data = {...data, ...{
|
||||
text: `KREDIT INVOICE CMS ${invoice.c_invoice_no} - ${invoice.doc_header_text}`,
|
||||
debit_kredit: item,
|
||||
customer: invoice.c_account_code_topup
|
||||
}}
|
||||
}
|
||||
|
||||
et.push(data)
|
||||
|
||||
});
|
||||
|
||||
posting_et = trx('public.posting_et').insert(et, ['no_dok'])
|
||||
|
||||
return posting_et
|
||||
|
||||
}
|
||||
|
||||
const setReturnSAP = (invoice, resSAP, trx) => {
|
||||
|
||||
// update invoice
|
||||
trx('trx.t_d_load_balance').update({
|
||||
c_return_sap: resSAP.E_MATERIALDOCUMENT
|
||||
}, ['c_load_balance'])
|
||||
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = ${invoice.c_invoice_no})`)
|
||||
|
||||
// update load balance
|
||||
trx('trx.t_d_load_balance').update({
|
||||
c_return_sap: resSAP.E_MATERIALDOCUMENT
|
||||
})
|
||||
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = ${invoice.c_invoice_no})`)
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateInvoice,
|
||||
insertPostingEt,
|
||||
setReturnSAP
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const auth = require("../middlewares/jwt.middleware");
|
||||
const controller = require("../modules/invoice/invoice.controller");
|
||||
|
||||
router.post(
|
||||
"/posting-invoice",
|
||||
// auth.authenticateToken,
|
||||
controller.postingInvoice
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
@@ -10,6 +10,7 @@ const loadBalanceRoute = require("./application/routes/loadbalance.routes");
|
||||
const hsmRoute = require("./application/routes/hsm.routes");
|
||||
const historyRoute = require("./application/routes/history.routes");
|
||||
const paymentReconRoute = require("./application/routes/paymentrecon.routes");
|
||||
const invoiceRoute = require("./application/routes/invoice.routes");
|
||||
|
||||
require("dotenv").config();
|
||||
|
||||
@@ -45,9 +46,10 @@ app.use("/api/", hsmRoute);
|
||||
app.use("/api/", loadBalanceRoute);
|
||||
app.use("/api/", paymentReconRoute);
|
||||
app.use("/api/", reservationRoute);
|
||||
app.use("/api/", invoiceRoute);
|
||||
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 8000;
|
||||
app.listen(PORT, () => {
|
||||
winston.logger.info(`Server is running on environment: ${process.env.NODE_ENV.toUpperCase()}`);
|
||||
});
|
||||
});
|
||||
Generated
+100
-1380
File diff suppressed because it is too large
Load Diff
+3
-1
@@ -32,11 +32,13 @@
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"knex": "^0.95.4",
|
||||
"moment": "^2.29.3",
|
||||
"node-cron": "^3.0.1",
|
||||
"pg": "^8.6.0",
|
||||
"pm2": "^5.2.0",
|
||||
"winston": "^3.7.2",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"ws": "^8.5.0"
|
||||
"ws": "^8.5.0",
|
||||
"xml2js": "^0.4.23"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.7"
|
||||
|
||||
Reference in New Issue
Block a user