mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:46:28 +00:00
770 lines
21 KiB
JavaScript
770 lines
21 KiB
JavaScript
const { param, body, validationResult } = require('express-validator');
|
|
const helper = require('../../helpers/helper');
|
|
const winston = require('../../helpers/winston.logger');
|
|
const model = require('./cahsin.model');
|
|
const moment = require('moment');
|
|
const knex = require('../../../infrastructure/database/knex');
|
|
|
|
moment.locale('id');
|
|
|
|
var result = {};
|
|
var uniqueCode;
|
|
|
|
// VALIDATION
|
|
const validate = (method) => {
|
|
switch (method) {
|
|
case 'generateInvoice':
|
|
return [
|
|
body('trx_date')
|
|
.notEmpty()
|
|
.withMessage('trx_date is required!')
|
|
.isISO8601()
|
|
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
|
.escape()
|
|
.trim(),
|
|
body('repost')
|
|
.notEmpty()
|
|
.withMessage('repost is required!')
|
|
.isBoolean()
|
|
.withMessage('repost must boolean!')
|
|
.escape()
|
|
.trim(),
|
|
];
|
|
case 'postingInvoice':
|
|
return [
|
|
body('trx_date')
|
|
.notEmpty()
|
|
.withMessage('trx_date is required!')
|
|
.isISO8601()
|
|
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
|
.escape()
|
|
.trim(),
|
|
];
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
|
|
// POSTING INVOICE
|
|
const apiGenerateCahsIn = async (req, res) => {
|
|
try {
|
|
// generate unique code
|
|
uniqueCode = helper.getUniqueCode();
|
|
// return uniqueCode
|
|
|
|
// log info
|
|
winston.logger.info(
|
|
`${uniqueCode} REQUEST generate cashin: ${JSON.stringify(req.body)}`
|
|
);
|
|
|
|
// check validator
|
|
const err = validationResult(req, res);
|
|
if (!err.isEmpty()) {
|
|
result = {
|
|
code: '400',
|
|
message: err.errors[0].msg,
|
|
data: {},
|
|
};
|
|
|
|
// log warn
|
|
winston.logger.warn(
|
|
`${uniqueCode} RESPONSE generate cashin: ${JSON.stringify(result)}`
|
|
);
|
|
|
|
return res.status(200).json(result);
|
|
}
|
|
|
|
const cashIn = await _generateCashIn(uniqueCode);
|
|
|
|
result = {
|
|
code: '200',
|
|
message: 'Succes posting',
|
|
data: cashIn,
|
|
};
|
|
|
|
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: {},
|
|
});
|
|
}
|
|
};
|
|
|
|
const apiGenerateCashInSales = async (req, res) => {
|
|
try {
|
|
// generate unique code
|
|
uniqueCode = helper.getUniqueCode();
|
|
// return uniqueCode
|
|
|
|
// log info
|
|
winston.logger.info(
|
|
`${uniqueCode} REQUEST generate cashin: ${JSON.stringify(req.body)}`
|
|
);
|
|
|
|
// check validator
|
|
const err = validationResult(req, res);
|
|
if (!err.isEmpty()) {
|
|
result = {
|
|
code: '400',
|
|
message: err.errors[0].msg,
|
|
data: {},
|
|
};
|
|
|
|
// log warn
|
|
winston.logger.warn(
|
|
`${uniqueCode} RESPONSE generate cashin: ${JSON.stringify(result)}`
|
|
);
|
|
|
|
return res.status(200).json(result);
|
|
}
|
|
|
|
const cashIn = await _generateCashInSales(uniqueCode);
|
|
|
|
result = {
|
|
code: '200',
|
|
message: 'Success generate cash-in',
|
|
data: cashIn,
|
|
};
|
|
|
|
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: {},
|
|
});
|
|
}
|
|
};
|
|
|
|
const apiGenerateCashInSalesInternal = async (req, res) => {
|
|
try {
|
|
// generate unique code
|
|
uniqueCode = helper.getUniqueCode();
|
|
// return uniqueCode
|
|
|
|
// log info
|
|
winston.logger.info(
|
|
`${uniqueCode} REQUEST generate cashin sales internal: ${JSON.stringify(req.body)}`
|
|
);
|
|
|
|
// check validator
|
|
const err = validationResult(req, res);
|
|
if (!err.isEmpty()) {
|
|
result = {
|
|
code: '400',
|
|
message: err.errors[0].msg,
|
|
data: {},
|
|
};
|
|
|
|
// log warn
|
|
winston.logger.warn(
|
|
`${uniqueCode} RESPONSE generate cashin sales internal: ${JSON.stringify(result)}`
|
|
);
|
|
|
|
return res.status(200).json(result);
|
|
}
|
|
|
|
const cashIn = await _generateCashInSalesInternal(uniqueCode);
|
|
|
|
result = {
|
|
code: '200',
|
|
message: 'Success generate cash-in',
|
|
data: cashIn,
|
|
};
|
|
|
|
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: {},
|
|
});
|
|
}
|
|
};
|
|
|
|
const apiGenerateCashInTopUpCashlessInternal = async (req, res) => {
|
|
try {
|
|
// generate unique code
|
|
uniqueCode = helper.getUniqueCode();
|
|
// return uniqueCode
|
|
|
|
// log info
|
|
winston.logger.info(
|
|
`${uniqueCode} REQUEST generate cashin topup cashless internal: ${JSON.stringify(req.body)}`
|
|
);
|
|
|
|
// check validator
|
|
const err = validationResult(req, res);
|
|
if (!err.isEmpty()) {
|
|
result = {
|
|
code: '400',
|
|
message: err.errors[0].msg,
|
|
data: {},
|
|
};
|
|
|
|
// log warn
|
|
winston.logger.warn(
|
|
`${uniqueCode} RESPONSE generate cashin topup cashless internal: ${JSON.stringify(result)}`
|
|
);
|
|
|
|
return res.status(200).json(result);
|
|
}
|
|
|
|
const cashIn = await _generateCashInTopUpCashlessInternal(uniqueCode);
|
|
|
|
result = {
|
|
code: '200',
|
|
message: 'Success generate cash-in',
|
|
data: cashIn,
|
|
};
|
|
|
|
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: {},
|
|
});
|
|
}
|
|
};
|
|
|
|
// RETRY POSTING CASH IN
|
|
const apiPostingCahsIn = async (req, res) => {
|
|
try {
|
|
// generate unique code
|
|
uniqueCode = helper.getUniqueCode();
|
|
let { body } = req;
|
|
// log info
|
|
winston.logger.info(
|
|
`${uniqueCode} REQUEST posting cash in : ${JSON.stringify(req.body)}`
|
|
);
|
|
|
|
// check validator
|
|
const err = validationResult(req, res);
|
|
if (!err.isEmpty()) {
|
|
result = {
|
|
code: '400',
|
|
message: err.errors[0].msg,
|
|
data: {},
|
|
};
|
|
|
|
// log warn
|
|
winston.logger.warn(
|
|
`${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 CAHS IN`);
|
|
|
|
const invoice = await _postingCashIn(uniqueCode);
|
|
|
|
result = {
|
|
code: '200',
|
|
message: 'Succes',
|
|
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: {},
|
|
});
|
|
}
|
|
};
|
|
|
|
const _generateCashIn = async (uniqueCode) => {
|
|
let partnerRecon = await model.getPartnerRecon(knex);
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
|
partnerRecon
|
|
)}`
|
|
);
|
|
|
|
for (const item of partnerRecon) {
|
|
try {
|
|
await knex.transaction(async (trx) => {
|
|
const reserv = await model.getReserve(
|
|
trx,
|
|
item.c_partner_code,
|
|
item.d_payment,
|
|
item.c_invoice_no
|
|
);
|
|
|
|
if (!reserv || reserv.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const cashInAmount = reserv.reduce(
|
|
(sum, row) => sum + parseInt(row.i_reservation_amount, 10),
|
|
0
|
|
);
|
|
|
|
if (cashInAmount <= 0) {
|
|
return;
|
|
}
|
|
|
|
let runningAmount = 0;
|
|
for (const detail of reserv) {
|
|
runningAmount += parseInt(detail.i_reservation_amount, 10);
|
|
if (runningAmount > parseInt(detail.invoice_amount, 10)) {
|
|
throw new Error(
|
|
`ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${runningAmount} > INVOICE AMOUNT (${detail.invoice_amount})`
|
|
);
|
|
}
|
|
}
|
|
|
|
const code = await model.generateCode(
|
|
trx,
|
|
item.c_partner_code,
|
|
moment().format('YYMMDD')
|
|
);
|
|
|
|
const dataCahsIn = {
|
|
c_partner_code: item.c_partner_code,
|
|
c_partner_name: item.c_partner_name,
|
|
c_cash_in_no: code,
|
|
c_in_period: item.c_in_period,
|
|
d_credit: item.d_payment,
|
|
c_invoice_no: item.c_invoice_no,
|
|
i_amount: cashInAmount,
|
|
};
|
|
|
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
|
await model.writePaynentHistory(dataCahsIn, 'SUCCESSFULLY', 0, trx);
|
|
|
|
const dataReserve = {
|
|
c_cash_in_no: cashIn.c_cash_in_no,
|
|
d_credit: cashIn.d_credit,
|
|
c_in_period: cashIn.c_in_period,
|
|
};
|
|
|
|
const reserveNos = reserv.map((detail) => detail.c_reservation_no);
|
|
const cashInDetails = reserv.map((detail) => ({
|
|
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,
|
|
}));
|
|
|
|
await model.updateIntoReserveBulk(trx, dataReserve, reserveNos);
|
|
await model.insertCashInDetailBulk(trx, cashInDetails);
|
|
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} SUCCESS. partner=${item.c_partner_code}, invoice=${item.c_invoice_no}, rows=${cashInDetails.length}, amount=${cashInAmount}`
|
|
);
|
|
});
|
|
} catch (error) {
|
|
winston.logger.error(
|
|
`SCHEDULER-FB70-${uniqueCode} generate cash in failed for partner=${item.c_partner_code}, invoice=${item.c_invoice_no} | ${error.message}`
|
|
);
|
|
}
|
|
}
|
|
|
|
return partnerRecon;
|
|
};
|
|
|
|
const _generateCashInSales = async (uniqueCode) => {
|
|
let partnerRecon = await model.getPartnerReconSales(knex);
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
|
partnerRecon
|
|
)}`
|
|
);
|
|
|
|
for (const item of partnerRecon) {
|
|
try {
|
|
await knex.transaction(async (trx) => {
|
|
const sales = await model.getSalesKMT(
|
|
trx,
|
|
item.c_partner_code,
|
|
item.d_payment,
|
|
item.c_invoice_no
|
|
);
|
|
|
|
if (!sales || sales.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const cashInAmount = sales.reduce(
|
|
(sum, row) => sum + parseInt(row.i_total_billing, 10),
|
|
0
|
|
);
|
|
|
|
if (cashInAmount <= 0) {
|
|
return;
|
|
}
|
|
|
|
let runningAmount = 0;
|
|
for (const detail of sales) {
|
|
runningAmount += parseInt(detail.i_total_billing, 10);
|
|
if (runningAmount > parseInt(detail.invoice_amount, 10)) {
|
|
throw new Error(
|
|
`ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${runningAmount} > INVOICE AMOUNT (${detail.invoice_amount})`
|
|
);
|
|
}
|
|
}
|
|
|
|
const code = await model.generateCode(
|
|
trx,
|
|
item.c_partner_code,
|
|
moment().format('YYMMDD')
|
|
);
|
|
|
|
const dataCahsIn = {
|
|
c_partner_code: item.c_partner_code,
|
|
c_partner_name: item.c_partner_name,
|
|
c_cash_in_no: code,
|
|
c_in_period: item.c_in_period,
|
|
d_credit: item.d_payment,
|
|
c_invoice_no: item.c_invoice_no,
|
|
i_amount: cashInAmount,
|
|
c_source: 'S',
|
|
};
|
|
|
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
|
await model.writePaynentHistory(dataCahsIn, 'SUCCESSFULLY', 0, trx);
|
|
|
|
const dataSales = {
|
|
c_cash_in_no: cashIn.c_cash_in_no,
|
|
d_credit: cashIn.d_credit,
|
|
c_in_period: cashIn.c_in_period,
|
|
};
|
|
|
|
const salesNos = sales.map((detail) => detail.c_sales_no);
|
|
const cashInDetails = sales.map((detail) => ({
|
|
i_cash_in: cashIn.i_cash_in,
|
|
c_reservation_no: detail.c_sales_no,
|
|
m_amount: detail.i_total_billing,
|
|
c_payment_recon_no: detail.c_payment_recon_no,
|
|
d_payment: detail.d_payment,
|
|
d_payment_recon: detail.d_payment_recon,
|
|
}));
|
|
|
|
await model.updateIntoSalesKMTBulk(trx, dataSales, salesNos);
|
|
await model.insertCashInDetailBulk(trx, cashInDetails);
|
|
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN SALES ${code} SUCCESS. partner=${item.c_partner_code}, invoice=${item.c_invoice_no}, rows=${cashInDetails.length}, amount=${cashInAmount}`
|
|
);
|
|
});
|
|
} catch (error) {
|
|
winston.logger.error(
|
|
`SCHEDULER-FB70-${uniqueCode} generate cash in sales failed for partner=${item.c_partner_code}, invoice=${item.c_invoice_no} | ${error.message}`
|
|
);
|
|
}
|
|
}
|
|
return partnerRecon;
|
|
};
|
|
|
|
const _generateCashInSalesInternal = async (uniqueCode) => {
|
|
let partnerRecon = await model.getPartnerReconSalesInternal(knex);
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
|
partnerRecon
|
|
)}`
|
|
);
|
|
|
|
for (const item of partnerRecon) {
|
|
await knex.transaction(async (trx) => {
|
|
const sales = await model.getSalesInternal(
|
|
trx,
|
|
item.c_partner_code,
|
|
item.d_payment,
|
|
item.c_invoice_no
|
|
);
|
|
|
|
if (!sales || sales.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const cashInAmount = sales.reduce(
|
|
(sum, row) => sum + parseInt(row.i_total_price, 10),
|
|
0
|
|
);
|
|
|
|
if (cashInAmount <= 0) {
|
|
return;
|
|
}
|
|
|
|
let runningAmount = 0;
|
|
for (const detail of sales) {
|
|
runningAmount += parseInt(detail.i_total_price, 10);
|
|
if (runningAmount > parseInt(detail.invoice_amount, 10)) {
|
|
throw new Error(
|
|
`ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${runningAmount} > INVOICE AMOUNT (${detail.invoice_amount})`
|
|
);
|
|
}
|
|
}
|
|
|
|
const code = await model.generateCode(
|
|
trx,
|
|
item.c_partner_code,
|
|
moment().format('YYMMDD')
|
|
);
|
|
|
|
const dataCahsIn = {
|
|
c_partner_code: item.c_partner_code,
|
|
c_partner_name: item.c_partner_name,
|
|
c_cash_in_no: code,
|
|
c_in_period: item.c_in_period,
|
|
d_credit: item.d_payment,
|
|
c_invoice_no: item.c_invoice_no,
|
|
i_amount: cashInAmount,
|
|
c_source: 'S',
|
|
};
|
|
|
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
|
await model.writePaynentHistory(dataCahsIn, 'SUCCESSFULLY', 0, trx);
|
|
|
|
const dataSales = {
|
|
i_cash_in: cashIn.i_cash_in,
|
|
};
|
|
|
|
const salesNos = sales.map((detail) => detail.c_sales_no);
|
|
const cashInDetails = sales.map((detail) => ({
|
|
i_cash_in: cashIn.i_cash_in,
|
|
c_reservation_no: detail.c_sales_no,
|
|
m_amount: detail.i_total_price,
|
|
c_payment_recon_no: detail.c_payment_recon_no,
|
|
d_payment: detail.d_payment,
|
|
d_payment_recon: detail.d_payment_recon,
|
|
}));
|
|
|
|
await model.updateIntoSalesInternalBulk(trx, dataSales, salesNos);
|
|
await model.insertCashInDetailBulk(trx, cashInDetails);
|
|
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN SALES INTERNAL ${code} SUCCESS. partner=${item.c_partner_code}, invoice=${item.c_invoice_no}, rows=${cashInDetails.length}, amount=${cashInAmount}`
|
|
);
|
|
});
|
|
}
|
|
return partnerRecon;
|
|
};
|
|
|
|
const _generateCashInTopUpCashlessInternal = async (uniqueCode) => {
|
|
let partnerRecon = await model.getPartnerReconTopUpCashlessInternal(knex);
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
|
partnerRecon
|
|
)}`
|
|
);
|
|
|
|
for (const item of partnerRecon) {
|
|
await knex.transaction(async (trx) => {
|
|
const topup = await model.getTopUpCashlessInternal(
|
|
trx,
|
|
item.c_partner_code,
|
|
item.d_payment,
|
|
item.c_invoice_no
|
|
);
|
|
|
|
if (!topup || topup.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const cashInAmount = topup.reduce(
|
|
(sum, row) => sum + parseInt(row.i_amount, 10),
|
|
0
|
|
);
|
|
|
|
if (cashInAmount <= 0) {
|
|
return;
|
|
}
|
|
|
|
let runningAmount = 0;
|
|
for (const detail of topup) {
|
|
runningAmount += parseInt(detail.i_amount, 10);
|
|
if (runningAmount > parseInt(detail.invoice_amount, 10)) {
|
|
throw new Error(
|
|
`ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${runningAmount} > INVOICE AMOUNT (${detail.invoice_amount})`
|
|
);
|
|
}
|
|
}
|
|
|
|
const code = await model.generateCode(
|
|
trx,
|
|
item.c_partner_code,
|
|
moment().format('YYMMDD')
|
|
);
|
|
|
|
const dataCahsIn = {
|
|
c_partner_code: item.c_partner_code,
|
|
c_partner_name: item.c_partner_name,
|
|
c_cash_in_no: code,
|
|
c_in_period: item.c_in_period,
|
|
d_credit: item.d_payment,
|
|
c_invoice_no: item.c_invoice_no,
|
|
i_amount: cashInAmount,
|
|
c_source: 'T',
|
|
};
|
|
|
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
|
await model.writePaynentHistory(dataCahsIn, 'SUCCESSFULLY', 0, trx);
|
|
|
|
const dataTopup = {
|
|
i_cash_in: cashIn.i_cash_in,
|
|
};
|
|
|
|
const topupNos = topup.map((detail) => detail.c_topup_no);
|
|
const cashInDetails = topup.map((detail) => ({
|
|
i_cash_in: cashIn.i_cash_in,
|
|
c_reservation_no: detail.c_topup_no,
|
|
m_amount: detail.i_amount,
|
|
c_payment_recon_no: detail.c_payment_recon_no,
|
|
d_payment: detail.d_payment,
|
|
d_payment_recon: detail.d_payment_recon,
|
|
}));
|
|
|
|
await model.updateIntoTopUpCashlessInternalBulk(trx, dataTopup, topupNos);
|
|
await model.insertCashInDetailBulk(trx, cashInDetails);
|
|
|
|
winston.logger.info(
|
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TOPUP CASHLESS INTERNAL ${code} SUCCESS. partner=${item.c_partner_code}, invoice=${item.c_invoice_no}, rows=${cashInDetails.length}, amount=${cashInAmount}`
|
|
);
|
|
});
|
|
}
|
|
return partnerRecon;
|
|
};
|
|
|
|
const _postingCashIn = async (uniqueCode) => {
|
|
let data = [];
|
|
let postingEt = await model.getPostingEt(knex);
|
|
|
|
for (const item of postingEt) {
|
|
await knex.transaction(async (trx) => {
|
|
winston.logger.info(
|
|
`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`
|
|
);
|
|
|
|
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
|
|
);
|
|
console.log(xmlRequest);
|
|
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)}`
|
|
);
|
|
|
|
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.no_dok, resSAP, trx);
|
|
|
|
winston.logger.info(
|
|
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
|
);
|
|
});
|
|
}
|
|
|
|
return postingEt;
|
|
};
|
|
|
|
module.exports = {
|
|
validate,
|
|
apiGenerateCahsIn,
|
|
apiGenerateCashInSales,
|
|
apiGenerateCashInSalesInternal,
|
|
apiGenerateCashInTopUpCashlessInternal,
|
|
apiPostingCahsIn,
|
|
_postingCashIn,
|
|
_generateCashIn,
|
|
_generateCashInSales,
|
|
_generateCashInSalesInternal,
|
|
_generateCashInTopUpCashlessInternal,
|
|
};
|