This commit is contained in:
Nuranggi Hermawan
2022-09-15 20:06:52 +07:00
parent 33985aa52c
commit 52716f44a9
4 changed files with 100 additions and 182 deletions
+64 -155
View File
@@ -28,7 +28,7 @@ const validate = (method) => {
};
// POSTING INVOICE
const apiGenerateInvoice = async (req, res) => {
const apiGenerateCahsIn = async (req, res) => {
try {
// generate unique code
@@ -56,96 +56,8 @@ const apiGenerateInvoice = async (req, res) => {
return res.status(200).json(result);
}
const cashIn = await _generateCashIn(uniqueCode)
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'
let partnerRecon = await model.getPartnerRecon(knex)
for (const item of partnerRecon) {
let reserve = []
let code = ""
await knex.transaction(async trx => {
code = await model.generateCode(trx, item.c_partner_code, moment().format("YYMMDD"))
// Insert cahs in
const dataCahsIn = {
c_partner_code : item.c_partner_code,
c_partner_name : item.c_partner_name,
c_cash_in_no : code,
d_cash_in : item.d_payment,
c_invoice_no : item.c_invoice_no,
i_amount : item.amount
}
const cashIn = await model.insertCashIn(trx, dataCahsIn)
// Insert cahs in detail
const reserv = await model.getReserve(trx, item.c_partner_code, item.d_payment)
for (const detail of reserv) {
reserve.push(detail.c_reservation_no)
let data = {
i_cash_in : cashIn.i_cash_in,
c_reservation_no : detail.c_reservation_no,
m_amount : detail.i_reservation_amount,
c_payment_recon_no : detail.c_payment_recon_no,
d_payment : detail.d_payment,
d_payment_recon : detail.d_payment_recon,
c_load_balance_no : detail.c_load_balance_no
}
const insert = await model.insertCashInDetail(trx, data)
}
const insertPostingEt = await model.insertPostingEt(code, item, trx)
})
let xmlHeader = {
doc_header_text : code,
ba: item.ba,
doc_date : item.doc_date,
posting_date : item.posting_date,
fisc_year : item.fisc_year,
fisc_period : item.fisc_period,
doc_type: item.doc_type,
c_invoice_no : code
}
let xmlItem = ['S', 'H'].map(items => {
return {
c_account_code_topup : items == 'S' ? item.c_account_code_topup : "",
c_account_topup : items == 'H' ? item.c_account_topup : "",
ba : item.ba,
amount : item.amount,
posting_date : item.posting_date,
c_invoice_no : code,
item_text : `${items == 'S' ? "DEBIT" : "KREDIT"} CAHSIN CMS ${code}`,
de_cre : items
}
});
let xmlRequest = helper.generateXMLRequest('ZFMCMS_FI_001', xmlHeader, xmlItem)
winston.logger.debug(`SCHEDULER-FB70-${uniqueCode} REQUEST posting ${code} to SAP : ${xmlRequest}`);
const response = await helper.postingSAP(url, xmlRequest)
winston.logger.debug(`SCHEDULER-FB70-${uniqueCode} RESPONSE posting ${code} to SAP : ${JSON.stringify(response)}`);
// new transaction
await knex.transaction(async trx => {
const resSAP = helper.getXMLData(response)
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} TRANSACTION 2`);
// UPDATE CMS
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(resSAP)}`)
const cms = await model.setReturnSAP(code, reserve, resSAP, trx)
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`)
})
}
result = {
code: "200",
@@ -174,14 +86,14 @@ const apiGenerateInvoice = async (req, res) => {
};
// RETRY POSTING INVOICE
const apiPostingInvoice = async (req, res) => {
const apiPostingCahsIn = async (req, res) => {
try {
// generate unique code
uniqueCode = helper.getUniqueCode()
let { body } = req
// log info
winston.logger.info(
`${uniqueCode} REQUEST posting invoice: ${JSON.stringify(req.body)}`
`${uniqueCode} REQUEST posting cash in : ${JSON.stringify(req.body)}`
);
// check validator
@@ -195,16 +107,16 @@ const apiPostingInvoice = async (req, res) => {
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE generate invoice: ${JSON.stringify(result)}`
`${uniqueCode} RESPONSE generate posting cash in : ${JSON.stringify(result)}`
);
return res.status(200).json(result);
}
// return uniqueCode
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RE-TRY POSTING INVOICE`)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RE-TRY POSTING CAHS IN`)
const invoice = await _postingInvoice(uniqueCode)
const invoice = await _postingCashIn(body.c_cash_in_no, uniqueCode)
result = {
code: "200",
@@ -246,10 +158,12 @@ const _generateCashIn = async (uniqueCode) => {
c_partner_code : item.c_partner_code,
c_partner_name : item.c_partner_name,
c_cash_in_no : code,
d_cash_in : item.d_payment,
c_in_period : item.c_in_period,
d_credit : item.d_payment,
c_invoice_no : item.c_invoice_no,
i_amount : item.amount
}
}
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} cash in ${code} data : ${JSON.stringify(dataCahsIn)}`)
const cashIn = await model.insertCashIn(trx, dataCahsIn)
@@ -268,70 +182,65 @@ const _generateCashIn = async (uniqueCode) => {
}
await model.insertCashInDetail(trx, data)
}
await model.insertPostingEt(code, item, trx)
// await model.insertPostingEt(code, item, trx)
})
return partnerRecon
}
return partnerRecon
}
const _postingCashIn = async (uniqueCode) => {
const _postingCashIn = async (reference, uniqueCode) => {
let postingEt = []
await knex.transaction(async trx => {
postingEt = await model.getPostingEt(trx)
let postingEt = await model.getPostingEt(trx, reference)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(postingEt)}`)
for (const item of postingEt) {
let xmlHeader = {
doc_header_text : item.doc_header_text ? item.doc_header_text : "",
ba: item.ba ? item.ba : "",
doc_date : item.doc_date ? item.doc_date : "",
posting_date : item.posting_date ? item.posting_date : "",
fisc_year : item.fiscal_year ? item.fiscal_year : "",
fisc_period : item.fis_period ? item.fis_period: "",
doc_type: item.doc_type ? item.doc_type : "",
c_invoice_no : item.reference ? item.reference : ""
}
let xmlItem = ['S', 'H'].map(key => {
return {
c_account_code_topup : key == 'S' ? item.customer : "",
c_account_topup : key == 'H' ? item.account : "",
ba : item.ba,
amount : item.amount,
posting_date : item.posting_date,
c_invoice_no : item.reference,
item_text :key == 'S' ? item.text1 : item.text2,
de_cre : key
}
});
let xmlRequest = helper.generateXMLRequest('ZFMCMS_FI_001', xmlHeader, xmlItem)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${item.reference} to SAP : ${xmlRequest}`);
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 response = await helper.postingSAP(url, xmlRequest)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${item.reference} to SAP : ${JSON.stringify(response)}`);
// new transaction
// await knex.transaction(async trx => {
const resSAP = helper.getXMLData(response)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} TRANSACTION 2`);
// UPDATE CMS
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(resSAP)}`)
const cms = await model.setReturnSAP(item.reference, resSAP, trx)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`)
// })
let xmlHeader = {
doc_header_text : postingEt.doc_header_text ? postingEt.doc_header_text : "",
ba: postingEt.ba ? postingEt.ba : "",
doc_date : postingEt.doc_date ? postingEt.doc_date : "",
posting_date : postingEt.posting_date ? postingEt.posting_date : "",
fisc_year : postingEt.fiscal_year ? postingEt.fiscal_year : "",
fisc_period : postingEt.fis_period ? postingEt.fis_period: "",
doc_type: postingEt.doc_type ? postingEt.doc_type : "",
c_invoice_no : postingEt.reference ? postingEt.reference : ""
}
let xmlItem = ['S', 'H'].map(key => {
return {
c_account_code_topup : key == 'S' ? postingEt.customer : "",
c_account_topup : key == 'H' ? postingEt.account : "",
ba : postingEt.ba,
amount : postingEt.amount,
posting_date : postingEt.posting_date,
c_invoice_no : postingEt.reference,
item_text :key == 'S' ? postingEt.text1 : postingEt.text2,
de_cre : key
}
});
let xmlRequest = helper.generateXMLRequest('ZFMCMS_FI_001', xmlHeader, xmlItem)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${postingEt.reference} to SAP : ${xmlRequest}`);
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 response = await helper.postingSAP(url, xmlRequest)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${postingEt.reference} to SAP : ${JSON.stringify(response)}`);
const resSAP = helper.getXMLData(response)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} TRANSACTION 2`);
// UPDATE CMS
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(resSAP)}`)
const cms = await model.setReturnSAP(postingEt.reference, resSAP, trx)
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`)
})
return postingEt
@@ -340,8 +249,8 @@ const _postingCashIn = async (uniqueCode) => {
module.exports = {
validate,
apiPostingInvoice,
apiGenerateInvoice,
apiGenerateCahsIn,
apiPostingCahsIn,
_postingCashIn,
_generateCashIn
};
+22 -20
View File
@@ -33,14 +33,14 @@ const insertPostingEt = async (code, dataCashIn, trx) => {
if(item == 'H'){
data = {...data, ...{
text: `Posting Cash-in CMS ${code}`,
text: `Cash-in CMS ${code}`,
debit_kredit: item,
account: dataCashIn.c_account_topup,
customer: null
}}
}else{
data = {...data, ...{
text: `Posting Cash-in CMS ${code}`,
text: `Cash-in CMS ${code}`,
debit_kredit: item,
account: null,
customer: dataCashIn.c_account_code_topup
@@ -57,9 +57,9 @@ const insertPostingEt = async (code, dataCashIn, trx) => {
}
const getPostingEt = async(trx) => {
const getPostingEt = async(trx, reference) => {
const result = await trx('public.posting_et').select([
const result = await trx('public.posting_et AS pe').select([
'doc_header_text',
'ba',
'doc_date',
@@ -71,23 +71,24 @@ const getPostingEt = async(trx) => {
'tcode',
'amount',
trx.raw(`'IDR' AS currency`),
trx.raw(`(SELECT customer FROM public.posting_et where no_dok = no_dok and debit_kredit = 'S') as customer `),
trx.raw(`(SELECT account FROM public.posting_et where no_dok = no_dok and debit_kredit = 'H') as account `),
trx.raw(`(SELECT text FROM public.posting_et where no_dok = no_dok and debit_kredit = 'S') as text1`),
trx.raw(`(SELECT text FROM public.posting_et where no_dok = no_dok and debit_kredit = 'H') as text2`)
trx.raw(`(SELECT customer FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as customer`),
trx.raw(`(SELECT account FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as account `),
trx.raw(`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as text1`),
trx.raw(`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as text2`)
])
.where('tcode', '=', "FB70")
.whereIn('status0', ["3"])
.where('reference', '=', reference)
.whereIn('pos_status', ["4"])
.groupBy(['doc_header_text', 'ba', 'doc_header_text', 'tcode', 'ba', 'amount', 'posting_date', 'doc_date', 'doc_type', 'fiscal_year', 'reference'])
.first()
return result
}
const setReturnSAP = async (code, reserve, resSAP, trx) => {
let t_cash_in = {}
let reserveBalance = {}
const setReturnSAP = async (code, resSAP, trx) => {
let t_cash_in = []
let reserveBalance = []
if(resSAP.type == 'S'){
// update invoice
@@ -103,7 +104,7 @@ const setReturnSAP = async (code, reserve, resSAP, trx) => {
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
c_cash_in_no: code
}, ['c_cash_in_no', 'c_return_sap'])
.whereIn("c_reservation_no", reserve)
.whereRaw("c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '')")
}
@@ -118,9 +119,9 @@ const setReturnSAP = async (code, reserve, resSAP, trx) => {
})
return {
cash_in : t_cash_in,
reserveBalance : reserveBalance,
posting_et : posting_et
cash_in : t_cash_in[0],
reserveBalance : reserveBalance[0],
posting_et : posting_et[0]
}
}
@@ -244,6 +245,7 @@ const getPartnerRecon = async(trx) => {
trx.raw("to_char(tdpr.d_payment, 'MM') AS fisc_period"),
trx.raw("to_char(tdpr.d_payment, 'YYYY') AS fisc_year"),
trx.raw("to_char(tdpr.d_payment, 'YYYYMMDD') AS doc_date"),
trx.raw("to_char(tdpr.d_payment, 'YYYYMMDD') AS posting_date"),
trx.raw("'FB70' AS tcode"),
trx.raw("'A' as reversal"),
trx.raw("'DR' AS doc_type"),
@@ -254,10 +256,10 @@ const getPartnerRecon = async(trx) => {
"i_holding",
trx.raw(`CASE
WHEN to_char(tdpr.d_payment, 'MM') = to_char(tdi.d_invoice_date, 'MM')
THEN FALSE
THEN 'Y'
ELSE
TRUE
END b_past_month`),
'N'
END c_in_period`),
])
.from("trx.t_d_reservation_balance AS tdrb")
.leftJoin('trx.t_d_load_balance as tdlb', function () {
@@ -60,7 +60,7 @@ const insertPostingEt = async (invoice, trx) => {
const getPostingEt = async(trx) => {
const result = await trx('public.posting_et').select([
const result = await trx('public.posting_et AS pe').select([
'doc_header_text',
'ba',
'doc_date',
@@ -72,13 +72,13 @@ const getPostingEt = async(trx) => {
'tcode',
'amount',
trx.raw(`'IDR' AS currency`),
trx.raw(`(SELECT customer FROM public.posting_et where no_dok = no_dok and debit_kredit = 'S') as customer `),
trx.raw(`(SELECT account FROM public.posting_et where no_dok = no_dok and debit_kredit = 'H') as account `),
trx.raw(`(SELECT text FROM public.posting_et where no_dok = no_dok and debit_kredit = 'S') as text1`),
trx.raw(`(SELECT text FROM public.posting_et where no_dok = no_dok and debit_kredit = 'H') as text2`)
trx.raw(`(SELECT customer FROM public.posting_et where no_dok = pe.no_dok and debit_kredit = 'S') as customer `),
trx.raw(`(SELECT account FROM public.posting_et where no_dok = pe.no_dok and debit_kredit = 'H') as account `),
trx.raw(`(SELECT text FROM public.posting_et where no_dok = pe.no_dok and debit_kredit = 'S') as text1`),
trx.raw(`(SELECT text FROM public.posting_et where no_dok = pe.no_dok and debit_kredit = 'H') as text2`)
])
.where('tcode', '=', "FB70")
.whereIn('status0', ["3"])
.whereIn('pos_status', ["3"])
.groupBy(['doc_header_text', 'ba', 'doc_header_text', 'tcode', 'ba', 'amount', 'posting_date', 'doc_date', 'doc_type', 'fiscal_year', 'reference'])
+8 -1
View File
@@ -7,7 +7,14 @@ router.get(
"/online/cash-in",
// auth.authenticateToken,
// controller.validate("generateInvoice"),
controller.apiGenerateInvoice
controller.apiGenerateCahsIn
);
router.post(
"/online/cash-in/posting",
// auth.authenticateToken,
// controller.validate("generateInvoice"),
controller.apiPostingCahsIn
);
module.exports = router;