mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 11:06:28 +00:00
update
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
"date": 1655004752426,
|
||||
"name": "2022-06-12-onlinetopup.log",
|
||||
"hash": "984c1c0ba67f63bc2f51c096864e54f9d8695ced7838e6846f18b5ccb2ff7966"
|
||||
},
|
||||
{
|
||||
"date": 1655054074401,
|
||||
"name": "2022-06-13-onlinetopup.log",
|
||||
"hash": "4a6c5caeb3f4ccc38429ce95f762a04f650055a2d0831cbe85ce7fa4b5c50021"
|
||||
}
|
||||
],
|
||||
"hashType": "sha256"
|
||||
|
||||
@@ -86,6 +86,8 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
let year = moment().format("Y");
|
||||
let month = moment().format("M");
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking partner...`);
|
||||
@@ -334,7 +336,17 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||
|
||||
// get accumulated balance in this month
|
||||
let accumulatedBalance = 19900000;
|
||||
let accumulatedBalance = 0;
|
||||
let getAccumulationBalanceInThisMonthFromCardHistory =
|
||||
await model.getAccumulationBalanceInThisMonthFromCardHistory(
|
||||
card_number,
|
||||
year,
|
||||
month
|
||||
);
|
||||
if (getAccumulationBalanceInThisMonthFromCardHistory) {
|
||||
accumulatedBalance =
|
||||
getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance;
|
||||
}
|
||||
|
||||
// validate max topup per month
|
||||
const getMaxTopupPerMonth = await model.getMaxTopupPerMonth();
|
||||
|
||||
@@ -441,6 +441,25 @@ const updateFlag = async (now, cardNumber, uid, balance, flag) => {
|
||||
});
|
||||
};
|
||||
|
||||
// GET ACCUMULATION BALANCE IN THIS MONTH FROM CARD HISTORY
|
||||
const getAccumulationBalanceInThisMonthFromCardHistory = (
|
||||
cardNumber,
|
||||
year,
|
||||
month
|
||||
) => {
|
||||
let result = knex("log.t_log_card")
|
||||
.sum("m_balance_after as accumulation_balance")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "S")
|
||||
.where("m_balance_after", ">", 0)
|
||||
.whereRaw("DATE_PART('YEAR', ??) = ?", ["d_log", year])
|
||||
.whereRaw("DATE_PART('MONTH', ??) = ?", ["d_log", month])
|
||||
.groupBy("c_card_number")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// CREATE LOG FOR CARD HISTORY
|
||||
const createLoadBalanceLog = (data) => {
|
||||
let result = knex("log.t_log_card").insert(data);
|
||||
return result;
|
||||
@@ -469,5 +488,6 @@ module.exports = {
|
||||
getLastLoadingBalanceDetailFlag,
|
||||
updateStatusReservation,
|
||||
updateFlag,
|
||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||
createLoadBalanceLog,
|
||||
};
|
||||
|
||||
@@ -66,6 +66,8 @@ const reservation = async (req, res) => {
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
let today = moment().format("YYYY-MM-DD");
|
||||
let year = moment().format("Y");
|
||||
let month = moment().format("M");
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking partner...`);
|
||||
@@ -132,7 +134,12 @@ const reservation = async (req, res) => {
|
||||
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
||||
|
||||
// get last balance on the card
|
||||
let balance = 1950000;
|
||||
let balance = 0;
|
||||
let getLastBalanceFromCardHistory =
|
||||
await model.getLastBalanceFromCardHistory(card_number);
|
||||
if (getLastBalanceFromCardHistory) {
|
||||
balance = getLastBalanceFromCardHistory.m_balance_after;
|
||||
}
|
||||
|
||||
// get max saldo on the card
|
||||
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
||||
@@ -160,7 +167,19 @@ const reservation = async (req, res) => {
|
||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||
|
||||
// get accumulated balance in this month
|
||||
let accumulatedBalance = 19950000;
|
||||
let accumulatedBalance = 0;
|
||||
let getAccumulationBalanceInThisMonthFromCardHistory =
|
||||
await model.getAccumulationBalanceInThisMonthFromCardHistory(
|
||||
card_number,
|
||||
year,
|
||||
month
|
||||
);
|
||||
if (getAccumulationBalanceInThisMonthFromCardHistory) {
|
||||
accumulatedBalance =
|
||||
getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance;
|
||||
}
|
||||
|
||||
console.log("accumulatedBalance: " + accumulatedBalance);
|
||||
|
||||
// validate max topup per month
|
||||
const getMaxTopupPerMonth = await model.getMaxTopupPerMonth();
|
||||
|
||||
@@ -212,6 +212,37 @@ const insertReservation = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET LAST BALANCE FROM CARD HISTORY
|
||||
const getLastBalanceFromCardHistory = (cardNumber) => {
|
||||
let result = knex("log.t_log_card")
|
||||
.select("m_balance_after")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "S")
|
||||
.where("m_balance_after", ">", 0)
|
||||
.orderBy("d_log", "desc")
|
||||
.limit(1)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET ACCUMULATION BALANCE IN THIS MONTH FROM CARD HISTORY
|
||||
const getAccumulationBalanceInThisMonthFromCardHistory = (
|
||||
cardNumber,
|
||||
year,
|
||||
month
|
||||
) => {
|
||||
let result = knex("log.t_log_card")
|
||||
.sum("m_balance_after as accumulation_balance")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "S")
|
||||
.where("m_balance_after", ">", 0)
|
||||
.whereRaw("DATE_PART('YEAR', ??) = ?", ["d_log", year])
|
||||
.whereRaw("DATE_PART('MONTH', ??) = ?", ["d_log", month])
|
||||
.groupBy("c_card_number")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
checkCardNumber,
|
||||
getReservationNumberSequence,
|
||||
@@ -229,4 +260,6 @@ module.exports = {
|
||||
getReservationPending,
|
||||
getReservationWithFlag,
|
||||
insertReservation,
|
||||
getLastBalanceFromCardHistory,
|
||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user