Compare commits

...

71 Commits

Author SHA1 Message Date
teddys48 4140360736 update response posting invoice 2025-11-12 10:20:29 +07:00
teddys48 f4fc8cd147 update response posting invoice 2025-11-12 10:12:30 +07:00
Mohamad Ihsan f5f75381ca adding version and description 2025-10-30 21:08:19 +07:00
Mohamad Ihsan 5cbdccca11 update packages 2025-10-30 21:07:49 +07:00
ihsan fd386788f8 remove pengkondisian 2025-08-28 12:54:08 +07:00
ihsan 6ddf225485 pengkondisian kebutuhan uji coba posting posting sales 2025-08-28 10:42:48 +07:00
ihsan 1645aa54aa bug fixed last balance 2025-08-26 19:00:01 +07:00
ihsan 797bf97bf8 add version 2025-08-26 18:25:06 +07:00
ihsan a7f5c8c8e0 bug fixed 2025-08-26 18:20:52 +07:00
ihsan d2d44f3ba9 add check balance to CTS 2025-08-26 18:15:45 +07:00
ihsan 4dccbf20f5 change url cts 2025-08-26 17:24:02 +07:00
ihsan b888951ee3 remove bearer 2025-08-26 17:14:34 +07:00
ihsan 87dedd241a change url cts from env 2025-08-26 17:11:49 +07:00
ihsan d4f56aacd8 update query pengecekkan card theme 2025-08-25 17:54:22 +07:00
ihsan fec5209c83 update bugs 2025-07-04 10:57:33 +07:00
ihsan 93b6bd94ca add log 2025-07-04 10:47:35 +07:00
ihsan 39ac9e0e2d add log 2025-07-04 10:46:13 +07:00
ihsan 5037e022fd bug fixed generate cash-in untuk transaksi topup cashless internal 2025-07-03 11:52:56 +07:00
ihsan cbb1d353a3 bug fixed field 2025-06-30 21:38:43 +07:00
ihsan f73accc275 Merge branch 'develop_v1.6.1' of https://github.com/mohamadihsan/topuponline into develop 2025-06-30 17:52:54 +07:00
ihsan d7c62eda3f add new service generate cash in topup cashless internal 2025-06-30 17:52:22 +07:00
WildanFahri a4b089ac85 Merge branch 'develop' of https://github.com/mohamadihsan/topuponline into develop 2025-06-30 14:41:16 +07:00
WildanFahri 3bf01d9059 add new endpoint for replacement validate new card 2025-06-30 14:41:10 +07:00
ihsan 8e54ebb704 bug fixed variable in query 2025-06-30 13:26:13 +07:00
ihsan 48fb780252 add new service completing data v2 2025-06-25 19:52:47 +07:00
ihsan 382ccaab58 add debugging 2025-06-25 18:39:12 +07:00
ihsan 41444e037c bug fixed 2025-06-25 18:34:36 +07:00
ihsan c49e4b3526 update bug code 2025-06-25 18:25:55 +07:00
ihsan d99882b8b9 update 2025-06-25 17:54:24 +07:00
ihsan 45091038fe update knex poo config untuk development 2025-06-25 17:53:04 +07:00
ihsan 7c6e08a5b5 update log 2025-06-25 17:49:52 +07:00
ihsan 6e7d727b40 update pool sesuai rekomendasi 2025-06-25 17:33:07 +07:00
ihsan 3bb2748387 bug fixed 2025-06-25 17:24:13 +07:00
ihsan 6fea76b721 bug fixed reservation success jika terjadi how many client 2025-06-25 17:10:17 +07:00
ihsan 934e962dba Merge branch 'develop_v1.6.1' of https://github.com/mohamadihsan/topuponline into develop 2025-06-25 16:59:16 +07:00
ihsan 3ccac7d220 bug fixed 2025-06-25 16:58:38 +07:00
WildanFahri cede2396b7 update get cts is_warranty 2025-06-17 17:58:29 +07:00
WildanFahri 9c06ec992e update getLastBalanceCTS 2025-06-17 17:42:58 +07:00
ihsan 419700d6c5 bugs fixed ppn value 2025-06-13 20:13:33 +07:00
ihsan 6af2637bca update bugs 2025-06-13 20:00:58 +07:00
ihsan 8bb705f973 update query lengkapi data sales internal 2025-06-13 18:47:42 +07:00
ihsan 6755824ad0 update service completing data dengan menambahkan ppn value dari globala parameter 2025-06-13 16:23:25 +07:00
ihsan d93e3549ea add new service completing data sales internal 2025-06-13 14:26:45 +07:00
ihsan af697bd24d add generate cash in sales internal 2025-06-05 19:04:50 +07:00
WildanFahri c792a5ef15 update validate replacement 2025-05-27 15:14:40 +07:00
WildanFahri 282cc6372a update 2025-05-27 14:54:44 +07:00
WildanFahri aea6577e38 update valid_date 2025-05-27 14:37:10 +07:00
WildanFahri 6ae2de5010 update 2025-05-26 12:12:05 +07:00
WildanFahri d7c3ad199a update response code pos cms 2025-05-23 14:21:01 +07:00
WildanFahri 3808dafda7 update response code pos cms 2025-05-23 14:12:07 +07:00
WildanFahri 14ea651b28 update response code pos cms 2025-05-16 14:30:20 +07:00
WildanFahri 4079caa059 update response code pos cms 2025-05-16 13:38:30 +07:00
WildanFahri 351a81a069 update pos cms 2025-05-15 15:01:20 +07:00
ihsan 35aad851ba bug fix 2025-05-06 17:27:20 +07:00
ihsan e25797e091 add logger 2025-05-06 17:01:54 +07:00
ihsan ac1c3c969b Merge branch 'develop' of https://github.com/mohamadihsan/topuponline into develop 2025-05-06 12:15:57 +07:00
ihsan 0e256ae481 remove pengecekkan last balance dari card history server 2025-05-06 12:15:49 +07:00
WildanFahri 2179a67b41 update pos cms - handle status replacement 2025-05-06 10:47:58 +07:00
WildanFahri fd3741e2ee update pos improvement temp 2025-05-06 09:49:40 +07:00
WildanFahri 2eb91dc105 debuging hardcode redeem validate 2025-05-05 21:29:18 +07:00
WildanFahri a257d50872 debuging 2025-05-05 21:26:50 +07:00
WildanFahri fdebd4dbe9 debuging 2025-05-05 21:24:07 +07:00
WildanFahri 745d186b3f debuging redeem validate 2025-05-05 21:22:52 +07:00
WildanFahri 0145ce5703 debuging redeem validate 2025-05-05 21:11:43 +07:00
WildanFahri a45acf1488 update redeem validate 2025-05-05 21:06:38 +07:00
WildanFahri bbc26c5964 update redeem validate 2025-05-05 20:48:59 +07:00
WildanFahri 7058143c4e update version 2025-04-25 14:23:15 +07:00
WildanFahri 5af2cc37d0 update merge conflict 2025-04-25 11:27:34 +07:00
WildanFahri 75acdc4195 Merge branch 'develop_v1.6.1' of https://github.com/mohamadihsan/topuponline into develop 2025-04-24 15:14:01 +07:00
ihsan a08cedf7e8 update 2025-04-24 14:55:51 +07:00
WildanFahri a16a0172a4 update pos improvement (CMS) 2025-04-23 11:33:10 +07:00
14 changed files with 5894 additions and 9219 deletions
+368 -4
View File
@@ -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,
}; };
+169 -1
View File
@@ -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]);
}); });
} }
+261 -189
View File
@@ -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
}}
}
et.push(data) if (item == "H") {
data = {
}); ...data,
...{
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit']) text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
debit_kredit: item,
return posting_et[0] account: invoice.c_account_topup,
customer: null,
} },
};
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"])
.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
t_invoice = await trx('payment.t_d_invoice').update({
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
}, ["*"])
.where({
c_invoice_no: c_invoice_no
});
// update load balance
t_load_balance = await trx('trx.t_d_load_balance').update({
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({
pos_status : 0,
status0 : resSAP.type,
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
status1 : resSAP.message ? resSAP.message : null
}, ['file_name','status0']).where({
reference: c_invoice_no
})
if(posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
} else { } else {
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx) data = {
...data,
...{
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
debit_kredit: item,
account: null,
customer: invoice.c_account_code_topup,
},
};
} }
}else { et.push(data);
});
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];
};
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]);
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
t_invoice = await trx("payment.t_d_invoice")
.update(
{
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
},
["*"]
)
.where({
c_invoice_no: c_invoice_no,
});
// update load balance
t_load_balance = await trx("trx.t_d_load_balance")
.update(
{
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(
{
pos_status: 0,
status0: resSAP.type,
no_doksap: resSAP.data.E_DOCUMENTNUMBER
? resSAP.data.E_DOCUMENTNUMBER
: null,
status1: resSAP.message ? resSAP.message : null,
},
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
if (posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
} else {
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx);
}
} 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,
},
if(posting) { ["c_load_balance_no", "c_return_sap"]
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx) )
.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) {
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,
}; };
@@ -1869,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',
@@ -320,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,
@@ -352,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,
@@ -413,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 insertLoadingBalance", 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 insertLoadingBalance", 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
+273 -1
View File
@@ -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(
+14
View File
@@ -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,
+49
View File
@@ -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;
+8 -2
View File
@@ -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',
+2608 -8414
View File
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -1,7 +1,7 @@
{ {
"name": "topuponline", "name": "onlinetopup-v1",
"version": "1.6.0", "version": "1.6.3",
"description": "handling maximum flag 255", "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",