Compare commits

...

1 Commits

Author SHA1 Message Date
lutfi 79d4269b70 update cash-in 2024-03-28 15:07:54 +07:00
2 changed files with 119 additions and 91 deletions
@@ -172,6 +172,7 @@ const _generateCashIn = async (uniqueCode) => {
let reserve = []; let reserve = [];
let code = ''; let code = '';
await knex.transaction(async (trx) => { await knex.transaction(async (trx) => {
try {
code = await model.generateCode( code = await model.generateCode(
trx, trx,
item.c_partner_code, item.c_partner_code,
@@ -214,6 +215,7 @@ const _generateCashIn = async (uniqueCode) => {
} }
dataCahsIn.i_amount = cashInAmount; dataCahsIn.i_amount = cashInAmount;
if(cashInAmount > 0) {
//INSERT CASH-IN //INSERT CASH-IN
const cashIn = await model.insertCashIn(trx, dataCahsIn); const cashIn = await model.insertCashIn(trx, dataCahsIn);
winston.logger.info( winston.logger.info(
@@ -228,6 +230,7 @@ const _generateCashIn = async (uniqueCode) => {
trx trx
); );
let m_amount = 0;
for (const detail of reserv) { for (const detail of reserv) {
// data.push({ // data.push({
// i_cash_in: cashIn.i_cash_in, // i_cash_in: cashIn.i_cash_in,
@@ -254,22 +257,46 @@ const _generateCashIn = async (uniqueCode) => {
d_credit: cashIn.d_credit, d_credit: cashIn.d_credit,
c_in_period: cashIn.c_in_period, 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); 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); 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(5000); await wait(10000);
winston.logger.info( winston.logger.info(
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify( `SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(
dataCahsIn dataCahsIn
)}` )}`
); );
// await model.insertCashInDetail(trx, data); }
// await model.insertPostingEt(code, item, trx) await trx.commit();
});
} catch (error) {
sts = "error";
await trx.rollback();
} }
});
}
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 () {