mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 10:36:28 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79d4269b70 |
@@ -172,104 +172,131 @@ const _generateCashIn = async (uniqueCode) => {
|
|||||||
let reserve = [];
|
let reserve = [];
|
||||||
let code = '';
|
let code = '';
|
||||||
await knex.transaction(async (trx) => {
|
await knex.transaction(async (trx) => {
|
||||||
code = await model.generateCode(
|
try {
|
||||||
trx,
|
code = await model.generateCode(
|
||||||
item.c_partner_code,
|
trx,
|
||||||
moment().format('YYMMDD')
|
item.c_partner_code,
|
||||||
);
|
moment().format('YYMMDD')
|
||||||
winston.logger.info(
|
);
|
||||||
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
winston.logger.info(
|
||||||
);
|
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
||||||
|
);
|
||||||
|
|
||||||
// Cash-in
|
// Cash-in
|
||||||
let dataCahsIn = {
|
let dataCahsIn = {
|
||||||
c_partner_code: item.c_partner_code,
|
c_partner_code: item.c_partner_code,
|
||||||
c_partner_name: item.c_partner_name,
|
c_partner_name: item.c_partner_name,
|
||||||
c_cash_in_no: code,
|
c_cash_in_no: code,
|
||||||
c_in_period: item.c_in_period,
|
c_in_period: item.c_in_period,
|
||||||
d_credit: item.d_payment,
|
d_credit: item.d_payment,
|
||||||
c_invoice_no: item.c_invoice_no,
|
c_invoice_no: item.c_invoice_no,
|
||||||
i_amount: item.amount,
|
i_amount: item.amount,
|
||||||
};
|
|
||||||
|
|
||||||
winston.logger.info(
|
|
||||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(
|
|
||||||
dataCahsIn
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// CASH-IN DETAIL
|
|
||||||
let data = [];
|
|
||||||
const reserv = await model.getReserve(
|
|
||||||
trx,
|
|
||||||
item.c_partner_code,
|
|
||||||
item.d_payment,
|
|
||||||
item.c_invoice_no
|
|
||||||
);
|
|
||||||
|
|
||||||
//TOTAL AMOUNT CASH-IN
|
|
||||||
let cashInAmount = 0;
|
|
||||||
for (const itemCI of reserv) {
|
|
||||||
cashInAmount += parseInt(itemCI.i_reservation_amount);
|
|
||||||
}
|
|
||||||
dataCahsIn.i_amount = cashInAmount;
|
|
||||||
|
|
||||||
//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
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const detail of reserv) {
|
|
||||||
// data.push({
|
|
||||||
// i_cash_in: cashIn.i_cash_in,
|
|
||||||
// c_reservation_no: detail.c_reservation_no,
|
|
||||||
// m_amount: detail.i_reservation_amount,
|
|
||||||
// c_payment_recon_no: detail.c_payment_recon_no,
|
|
||||||
// d_payment: detail.d_payment,
|
|
||||||
// d_payment_recon: detail.d_payment_recon,
|
|
||||||
// c_load_balance_no: detail.c_load_balance_no,
|
|
||||||
// });
|
|
||||||
let temp = {
|
|
||||||
i_cash_in: cashIn.i_cash_in,
|
|
||||||
c_reservation_no: detail.c_reservation_no,
|
|
||||||
m_amount: detail.i_reservation_amount,
|
|
||||||
c_payment_recon_no: detail.c_payment_recon_no,
|
|
||||||
d_payment: detail.d_payment,
|
|
||||||
d_payment_recon: detail.d_payment_recon,
|
|
||||||
c_load_balance_no: detail.c_load_balance_no,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let reserveNo = detail.c_reservation_no;
|
winston.logger.info(
|
||||||
let dataReserve = {
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(
|
||||||
c_cash_in_no: cashIn.c_cash_in_no,
|
dataCahsIn
|
||||||
d_credit: cashIn.d_credit,
|
)}`
|
||||||
c_in_period: cashIn.c_in_period,
|
);
|
||||||
};
|
|
||||||
|
|
||||||
await model.updateIntoReserve(trx, dataReserve, reserveNo);
|
// CASH-IN DETAIL
|
||||||
await model.insertCashInDetail(trx, temp);
|
let data = [];
|
||||||
|
const reserv = await model.getReserve(
|
||||||
|
trx,
|
||||||
|
item.c_partner_code,
|
||||||
|
item.d_payment,
|
||||||
|
item.c_invoice_no
|
||||||
|
);
|
||||||
|
|
||||||
|
//TOTAL AMOUNT CASH-IN
|
||||||
|
let cashInAmount = 0;
|
||||||
|
for (const itemCI of reserv) {
|
||||||
|
cashInAmount += parseInt(itemCI.i_reservation_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 reserv) {
|
||||||
|
// data.push({
|
||||||
|
// i_cash_in: cashIn.i_cash_in,
|
||||||
|
// c_reservation_no: detail.c_reservation_no,
|
||||||
|
// m_amount: detail.i_reservation_amount,
|
||||||
|
// c_payment_recon_no: detail.c_payment_recon_no,
|
||||||
|
// d_payment: detail.d_payment,
|
||||||
|
// d_payment_recon: detail.d_payment_recon,
|
||||||
|
// c_load_balance_no: detail.c_load_balance_no,
|
||||||
|
// });
|
||||||
|
let temp = {
|
||||||
|
i_cash_in: cashIn.i_cash_in,
|
||||||
|
c_reservation_no: detail.c_reservation_no,
|
||||||
|
m_amount: detail.i_reservation_amount,
|
||||||
|
c_payment_recon_no: detail.c_payment_recon_no,
|
||||||
|
d_payment: detail.d_payment,
|
||||||
|
d_payment_recon: detail.d_payment_recon,
|
||||||
|
c_load_balance_no: detail.c_load_balance_no,
|
||||||
|
};
|
||||||
|
|
||||||
|
let reserveNo = detail.c_reservation_no;
|
||||||
|
let dataReserve = {
|
||||||
|
c_cash_in_no: cashIn.c_cash_in_no,
|
||||||
|
d_credit: cashIn.d_credit,
|
||||||
|
c_in_period: cashIn.c_in_period,
|
||||||
|
};
|
||||||
|
m_amount += parseInt(detail.i_reservation_amount);
|
||||||
|
|
||||||
|
if(m_amount <= detail.invoice_amount) {
|
||||||
|
await model.updateIntoReserve(trx, dataReserve, reserveNo);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} CASH-IN UPDATE RESERVE BALANCE ${reserveNo} DATA : ${JSON.stringify(
|
||||||
|
dataReserve
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
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);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await trx.commit();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
sts = "error";
|
||||||
|
await trx.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
await wait(5000);
|
|
||||||
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)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return partnerRecon;
|
return partnerRecon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ const getReserve = async (trx, code, date, invoice) => {
|
|||||||
'tdrb.c_partner_name',
|
'tdrb.c_partner_name',
|
||||||
'tdrb.c_load_balance_no',
|
'tdrb.c_load_balance_no',
|
||||||
'tdi.c_invoice_no',
|
'tdi.c_invoice_no',
|
||||||
|
'tdi.m_amount as invoice_amount'
|
||||||
])
|
])
|
||||||
.from('trx.t_d_reservation_balance AS tdrb')
|
.from('trx.t_d_reservation_balance AS tdrb')
|
||||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user