mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 20:26:28 +00:00
Compare commits
102 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4140360736 | |||
| f4fc8cd147 | |||
| f5f75381ca | |||
| 5cbdccca11 | |||
| fd386788f8 | |||
| 6ddf225485 | |||
| 1645aa54aa | |||
| 797bf97bf8 | |||
| a7f5c8c8e0 | |||
| d2d44f3ba9 | |||
| 4dccbf20f5 | |||
| b888951ee3 | |||
| 87dedd241a | |||
| d4f56aacd8 | |||
| fec5209c83 | |||
| 93b6bd94ca | |||
| 39ac9e0e2d | |||
| 5037e022fd | |||
| cbb1d353a3 | |||
| f73accc275 | |||
| d7c62eda3f | |||
| a4b089ac85 | |||
| 3bf01d9059 | |||
| 8e54ebb704 | |||
| 48fb780252 | |||
| 382ccaab58 | |||
| 41444e037c | |||
| c49e4b3526 | |||
| d99882b8b9 | |||
| 45091038fe | |||
| 7c6e08a5b5 | |||
| 6e7d727b40 | |||
| 3bb2748387 | |||
| 6fea76b721 | |||
| 934e962dba | |||
| 3ccac7d220 | |||
| cede2396b7 | |||
| 9c06ec992e | |||
| 419700d6c5 | |||
| 6af2637bca | |||
| 8bb705f973 | |||
| 6755824ad0 | |||
| d93e3549ea | |||
| af697bd24d | |||
| c792a5ef15 | |||
| 282cc6372a | |||
| aea6577e38 | |||
| 6ae2de5010 | |||
| d7c3ad199a | |||
| 3808dafda7 | |||
| 14ea651b28 | |||
| 4079caa059 | |||
| 351a81a069 | |||
| 35aad851ba | |||
| e25797e091 | |||
| ac1c3c969b | |||
| 0e256ae481 | |||
| 2179a67b41 | |||
| fd3741e2ee | |||
| 2eb91dc105 | |||
| a257d50872 | |||
| fdebd4dbe9 | |||
| 745d186b3f | |||
| 0145ce5703 | |||
| a45acf1488 | |||
| bbc26c5964 | |||
| 7058143c4e | |||
| 5af2cc37d0 | |||
| 75acdc4195 | |||
| a08cedf7e8 | |||
| a16a0172a4 | |||
| 9af6f4f823 | |||
| 5259fd89ef | |||
| 0e35368e22 | |||
| 0fdc901193 | |||
| c3a458313e | |||
| 8ed7e738ab | |||
| 11b2ff8721 | |||
| 851f1b14f6 | |||
| 67c33c8e1f | |||
| ad8951c567 | |||
| 5da07d9330 | |||
| a680bc235d | |||
| 269ae0088d | |||
| fe6fe9e72e | |||
| 060c9d0b0b | |||
| 7eff55e7f3 | |||
| 810d432374 | |||
| 687521146e | |||
| e82a09187c | |||
| 3a8e2976f0 | |||
| 530b5eed7e | |||
| e9e9bbf4c8 | |||
| 29c8f60135 | |||
| cc497f606b | |||
| c17e56731f | |||
| f5574250d7 | |||
| 3a85e63c01 | |||
| 301696661d | |||
| 9fa469fc67 | |||
| 02fa5cb909 | |||
| 3dfd2a50d4 |
@@ -27,7 +27,13 @@ var logger;
|
|||||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||||
filename: `application/logs/%DATE%-onlinetopup.log`,
|
filename: `application/logs/%DATE%-onlinetopup.log`,
|
||||||
datePattern: "YYYY-MM-DD",
|
datePattern: "YYYY-MM-DD",
|
||||||
maxFiles: "90d",
|
maxFiles: "60d",
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileRotateTransportDebug = new winston.transports.DailyRotateFile({
|
||||||
|
filename: `application/logs/debug/%DATE%-onlinetopup.log`,
|
||||||
|
datePattern: "YYYY-MM-DD",
|
||||||
|
maxFiles: "30d",
|
||||||
});
|
});
|
||||||
//
|
//
|
||||||
// If we're not in production then log to the `console` with the format:
|
// If we're not in production then log to the `console` with the format:
|
||||||
@@ -54,6 +60,7 @@ if (
|
|||||||
defaultMeta: { service: "topuponline-service" },
|
defaultMeta: { service: "topuponline-service" },
|
||||||
transports: [
|
transports: [
|
||||||
fileRotateTransport,
|
fileRotateTransport,
|
||||||
|
fileRotateTransportDebug,
|
||||||
//
|
//
|
||||||
// - Write all logs with importance level of `error` or less to `error.log`
|
// - Write all logs with importance level of `error` or less to `error.log`
|
||||||
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
||||||
@@ -84,6 +91,7 @@ if (
|
|||||||
defaultMeta: { service: "topuponline-service" },
|
defaultMeta: { service: "topuponline-service" },
|
||||||
transports: [
|
transports: [
|
||||||
fileRotateTransport,
|
fileRotateTransport,
|
||||||
|
fileRotateTransportDebug,
|
||||||
//
|
//
|
||||||
// - Write all logs with importance level of `error` or less to `error.log`
|
// - Write all logs with importance level of `error` or less to `error.log`
|
||||||
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
||||||
|
|||||||
@@ -154,7 +154,115 @@ const apiGenerateCashInSales = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// RETRY POSTING INVOICE
|
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) => {
|
const apiPostingCahsIn = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// generate unique code
|
// generate unique code
|
||||||
@@ -377,7 +485,6 @@ const _generateCashInSales = async (uniqueCode) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const item of partnerRecon) {
|
for (const item of partnerRecon) {
|
||||||
let reserve = [];
|
|
||||||
let code = '';
|
let code = '';
|
||||||
await knex.transaction(async (trx) => {
|
await knex.transaction(async (trx) => {
|
||||||
try {
|
try {
|
||||||
@@ -481,7 +588,6 @@ const _generateCashInSales = async (uniqueCode) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await wait(10000);
|
await wait(10000);
|
||||||
winston.logger.info();
|
|
||||||
}
|
}
|
||||||
await trx.commit();
|
await trx.commit();
|
||||||
|
|
||||||
@@ -495,6 +601,260 @@ const _generateCashInSales = async (uniqueCode) => {
|
|||||||
return partnerRecon;
|
return partnerRecon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _generateCashInSalesInternal = async (uniqueCode) => {
|
||||||
|
let partnerRecon = await model.getPartnerReconSalesInternal(knex);
|
||||||
|
|
||||||
|
// return partnerRecon
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
||||||
|
partnerRecon
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const item of partnerRecon) {
|
||||||
|
let code = '';
|
||||||
|
await knex.transaction(async (trx) => {
|
||||||
|
try {
|
||||||
|
code = await model.generateCode(
|
||||||
|
trx,
|
||||||
|
item.c_partner_code,
|
||||||
|
moment().format('YYMMDD')
|
||||||
|
);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Cash-in
|
||||||
|
let 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: item.amount,
|
||||||
|
c_source: 'S'
|
||||||
|
};
|
||||||
|
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN SALES ${code} DATA : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// CASH-IN DETAIL
|
||||||
|
const sales = await model.getSalesInternal(
|
||||||
|
trx,
|
||||||
|
item.c_partner_code,
|
||||||
|
item.d_payment,
|
||||||
|
item.c_invoice_no
|
||||||
|
);
|
||||||
|
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} DATA SALES INTERNAL ${code} : ${JSON.stringify( sales )}`
|
||||||
|
);
|
||||||
|
|
||||||
|
//TOTAL AMOUNT CASH-IN
|
||||||
|
let cashInAmount = 0;
|
||||||
|
for (const itemCI of sales) {
|
||||||
|
cashInAmount += parseInt(itemCI.i_total_price);
|
||||||
|
}
|
||||||
|
dataCahsIn.i_amount = cashInAmount;
|
||||||
|
|
||||||
|
if(cashInAmount > 0) {
|
||||||
|
//INSERT CASH-IN
|
||||||
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
const paymentyHistory = await model.writePaynentHistory(
|
||||||
|
dataCahsIn, 'SUCCESSFULLY', 0, trx
|
||||||
|
);
|
||||||
|
|
||||||
|
let m_amount = 0;
|
||||||
|
for (const detail of sales) {
|
||||||
|
let temp = {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
|
let salesNo = detail.c_sales_no;
|
||||||
|
let dataSales = {
|
||||||
|
i_cash_in: cashIn.i_cash_in,
|
||||||
|
};
|
||||||
|
m_amount += parseInt(detail.i_total_price);
|
||||||
|
|
||||||
|
if(m_amount <= detail.invoice_amount) {
|
||||||
|
await model.updateIntoSalesInternal(trx, dataSales, salesNo);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} CASH-IN UPDATE SALES INTERNAL ${salesNo} DATA : ${JSON.stringify(
|
||||||
|
dataSales
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
await model.insertCashInDetail(trx, temp);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN DETAIL, ID CASH-IN ${cashIn.i_cash_in} : ${JSON.stringify(
|
||||||
|
temp
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await trx.rollback();
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${m_amount} > INVOICE AMOUNT (${detail.invoice_amount}) : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await wait(10000);
|
||||||
|
}
|
||||||
|
await trx.commit();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
sts = "error";
|
||||||
|
await trx.rollback();
|
||||||
|
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return partnerRecon;
|
||||||
|
};
|
||||||
|
|
||||||
|
const _generateCashInTopUpCashlessInternal = async (uniqueCode) => {
|
||||||
|
let partnerRecon = await model.getPartnerReconTopUpCashlessInternal(knex);
|
||||||
|
|
||||||
|
// return partnerRecon
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
||||||
|
partnerRecon
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const item of partnerRecon) {
|
||||||
|
let code = '';
|
||||||
|
await knex.transaction(async (trx) => {
|
||||||
|
try {
|
||||||
|
code = await model.generateCode(
|
||||||
|
trx,
|
||||||
|
item.c_partner_code,
|
||||||
|
moment().format('YYMMDD')
|
||||||
|
);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Cash-in
|
||||||
|
let 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: item.amount,
|
||||||
|
c_source: 'T'
|
||||||
|
};
|
||||||
|
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TOPUP CASHLESS INTERNAL ${code} DATA : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// CASH-IN DETAIL
|
||||||
|
const topup = await model.getTopUpCashlessInternal(
|
||||||
|
trx,
|
||||||
|
item.c_partner_code,
|
||||||
|
item.d_payment,
|
||||||
|
item.c_invoice_no
|
||||||
|
);
|
||||||
|
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} DATA TOPUP CASHLESS INTERNAL ${code} : ${JSON.stringify( topup )}`
|
||||||
|
);
|
||||||
|
|
||||||
|
//TOTAL AMOUNT CASH-IN
|
||||||
|
let cashInAmount = 0;
|
||||||
|
for (const itemCI of topup) {
|
||||||
|
cashInAmount += parseInt(itemCI.i_amount);
|
||||||
|
}
|
||||||
|
dataCahsIn.i_amount = cashInAmount;
|
||||||
|
|
||||||
|
if(cashInAmount > 0) {
|
||||||
|
|
||||||
|
//INSERT CASH-IN
|
||||||
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
const paymentyHistory = await model.writePaynentHistory(
|
||||||
|
dataCahsIn, 'SUCCESSFULLY', 0, trx
|
||||||
|
);
|
||||||
|
|
||||||
|
let m_amount = 0;
|
||||||
|
for (const detail of topup) {
|
||||||
|
let temp = {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
|
let topupNo = detail.c_topup_no;
|
||||||
|
let dataTopup = {
|
||||||
|
i_cash_in: cashIn.i_cash_in,
|
||||||
|
};
|
||||||
|
m_amount += parseInt(detail.i_amount);
|
||||||
|
|
||||||
|
if(m_amount <= detail.invoice_amount) {
|
||||||
|
await model.updateIntoTopUpCashlessInternal(trx, dataTopup, topupNo);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} CASH-IN UPDATE TOPUP CASHLESS INTERNAL ${topupNo} DATA : ${JSON.stringify(
|
||||||
|
dataTopup
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
await model.insertCashInDetail(trx, temp);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN DETAIL, ID CASH-IN ${cashIn.i_cash_in} : ${JSON.stringify(
|
||||||
|
temp
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await trx.rollback();
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${m_amount} > INVOICE AMOUNT (${detail.invoice_amount}) : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await wait(10000);
|
||||||
|
}
|
||||||
|
await trx.commit();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
sts = "error";
|
||||||
|
await trx.rollback();
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return partnerRecon;
|
||||||
|
};
|
||||||
|
|
||||||
const _postingCashIn = async (uniqueCode) => {
|
const _postingCashIn = async (uniqueCode) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
let postingEt = await model.getPostingEt(knex);
|
let postingEt = await model.getPostingEt(knex);
|
||||||
@@ -579,8 +939,12 @@ module.exports = {
|
|||||||
validate,
|
validate,
|
||||||
apiGenerateCahsIn,
|
apiGenerateCahsIn,
|
||||||
apiGenerateCashInSales,
|
apiGenerateCashInSales,
|
||||||
|
apiGenerateCashInSalesInternal,
|
||||||
|
apiGenerateCashInTopUpCashlessInternal,
|
||||||
apiPostingCahsIn,
|
apiPostingCahsIn,
|
||||||
_postingCashIn,
|
_postingCashIn,
|
||||||
_generateCashIn,
|
_generateCashIn,
|
||||||
_generateCashInSales
|
_generateCashInSales,
|
||||||
|
_generateCashInSalesInternal,
|
||||||
|
_generateCashInTopUpCashlessInternal,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -340,6 +340,66 @@ const getSalesKMT = async (trx, code, date, invoice) => {
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSalesInternal = async (trx, code, date, invoice) => {
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tdskm.c_sales_no',
|
||||||
|
'tdskm.i_total_price',
|
||||||
|
'tdpr.c_payment_recon_no',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tdpr.d_payment_recon',
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as c_partner_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.i_total_price as invoice_amount'
|
||||||
|
])
|
||||||
|
.from('trx.t_d_sales_internal AS tdskm')
|
||||||
|
.leftJoin('payment.t_d_payment_recon_sales_internal as tdpr', 'tdpr.c_sales_no', 'tdskm.c_sales_no')
|
||||||
|
.leftJoin('payment.t_d_sales_invoice_internal as tdsi', 'tdsi.i_sales_invoice_internal', 'tdskm.i_sales_invoice_internal')
|
||||||
|
.leftJoin('public.t_m_partner as tmp', 'tmp.i_partner', 'tdskm.i_partner')
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tmp.c_code', '=', code)
|
||||||
|
.where('tdpr.d_payment', '=', date)
|
||||||
|
.where('tdsi.c_invoice_no', '=', invoice)
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap_fi')
|
||||||
|
.whereRaw(
|
||||||
|
`tdskm.c_sales_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTopUpCashlessInternal = async (trx, code, date, invoice) => {
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tdskm.c_topup_no',
|
||||||
|
'tdskm.i_amount',
|
||||||
|
'tdpr.c_payment_recon_no',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tdpr.d_payment_recon',
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as c_partner_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.i_total_amount as invoice_amount'
|
||||||
|
])
|
||||||
|
.from('trx.t_d_topup_cashless_internal AS tdskm')
|
||||||
|
.leftJoin('payment.t_d_payment_recon_topup_cashless_internal as tdpr', 'tdpr.c_topup_no', 'tdskm.c_topup_no')
|
||||||
|
.leftJoin('payment.t_d_topup_cashless_invoice_internal as tdsi', 'tdsi.i_topup_cashless_invoice_internal', 'tdskm.i_topup_cashless_invoice_internal')
|
||||||
|
.leftJoin('public.t_m_partner as tmp', 'tmp.i_partner', 'tdskm.i_partner')
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tmp.c_code', '=', code)
|
||||||
|
.where('tdpr.d_payment', '=', date)
|
||||||
|
.where('tdsi.c_invoice_no', '=', invoice)
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap')
|
||||||
|
.whereRaw(
|
||||||
|
`tdskm.c_topup_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
const getPartnerRecon = async (trx) => {
|
const getPartnerRecon = async (trx) => {
|
||||||
// const res = await trx
|
// const res = await trx
|
||||||
// .select([
|
// .select([
|
||||||
@@ -510,6 +570,94 @@ const getPartnerReconSales = async (trx) => {
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPartnerReconSalesInternal = async (trx) => {
|
||||||
|
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as c_partner_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.d_invoice_date',
|
||||||
|
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||||
|
trx.raw('coalesce(SUM(tdskm.i_total_price),0) AS amount'),
|
||||||
|
'tmp.c_account_sales_revenue',
|
||||||
|
'tmp.c_account_code_sales_ar',
|
||||||
|
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
|
||||||
|
THEN 'IP' ELSE 'OP'
|
||||||
|
END c_in_period`),
|
||||||
|
])
|
||||||
|
.from('trx.t_d_sales_internal AS tdskm')
|
||||||
|
|
||||||
|
.leftJoin('payment.t_d_sales_invoice_internal as tdsi', function () {
|
||||||
|
this.on('tdsi.i_sales_invoice_internal', '=', 'tdskm.i_sales_invoice_internal');
|
||||||
|
})
|
||||||
|
.leftJoin('payment.t_d_payment_recon_sales_internal as tdpr', function () {
|
||||||
|
this.on('tdpr.c_sales_no', '=', 'tdskm.c_sales_no');
|
||||||
|
})
|
||||||
|
.leftJoin('public.t_m_partner as tmp', function () {
|
||||||
|
this.on('tmp.i_partner', '=', 'tdskm.i_partner');
|
||||||
|
})
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap_fi')
|
||||||
|
.whereNull('tdskm.i_cash_in')
|
||||||
|
.groupBy([
|
||||||
|
'tmp.c_code',
|
||||||
|
'tmp.c_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.d_invoice_date',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tmp.c_account_sales_revenue',
|
||||||
|
'tmp.c_account_code_sales_ar'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPartnerReconTopUpCashlessInternal = async (trx) => {
|
||||||
|
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as c_partner_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.d_invoice_date',
|
||||||
|
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||||
|
trx.raw('coalesce(SUM(tdskm.i_amount),0) AS amount'),
|
||||||
|
'tmp.c_account_topup',
|
||||||
|
'tmp.c_account_code_topup',
|
||||||
|
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
|
||||||
|
THEN 'IP' ELSE 'OP'
|
||||||
|
END c_in_period`),
|
||||||
|
])
|
||||||
|
.from('trx.t_d_topup_cashless_internal AS tdskm')
|
||||||
|
|
||||||
|
.leftJoin('payment.t_d_topup_cashless_invoice_internal as tdsi', function () {
|
||||||
|
this.on('tdsi.i_topup_cashless_invoice_internal', '=', 'tdskm.i_topup_cashless_invoice_internal');
|
||||||
|
})
|
||||||
|
.leftJoin('payment.t_d_payment_recon_topup_cashless_internal as tdpr', function () {
|
||||||
|
this.on('tdpr.c_topup_no', '=', 'tdskm.c_topup_no');
|
||||||
|
})
|
||||||
|
.leftJoin('public.t_m_partner as tmp', function () {
|
||||||
|
this.on('tmp.i_partner', '=', 'tdskm.i_partner');
|
||||||
|
})
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap')
|
||||||
|
.whereNull('tdskm.i_cash_in')
|
||||||
|
.groupBy([
|
||||||
|
'tmp.c_code',
|
||||||
|
'tmp.c_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.d_invoice_date',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tmp.c_account_topup',
|
||||||
|
'tmp.c_account_code_topup'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
const generateCode = async (trx, c_partner_code, d_payment_recon) => {
|
const generateCode = async (trx, c_partner_code, d_payment_recon) => {
|
||||||
let code = '';
|
let code = '';
|
||||||
let prefix = `CIN${c_partner_code}${d_payment_recon}`;
|
let prefix = `CIN${c_partner_code}${d_payment_recon}`;
|
||||||
@@ -560,6 +708,20 @@ const updateIntoSalesKMT = async (trx, dataSales, salesNo) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateIntoSalesInternal = async (trx, dataSales, salesNo) => {
|
||||||
|
let result = await trx('trx.t_d_sales_internal')
|
||||||
|
.update(dataSales, ['*'])
|
||||||
|
.where({ c_sales_no: salesNo });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateIntoTopUpCashlessInternal = async (trx, dataTopup, topupNo) => {
|
||||||
|
let result = await trx('trx.t_d_topup_cashless_internal')
|
||||||
|
.update(dataTopup, ['*'])
|
||||||
|
.where({ c_topup_no: topupNo });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const insertCashIn = async (trx, data) => {
|
const insertCashIn = async (trx, data) => {
|
||||||
let result = await trx('payment.t_d_cash_in').insert(data, ['*']);
|
let result = await trx('payment.t_d_cash_in').insert(data, ['*']);
|
||||||
return result[0];
|
return result[0];
|
||||||
@@ -600,9 +762,15 @@ module.exports = {
|
|||||||
insertCashInDetail,
|
insertCashInDetail,
|
||||||
getPartnerRecon,
|
getPartnerRecon,
|
||||||
getPartnerReconSales,
|
getPartnerReconSales,
|
||||||
|
getPartnerReconSalesInternal,
|
||||||
|
getPartnerReconTopUpCashlessInternal,
|
||||||
getReserve,
|
getReserve,
|
||||||
getSalesKMT,
|
getSalesKMT,
|
||||||
|
getSalesInternal,
|
||||||
|
getTopUpCashlessInternal,
|
||||||
insertCashIn,
|
insertCashIn,
|
||||||
updateIntoReserve,
|
updateIntoReserve,
|
||||||
updateIntoSalesKMT
|
updateIntoSalesKMT,
|
||||||
|
updateIntoSalesInternal,
|
||||||
|
updateIntoTopUpCashlessInternal,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
const { param, body, validationResult } = require('express-validator');
|
const { param, body, validationResult } = require("express-validator");
|
||||||
const helper = require('../../helpers/helper');
|
const helper = require("../../helpers/helper");
|
||||||
const winston = require('../../helpers/winston.logger');
|
const winston = require("../../helpers/winston.logger");
|
||||||
const model = require('./invoice.model');
|
const model = require("./invoice.model");
|
||||||
const moment = require('moment');
|
const moment = require("moment");
|
||||||
const knex = require('../../../infrastructure/database/knex');
|
const knex = require("../../../infrastructure/database/knex");
|
||||||
moment.locale('id');
|
moment.locale("id");
|
||||||
|
|
||||||
// VALIDATION
|
// VALIDATION
|
||||||
const validate = (method) => {
|
const validate = (method) => {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'generateInvoice':
|
case "generateInvoice":
|
||||||
return [
|
return [
|
||||||
body('trx_date')
|
body("trx_date")
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('trx_date is required!')
|
.withMessage("trx_date is required!")
|
||||||
.isISO8601()
|
.isISO8601()
|
||||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
.withMessage("invalid trx_date format YYYY-MM-DD !")
|
||||||
.escape()
|
.escape()
|
||||||
.trim(),
|
.trim(),
|
||||||
body('repost')
|
body("repost")
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('repost is required!')
|
.withMessage("repost is required!")
|
||||||
.isBoolean()
|
.isBoolean()
|
||||||
.withMessage('repost must boolean!')
|
.withMessage("repost must boolean!")
|
||||||
.escape()
|
.escape()
|
||||||
.trim(),
|
.trim(),
|
||||||
];
|
];
|
||||||
case 'postingInvoice':
|
case "postingInvoice":
|
||||||
return [
|
return [
|
||||||
body('trx_date')
|
body("trx_date")
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('trx_date is required!')
|
.withMessage("trx_date is required!")
|
||||||
.isISO8601()
|
.isISO8601()
|
||||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
.withMessage("invalid trx_date format YYYY-MM-DD !")
|
||||||
.escape()
|
.escape()
|
||||||
.trim(),
|
.trim(),
|
||||||
];
|
];
|
||||||
@@ -57,7 +57,7 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
let err = validationResult(req, res);
|
let err = validationResult(req, res);
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
result = {
|
result = {
|
||||||
code: '400',
|
code: "400",
|
||||||
message: err.errors[0].msg,
|
message: err.errors[0].msg,
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
@@ -71,7 +71,7 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let invoiceDate = moment(req.body.trx_date).format('YYYY-MM-DD');
|
let invoiceDate = moment(req.body.trx_date).format("YYYY-MM-DD");
|
||||||
|
|
||||||
let invoice = await _generateInvoice(
|
let invoice = await _generateInvoice(
|
||||||
invoiceDate,
|
invoiceDate,
|
||||||
@@ -80,8 +80,8 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: '200',
|
code: "200",
|
||||||
message: 'Succes posting',
|
message: "Succes posting",
|
||||||
data: invoice,
|
data: invoice,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,11 +93,11 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
code: '500',
|
code: "500",
|
||||||
message:
|
message:
|
||||||
process.env.NODE_ENV != 'production'
|
process.env.NODE_ENV != "production"
|
||||||
? error.message
|
? error.message
|
||||||
: '500 internal server error - backend server.',
|
: "500 internal server error - backend server.",
|
||||||
data: {},
|
data: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ const apiPostingInvoice = async (req, res) => {
|
|||||||
let err = validationResult(req, res);
|
let err = validationResult(req, res);
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
result = {
|
result = {
|
||||||
code: '400',
|
code: "400",
|
||||||
message: err.errors[0].msg,
|
message: err.errors[0].msg,
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
@@ -137,10 +137,15 @@ const apiPostingInvoice = async (req, res) => {
|
|||||||
|
|
||||||
let invoice = await _postingInvoice(uniqueCode);
|
let invoice = await _postingInvoice(uniqueCode);
|
||||||
|
|
||||||
|
let errorCount = invoice[0].error;
|
||||||
|
|
||||||
|
invoice.splice(0, 1);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: '200',
|
code: "200",
|
||||||
message: 'Succes',
|
message: "Succes",
|
||||||
data: invoice,
|
data: invoice,
|
||||||
|
error: errorCount,
|
||||||
};
|
};
|
||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
@@ -151,11 +156,11 @@ const apiPostingInvoice = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
code: '500',
|
code: "500",
|
||||||
message:
|
message:
|
||||||
process.env.NODE_ENV != 'production'
|
process.env.NODE_ENV != "production"
|
||||||
? error.message
|
? error.message
|
||||||
: '500 internal server error - backend server.',
|
: "500 internal server error - backend server.",
|
||||||
data: {},
|
data: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -200,29 +205,29 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
|
|
||||||
let credUsername = await model.getParameterSetting(
|
let credUsername = await model.getParameterSetting(
|
||||||
knex,
|
knex,
|
||||||
'SAP_AUTH_USERNAME'
|
"SAP_AUTH_USERNAME"
|
||||||
);
|
);
|
||||||
let credPassword = await model.getParameterSetting(
|
let credPassword = await model.getParameterSetting(
|
||||||
knex,
|
knex,
|
||||||
'SAP_AUTH_PASSWORD'
|
"SAP_AUTH_PASSWORD"
|
||||||
);
|
);
|
||||||
let parameter = await model.getParameterSetting(
|
let parameter = await model.getParameterSetting(
|
||||||
knex,
|
knex,
|
||||||
'SAP_FI_URL_FOR_FB70'
|
"SAP_FI_URL_FOR_FB70"
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let key in invoice) {
|
for (let key in invoice) {
|
||||||
let prepare = {
|
let prepare = {
|
||||||
status: true,
|
status: true,
|
||||||
cms: true,
|
cms: true,
|
||||||
message: 'Success',
|
message: "Success",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!credUsername) {
|
if (!credUsername) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_USERNAME',
|
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_USERNAME",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +235,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +243,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,49 +260,49 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message:
|
message:
|
||||||
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP',
|
"[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
invoice[key].c_account_code_topup == '' ||
|
invoice[key].c_account_code_topup == "" ||
|
||||||
invoice[key].c_account_topup == ''
|
invoice[key].c_account_topup == ""
|
||||||
) {
|
) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message:
|
message:
|
||||||
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP',
|
"[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let xmlHeader = {
|
let xmlHeader = {
|
||||||
doc_header_text: invoice[key].doc_header_text
|
doc_header_text: invoice[key].doc_header_text
|
||||||
? invoice[key].doc_header_text
|
? invoice[key].doc_header_text
|
||||||
: '',
|
: "",
|
||||||
ba: invoice[key].ba ? invoice[key].ba : '',
|
ba: invoice[key].ba ? invoice[key].ba : "",
|
||||||
doc_date: invoice[key].doc_date ? invoice[key].doc_date : '',
|
doc_date: invoice[key].doc_date ? invoice[key].doc_date : "",
|
||||||
posting_date: invoice[key].posting_date
|
posting_date: invoice[key].posting_date
|
||||||
? invoice[key].posting_date
|
? invoice[key].posting_date
|
||||||
: '',
|
: "",
|
||||||
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : '',
|
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : "",
|
||||||
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : '',
|
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : "",
|
||||||
doc_type: invoice[key].doc_type ? invoice[key].doc_type : '',
|
doc_type: invoice[key].doc_type ? invoice[key].doc_type : "",
|
||||||
c_invoice_no: invoice[key].c_invoice_no
|
c_invoice_no: invoice[key].c_invoice_no
|
||||||
? invoice[key].c_invoice_no
|
? invoice[key].c_invoice_no
|
||||||
: '',
|
: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
let xmlItem = ['S', 'H'].map((item) => {
|
let xmlItem = ["S", "H"].map((item) => {
|
||||||
return {
|
return {
|
||||||
c_account_code_topup:
|
c_account_code_topup:
|
||||||
item == 'S' ? invoice[key].c_account_code_topup : '',
|
item == "S" ? invoice[key].c_account_code_topup : "",
|
||||||
c_account_topup: item == 'H' ? invoice[key].c_account_topup : '',
|
c_account_topup: item == "H" ? invoice[key].c_account_topup : "",
|
||||||
ba: invoice[key].ba,
|
ba: invoice[key].ba,
|
||||||
amount: invoice[key].amount,
|
amount: invoice[key].amount,
|
||||||
posting_date: invoice[key].posting_date,
|
posting_date: invoice[key].posting_date,
|
||||||
c_invoice_no: invoice[key].c_invoice_no,
|
c_invoice_no: invoice[key].c_invoice_no,
|
||||||
item_text: `${item == 'S' ? 'DEBIT' : 'KREDIT'} INVOICE CMS ${
|
item_text: `${item == "S" ? "DEBIT" : "KREDIT"} INVOICE CMS ${
|
||||||
invoice[key].doc_header_text
|
invoice[key].doc_header_text
|
||||||
}`,
|
}`,
|
||||||
de_cre: item,
|
de_cre: item,
|
||||||
@@ -305,7 +310,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let xmlRequest = helper.generateXMLRequest(
|
let xmlRequest = helper.generateXMLRequest(
|
||||||
'ZFMCMS_FI_001',
|
"ZFMCMS_FI_001",
|
||||||
xmlHeader,
|
xmlHeader,
|
||||||
xmlItem
|
xmlItem
|
||||||
);
|
);
|
||||||
@@ -338,8 +343,8 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
resSAP = helper.getXMLData(response);
|
resSAP = helper.getXMLData(response);
|
||||||
} else {
|
} else {
|
||||||
resSAP = {
|
resSAP = {
|
||||||
type: 'E',
|
type: "E",
|
||||||
message: prepare?.message || 'FAILED GET PARAMETER SETTING',
|
message: prepare?.message || "FAILED GET PARAMETER SETTING",
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -382,33 +387,33 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
let credUsername = await model.getParameterSetting(knex, 'SAP_AUTH_USERNAME');
|
let credUsername = await model.getParameterSetting(knex, "SAP_AUTH_USERNAME");
|
||||||
let credPassword = await model.getParameterSetting(knex, 'SAP_AUTH_PASSWORD');
|
let credPassword = await model.getParameterSetting(knex, "SAP_AUTH_PASSWORD");
|
||||||
let parameter = await model.getParameterSetting(knex, 'SAP_FI_URL_FOR_FB70');
|
let parameter = await model.getParameterSetting(knex, "SAP_FI_URL_FOR_FB70");
|
||||||
|
|
||||||
let prepare = {
|
let prepare = {
|
||||||
status: true,
|
status: true,
|
||||||
message: 'Success',
|
message: "Success",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!credUsername) {
|
if (!credUsername) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
message: 'FAILED GET SETTING FOR SAP_AUTH_USERNAME',
|
message: "FAILED GET SETTING FOR SAP_AUTH_USERNAME",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!credPassword) {
|
if (!credPassword) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parameter) {
|
if (!parameter) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +422,7 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
password: credPassword.c_value,
|
password: credPassword.c_value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let errorCount = 0;
|
||||||
for (let item of postingEt) {
|
for (let item of postingEt) {
|
||||||
await knex.transaction(async (trx) => {
|
await knex.transaction(async (trx) => {
|
||||||
let response = {};
|
let response = {};
|
||||||
@@ -425,31 +431,31 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
|
|
||||||
if (prepare.status) {
|
if (prepare.status) {
|
||||||
let xmlHeader = {
|
let xmlHeader = {
|
||||||
doc_header_text: item.doc_header_text ? item.doc_header_text : '',
|
doc_header_text: item.doc_header_text ? item.doc_header_text : "",
|
||||||
ba: item.ba ? item.ba : '',
|
ba: item.ba ? item.ba : "",
|
||||||
doc_date: item.doc_date ? item.doc_date : '',
|
doc_date: item.doc_date ? item.doc_date : "",
|
||||||
posting_date: item.posting_date ? item.posting_date : '',
|
posting_date: item.posting_date ? item.posting_date : "",
|
||||||
fisc_year: item.fiscal_year ? item.fiscal_year : '',
|
fisc_year: item.fiscal_year ? item.fiscal_year : "",
|
||||||
fisc_period: item.fis_period ? item.fis_period : '',
|
fisc_period: item.fis_period ? item.fis_period : "",
|
||||||
doc_type: item.doc_type ? item.doc_type : '',
|
doc_type: item.doc_type ? item.doc_type : "",
|
||||||
c_invoice_no: item.reference ? item.reference : '',
|
c_invoice_no: item.reference ? item.reference : "",
|
||||||
};
|
};
|
||||||
|
|
||||||
let xmlItem = ['S', 'H'].map((key) => {
|
let xmlItem = ["S", "H"].map((key) => {
|
||||||
return {
|
return {
|
||||||
c_account_code_topup: key == 'S' ? item.customer : '',
|
c_account_code_topup: key == "S" ? item.customer : "",
|
||||||
c_account_topup: key == 'H' ? item.account : '',
|
c_account_topup: key == "H" ? item.account : "",
|
||||||
ba: item.ba,
|
ba: item.ba,
|
||||||
amount: item.amount,
|
amount: item.amount,
|
||||||
posting_date: item.posting_date,
|
posting_date: item.posting_date,
|
||||||
c_invoice_no: item.reference,
|
c_invoice_no: item.reference,
|
||||||
item_text: key == 'S' ? item.text1 : item.text2,
|
item_text: key == "S" ? item.text1 : item.text2,
|
||||||
de_cre: key,
|
de_cre: key,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let xmlRequest = helper.generateXMLRequest(
|
let xmlRequest = helper.generateXMLRequest(
|
||||||
'ZFMCMS_FI_001',
|
"ZFMCMS_FI_001",
|
||||||
xmlHeader,
|
xmlHeader,
|
||||||
xmlItem
|
xmlItem
|
||||||
);
|
);
|
||||||
@@ -471,10 +477,13 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
resSAP = helper.getXMLData(response);
|
resSAP = helper.getXMLData(response);
|
||||||
|
if (resSAP.type == "E") {
|
||||||
|
errorCount++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resSAP = {
|
resSAP = {
|
||||||
type: 'E',
|
type: "E",
|
||||||
message: prepare?.message || 'FAILED GET PARAMETER SETTING',
|
message: prepare?.message || "FAILED GET PARAMETER SETTING",
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -511,6 +520,8 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
collection.push({ error: errorCount });
|
||||||
|
|
||||||
collection.push(cms.invoice[0]);
|
collection.push(cms.invoice[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
|
|
||||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||||
const generateInvoice = async (invoiceDate, repost, trx) => {
|
const generateInvoice = async (invoiceDate, repost, trx) => {
|
||||||
|
let result = await trx.select(
|
||||||
let result = await trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`))
|
trx.raw(
|
||||||
|
`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const insertPostingEt = async (invoice, trx) => {
|
const insertPostingEt = async (invoice, trx) => {
|
||||||
console.log("invoice : ", invoice)
|
console.log("invoice : ", invoice);
|
||||||
let type = ['S', 'H']
|
let type = ["S", "H"];
|
||||||
let et = []
|
let et = [];
|
||||||
let posting_et = []
|
let posting_et = [];
|
||||||
type.forEach((item, index) => {
|
type.forEach((item, index) => {
|
||||||
let data = {
|
let data = {
|
||||||
file_name: invoice.file_name,
|
file_name: invoice.file_name,
|
||||||
@@ -26,222 +27,293 @@ const insertPostingEt = async (invoice, trx) => {
|
|||||||
reference: invoice.c_invoice_no,
|
reference: invoice.c_invoice_no,
|
||||||
amount: invoice.amount,
|
amount: invoice.amount,
|
||||||
ba: invoice.ba,
|
ba: invoice.ba,
|
||||||
indeks: (index+1),
|
indeks: index + 1,
|
||||||
totalidx: type.length,
|
totalidx: type.length,
|
||||||
doc_header_text: invoice.c_invoice_no,
|
doc_header_text: invoice.c_invoice_no,
|
||||||
pos_status : 3
|
pos_status: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (item == "H") {
|
||||||
|
data = {
|
||||||
|
...data,
|
||||||
|
...{
|
||||||
|
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
||||||
|
debit_kredit: item,
|
||||||
|
account: invoice.c_account_topup,
|
||||||
|
customer: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
|
...data,
|
||||||
|
...{
|
||||||
|
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
||||||
|
debit_kredit: item,
|
||||||
|
account: null,
|
||||||
|
customer: invoice.c_account_code_topup,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item == 'H'){
|
et.push(data);
|
||||||
data = {...data, ...{
|
|
||||||
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
|
||||||
debit_kredit: item,
|
|
||||||
account: invoice.c_account_topup,
|
|
||||||
customer: null
|
|
||||||
}}
|
|
||||||
}else{
|
|
||||||
data = {...data, ...{
|
|
||||||
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
|
||||||
debit_kredit: item,
|
|
||||||
account: null,
|
|
||||||
customer: invoice.c_account_code_topup
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
et.push(data)
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit'])
|
posting_et = await trx("public.posting_et").insert(et, [
|
||||||
|
"indeks",
|
||||||
|
"customer",
|
||||||
|
"account",
|
||||||
|
"ba",
|
||||||
|
"fiscal_year",
|
||||||
|
"amount",
|
||||||
|
"no_dok",
|
||||||
|
"text",
|
||||||
|
"debit_kredit",
|
||||||
|
]);
|
||||||
|
|
||||||
return posting_et[0]
|
return posting_et[0];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
const getPostingEt = async (trx) => {
|
||||||
|
const result = await trx("public.posting_et AS pe")
|
||||||
|
.select([
|
||||||
|
"doc_header_text",
|
||||||
|
"ba",
|
||||||
|
"doc_date",
|
||||||
|
"posting_date",
|
||||||
|
"fiscal_year",
|
||||||
|
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
||||||
|
"doc_type",
|
||||||
|
"reference",
|
||||||
|
"tcode",
|
||||||
|
"amount",
|
||||||
|
trx.raw(`'IDR' AS currency`),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.customer from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as customer`
|
||||||
|
),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.account from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as account`
|
||||||
|
),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as text1`
|
||||||
|
),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as text2`
|
||||||
|
),
|
||||||
|
])
|
||||||
|
.where("tcode", "=", "FB70")
|
||||||
|
.whereIn("pos_status", ["3"])
|
||||||
|
// .limit(1)
|
||||||
|
.groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12]);
|
||||||
|
|
||||||
const getPostingEt = async(trx) => {
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const result = await trx('public.posting_et AS pe').select([
|
const setReturnSAP = async (
|
||||||
'doc_header_text',
|
invoice,
|
||||||
'ba',
|
resSAP,
|
||||||
'doc_date',
|
trx,
|
||||||
'posting_date',
|
posting = false,
|
||||||
'fiscal_year',
|
c_invoice_no
|
||||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
) => {
|
||||||
'doc_type',
|
let t_invoice = {};
|
||||||
'reference',
|
let t_load_balance = {};
|
||||||
'tcode',
|
let posting_et = {};
|
||||||
'amount',
|
if (resSAP.type == "S") {
|
||||||
trx.raw(`'IDR' AS currency`),
|
|
||||||
trx.raw(`(select pe2.customer from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as customer`),
|
|
||||||
trx.raw(`(select pe2.account from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as account`),
|
|
||||||
trx.raw(`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as text1`),
|
|
||||||
trx.raw(`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as text2`),
|
|
||||||
])
|
|
||||||
.where('tcode', '=', "FB70")
|
|
||||||
.whereIn('pos_status', ["3"])
|
|
||||||
.groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12])
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const setReturnSAP = async (invoice, resSAP, trx, posting = false, c_invoice_no) => {
|
|
||||||
let t_invoice = {}
|
|
||||||
let t_load_balance = {}
|
|
||||||
let posting_et = {}
|
|
||||||
if(resSAP.type == 'S'){
|
|
||||||
// update invoice
|
// update invoice
|
||||||
t_invoice = await trx('payment.t_d_invoice').update({
|
t_invoice = await trx("payment.t_d_invoice")
|
||||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
|
.update(
|
||||||
}, ["*"])
|
{
|
||||||
.where({
|
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
c_invoice_no: c_invoice_no
|
},
|
||||||
});
|
["*"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
c_invoice_no: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update load balance
|
// update load balance
|
||||||
t_load_balance = await trx('trx.t_d_load_balance').update({
|
t_load_balance = await trx("trx.t_d_load_balance")
|
||||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
|
.update(
|
||||||
}, ['c_load_balance_no', 'c_return_sap'])
|
{
|
||||||
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`)
|
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
|
},
|
||||||
|
["c_load_balance_no", "c_return_sap"]
|
||||||
|
)
|
||||||
|
.whereRaw(
|
||||||
|
`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`
|
||||||
|
);
|
||||||
|
|
||||||
posting_et = await trx('public.posting_et').update({
|
posting_et = await trx("public.posting_et")
|
||||||
pos_status : 0,
|
.update(
|
||||||
status0 : resSAP.type,
|
{
|
||||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
pos_status: 0,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: resSAP.type,
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||||
reference: c_invoice_no
|
? resSAP.data.E_DOCUMENTNUMBER
|
||||||
})
|
: null,
|
||||||
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
|
},
|
||||||
|
["file_name", "status0"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
reference: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
if(posting) {
|
if (posting) {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
|
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
|
||||||
} else {
|
} else {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}else {
|
|
||||||
|
|
||||||
let text = resSAP.message;
|
let text = resSAP.message;
|
||||||
let result = text.toUpperCase();
|
let result = text.toUpperCase();
|
||||||
|
|
||||||
if(result.includes("ALREADY")){
|
if (result.includes("ALREADY")) {
|
||||||
let result = text.toUpperCase().split('-');
|
let result = text.toUpperCase().split("-");
|
||||||
let doc_number = result[1].trim().split(" ")[0]
|
let doc_number = result[1].trim().split(" ")[0];
|
||||||
// update invoice
|
// update invoice
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
let year = d.getFullYear();
|
let year = d.getFullYear();
|
||||||
|
|
||||||
posting_et = await trx('public.posting_et').update({
|
posting_et = await trx("public.posting_et")
|
||||||
pos_status : 0,
|
.update(
|
||||||
status0 : 'S',
|
{
|
||||||
no_doksap : doc_number,
|
pos_status: 0,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: "S",
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: doc_number,
|
||||||
reference: c_invoice_no
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
})
|
},
|
||||||
|
["file_name", "status0"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
reference: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update invoice
|
// update invoice
|
||||||
t_invoice = await trx('payment.t_d_invoice').update({
|
t_invoice = await trx("payment.t_d_invoice")
|
||||||
c_return_sap: doc_number
|
.update(
|
||||||
}, ['*'])
|
{
|
||||||
.where({
|
c_return_sap: doc_number,
|
||||||
c_invoice_no: c_invoice_no
|
},
|
||||||
});
|
["*"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
c_invoice_no: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update load balance
|
// update load balance
|
||||||
t_load_balance = await trx('trx.t_d_load_balance').update({
|
t_load_balance = await trx("trx.t_d_load_balance")
|
||||||
c_return_sap: doc_number
|
.update(
|
||||||
}, ['c_load_balance_no', 'c_return_sap'])
|
{
|
||||||
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`)
|
c_return_sap: doc_number,
|
||||||
|
},
|
||||||
|
["c_load_balance_no", "c_return_sap"]
|
||||||
|
)
|
||||||
|
.whereRaw(
|
||||||
|
`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`
|
||||||
|
);
|
||||||
|
|
||||||
if(posting) {
|
if (posting) {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
|
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
|
||||||
} else {
|
} else {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
await writePaynentHistory(
|
||||||
|
t_invoice[0],
|
||||||
|
"SUCCESS TO RETRY SAP",
|
||||||
|
118,
|
||||||
|
trx
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
// update posting et
|
// update posting et
|
||||||
posting_et = await trx('public.posting_et').update({
|
posting_et = await trx("public.posting_et")
|
||||||
pos_status : resSAP.type == 'S' ? 0 : 3,
|
.update(
|
||||||
status0 : resSAP.type,
|
{
|
||||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
pos_status: resSAP.type == "S" ? 0 : 3,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: resSAP.type,
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||||
reference: c_invoice_no
|
? resSAP.data.E_DOCUMENTNUMBER
|
||||||
})
|
: null,
|
||||||
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
|
},
|
||||||
|
["file_name", "status0"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
reference: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update invoice
|
// update invoice
|
||||||
t_invoice = await trx('payment.t_d_invoice').select(['*'])
|
t_invoice = await trx("payment.t_d_invoice").select(["*"]).where({
|
||||||
.where({
|
c_invoice_no: c_invoice_no,
|
||||||
c_invoice_no: c_invoice_no
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(posting) {
|
if (posting) {
|
||||||
await writePaynentHistory(t_invoice[0], `SUCCESS WITH SAP ERR: ${resSAP.message}`,102, trx)
|
await writePaynentHistory(
|
||||||
|
t_invoice[0],
|
||||||
|
`SUCCESS WITH SAP ERR: ${resSAP.message}`,
|
||||||
|
102,
|
||||||
|
trx
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await writePaynentHistory(t_invoice[0], `FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,118, trx)
|
await writePaynentHistory(
|
||||||
|
t_invoice[0],
|
||||||
|
`FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,
|
||||||
|
118,
|
||||||
|
trx
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update posting et
|
// update posting et
|
||||||
|
|
||||||
return {
|
return {
|
||||||
invoice : t_invoice,
|
invoice: t_invoice,
|
||||||
load_balance : t_load_balance,
|
load_balance: t_load_balance,
|
||||||
posting_et : posting_et
|
posting_et: posting_et,
|
||||||
}
|
};
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const writePaynentHistory = async (data, message, i_log_name, trx) => {
|
const writePaynentHistory = async (data, message, i_log_name, trx) => {
|
||||||
console.log(data)
|
console.log(data);
|
||||||
const result = await trx('log.t_log_invoice').insert({
|
const result = await trx("log.t_log_invoice").insert(
|
||||||
// i_log_name : 102,
|
{
|
||||||
i_log_name : i_log_name,
|
// i_log_name : 102,
|
||||||
d_log : trx.raw('NOW()'),
|
i_log_name: i_log_name,
|
||||||
c_invoice_no : data?.c_invoice_no || '',
|
d_log: trx.raw("NOW()"),
|
||||||
c_partner_name : data?.c_partner_name || '',
|
c_invoice_no: data?.c_invoice_no || "",
|
||||||
j_new_data : JSON.stringify(data),
|
c_partner_name: data?.c_partner_name || "",
|
||||||
d_payment_date: trx.raw('NOW()'),
|
j_new_data: JSON.stringify(data),
|
||||||
c_note : message,
|
d_payment_date: trx.raw("NOW()"),
|
||||||
c_status : 'S',
|
c_note: message,
|
||||||
d_created : trx.raw('NOW()'),
|
c_status: "S",
|
||||||
m_amount : data?.amount || 0,
|
d_created: trx.raw("NOW()"),
|
||||||
m_mdr_amount : 0,
|
m_amount: data?.amount || 0,
|
||||||
m_mdr_net : data?.amount || 0
|
m_mdr_amount: 0,
|
||||||
|
m_mdr_net: data?.amount || 0,
|
||||||
|
},
|
||||||
|
["i_log_name", "c_note"]
|
||||||
|
);
|
||||||
|
|
||||||
}, ['i_log_name', 'c_note'])
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
return result
|
const getParameterSetting = async (trx, code) => {
|
||||||
|
const result = await trx("public.t_m_global_parameter_sap AS tmgps")
|
||||||
|
.select(["c_value"])
|
||||||
|
.where("c_code", "=", code)
|
||||||
|
.where("c_status", "=", "A")
|
||||||
|
.first();
|
||||||
|
|
||||||
}
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const getParameterSetting = async(trx, code) => {
|
const getInvoice = async (code, trx) => {
|
||||||
|
const result = await trx("payment.t_d_invoice")
|
||||||
|
.where("c_invoice_no", "=", code)
|
||||||
|
.first();
|
||||||
|
|
||||||
const result = await trx('public.t_m_global_parameter_sap AS tmgps').select([
|
return result;
|
||||||
"c_value"
|
};
|
||||||
])
|
|
||||||
.where('c_code', '=', code)
|
|
||||||
.where('c_status', '=', "A")
|
|
||||||
.first()
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const getInvoice = async(code, trx) => {
|
|
||||||
|
|
||||||
const result = await trx('payment.t_d_invoice')
|
|
||||||
.where('c_invoice_no', '=', code)
|
|
||||||
.first()
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateInvoice,
|
generateInvoice,
|
||||||
@@ -250,5 +322,5 @@ module.exports = {
|
|||||||
getPostingEt,
|
getPostingEt,
|
||||||
writePaynentHistory,
|
writePaynentHistory,
|
||||||
getParameterSetting,
|
getParameterSetting,
|
||||||
getInvoice
|
getInvoice,
|
||||||
};
|
};
|
||||||
@@ -430,7 +430,15 @@ const updateAllTransaction = async (
|
|||||||
const loadingBalanceRequest = async (req, res) => {
|
const loadingBalanceRequest = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// param
|
// param
|
||||||
let { mid, tid, card_number, uid, balance, flag, unique_code } = req.body;
|
// let { mid, tid, card_number, uid, balance, flag, unique_code } = req.body;
|
||||||
|
|
||||||
|
let mid = req.body.mid;
|
||||||
|
let tid = req.body.tid;
|
||||||
|
let card_number = req.body.card_number;
|
||||||
|
let uid = req.body.uid;
|
||||||
|
let balance = req.body.balance;
|
||||||
|
let flag = req.body.flag;
|
||||||
|
let unique_code = req.body.unique_code;
|
||||||
|
|
||||||
// uniqueCode = await helper.getUniqueCode();
|
// uniqueCode = await helper.getUniqueCode();
|
||||||
let uniqueCode = unique_code;
|
let uniqueCode = unique_code;
|
||||||
@@ -710,9 +718,45 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// let getReservationPendingWithFlag =
|
// let getReservationPendingWithFlag =
|
||||||
// await model.getReservationPendingWithFlag(card_number, now);
|
// await model.getReservationPendingWithFlag(card_number, now);
|
||||||
|
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST DEBUG X ]: ${JSON.stringify(
|
||||||
|
getReservationPendingWithFlagCounter
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// winston.logger.warn(
|
||||||
|
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST DEBUG 1.1 ]: ${JSON.stringify(
|
||||||
|
// getReservationPending
|
||||||
|
// )}`
|
||||||
|
// );
|
||||||
|
|
||||||
|
|
||||||
|
// winston.logger.warn(
|
||||||
|
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST DEBUG 2 ]: ${JSON.stringify(req.body)}`
|
||||||
|
// );
|
||||||
|
|
||||||
|
// winston.logger.warn(
|
||||||
|
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST DEBUG 2.1 ]: ${flag}`
|
||||||
|
// );
|
||||||
|
|
||||||
if (getReservationPendingWithFlagCounter.length > 0) {
|
if (getReservationPendingWithFlagCounter.length > 0) {
|
||||||
if (lastFlag) {
|
if (lastFlag) {
|
||||||
if (parseInt(lastFlag) <= parseInt(flag)) {
|
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST DEBUG Y ]: ${card_number}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// manipulasi last flag jika flag kartu sudah kembali ke 0
|
||||||
|
if (parseInt(lastFlag) == 255 && parseInt(flag) == 0) {
|
||||||
|
lastFlag = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(lastFlag) < parseInt(flag)) {
|
||||||
|
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST DEBUG Z ]: ${card_number}`
|
||||||
|
);
|
||||||
|
|
||||||
let reservationNumberPendingSuccessLoaded = [];
|
let reservationNumberPendingSuccessLoaded = [];
|
||||||
let loadBalanceNumberPendingSuccessLoaded = [];
|
let loadBalanceNumberPendingSuccessLoaded = [];
|
||||||
let totalReservationAmount = 0;
|
let totalReservationAmount = 0;
|
||||||
@@ -1825,6 +1869,9 @@ const loadingBalanceInsert = async (req, param) => {
|
|||||||
// balance
|
// balance
|
||||||
// )} [FLAG] : ${JSON.stringify(flag)}`
|
// )} [FLAG] : ${JSON.stringify(flag)}`
|
||||||
// );
|
// );
|
||||||
|
console.log("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
|
||||||
|
console.log(insertLoadingBalance);
|
||||||
|
|
||||||
if (insertLoadingBalance > 0) {
|
if (insertLoadingBalance > 0) {
|
||||||
result = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
@@ -2103,7 +2150,7 @@ const loadingBalanceUpdate = async (param) => {
|
|||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-INSERT ]: ${JSON.stringify(
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-UPDATE ]: ${JSON.stringify(
|
||||||
result
|
result
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -119,7 +119,24 @@ const getReservationPendingV2 = (cardNumber, time, flag) => {
|
|||||||
|
|
||||||
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
||||||
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
let result
|
||||||
|
if (flag == '0' || flag == 0) {
|
||||||
|
result = knex('trx.t_d_reservation_balance')
|
||||||
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
|
// .count("* as total_reservation")
|
||||||
|
.select(
|
||||||
|
'i_reservation_amount',
|
||||||
|
'c_reservation_no',
|
||||||
|
'c_flag',
|
||||||
|
'c_load_balance_no'
|
||||||
|
)
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('c_status', ['P', 'I'])
|
||||||
|
.whereRaw('??::INT <= ??', ['c_flag', parseInt(255)])
|
||||||
|
// .where("d_expired", ">=", time)
|
||||||
|
.where('c_flag', '!=', '-1');
|
||||||
|
} else {
|
||||||
|
result = knex('trx.t_d_reservation_balance')
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
// .count("* as total_reservation")
|
// .count("* as total_reservation")
|
||||||
.select(
|
.select(
|
||||||
@@ -133,6 +150,8 @@ const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
|||||||
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
||||||
// .where("d_expired", ">=", time)
|
// .where("d_expired", ">=", time)
|
||||||
.where('c_flag', '!=', '-1');
|
.where('c_flag', '!=', '-1');
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -301,11 +320,11 @@ const insertLoadingBalance = async (
|
|||||||
.insert(data)
|
.insert(data)
|
||||||
.returning('i_load_balance')
|
.returning('i_load_balance')
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
let id = resp[0];
|
let id = typeof resp[0] === 'object' ? resp[0].i_load_balance : resp[0];
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detail.forEach((element) => {
|
detail.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id.i_load_balance,
|
i_load_balance: id ? id : id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_amount,
|
i_amount: element.i_amount,
|
||||||
@@ -333,11 +352,11 @@ const insertLoadingBalance = async (
|
|||||||
.insert(data);
|
.insert(data);
|
||||||
})
|
})
|
||||||
.then((history) => {
|
.then((history) => {
|
||||||
let id = history[0];
|
let id = typeof history[0] === 'object' ? history[0].i_load_balance : history[0];
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detail.forEach((element) => {
|
detail.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id.i_load_balance,
|
i_load_balance: id ? id : id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_amount,
|
i_amount: element.i_amount,
|
||||||
@@ -394,14 +413,23 @@ const insertLoadingBalance = async (
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(trx.commit)
|
.then(trx.commit)
|
||||||
.catch(trx.rollback);
|
.catch((error) => {
|
||||||
|
console.log("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
|
trx.rollback
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// console.log(result);
|
// console.log("result insertLoadingBalance", result);
|
||||||
|
winston.logger.debug(`XXXXXXXXXXX1 : ${result}`);
|
||||||
|
winston.logger.debug(`XXXXXXXXXXX2 : ${JSON.stringify(result)}`);
|
||||||
return result.rowCount;
|
return result.rowCount;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
// console.log(error.message);
|
// console.log("error.message insertLoadingBalance", error.message);
|
||||||
|
winston.logger.debug(`YYYYYYYYYYY1 : ${error}`);
|
||||||
|
winston.logger.debug(`YYYYYYYYYYY2 : ${JSON.stringify(error)}`);
|
||||||
return error.message;
|
return error.message;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,28 @@ const getCardReplacement = (card_number) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getCardReplacementScheduler = async () => {
|
||||||
|
const today = new Date().toISOString().split('T')[0]; // Format: 'YYYY-MM-DD'
|
||||||
|
|
||||||
|
const result = await knex('trx.t_d_card_replacement')
|
||||||
|
.select('c_card_no')
|
||||||
|
.where('i_last_balance', null)
|
||||||
|
.where('d_valid_date', '>=', today);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET IS CARD SALES
|
||||||
|
const getCardSales = (card_number) => {
|
||||||
|
let result = knex('trx.t_d_sales_kmt_temp')
|
||||||
|
.select()
|
||||||
|
.where('card_number', card_number)
|
||||||
|
.orderBy('i_sales_kmt_temp', 'DESC')
|
||||||
|
.first();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// GET IS CARD ADDED TO BLACKLIST
|
// GET IS CARD ADDED TO BLACKLIST
|
||||||
const getCardProduct = (card_number) => {
|
const getCardProduct = (card_number) => {
|
||||||
let result = knex('public.t_m_card_product')
|
let result = knex('public.t_m_card_product')
|
||||||
@@ -80,11 +102,251 @@ const updateReplacement = async (i_card_replacement, dataReplacement) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// UPDATE CARD REPLACEMENT BY CARD NUMBER
|
||||||
|
const updateReplacementByCardNumber = async (card_number, dataReplacement) => {
|
||||||
|
let result = await knex('trx.t_d_card_replacement')
|
||||||
|
.update(dataReplacement, ['*'])
|
||||||
|
.where({ c_card_no: card_number });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE CARD SALES
|
||||||
|
const updateSales = async (i_sales_kmt_temp, dataSales) => {
|
||||||
|
let result = await knex('trx.t_d_sales_kmt_temp')
|
||||||
|
.update(dataSales, ['*'])
|
||||||
|
.where({ i_sales_kmt_temp: i_sales_kmt_temp });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const insertReplacementDetail = async (dataReplacement) => {
|
const insertReplacementDetail = async (dataReplacement) => {
|
||||||
let result = await knex("trx.t_d_card_replacement_detail").insert(dataReplacement);
|
let result = await knex("trx.t_d_card_replacement_detail").insert(dataReplacement);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const insertSales = async (dataSales) => {
|
||||||
|
let result = await knex("trx.t_d_sales_kmt_temp").insert(dataSales);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPPNCardSales = async () => {
|
||||||
|
let result = await knex('public.t_m_global_parameter')
|
||||||
|
.select('c_value')
|
||||||
|
.where('c_code', 'CARD_SALES_TAX')
|
||||||
|
.where('c_status', 'A')
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const completingDataSalesInternal = async (ppn) => {
|
||||||
|
let result
|
||||||
|
await knex.transaction(async (trx) => {
|
||||||
|
try {
|
||||||
|
await trx.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_card_theme = subquery.i_card_theme,
|
||||||
|
i_tax_amount = subquery.tax,
|
||||||
|
is_complete = subquery.is_complete
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_card_number = subquery.c_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
|
||||||
|
await trx.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_old_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_old_card_theme = subquery.i_card_theme,
|
||||||
|
i_old_tax_amount = subquery.tax,
|
||||||
|
is_complete = subquery.is_complete
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_old_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_old_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
WHEN trx.t_d_sales_internal.c_category IN ('N', 'W') THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_old_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.c_category IN ('N', 'W')
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_old_card_number = subquery.c_old_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
|
||||||
|
await trx.commit();
|
||||||
|
|
||||||
|
result = {
|
||||||
|
success: true,
|
||||||
|
message: 'Berhasil update data sales internal.'
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
await trx.rollback();
|
||||||
|
result = {
|
||||||
|
success: false,
|
||||||
|
message: `Gagal update data sales internal: ${error.message}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const completingDataSalesNewCard = async (ppn) => {
|
||||||
|
return await knex.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_card_theme = subquery.i_card_theme,
|
||||||
|
i_tax_amount = subquery.tax,
|
||||||
|
is_complete = subquery.is_complete
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_card_number = subquery.c_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const completingDataSalesOldCard = async (ppn) => {
|
||||||
|
return await knex.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_old_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_old_card_theme = subquery.i_card_theme,
|
||||||
|
i_old_tax_amount = subquery.tax
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_old_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_old_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
WHEN trx.t_d_sales_internal.c_category IN ('N', 'W') THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_old_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.c_category IN ('N', 'W')
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_old_card_number = subquery.c_old_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateDataSalesIsComplete = async () => {
|
||||||
|
return await knex.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal SET is_complete = true
|
||||||
|
WHERE
|
||||||
|
is_complete is not true
|
||||||
|
AND c_material_number_sap is not null
|
||||||
|
AND i_tax_amount is not null
|
||||||
|
AND c_old_material_number_sap is not null
|
||||||
|
AND i_old_tax_amount is not null
|
||||||
|
AND c_category IN ('N', 'W')
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getCardBlacklist,
|
getCardBlacklist,
|
||||||
getCardReplacement,
|
getCardReplacement,
|
||||||
@@ -93,5 +355,15 @@ module.exports = {
|
|||||||
getLastBalanceFromCardHistory,
|
getLastBalanceFromCardHistory,
|
||||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||||
updateReplacement,
|
updateReplacement,
|
||||||
insertReplacementDetail
|
insertReplacementDetail,
|
||||||
|
insertSales,
|
||||||
|
getCardSales,
|
||||||
|
updateSales,
|
||||||
|
getCardReplacementScheduler,
|
||||||
|
updateReplacementByCardNumber,
|
||||||
|
getPPNCardSales,
|
||||||
|
completingDataSalesInternal,
|
||||||
|
completingDataSalesNewCard,
|
||||||
|
completingDataSalesOldCard,
|
||||||
|
updateDataSalesIsComplete,
|
||||||
};
|
};
|
||||||
@@ -1823,7 +1823,58 @@ const reservation = async (req, res) => {
|
|||||||
|
|
||||||
// jika proses insert data semua yang berkaitan dengan reservasi saldo mengalami kegagalan, maka lakukan rollback
|
// jika proses insert data semua yang berkaitan dengan reservasi saldo mengalami kegagalan, maka lakukan rollback
|
||||||
// kegagalan insert data transaksi bisa disebabkan karena data ref no yang di berikan client sudah digunakan
|
// kegagalan insert data transaksi bisa disebabkan karena data ref no yang di berikan client sudah digunakan
|
||||||
if (insert.rowCount < 1) {
|
if (insert.rowCount > 0) {
|
||||||
|
// log debug
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${uniqueCode} [ PROCESSING RESERVATION ] inserting log for card history...`
|
||||||
|
// );
|
||||||
|
|
||||||
|
// log card history
|
||||||
|
await model.createReserveBalanceLog({
|
||||||
|
i_log_name: 90,
|
||||||
|
d_log: now,
|
||||||
|
c_card_number: card_number,
|
||||||
|
c_source: 'CMS',
|
||||||
|
c_location: getPartner ? getPartner.partner_name : null,
|
||||||
|
m_balance_before: balance > 0 ? balance : 0,
|
||||||
|
m_amount: 0,
|
||||||
|
m_balance_after: balance > 0 ? balance : 0,
|
||||||
|
j_new_data: data,
|
||||||
|
j_old_data: null,
|
||||||
|
c_note: `RESERVED BALANCE ${amount} FROM ${
|
||||||
|
getPartner ? getPartner.partner_name : null
|
||||||
|
} SUCCESSFULLY`,
|
||||||
|
c_status: 'S',
|
||||||
|
d_created: now,
|
||||||
|
i_create: null,
|
||||||
|
c_create_username: 'HSM',
|
||||||
|
c_create_fullname: 'HARDWARE SECURE MODULE',
|
||||||
|
c_category: 'T',
|
||||||
|
});
|
||||||
|
|
||||||
|
result = {
|
||||||
|
code: '00',
|
||||||
|
message: 'reservation saved successfully.',
|
||||||
|
data: {
|
||||||
|
reservation_number: reservationNumber,
|
||||||
|
reservation_time: now,
|
||||||
|
partner: getPartner ? getPartner.partner_name : null,
|
||||||
|
merchant: getPartner ? getPartner.merchant_name : null,
|
||||||
|
terminal: getPartner ? getPartner.terminal_name : null,
|
||||||
|
card_number: card_number,
|
||||||
|
reserved_amount: amount,
|
||||||
|
issuer_fee: issuerFee,
|
||||||
|
channel_fee: channelFee,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log info
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} [ RESPONSE RESERVATION ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
} else {
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
// `${uniqueCode} [ PROCESSING RESERVATION ] deleting reservation number validate...`
|
// `${uniqueCode} [ PROCESSING RESERVATION ] deleting reservation number validate...`
|
||||||
@@ -1845,57 +1896,6 @@ const reservation = async (req, res) => {
|
|||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
|
||||||
// winston.logger.debug(
|
|
||||||
// `${uniqueCode} [ PROCESSING RESERVATION ] inserting log for card history...`
|
|
||||||
// );
|
|
||||||
|
|
||||||
// log card history
|
|
||||||
await model.createReserveBalanceLog({
|
|
||||||
i_log_name: 90,
|
|
||||||
d_log: now,
|
|
||||||
c_card_number: card_number,
|
|
||||||
c_source: 'CMS',
|
|
||||||
c_location: getPartner ? getPartner.partner_name : null,
|
|
||||||
m_balance_before: balance > 0 ? balance : 0,
|
|
||||||
m_amount: 0,
|
|
||||||
m_balance_after: balance > 0 ? balance : 0,
|
|
||||||
j_new_data: data,
|
|
||||||
j_old_data: null,
|
|
||||||
c_note: `RESERVED BALANCE ${amount} FROM ${
|
|
||||||
getPartner ? getPartner.partner_name : null
|
|
||||||
} SUCCESSFULLY`,
|
|
||||||
c_status: 'S',
|
|
||||||
d_created: now,
|
|
||||||
i_create: null,
|
|
||||||
c_create_username: 'HSM',
|
|
||||||
c_create_fullname: 'HARDWARE SECURE MODULE',
|
|
||||||
c_category: 'T',
|
|
||||||
});
|
|
||||||
|
|
||||||
result = {
|
|
||||||
code: '00',
|
|
||||||
message: 'reservation saved successfully.',
|
|
||||||
data: {
|
|
||||||
reservation_number: reservationNumber,
|
|
||||||
reservation_time: now,
|
|
||||||
partner: getPartner ? getPartner.partner_name : null,
|
|
||||||
merchant: getPartner ? getPartner.merchant_name : null,
|
|
||||||
terminal: getPartner ? getPartner.terminal_name : null,
|
|
||||||
card_number: card_number,
|
|
||||||
reserved_amount: amount,
|
|
||||||
issuer_fee: issuerFee,
|
|
||||||
channel_fee: channelFee,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log info
|
|
||||||
winston.logger.info(
|
|
||||||
`${uniqueCode} [ RESPONSE RESERVATION ]: ${JSON.stringify(result)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).json(result);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
@@ -2660,7 +2660,58 @@ const reservationV2 = async (req, res) => {
|
|||||||
|
|
||||||
// jika proses insert data semua yang berkaitan dengan reservasi saldo mengalami kegagalan, maka lakukan rollback
|
// jika proses insert data semua yang berkaitan dengan reservasi saldo mengalami kegagalan, maka lakukan rollback
|
||||||
// kegagalan insert data transaksi bisa disebabkan karena data ref no yang di berikan client sudah digunakan
|
// kegagalan insert data transaksi bisa disebabkan karena data ref no yang di berikan client sudah digunakan
|
||||||
if (insert.rowCount < 1) {
|
if (insert.rowCount > 0) {
|
||||||
|
// log debug
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] inserting log for card history...`
|
||||||
|
// );
|
||||||
|
|
||||||
|
// log card history
|
||||||
|
await model.createReserveBalanceLog({
|
||||||
|
i_log_name: 90,
|
||||||
|
d_log: now,
|
||||||
|
c_card_number: card_number,
|
||||||
|
c_source: 'CMS',
|
||||||
|
c_location: getPartner ? getPartner.partner_name : null,
|
||||||
|
m_balance_before: balance > 0 ? balance : 0,
|
||||||
|
m_amount: 0,
|
||||||
|
m_balance_after: balance > 0 ? balance : 0,
|
||||||
|
j_new_data: data,
|
||||||
|
j_old_data: null,
|
||||||
|
c_note: `RESERVED BALANCE ${amount} FROM ${
|
||||||
|
getPartner ? getPartner.partner_name : null
|
||||||
|
} SUCCESSFULLY`,
|
||||||
|
c_status: 'S',
|
||||||
|
d_created: now,
|
||||||
|
i_create: null,
|
||||||
|
c_create_username: 'HSM',
|
||||||
|
c_create_fullname: 'HARDWARE SECURE MODULE',
|
||||||
|
c_category: 'T',
|
||||||
|
});
|
||||||
|
|
||||||
|
result = {
|
||||||
|
code: '00',
|
||||||
|
message: 'reservation saved successfully.',
|
||||||
|
data: {
|
||||||
|
reservation_number: reservationNumber,
|
||||||
|
reservation_time: now,
|
||||||
|
partner: getPartner ? getPartner.partner_name : null,
|
||||||
|
merchant: getPartner ? getPartner.merchant_name : null,
|
||||||
|
terminal: getPartner ? getPartner.terminal_name : null,
|
||||||
|
card_number: card_number,
|
||||||
|
reserved_amount: amount,
|
||||||
|
issuer_fee: issuerFee,
|
||||||
|
channel_fee: channelFee,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log info
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
} else {
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] deleting reservation number validate...`
|
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] deleting reservation number validate...`
|
||||||
@@ -2682,57 +2733,6 @@ const reservationV2 = async (req, res) => {
|
|||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
|
||||||
// winston.logger.debug(
|
|
||||||
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] inserting log for card history...`
|
|
||||||
// );
|
|
||||||
|
|
||||||
// log card history
|
|
||||||
await model.createReserveBalanceLog({
|
|
||||||
i_log_name: 90,
|
|
||||||
d_log: now,
|
|
||||||
c_card_number: card_number,
|
|
||||||
c_source: 'CMS',
|
|
||||||
c_location: getPartner ? getPartner.partner_name : null,
|
|
||||||
m_balance_before: balance > 0 ? balance : 0,
|
|
||||||
m_amount: 0,
|
|
||||||
m_balance_after: balance > 0 ? balance : 0,
|
|
||||||
j_new_data: data,
|
|
||||||
j_old_data: null,
|
|
||||||
c_note: `RESERVED BALANCE ${amount} FROM ${
|
|
||||||
getPartner ? getPartner.partner_name : null
|
|
||||||
} SUCCESSFULLY`,
|
|
||||||
c_status: 'S',
|
|
||||||
d_created: now,
|
|
||||||
i_create: null,
|
|
||||||
c_create_username: 'HSM',
|
|
||||||
c_create_fullname: 'HARDWARE SECURE MODULE',
|
|
||||||
c_category: 'T',
|
|
||||||
});
|
|
||||||
|
|
||||||
result = {
|
|
||||||
code: '00',
|
|
||||||
message: 'reservation saved successfully.',
|
|
||||||
data: {
|
|
||||||
reservation_number: reservationNumber,
|
|
||||||
reservation_time: now,
|
|
||||||
partner: getPartner ? getPartner.partner_name : null,
|
|
||||||
merchant: getPartner ? getPartner.merchant_name : null,
|
|
||||||
terminal: getPartner ? getPartner.terminal_name : null,
|
|
||||||
card_number: card_number,
|
|
||||||
reserved_amount: amount,
|
|
||||||
issuer_fee: issuerFee,
|
|
||||||
channel_fee: channelFee,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log info
|
|
||||||
winston.logger.info(
|
|
||||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).json(result);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
|
|||||||
@@ -17,6 +17,20 @@ router.get(
|
|||||||
controller.apiGenerateCashInSales
|
controller.apiGenerateCashInSales
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
"/online/cash-in-sales-internal",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
// controller.validate("generateInvoice"),
|
||||||
|
controller.apiGenerateCashInSalesInternal
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
"/online/cash-in-topup-cashless-internal",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
// controller.validate("generateInvoice"),
|
||||||
|
controller.apiGenerateCashInTopUpCashlessInternal
|
||||||
|
);
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/online/cash-in/posting",
|
"/online/cash-in/posting",
|
||||||
// auth.authenticateToken,
|
// auth.authenticateToken,
|
||||||
|
|||||||
@@ -51,6 +51,14 @@ router.post(
|
|||||||
controller.validateReplacement
|
controller.validateReplacement
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// API Validate Replacement New Card
|
||||||
|
router.post(
|
||||||
|
"/pos/cardreplacement/validatenewcard",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("validateNewCardReplacement"),
|
||||||
|
controller.validateNewCardReplacement
|
||||||
|
);
|
||||||
|
|
||||||
// API Replacement Confirm
|
// API Replacement Confirm
|
||||||
router.post(
|
router.post(
|
||||||
"/pos/cardreplacement/confirm",
|
"/pos/cardreplacement/confirm",
|
||||||
@@ -59,4 +67,45 @@ router.post(
|
|||||||
controller.replacementConfirm
|
controller.replacementConfirm
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// API Redeem Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/cardredeem/confirm",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("confirmCardRedeem"),
|
||||||
|
controller.confirmRedeem
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Sales Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/cardsales/confirm",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("confirmCardSales"),
|
||||||
|
controller.confirmSales
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Sales Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/schedulerCTS/lastbalance",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.getLastBalanceCTS
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Scheduler Lengkapi Data Sales Internal
|
||||||
|
router.post(
|
||||||
|
"/pos/sales/complete-data",
|
||||||
|
controller.completeDataSalesInternal
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Scheduler Lengkapi Data Sales Internal V2
|
||||||
|
router.post(
|
||||||
|
"/pos/sales/complete-data-v2",
|
||||||
|
controller.completeDataSalesInternalV2
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Test
|
||||||
|
router.post(
|
||||||
|
"/pos/test",
|
||||||
|
controller.testAPI
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
|||||||
|
|
||||||
function startExpress() {
|
function startExpress() {
|
||||||
// set port, listen for requests
|
// set port, listen for requests
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = parseInt(process.env.PORT) || 3000;
|
||||||
|
|
||||||
// jika settingan running on multiple
|
// jika settingan running on multiple
|
||||||
if (
|
if (
|
||||||
@@ -75,7 +75,7 @@ function startExpress() {
|
|||||||
let ports = PORTS.split(',');
|
let ports = PORTS.split(',');
|
||||||
|
|
||||||
for (let index = 0; index < ports.length; index++) {
|
for (let index = 0; index < ports.length; index++) {
|
||||||
const port = ports[index];
|
const port = parseInt(ports[index]);
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
|
|||||||
+8
-2
@@ -70,7 +70,10 @@ module.exports = {
|
|||||||
// connection: process.env.DB_URL,
|
// connection: process.env.DB_URL,
|
||||||
pool: {
|
pool: {
|
||||||
min: 2,
|
min: 2,
|
||||||
max: 30,
|
max: 100,
|
||||||
|
idleTimeoutMillis: 30000, // ← Contoh: 30 detik idle timeout
|
||||||
|
acquireTimeoutMillis: 20000, // Maksimal waktu tunggu koneksi dari pool
|
||||||
|
// maxLifetimeMillis: 300000 // maksimal umur koneksi: 5 menit (300.000 ms)
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: './infrastructure/database/migrations',
|
directory: './infrastructure/database/migrations',
|
||||||
@@ -97,7 +100,10 @@ module.exports = {
|
|||||||
// connection: process.env.DB_URL,
|
// connection: process.env.DB_URL,
|
||||||
pool: {
|
pool: {
|
||||||
min: 2,
|
min: 2,
|
||||||
max: 20,
|
max: 100,
|
||||||
|
idleTimeoutMillis: 30000, // ← Contoh: 30 detik idle timeout
|
||||||
|
acquireTimeoutMillis: 20000, // Maksimal waktu tunggu koneksi dari pool
|
||||||
|
// maxLifetimeMillis: 300000 // maksimal umur koneksi: 5 menit (300.000 ms)
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: './infrastructure/database/migrations',
|
directory: './infrastructure/database/migrations',
|
||||||
|
|||||||
Generated
+2608
-8414
File diff suppressed because it is too large
Load Diff
+8
-6
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "topuponline",
|
"name": "onlinetopup-v1",
|
||||||
"version": "1.5.6",
|
"version": "1.6.3",
|
||||||
"description": "bug fixed autocomplete transactions",
|
"description": "update packages",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon index",
|
"start": "nodemon index",
|
||||||
@@ -37,11 +37,13 @@
|
|||||||
"moment": "^2.29.3",
|
"moment": "^2.29.3",
|
||||||
"node-cron": "^3.0.1",
|
"node-cron": "^3.0.1",
|
||||||
"pg": "^8.6.0",
|
"pg": "^8.6.0",
|
||||||
"pm2": "^5.2.0",
|
"pm2": "^6.0.13",
|
||||||
"prom-client": "^14.2.0",
|
"prom-client": "^14.2.0",
|
||||||
"redis": "^4.6.5",
|
"redis": "^4.6.5",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
|
"simple-update-notifier": "^2.0.0",
|
||||||
"sticky-session": "^0.1.0",
|
"sticky-session": "^0.1.0",
|
||||||
|
"superagent": "^10.2.3",
|
||||||
"winston": "^3.7.2",
|
"winston": "^3.7.2",
|
||||||
"winston-daily-rotate-file": "^4.7.1",
|
"winston-daily-rotate-file": "^4.7.1",
|
||||||
"winston-loki": "^6.0.6",
|
"winston-loki": "^6.0.6",
|
||||||
@@ -50,8 +52,8 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^29.0.2",
|
"jest": "^29.0.2",
|
||||||
"nodemon": "^2.0.7",
|
"nodemon": "^3.1.10",
|
||||||
"supertest": "^6.2.4"
|
"supertest": "^7.1.3"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"testEnvironment": "node",
|
"testEnvironment": "node",
|
||||||
|
|||||||
Reference in New Issue
Block a user