mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 21:06:28 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db57e1682a |
@@ -309,6 +309,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let partialTopup = false;
|
||||||
let totalReservation = 0;
|
let totalReservation = 0;
|
||||||
let amountTopup = 0;
|
let amountTopup = 0;
|
||||||
let reservationNumber = [];
|
let reservationNumber = [];
|
||||||
@@ -321,14 +322,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} updating status reservation to in progress...`
|
|
||||||
);
|
|
||||||
|
|
||||||
// update status to in progress
|
|
||||||
await model.updateStatusReservation(reservationNumberTemp, now);
|
|
||||||
|
|
||||||
totalReservation = i;
|
totalReservation = i;
|
||||||
if (totalReservation == 0) {
|
if (totalReservation == 0) {
|
||||||
result = {
|
result = {
|
||||||
@@ -374,6 +367,12 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// get BI regulation status
|
// get BI regulation status
|
||||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||||
if (getBIRegulationStatus.c_value == 'A') {
|
if (getBIRegulationStatus.c_value == 'A') {
|
||||||
|
// log debug
|
||||||
|
winston.logger.debug(`${uniqueCode} checking topup partial status...`);
|
||||||
|
|
||||||
|
// check topup partial status
|
||||||
|
const getTopupPartialStatus = await model.getTopupPartialStatus();
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
||||||
|
|
||||||
@@ -384,6 +383,58 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
parseInt(balance) + parseInt(amountTopup) >
|
parseInt(balance) + parseInt(amountTopup) >
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
) {
|
) {
|
||||||
|
// if topup partial is active
|
||||||
|
if (getTopupPartialStatus.c_value == 'A') {
|
||||||
|
// reset reservation data
|
||||||
|
partialTopup = true;
|
||||||
|
totalReservation = 0;
|
||||||
|
amountTopup = 0;
|
||||||
|
reservationNumber = [];
|
||||||
|
reservationNumberTemp = [];
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// sum amount can be topup
|
||||||
|
getReservationPending.forEach((rsv) => {
|
||||||
|
if (
|
||||||
|
parseInt(balance) + parseInt(amountTopup) <=
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
|
if (
|
||||||
|
amountTopup > parseInt(getMaxAmountOnTheCard.c_value) ||
|
||||||
|
parseInt(balance) + amountTopup >
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup =
|
||||||
|
amountTopup - parseInt(rsv.i_reservation_amount);
|
||||||
|
i--;
|
||||||
|
} else {
|
||||||
|
reservationNumber.push(rsv.c_reservation_no);
|
||||||
|
reservationNumberTemp.push(rsv.c_reservation_no);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
|
||||||
|
totalReservation = i;
|
||||||
|
if (totalReservation == 0) {
|
||||||
|
result = {
|
||||||
|
code: '414',
|
||||||
|
message:
|
||||||
|
"reservation doesn't exist. Lowest amount exceeds the maximum balance",
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||||
|
result
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
result = {
|
result = {
|
||||||
code: '416',
|
code: '416',
|
||||||
message: 'your card number has reached the maximum balance',
|
message: 'your card number has reached the maximum balance',
|
||||||
@@ -400,6 +451,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||||
@@ -424,6 +476,58 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
||||||
parseInt(getMaxTopupPerMonth.c_value)
|
parseInt(getMaxTopupPerMonth.c_value)
|
||||||
) {
|
) {
|
||||||
|
// if topup partial is active
|
||||||
|
if (getTopupPartialStatus.c_value == 'A') {
|
||||||
|
// reset reservation data
|
||||||
|
partialTopup = true;
|
||||||
|
totalReservation = 0;
|
||||||
|
amountTopup = 0;
|
||||||
|
reservationNumber = [];
|
||||||
|
reservationNumberTemp = [];
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// sum amount can be topup
|
||||||
|
getReservationPending.forEach((rsv) => {
|
||||||
|
if (
|
||||||
|
parseInt(balance) + parseInt(amountTopup) <=
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
|
if (
|
||||||
|
amountTopup > parseInt(getMaxAmountOnTheCard.c_value) ||
|
||||||
|
parseInt(balance) + amountTopup >
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup =
|
||||||
|
amountTopup - parseInt(rsv.i_reservation_amount);
|
||||||
|
i--;
|
||||||
|
} else {
|
||||||
|
reservationNumber.push(rsv.c_reservation_no);
|
||||||
|
reservationNumberTemp.push(rsv.c_reservation_no);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
|
||||||
|
totalReservation = i;
|
||||||
|
if (totalReservation == 0) {
|
||||||
|
result = {
|
||||||
|
code: '417',
|
||||||
|
message:
|
||||||
|
"reservation doesn't exist. Lowest amount exceeds the limit top up for this month",
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||||
|
result
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
result = {
|
result = {
|
||||||
code: '417',
|
code: '417',
|
||||||
message: 'your card number has been limit top up for this month',
|
message: 'your card number has been limit top up for this month',
|
||||||
@@ -441,6 +545,15 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// log debug
|
||||||
|
winston.logger.debug(
|
||||||
|
`${uniqueCode} updating status reservation to in progress...`
|
||||||
|
);
|
||||||
|
|
||||||
|
// update status to in progress
|
||||||
|
await model.updateStatusReservation(reservationNumberTemp, now);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
@@ -449,6 +562,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
amount: amountTopup,
|
amount: amountTopup,
|
||||||
total_reservation: totalReservation,
|
total_reservation: totalReservation,
|
||||||
reservation_number: reservationNumber,
|
reservation_number: reservationNumber,
|
||||||
|
partial_topup: partialTopup,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const knex = require("../../../infrastructure/database/knex");
|
const knex = require('../../../infrastructure/database/knex');
|
||||||
|
|
||||||
// CHECK CARD NUMBER
|
// CHECK CARD NUMBER
|
||||||
const checkCardNumber = (cardNumber) => {
|
const checkCardNumber = (cardNumber) => {
|
||||||
let result = knex("t_m_card_product")
|
let result = knex('t_m_card_product')
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.where("c_status", "!=", "X")
|
.where('c_status', '!=', 'X')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -13,193 +13,194 @@ const checkCardNumber = (cardNumber) => {
|
|||||||
const getPartner = (mid, tid) => {
|
const getPartner = (mid, tid) => {
|
||||||
let result = knex
|
let result = knex
|
||||||
.select(
|
.select(
|
||||||
"t_m_partner.i_partner",
|
't_m_partner.i_partner',
|
||||||
"t_m_partner.c_code as partner_code",
|
't_m_partner.c_code as partner_code',
|
||||||
"t_m_partner.c_name as partner_name",
|
't_m_partner.c_name as partner_name',
|
||||||
"t_m_merchant.i_merchant",
|
't_m_merchant.i_merchant',
|
||||||
"t_m_merchant.c_code as merchant_code",
|
't_m_merchant.c_code as merchant_code',
|
||||||
"t_m_merchant.c_name as merchant_name",
|
't_m_merchant.c_name as merchant_name',
|
||||||
"t_m_merchant.e_mid as mid",
|
't_m_merchant.e_mid as mid',
|
||||||
"t_m_terminal.i_terminal",
|
't_m_terminal.i_terminal',
|
||||||
"t_m_terminal.c_code as terminal_code",
|
't_m_terminal.c_code as terminal_code',
|
||||||
"t_m_terminal.c_name as terminal_name",
|
't_m_terminal.c_name as terminal_name',
|
||||||
"t_m_terminal.e_tid as tid"
|
't_m_terminal.e_tid as tid'
|
||||||
)
|
)
|
||||||
.from("t_m_terminal")
|
.from('t_m_terminal')
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
"t_m_merchant",
|
't_m_merchant',
|
||||||
"t_m_terminal.i_merchant",
|
't_m_terminal.i_merchant',
|
||||||
"t_m_merchant.i_merchant"
|
't_m_merchant.i_merchant'
|
||||||
)
|
)
|
||||||
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
.leftJoin('t_m_partner', 't_m_merchant.i_partner', 't_m_partner.i_partner')
|
||||||
.where("t_m_merchant.e_mid", mid)
|
.where('t_m_merchant.e_mid', mid)
|
||||||
.where("t_m_terminal.e_tid", tid)
|
.where('t_m_terminal.e_tid', tid)
|
||||||
.where("t_m_terminal.c_status", "A")
|
.where('t_m_terminal.c_status', 'A')
|
||||||
.where("t_m_merchant.c_status", "A")
|
.where('t_m_merchant.c_status', 'A')
|
||||||
.where("t_m_partner.c_status", "A")
|
.where('t_m_partner.c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET ISSUER
|
// GET ISSUER
|
||||||
const getIssuer = (id) => {
|
const getIssuer = (id) => {
|
||||||
let result = knex("t_c_partner_fee")
|
let result = knex('t_c_partner_fee')
|
||||||
.select("i_issuer_fee_perc", "i_channel_fee_perc")
|
.select('i_issuer_fee_perc', 'i_channel_fee_perc')
|
||||||
.where("i_partner", id)
|
.where('i_partner', id)
|
||||||
.where("c_status", "A")
|
.where('c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
||||||
const getCheckByCardProductStatusValue = () => {
|
const getCheckByCardProductStatusValue = () => {
|
||||||
let result = knex("t_m_global_parameter")
|
let result = knex('t_m_global_parameter')
|
||||||
.select("c_value")
|
.select('c_value')
|
||||||
.where("c_code", "HSM_CHECK_BY_CARD_PRODUCT_STAT")
|
.where('c_code', 'HSM_CHECK_BY_CARD_PRODUCT_STAT')
|
||||||
.where("c_status", "A")
|
.where('c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING
|
// GET RESERVATION PENDING
|
||||||
const getReservationPending = (cardNumber, time, flag) => {
|
const getReservationPending = (cardNumber, time, flag) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
// .count("* as total_reservation")
|
// .count("* as total_reservation")
|
||||||
.select("i_reservation_amount", "c_reservation_no", "c_flag")
|
.select('i_reservation_amount', 'c_reservation_no', 'c_flag')
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereIn("c_status", ["P", "I"])
|
.whereIn('c_status', ['P', 'I'])
|
||||||
// .where("d_expired", ">=", time)
|
// .where("d_expired", ">=", time)
|
||||||
.where(function () {
|
.where(function () {
|
||||||
this.orWhere("c_flag", flag).orWhere("c_flag", "-1");
|
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
||||||
});
|
})
|
||||||
|
.orderBy('i_reservation_amount', 'asc');
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
||||||
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
// .count("* as total_reservation")
|
// .count("* as total_reservation")
|
||||||
.select(
|
.select(
|
||||||
"i_reservation_amount",
|
'i_reservation_amount',
|
||||||
"c_reservation_no",
|
'c_reservation_no',
|
||||||
"c_flag",
|
'c_flag',
|
||||||
"c_load_balance_no"
|
'c_load_balance_no'
|
||||||
)
|
)
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereIn("c_status", ["P", "I"])
|
.whereIn('c_status', ['P', 'I'])
|
||||||
.whereRaw("??::INT < ??", ["c_flag", parseInt(flag)])
|
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
||||||
// .where("d_expired", ">=", time)
|
// .where("d_expired", ">=", time)
|
||||||
.where("c_flag", "!=", "-1");
|
.where('c_flag', '!=', '-1');
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITH FLAG
|
// GET RESERVATION PENDING WITH FLAG
|
||||||
const getReservationPendingWithFlag = (cardNumber, time) => {
|
const getReservationPendingWithFlag = (cardNumber, time) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
// .count("* as total_reservation")
|
// .count("* as total_reservation")
|
||||||
.select("i_reservation_amount", "c_reservation_no", "c_flag")
|
.select('i_reservation_amount', 'c_reservation_no', 'c_flag')
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereIn("c_status", ["P", "I"])
|
.whereIn('c_status', ['P', 'I'])
|
||||||
.whereNotNull("c_flag_code");
|
.whereNotNull('c_flag_code');
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
||||||
const getBIRegulationStatus = () => {
|
const getBIRegulationStatus = () => {
|
||||||
let result = knex("t_m_global_parameter")
|
let result = knex('t_m_global_parameter')
|
||||||
.select("c_value")
|
.select('c_value')
|
||||||
.where("c_code", "HSM_BI_REGULATION_STAT")
|
.where('c_code', 'HSM_BI_REGULATION_STAT')
|
||||||
.where("c_status", "A")
|
.where('c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET MAX AMOUNT ON THE CARD FROM GLOBAL PARAMETER
|
// GET MAX AMOUNT ON THE CARD FROM GLOBAL PARAMETER
|
||||||
const getMaxAmountOnTheCard = () => {
|
const getMaxAmountOnTheCard = () => {
|
||||||
let result = knex("t_m_global_parameter")
|
let result = knex('t_m_global_parameter')
|
||||||
.select("c_value")
|
.select('c_value')
|
||||||
.where("c_code", "HSM_BI_MAX_AMOUNT_ON_THE_CARD")
|
.where('c_code', 'HSM_BI_MAX_AMOUNT_ON_THE_CARD')
|
||||||
.where("c_status", "A")
|
.where('c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET MAX TOPUP PER MONTH FROM GLOBAL PARAMETER
|
// GET MAX TOPUP PER MONTH FROM GLOBAL PARAMETER
|
||||||
const getMaxTopupPerMonth = () => {
|
const getMaxTopupPerMonth = () => {
|
||||||
let result = knex("t_m_global_parameter")
|
let result = knex('t_m_global_parameter')
|
||||||
.select("c_value")
|
.select('c_value')
|
||||||
.where("c_code", "HSM_BI_MAX_TOPUP_PER_MONTH")
|
.where('c_code', 'HSM_BI_MAX_TOPUP_PER_MONTH')
|
||||||
.where("c_status", "A")
|
.where('c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// INQUIRY BY RESERVATION NUMBER
|
// INQUIRY BY RESERVATION NUMBER
|
||||||
let inquiryByLoadBalanceNumber = (loadBalanceNumber) => {
|
let inquiryByLoadBalanceNumber = (loadBalanceNumber) => {
|
||||||
let result = knex("trx.t_d_load_balance")
|
let result = knex('trx.t_d_load_balance')
|
||||||
.select(
|
.select(
|
||||||
"c_load_balance_no as load_balance_number",
|
'c_load_balance_no as load_balance_number',
|
||||||
"d_load_balance as load_balance_date",
|
'd_load_balance as load_balance_date',
|
||||||
"c_ref_no as ref_no",
|
'c_ref_no as ref_no',
|
||||||
"c_partner_name as partner_name",
|
'c_partner_name as partner_name',
|
||||||
"c_merchant_name as merchant_name",
|
'c_merchant_name as merchant_name',
|
||||||
"c_terminal_name as terminal_name",
|
'c_terminal_name as terminal_name',
|
||||||
"c_card_number as card_number",
|
'c_card_number as card_number',
|
||||||
"i_topup_amount as topup_amount",
|
'i_topup_amount as topup_amount',
|
||||||
"c_status as status_code",
|
'c_status as status_code',
|
||||||
"c_status_name as description"
|
'c_status_name as description'
|
||||||
)
|
)
|
||||||
.where("c_load_balance_no", loadBalanceNumber)
|
.where('c_load_balance_no', loadBalanceNumber)
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// INQUIRY BY CARD NUMBER
|
// INQUIRY BY CARD NUMBER
|
||||||
let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
||||||
let result = knex("trx.t_d_load_balance")
|
let result = knex('trx.t_d_load_balance')
|
||||||
.select(
|
.select(
|
||||||
"c_load_balance_no as load_balance_number",
|
'c_load_balance_no as load_balance_number',
|
||||||
"d_load_balance as load_balance_date",
|
'd_load_balance as load_balance_date',
|
||||||
"c_ref_no as ref_no",
|
'c_ref_no as ref_no',
|
||||||
"c_partner_name as partner_name",
|
'c_partner_name as partner_name',
|
||||||
"c_merchant_name as merchant_name",
|
'c_merchant_name as merchant_name',
|
||||||
"c_terminal_name as terminal_name",
|
'c_terminal_name as terminal_name',
|
||||||
"c_card_number as card_number",
|
'c_card_number as card_number',
|
||||||
"i_topup_amount as topup_amount",
|
'i_topup_amount as topup_amount',
|
||||||
"c_status as status_code",
|
'c_status as status_code',
|
||||||
"c_status_name as description"
|
'c_status_name as description'
|
||||||
)
|
)
|
||||||
.where("c_card_number", cardNumber);
|
.where('c_card_number', cardNumber);
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
result.whereRaw("??::date >= ?", ["d_load_balance", startDate]);
|
result.whereRaw('??::date >= ?', ['d_load_balance', startDate]);
|
||||||
result.whereRaw("??::date <= ?", ["d_load_balance", endDate]);
|
result.whereRaw('??::date <= ?', ['d_load_balance', endDate]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIND RESERVATION LOADED
|
// FIND RESERVATION LOADED
|
||||||
const findReservationLoaded = (reservationID) => {
|
const findReservationLoaded = (reservationID) => {
|
||||||
let result = knex("trx.t_d_load_balance")
|
let result = knex('trx.t_d_load_balance')
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
"trx.t_d_load_balance_detail",
|
'trx.t_d_load_balance_detail',
|
||||||
"trx.t_d_load_balance.i_load_balance",
|
'trx.t_d_load_balance.i_load_balance',
|
||||||
"trx.t_d_load_balance_detail.i_load_balance"
|
'trx.t_d_load_balance_detail.i_load_balance'
|
||||||
)
|
)
|
||||||
.where("trx.t_d_load_balance_detail.i_reservation_balance", reservationID)
|
.where('trx.t_d_load_balance_detail.i_reservation_balance', reservationID)
|
||||||
.where("trx.t_d_load_balance.c_status", "A")
|
.where('trx.t_d_load_balance.c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIND RESERVATION
|
// FIND RESERVATION
|
||||||
const findReservation = (reservationNumber) => {
|
const findReservation = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
.where("c_status", "!=", "X")
|
.where('c_status', '!=', 'X')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -218,10 +219,10 @@ const insertLoadingBalance = async (
|
|||||||
) => {
|
) => {
|
||||||
await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex("trx.t_d_load_balance")
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(data)
|
.insert(data)
|
||||||
.returning("i_load_balance")
|
.returning('i_load_balance')
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
let id = resp[0];
|
let id = resp[0];
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
@@ -243,15 +244,15 @@ const insertLoadingBalance = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// insert detail load balance
|
// insert detail load balance
|
||||||
return knex("trx.t_d_load_balance_detail")
|
return knex('trx.t_d_load_balance_detail')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(loadDetail);
|
.insert(loadDetail);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert load balance history
|
// insert load balance history
|
||||||
return knex("trx.t_d_load_balance_history")
|
return knex('trx.t_d_load_balance_history')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.returning("i_load_balance")
|
.returning('i_load_balance')
|
||||||
.insert(data);
|
.insert(data);
|
||||||
})
|
})
|
||||||
.then((history) => {
|
.then((history) => {
|
||||||
@@ -275,39 +276,39 @@ const insertLoadingBalance = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// insert detail load balance
|
// insert detail load balance
|
||||||
return knex("trx.t_d_load_balance_history_detail")
|
return knex('trx.t_d_load_balance_history_detail')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(loadDetail);
|
.insert(loadDetail);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// update reservation
|
// update reservation
|
||||||
return knex("trx.t_d_reservation_balance")
|
return knex('trx.t_d_reservation_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update({
|
.update({
|
||||||
c_status: "I",
|
c_status: 'I',
|
||||||
c_status_name: "IN PROGRESS",
|
c_status_name: 'IN PROGRESS',
|
||||||
d_load_balance: now,
|
d_load_balance: now,
|
||||||
c_load_balance_no: data.c_load_balance_no,
|
c_load_balance_no: data.c_load_balance_no,
|
||||||
c_flag_code: "FW",
|
c_flag_code: 'FW',
|
||||||
c_flag: flag,
|
c_flag: flag,
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
i_modify: null,
|
i_modify: null,
|
||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
c_modify_fullname: null,
|
c_modify_fullname: null,
|
||||||
})
|
})
|
||||||
.whereIn("c_reservation_no", reservationNumber);
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// delete flag counting
|
// delete flag counting
|
||||||
return knex("trx.t_d_flag_counting")
|
return knex('trx.t_d_flag_counting')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereRaw("UPPER(c_uid) = ?", [uid])
|
.whereRaw('UPPER(c_uid) = ?', [uid])
|
||||||
.del();
|
.del();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert flag counting
|
// insert flag counting
|
||||||
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
return knex('trx.t_d_flag_counting').transacting(trx).insert({
|
||||||
d_request: now,
|
d_request: now,
|
||||||
c_card_number: cardNumber,
|
c_card_number: cardNumber,
|
||||||
c_uid: uid,
|
c_uid: uid,
|
||||||
@@ -341,24 +342,24 @@ const updateLoadingBalance = async (
|
|||||||
) => {
|
) => {
|
||||||
await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex("trx.t_d_load_balance")
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update(data)
|
.update(data)
|
||||||
.where("c_load_balance_no", loadBalanceNumber)
|
.where('c_load_balance_no', loadBalanceNumber)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert load balance history
|
// insert load balance history
|
||||||
return knex("trx.t_d_load_balance_history")
|
return knex('trx.t_d_load_balance_history')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(data);
|
.insert(data);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// update reservation
|
// update reservation
|
||||||
return knex("trx.t_d_reservation_balance")
|
return knex('trx.t_d_reservation_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update({
|
.update({
|
||||||
c_flag_code: writeStatus ? "FW" : null,
|
c_flag_code: writeStatus ? 'FW' : null,
|
||||||
c_status: writeStatus ? "I" : "A",
|
c_status: writeStatus ? 'I' : 'A',
|
||||||
c_status_name: writeStatus ? "IN PROGRESS" : "LOADED",
|
c_status_name: writeStatus ? 'IN PROGRESS' : 'LOADED',
|
||||||
d_load_balance: now,
|
d_load_balance: now,
|
||||||
c_load_balance_no: loadBalanceNumber,
|
c_load_balance_no: loadBalanceNumber,
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
@@ -366,19 +367,19 @@ const updateLoadingBalance = async (
|
|||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
c_modify_fullname: null,
|
c_modify_fullname: null,
|
||||||
})
|
})
|
||||||
.where("c_load_balance_no", loadBalanceNumber);
|
.where('c_load_balance_no', loadBalanceNumber);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// delete flag counting
|
// delete flag counting
|
||||||
return knex("trx.t_d_flag_counting")
|
return knex('trx.t_d_flag_counting')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereRaw("UPPER(c_uid) = ?", [uid])
|
.whereRaw('UPPER(c_uid) = ?', [uid])
|
||||||
.del();
|
.del();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert flag counting
|
// insert flag counting
|
||||||
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
return knex('trx.t_d_flag_counting').transacting(trx).insert({
|
||||||
d_request: now,
|
d_request: now,
|
||||||
c_card_number: cardNumber,
|
c_card_number: cardNumber,
|
||||||
c_uid: uid,
|
c_uid: uid,
|
||||||
@@ -413,10 +414,10 @@ const insertLoadingBalanceHistoryOnly = async (
|
|||||||
) => {
|
) => {
|
||||||
await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex("trx.t_d_load_balance_history")
|
knex('trx.t_d_load_balance_history')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(data)
|
.insert(data)
|
||||||
.returning("i_load_balance")
|
.returning('i_load_balance')
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
let id = resp[0];
|
let id = resp[0];
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
@@ -438,18 +439,18 @@ const insertLoadingBalanceHistoryOnly = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// insert detail load balance
|
// insert detail load balance
|
||||||
return knex("trx.t_d_load_balance_history_detail")
|
return knex('trx.t_d_load_balance_history_detail')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(loadDetail);
|
.insert(loadDetail);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// update reservation
|
// update reservation
|
||||||
return knex("trx.t_d_reservation_balance")
|
return knex('trx.t_d_reservation_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update({
|
.update({
|
||||||
c_flag_code: writeStatus ? "FW" : null,
|
c_flag_code: writeStatus ? 'FW' : null,
|
||||||
c_status: writeStatus ? "I" : "A",
|
c_status: writeStatus ? 'I' : 'A',
|
||||||
c_status_name: writeStatus ? "IN PROGRESS" : "LOADED",
|
c_status_name: writeStatus ? 'IN PROGRESS' : 'LOADED',
|
||||||
// d_load_balance: now,
|
// d_load_balance: now,
|
||||||
// c_load_balance_no: data.c_load_balance_no,
|
// c_load_balance_no: data.c_load_balance_no,
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
@@ -457,19 +458,19 @@ const insertLoadingBalanceHistoryOnly = async (
|
|||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
c_modify_fullname: null,
|
c_modify_fullname: null,
|
||||||
})
|
})
|
||||||
.whereIn("c_reservation_no", reservationNumber);
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// delete flag counting
|
// delete flag counting
|
||||||
return knex("trx.t_d_flag_counting")
|
return knex('trx.t_d_flag_counting')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereRaw("UPPER(c_uid) = ?", [uid])
|
.whereRaw('UPPER(c_uid) = ?', [uid])
|
||||||
.del();
|
.del();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert flag counting
|
// insert flag counting
|
||||||
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
return knex('trx.t_d_flag_counting').transacting(trx).insert({
|
||||||
d_request: now,
|
d_request: now,
|
||||||
c_card_number: cardNumber,
|
c_card_number: cardNumber,
|
||||||
c_uid: uid,
|
c_uid: uid,
|
||||||
@@ -492,29 +493,29 @@ const insertLoadingBalanceHistoryOnly = async (
|
|||||||
|
|
||||||
// GET LOADING BALANCE SEQUENCE
|
// GET LOADING BALANCE SEQUENCE
|
||||||
const getLoadBalanceSequence = (data, date) => {
|
const getLoadBalanceSequence = (data, date) => {
|
||||||
let result = knex("trx.t_d_load_balance")
|
let result = knex('trx.t_d_load_balance')
|
||||||
.select("i_load_balance_no_seq")
|
.select('i_load_balance_no_seq')
|
||||||
.orderBy("i_load_balance_no_seq", "desc")
|
.orderBy('i_load_balance_no_seq', 'desc')
|
||||||
.whereNotNull("i_load_balance_no_seq")
|
.whereNotNull('i_load_balance_no_seq')
|
||||||
.where("i_partner", data.i_partner)
|
.where('i_partner', data.i_partner)
|
||||||
.where("i_merchant", data.i_merchant)
|
.where('i_merchant', data.i_merchant)
|
||||||
.whereRaw("??::date = ?", ["d_load_balance", date])
|
.whereRaw('??::date = ?', ['d_load_balance', date])
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIND LOAD BALANCE
|
// FIND LOAD BALANCE
|
||||||
let findLoadBalance = (loadBalanceNumber) => {
|
let findLoadBalance = (loadBalanceNumber) => {
|
||||||
let result = knex("trx.t_d_load_balance")
|
let result = knex('trx.t_d_load_balance')
|
||||||
.where("c_load_balance_no", loadBalanceNumber)
|
.where('c_load_balance_no', loadBalanceNumber)
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIND LOAD BALANCE DETAIL
|
// FIND LOAD BALANCE DETAIL
|
||||||
let findLoadBalanceDetail = (loadBalanceId) => {
|
let findLoadBalanceDetail = (loadBalanceId) => {
|
||||||
let result = knex("trx.t_d_load_balance_detail").where(
|
let result = knex('trx.t_d_load_balance_detail').where(
|
||||||
"i_load_balance",
|
'i_load_balance',
|
||||||
loadBalanceId
|
loadBalanceId
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
@@ -522,10 +523,10 @@ let findLoadBalanceDetail = (loadBalanceId) => {
|
|||||||
|
|
||||||
// CHECK FLAG
|
// CHECK FLAG
|
||||||
const checkFlag = (cardNumber, uid) => {
|
const checkFlag = (cardNumber, uid) => {
|
||||||
let result = knex("trx.t_d_flag_counting")
|
let result = knex('trx.t_d_flag_counting')
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereRaw("UPPER(c_uid) = ?", [uid])
|
.whereRaw('UPPER(c_uid) = ?', [uid])
|
||||||
.orderBy("d_request", "desc")
|
.orderBy('d_request', 'desc')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -540,15 +541,15 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
) => {
|
) => {
|
||||||
await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex("trx.t_d_load_balance")
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update(data)
|
.update(data)
|
||||||
.where("c_load_balance_no", data.c_load_balance_no)
|
.where('c_load_balance_no', data.c_load_balance_no)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert load balance history
|
// insert load balance history
|
||||||
return knex("trx.t_d_load_balance_history")
|
return knex('trx.t_d_load_balance_history')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.returning("i_load_balance")
|
.returning('i_load_balance')
|
||||||
.insert(data);
|
.insert(data);
|
||||||
})
|
})
|
||||||
.then((history) => {
|
.then((history) => {
|
||||||
@@ -572,27 +573,27 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// insert detail load balance
|
// insert detail load balance
|
||||||
return knex("trx.t_d_load_balance_history_detail")
|
return knex('trx.t_d_load_balance_history_detail')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.insert(loadDetail);
|
.insert(loadDetail);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// update reservation
|
// update reservation
|
||||||
return knex("trx.t_d_reservation_balance")
|
return knex('trx.t_d_reservation_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update({
|
.update({
|
||||||
d_load_balance: data.d_load_balance,
|
d_load_balance: data.d_load_balance,
|
||||||
c_load_balance_no: data.c_load_balance_no,
|
c_load_balance_no: data.c_load_balance_no,
|
||||||
c_flag: flag,
|
c_flag: flag,
|
||||||
c_flag_code: null,
|
c_flag_code: null,
|
||||||
c_status: "A",
|
c_status: 'A',
|
||||||
c_status_name: "LOADED",
|
c_status_name: 'LOADED',
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
i_modify: null,
|
i_modify: null,
|
||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
c_modify_fullname: null,
|
c_modify_fullname: null,
|
||||||
})
|
})
|
||||||
.whereIn("c_reservation_no", reservationNumber);
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
})
|
})
|
||||||
.then(trx.commit)
|
.then(trx.commit)
|
||||||
.catch(trx.rollback);
|
.catch(trx.rollback);
|
||||||
@@ -609,31 +610,31 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
|
|
||||||
//
|
//
|
||||||
const getLastReservationFlag = (reservationNumber) => {
|
const getLastReservationFlag = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.whereIn("c_reservation_no", reservationNumber)
|
.whereIn('c_reservation_no', reservationNumber)
|
||||||
.whereNotNull("c_flag_code")
|
.whereNotNull('c_flag_code')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
const getLastLoadingBalanceFlag = (loadBalanceNumber) => {
|
const getLastLoadingBalanceFlag = (loadBalanceNumber) => {
|
||||||
let result = knex("trx.t_d_load_balance_history")
|
let result = knex('trx.t_d_load_balance_history')
|
||||||
.select("trx.t_d_load_balance_history.*")
|
.select('trx.t_d_load_balance_history.*')
|
||||||
.whereIn(
|
.whereIn(
|
||||||
"trx.t_d_load_balance_history.c_load_balance_no",
|
'trx.t_d_load_balance_history.c_load_balance_no',
|
||||||
loadBalanceNumber
|
loadBalanceNumber
|
||||||
)
|
)
|
||||||
.whereIn("trx.t_d_load_balance_history.c_status", ["P", "I"])
|
.whereIn('trx.t_d_load_balance_history.c_status', ['P', 'I'])
|
||||||
.whereNotNull("trx.t_d_load_balance_history.c_load_balance_no")
|
.whereNotNull('trx.t_d_load_balance_history.c_load_balance_no')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
||||||
let result = knex("trx.t_d_load_balance_history_detail").where(
|
let result = knex('trx.t_d_load_balance_history_detail').where(
|
||||||
"i_load_balance",
|
'i_load_balance',
|
||||||
loadBalanceId
|
loadBalanceId
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
@@ -641,16 +642,16 @@ const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
|||||||
|
|
||||||
// update
|
// update
|
||||||
const updateStatusReservation = (reservationNumber, now) => {
|
const updateStatusReservation = (reservationNumber, now) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.update({
|
.update({
|
||||||
c_status: "I",
|
c_status: 'I',
|
||||||
c_status_name: "IN PROGRESS",
|
c_status_name: 'IN PROGRESS',
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
i_modify: null,
|
i_modify: null,
|
||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
c_modify_fullname: null,
|
c_modify_fullname: null,
|
||||||
})
|
})
|
||||||
.whereIn("c_reservation_no", reservationNumber);
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -658,14 +659,14 @@ const updateStatusReservation = (reservationNumber, now) => {
|
|||||||
const updateFlag = async (now, cardNumber, uid, balance, flag) => {
|
const updateFlag = async (now, cardNumber, uid, balance, flag) => {
|
||||||
await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex("trx.t_d_flag_counting")
|
knex('trx.t_d_flag_counting')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.whereRaw("UPPER(c_uid) = ?", [uid])
|
.whereRaw('UPPER(c_uid) = ?', [uid])
|
||||||
.del()
|
.del()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert flag counting
|
// insert flag counting
|
||||||
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
return knex('trx.t_d_flag_counting').transacting(trx).insert({
|
||||||
d_request: now,
|
d_request: now,
|
||||||
c_card_number: cardNumber,
|
c_card_number: cardNumber,
|
||||||
c_uid: uid,
|
c_uid: uid,
|
||||||
@@ -692,36 +693,46 @@ const getAccumulationBalanceInThisMonthFromCardHistory = (
|
|||||||
year,
|
year,
|
||||||
month
|
month
|
||||||
) => {
|
) => {
|
||||||
let result = knex("log.t_log_card")
|
let result = knex('log.t_log_card')
|
||||||
.sum("m_amount as accumulation_balance")
|
.sum('m_amount as accumulation_balance')
|
||||||
.where("c_card_number", cardNumber)
|
.where('c_card_number', cardNumber)
|
||||||
.where("c_status", "S")
|
.where('c_status', 'S')
|
||||||
.where("m_balance_after", ">", 0)
|
.where('m_balance_after', '>', 0)
|
||||||
.whereRaw("DATE_PART('YEAR', ??) = ?", ["d_log", year])
|
.whereRaw("DATE_PART('YEAR', ??) = ?", ['d_log', year])
|
||||||
.whereRaw("DATE_PART('MONTH', ??) = ?", ["d_log", month])
|
.whereRaw("DATE_PART('MONTH', ??) = ?", ['d_log', month])
|
||||||
.whereIn("i_log_name", [21])
|
.whereIn('i_log_name', [21])
|
||||||
.groupBy("c_card_number")
|
.groupBy('c_card_number')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// CREATE LOG FOR CARD HISTORY
|
// CREATE LOG FOR CARD HISTORY
|
||||||
const createLoadBalanceLog = (data) => {
|
const createLoadBalanceLog = (data) => {
|
||||||
let result = knex("log.t_log_card").insert(data);
|
let result = knex('log.t_log_card').insert(data);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// INSERT TEMP LOAD BALANCE NUMBER1
|
// INSERT TEMP LOAD BALANCE NUMBER1
|
||||||
const insertLoadBalanceNumber = (loadBalanceNumber) => {
|
const insertLoadBalanceNumber = (loadBalanceNumber) => {
|
||||||
let result = knex("trx.t_d_load_balance_no_validate")
|
let result = knex('trx.t_d_load_balance_no_validate')
|
||||||
.insert({
|
.insert({
|
||||||
c_load_balance_no: loadBalanceNumber,
|
c_load_balance_no: loadBalanceNumber,
|
||||||
})
|
})
|
||||||
.onConflict("c_load_balance_no")
|
.onConflict('c_load_balance_no')
|
||||||
.ignore();
|
.ignore();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET TOPUP PARTIAL STATUS FROM GLOBAL PARAMETER
|
||||||
|
const getTopupPartialStatus = () => {
|
||||||
|
let result = knex('t_m_global_parameter')
|
||||||
|
.select('c_value')
|
||||||
|
.where('c_code', 'HSM_TOPUP_PARTIAL_STAT')
|
||||||
|
.where('c_status', 'A')
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkCardNumber,
|
checkCardNumber,
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -753,4 +764,5 @@ module.exports = {
|
|||||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||||
createLoadBalanceLog,
|
createLoadBalanceLog,
|
||||||
insertLoadBalanceNumber,
|
insertLoadBalanceNumber,
|
||||||
|
getTopupPartialStatus,
|
||||||
};
|
};
|
||||||
|
|||||||
+25
-25
@@ -1,4 +1,4 @@
|
|||||||
require("dotenv").config();
|
require('dotenv').config();
|
||||||
|
|
||||||
let host;
|
let host;
|
||||||
let database;
|
let database;
|
||||||
@@ -6,27 +6,27 @@ let port;
|
|||||||
let user;
|
let user;
|
||||||
let password;
|
let password;
|
||||||
|
|
||||||
if (process.env.SERVER_FOR == "local") {
|
if (process.env.SERVER_FOR == 'local') {
|
||||||
host = "localhost";
|
host = 'localhost';
|
||||||
database = "postgres";
|
database = 'CMS_DEV';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = "postgres";
|
user = 'postgres';
|
||||||
password = "postgres";
|
password = 'postgres';
|
||||||
} else if (process.env.SERVER_FOR == "development") {
|
} else if (process.env.SERVER_FOR == 'development') {
|
||||||
host = "10.20.14.14";
|
host = '10.20.14.14';
|
||||||
database = "postgres";
|
database = 'postgres';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = "cms";
|
user = 'cms';
|
||||||
password = "Cm5kc1#2021";
|
password = 'Cm5kc1#2021';
|
||||||
} else if (process.env.SERVER_FOR == "production") {
|
} else if (process.env.SERVER_FOR == 'production') {
|
||||||
host = "10.1.201.75";
|
host = '10.1.201.75';
|
||||||
database = "postgres";
|
database = 'postgres';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = "postgres";
|
user = 'postgres';
|
||||||
password = "inhc0mmute_cms";
|
password = 'inhc0mmute_cms';
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// development: {
|
// development: {
|
||||||
// client: "pg",
|
// client: "pg",
|
||||||
// connection: process.env.DB_URL,
|
// connection: process.env.DB_URL,
|
||||||
@@ -36,7 +36,7 @@ if (process.env.SERVER_FOR == "local") {
|
|||||||
// seeds: { directory: "./infrastructure/database/seeds" },
|
// seeds: { directory: "./infrastructure/database/seeds" },
|
||||||
// },
|
// },
|
||||||
development: {
|
development: {
|
||||||
client: "pg",
|
client: 'pg',
|
||||||
connection: {
|
connection: {
|
||||||
host: host,
|
host: host,
|
||||||
database: database,
|
database: database,
|
||||||
@@ -49,21 +49,21 @@ if (process.env.SERVER_FOR == "local") {
|
|||||||
max: 10,
|
max: 10,
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: "./infrastructure/database/migrations",
|
directory: './infrastructure/database/migrations',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
testing: {
|
testing: {
|
||||||
client: "pg",
|
client: 'pg',
|
||||||
connection: process.env.DB_URL,
|
connection: process.env.DB_URL,
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: "./infrastructure/database/migrations",
|
directory: './infrastructure/database/migrations',
|
||||||
},
|
},
|
||||||
seeds: { directory: "./infrastructure/database/seeds" },
|
seeds: { directory: './infrastructure/database/seeds' },
|
||||||
},
|
},
|
||||||
|
|
||||||
production: {
|
production: {
|
||||||
client: "pg",
|
client: 'pg',
|
||||||
connection: {
|
connection: {
|
||||||
host: host,
|
host: host,
|
||||||
database: database,
|
database: database,
|
||||||
@@ -76,7 +76,7 @@ if (process.env.SERVER_FOR == "local") {
|
|||||||
max: 10,
|
max: 10,
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: "./infrastructure/database/migrations",
|
directory: './infrastructure/database/migrations',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user