From 3b77dcbf3ce54d0bd08968fb698895aa41d8e24a Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Mon, 12 Sep 2022 18:55:11 +0700 Subject: [PATCH] change logic masximum reservation with pending status --- .../reservebalance.controller.js | 18 ++++++++++-------- .../reservebalance/reservebalance.model.js | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/application/modules/reservebalance/reservebalance.controller.js b/application/modules/reservebalance/reservebalance.controller.js index b899823..7a2a437 100644 --- a/application/modules/reservebalance/reservebalance.controller.js +++ b/application/modules/reservebalance/reservebalance.controller.js @@ -337,7 +337,7 @@ const reservationValidate = async (req, res) => { let getMaxReservation = await model.getMaxReservation(); let maxReservation = getMaxReservation.c_value ? parseInt(getMaxReservation.c_value) - : 1; + : 0; // log debug winston.logger.debug(`${uniqueCode} checking total reservation pending...`); @@ -348,9 +348,10 @@ const reservationValidate = async (req, res) => { now ); let totalReservationPending = - getReservationPending.total_reservation > 0 - ? getReservationPending.total_reservation - : 0; + getReservationPending.total_nominal_reservation > 0 + ? parseInt(getReservationPending.total_nominal_reservation) + + parseInt(amount) + : parseInt(amount); if (totalReservationPending >= maxReservation) { result = { @@ -603,7 +604,7 @@ const reservation = async (req, res) => { let getMaxReservation = await model.getMaxReservation(); let maxReservation = getMaxReservation.c_value ? parseInt(getMaxReservation.c_value) - : 1; + : 0; // // log debug // winston.logger.debug(`${uniqueCode} checking reservation with flag...`); @@ -642,9 +643,10 @@ const reservation = async (req, res) => { now ); let totalReservationPending = - getReservationPending.total_reservation > 0 - ? getReservationPending.total_reservation - : 0; + getReservationPending.total_nominal_reservation > 0 + ? parseInt(getReservationPending.total_nominal_reservation) + + parseInt(amount) + : parseInt(amount); if (totalReservationPending >= maxReservation) { result = { diff --git a/application/modules/reservebalance/reservebalance.model.js b/application/modules/reservebalance/reservebalance.model.js index b9a1635..0a55587 100644 --- a/application/modules/reservebalance/reservebalance.model.js +++ b/application/modules/reservebalance/reservebalance.model.js @@ -180,6 +180,7 @@ let inquiryByCardNumber = (cardNumber, startDate, endDate) => { const getReservationPending = (cardNumber, time) => { let result = knex("trx.t_d_reservation_balance") .count("* as total_reservation") + .sum("* as total_nominal_reservation") .where("c_card_number", cardNumber) .where("c_status", "P") // .where("d_expired", ">=", time)