diff --git a/application/modules/cashin/cahsin.controller.js b/application/modules/cashin/cahsin.controller.js index f4e83cd..2a75ee5 100644 --- a/application/modules/cashin/cahsin.controller.js +++ b/application/modules/cashin/cahsin.controller.js @@ -172,11 +172,11 @@ const _generateCashIn = async (uniqueCode) => { const paymentyHistory = await model.writePaynentHistory(dataCahsIn, "SUCCESSFULLY", 0, trx) // Insert cahs in detail - // let data = [] + let data = [] const reserv = await model.getReserve(trx, item.c_partner_code, item.d_payment) - + await wait(1000) for (const detail of reserv) { - let data = { + data.push({ i_cash_in : cashIn.i_cash_in, c_reservation_no : detail.c_reservation_no, m_amount : detail.i_reservation_amount, @@ -184,7 +184,7 @@ const _generateCashIn = async (uniqueCode) => { d_payment : detail.d_payment, d_payment_recon : detail.d_payment_recon, c_load_balance_no : detail.c_load_balance_no - } + }) let reserveNo = detail.c_reservation_no @@ -194,13 +194,12 @@ const _generateCashIn = async (uniqueCode) => { c_in_period : cashIn.c_in_period, } - winston.logger.info(`SCHEDULER-FB70-${uniqueCode} UPDATE CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(dataCahsIn)}`) await model.updateIntoReserve(trx, dataReserve, reserveNo) - - winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(dataCahsIn)}`) - await model.insertCashInDetail(trx, data) - + } + await wait(1000) + winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(dataCahsIn)}`) + await model.insertCashInDetail(trx, data) // await model.insertPostingEt(code, item, trx) }) @@ -270,6 +269,11 @@ console.log(xmlRequest) } +function wait(milliseconds) { + return new Promise(resolve => setTimeout(resolve, milliseconds)); +} + + module.exports = { validate, apiGenerateCahsIn, diff --git a/application/modules/cashin/cahsin.model.js b/application/modules/cashin/cahsin.model.js index 94e7ba9..f1dae47 100644 --- a/application/modules/cashin/cahsin.model.js +++ b/application/modules/cashin/cahsin.model.js @@ -319,7 +319,10 @@ const generateCode = async (trx, c_partner_code, d_payment_recon) => { } const insertCashInDetail = async (trx, data) => { - let result = await trx('payment.t_d_cash_in_detail').insert(data,["*"]) + let result = [] + if(data.length > 0){ + result = await trx('payment.t_d_cash_in_detail').insert(data,["*"]) + } return result }