diff --git a/application/modules/paymentrecon/paymentrecon.controller.js b/application/modules/paymentrecon/paymentrecon.controller.js index 8e3e8d8..443b31d 100644 --- a/application/modules/paymentrecon/paymentrecon.controller.js +++ b/application/modules/paymentrecon/paymentrecon.controller.js @@ -175,13 +175,13 @@ const paymentRecon = async (req, res) => { } // log debug - winston.logger.debug(`${uniqueCode} checking reservation status...`); + winston.logger.debug(`${uniqueCode} checking reservation canceled status...`); // check reservation status - let checkReservationStatus = await model.checkReservationStatus( + let checkReservationCanceledStatus = await model.checkReservationCanceledStatus( reservation_number ); - if (!checkReservationStatus) { + if (checkReservationCanceledStatus) { result = { code: "431", message: "transaction has been canceled", diff --git a/application/modules/paymentrecon/paymentrecon.model.js b/application/modules/paymentrecon/paymentrecon.model.js index 5c11cf4..ef6e4a1 100644 --- a/application/modules/paymentrecon/paymentrecon.model.js +++ b/application/modules/paymentrecon/paymentrecon.model.js @@ -58,6 +58,14 @@ const checkReservationNumberAndAmount = (reservationNumber) => { return result; }; +const checkReservationCanceledStatus = (reservationNumber) => { + let result = knex("trx.t_d_reservation_balance") + .where("c_reservation_no", reservationNumber) + .where("c_status", "X") + .first(); + return result; +}; + const checkReservationNumberAndAmountAlreadyRecon = (reservationNumber) => { let result = knex("trx.t_d_reservation_balance") .select("c_payment_recon_no", "d_payment_recon") @@ -139,6 +147,7 @@ module.exports = { getPartner, getPartnerByID, checkReservationNumberAndAmount, + checkReservationCanceledStatus, checkReservationNumberAndAmountAlreadyRecon, updatePaymentReconNo, insertPaymentReconTransaction, diff --git a/application/modules/reservebalance/reservebalance.controller.js b/application/modules/reservebalance/reservebalance.controller.js index 142aa49..7678bff 100644 --- a/application/modules/reservebalance/reservebalance.controller.js +++ b/application/modules/reservebalance/reservebalance.controller.js @@ -96,7 +96,9 @@ const checkReservation = async (req, res) => { } // log debug - winston.logger.debug(`${uniqueCode} checking reservation with pending status and in progress status...`); + winston.logger.debug( + `${uniqueCode} checking reservation with pending status and in progress status...` + ); // get reservation pending & in progress status var checkSecure = false; @@ -1054,6 +1056,21 @@ const cancelReservationValidate = async (req, res) => { )}` ); + return res.status(200).json(result); + } else if (getReservationCanBeCanceled.c_payment_recon_no) { + result = { + code: "430", + message: `can not be cancelled. The transaction has been recon.`, + data: {}, + }; + + // log info + winston.logger.info( + `${uniqueCode} RESPONSE cancel reservation validate: ${JSON.stringify( + result + )}` + ); + return res.status(200).json(result); } } else { @@ -1193,6 +1210,21 @@ const cancelReservation = async (req, res) => { `${uniqueCode} RESPONSE cancel reservation: ${JSON.stringify(result)}` ); + return res.status(200).json(result); + } else if (getReservationCanBeCanceled.c_payment_recon_no) { + result = { + code: "430", + message: `can not be cancelled. The transaction has been recon.`, + data: {}, + }; + + // log info + winston.logger.info( + `${uniqueCode} RESPONSE cancel reservation validate: ${JSON.stringify( + result + )}` + ); + return res.status(200).json(result); } } else { @@ -1210,6 +1242,21 @@ const cancelReservation = async (req, res) => { return res.status(200).json(result); } + // log debug + winston.logger.debug( + `${uniqueCode} getting last balance on the card by card history...` + ); + + // get last balance on the card + let balance = 0; + let getLastBalanceFromCardHistory = + await model.getLastBalanceFromCardHistory( + getReservationCanBeCanceled.c_card_number + ); + if (getLastBalanceFromCardHistory) { + balance = getLastBalanceFromCardHistory.m_balance_after; + } + // time let now = moment().format("YYYY-MM-DD HH:mm:ss"); @@ -1236,14 +1283,14 @@ const cancelReservation = async (req, res) => { c_card_number: getReservationCanBeCanceled.c_card_number, c_source: "CMS", c_location: getPartner ? getPartner.partner_name : null, - m_balance_before: 0 > 0 ? 0 : 0, + m_balance_before: balance > 0 ? balance : 0, m_amount: 0, - m_balance_after: 0 > 0 ? 0 : 0, + m_balance_after: balance > 0 ? balance : 0, j_new_data: data, j_old_data: getReservationCanBeCanceled, - c_note: `CANCEL RESERVE BALANCE ${getReservationCanBeCanceled.i_reservation_amount} FROM ${ - getPartner ? getPartner.partner_name : null - }`, + c_note: `CANCEL RESERVE BALANCE ${ + getReservationCanBeCanceled.i_reservation_amount + } FROM ${getPartner ? getPartner.partner_name : null}`, c_status: "S", d_created: now, i_create: null, diff --git a/knexfile.js b/knexfile.js index aa65c35..d270088 100644 --- a/knexfile.js +++ b/knexfile.js @@ -1,31 +1,31 @@ require("dotenv").config(); module.exports = { - // development: { - // client: "pg", - // connection: process.env.DB_URL, - // migrations: { - // directory: "./infrastructure/database/migrations", - // }, - // seeds: { directory: "./infrastructure/database/seeds" }, - // }, development: { client: "pg", - connection: { - host : '10.1.201.95', - database: "postgres", - user: "cms", - password: "Cm5kc1#2021", - }, - // connection: process.env.DB_URL, - pool: { - min: 2, - max: 10, - }, + connection: process.env.DB_URL, migrations: { directory: "./infrastructure/database/migrations", }, + seeds: { directory: "./infrastructure/database/seeds" }, }, + // development: { + // client: "pg", + // connection: { + // host : '10.1.201.95', + // database: "postgres", + // user: "cms", + // password: "Cm5kc1#2021", + // }, + // // connection: process.env.DB_URL, + // pool: { + // min: 2, + // max: 10, + // }, + // migrations: { + // directory: "./infrastructure/database/migrations", + // }, + // }, testing: { client: "pg",