mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 18:06:27 +00:00
738 lines
22 KiB
JavaScript
738 lines
22 KiB
JavaScript
const knex = require("../../../infrastructure/database/knex");
|
|
|
|
// CHECK CARD NUMBER
|
|
const checkCardNumber = (cardNumber) => {
|
|
let result = knex("t_m_card_product")
|
|
.where("c_card_number", cardNumber)
|
|
.where("c_status", "!=", "X")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
|
const getPartner = (mid, tid) => {
|
|
let result = knex
|
|
.select(
|
|
"t_m_partner.i_partner",
|
|
"t_m_partner.c_code as partner_code",
|
|
"t_m_partner.c_name as partner_name",
|
|
"t_m_merchant.i_merchant",
|
|
"t_m_merchant.c_code as merchant_code",
|
|
"t_m_merchant.c_name as merchant_name",
|
|
"t_m_merchant.e_mid as mid",
|
|
"t_m_terminal.i_terminal",
|
|
"t_m_terminal.c_code as terminal_code",
|
|
"t_m_terminal.c_name as terminal_name",
|
|
"t_m_terminal.e_tid as tid"
|
|
)
|
|
.from("t_m_terminal")
|
|
.leftJoin(
|
|
"t_m_merchant",
|
|
"t_m_terminal.i_merchant",
|
|
"t_m_merchant.i_merchant"
|
|
)
|
|
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
|
.where("t_m_merchant.e_mid", mid)
|
|
.where("t_m_terminal.e_tid", tid)
|
|
.where("t_m_terminal.c_status", "A")
|
|
.where("t_m_merchant.c_status", "A")
|
|
.where("t_m_partner.c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET ISSUER
|
|
const getIssuer = (id) => {
|
|
let result = knex("t_c_partner_fee")
|
|
.select("i_issuer_fee_perc", "i_channel_fee_perc")
|
|
.where("i_partner", id)
|
|
.where("c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET RESERVATION PENDING
|
|
const getReservationPending = (cardNumber, time, flag) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
// .sum("i_reservation_amount as total_reservation_amount")
|
|
// .count("* as total_reservation")
|
|
.select("i_reservation_amount", "c_reservation_no", "c_flag")
|
|
.where("c_card_number", cardNumber)
|
|
.whereIn("c_status", ["P", "I"])
|
|
.where(function() {
|
|
this.orWhere("c_flag", flag).orWhere("c_flag", "-1");
|
|
})
|
|
.where("d_expired", ">=", time);
|
|
return result;
|
|
};
|
|
|
|
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
|
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
// .sum("i_reservation_amount as total_reservation_amount")
|
|
// .count("* as total_reservation")
|
|
.select("i_reservation_amount", "c_reservation_no", "c_flag", "c_load_balance_no")
|
|
.where("c_card_number", cardNumber)
|
|
.whereIn("c_status", ["P", "I"])
|
|
.whereRaw("??::INT < ??", ["c_flag", parseInt(flag)])
|
|
.where("c_flag", "!=", "-1")
|
|
.where("d_expired", ">=", time);
|
|
return result;
|
|
};
|
|
|
|
// GET RESERVATION PENDING WITH FLAG
|
|
const getReservationPendingWithFlag = (cardNumber, time) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
// .sum("i_reservation_amount as total_reservation_amount")
|
|
// .count("* as total_reservation")
|
|
.select("i_reservation_amount", "c_reservation_no", "c_flag")
|
|
.where("c_card_number", cardNumber)
|
|
.whereIn("c_status", ["P", "I"])
|
|
.whereNotNull("c_flag_code");
|
|
return result;
|
|
};
|
|
|
|
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
|
const getBIRegulationStatus = () => {
|
|
let result = knex("t_m_global_parameter")
|
|
.select("c_value")
|
|
.where("c_code", "HSM_BI_REGULATION_STAT")
|
|
.where("c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET MAX AMOUNT ON THE CARD FROM GLOBAL PARAMETER
|
|
const getMaxAmountOnTheCard = () => {
|
|
let result = knex("t_m_global_parameter")
|
|
.select("c_value")
|
|
.where("c_code", "HSM_BI_MAX_AMOUNT_ON_THE_CARD")
|
|
.where("c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET MAX TOPUP PER MONTH FROM GLOBAL PARAMETER
|
|
const getMaxTopupPerMonth = () => {
|
|
let result = knex("t_m_global_parameter")
|
|
.select("c_value")
|
|
.where("c_code", "HSM_BI_MAX_TOPUP_PER_MONTH")
|
|
.where("c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// INQUIRY BY RESERVATION NUMBER
|
|
let inquiryByLoadBalanceNumber = (loadBalanceNumber) => {
|
|
let result = knex("trx.t_d_load_balance")
|
|
.select(
|
|
"c_load_balance_no as load_balance_number",
|
|
"d_load_balance as load_balance_date",
|
|
"c_ref_no as ref_no",
|
|
"c_partner_name as partner_name",
|
|
"c_merchant_name as merchant_name",
|
|
"c_terminal_name as terminal_name",
|
|
"c_card_number as card_number",
|
|
"i_topup_amount as topup_amount",
|
|
"c_status as status_code",
|
|
"c_status_name as description"
|
|
)
|
|
.where("c_load_balance_no", loadBalanceNumber)
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// INQUIRY BY CARD NUMBER
|
|
let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
|
let result = knex("trx.t_d_load_balance")
|
|
.select(
|
|
"c_load_balance_no as load_balance_number",
|
|
"d_load_balance as load_balance_date",
|
|
"c_ref_no as ref_no",
|
|
"c_partner_name as partner_name",
|
|
"c_merchant_name as merchant_name",
|
|
"c_terminal_name as terminal_name",
|
|
"c_card_number as card_number",
|
|
"i_topup_amount as topup_amount",
|
|
"c_status as status_code",
|
|
"c_status_name as description"
|
|
)
|
|
.where("c_card_number", cardNumber);
|
|
|
|
if (startDate && endDate) {
|
|
result.whereRaw("??::date >= ?", ["d_load_balance", startDate]);
|
|
result.whereRaw("??::date <= ?", ["d_load_balance", endDate]);
|
|
}
|
|
return result;
|
|
};
|
|
|
|
// FIND RESERVATION LOADED
|
|
const findReservationLoaded = (reservationID) => {
|
|
let result = knex("trx.t_d_load_balance")
|
|
.leftJoin(
|
|
"trx.t_d_load_balance_detail",
|
|
"trx.t_d_load_balance.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.c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// FIND RESERVATION
|
|
const findReservation = (reservationNumber) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
.where("c_reservation_no", reservationNumber)
|
|
.where("c_status", "!=", "X")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// INSERT LOADING BALANCE
|
|
const insertLoadingBalance = async (
|
|
data,
|
|
detail,
|
|
reservationNumber,
|
|
now,
|
|
writeStatus,
|
|
cardNumber,
|
|
uid,
|
|
balance,
|
|
flag
|
|
) => {
|
|
await knex
|
|
.transaction((trx) => {
|
|
knex("trx.t_d_load_balance")
|
|
.transacting(trx)
|
|
.insert(data)
|
|
.returning("i_load_balance")
|
|
.then((resp) => {
|
|
let id = resp[0];
|
|
let loadDetail = [];
|
|
detail.forEach((element) => {
|
|
loadDetail.push({
|
|
i_load_balance: id,
|
|
i_reservation_balance: element.i_reservation_balance,
|
|
c_reservation_no: element.c_reservation_no,
|
|
i_amount: element.i_amount,
|
|
i_issuer: element.i_issuer,
|
|
i_issuer_code: element.i_issuer_code,
|
|
i_issuer_name: element.i_issuer_name,
|
|
i_issuer_fee: element.i_issuer_fee,
|
|
i_channel: element.i_channel,
|
|
i_channel_code: element.i_channel_code,
|
|
i_channel_name: element.i_channel_name,
|
|
i_channel_fee: element.i_channel_fee,
|
|
});
|
|
});
|
|
|
|
// insert detail load balance
|
|
return knex("trx.t_d_load_balance_detail")
|
|
.transacting(trx)
|
|
.insert(loadDetail);
|
|
})
|
|
.then(() => {
|
|
// insert load balance history
|
|
return knex("trx.t_d_load_balance_history")
|
|
.transacting(trx)
|
|
.returning("i_load_balance")
|
|
.insert(data);
|
|
})
|
|
.then((history) => {
|
|
let id = history[0];
|
|
let loadDetail = [];
|
|
detail.forEach((element) => {
|
|
loadDetail.push({
|
|
i_load_balance: id,
|
|
i_reservation_balance: element.i_reservation_balance,
|
|
c_reservation_no: element.c_reservation_no,
|
|
i_amount: element.i_amount,
|
|
i_issuer: element.i_issuer,
|
|
i_issuer_code: element.i_issuer_code,
|
|
i_issuer_name: element.i_issuer_name,
|
|
i_issuer_fee: element.i_issuer_fee,
|
|
i_channel: element.i_channel,
|
|
i_channel_code: element.i_channel_code,
|
|
i_channel_name: element.i_channel_name,
|
|
i_channel_fee: element.i_channel_fee,
|
|
});
|
|
});
|
|
|
|
// insert detail load balance
|
|
return knex("trx.t_d_load_balance_history_detail")
|
|
.transacting(trx)
|
|
.insert(loadDetail);
|
|
})
|
|
.then(() => {
|
|
// update reservation
|
|
return knex("trx.t_d_reservation_balance")
|
|
.transacting(trx)
|
|
.update({
|
|
c_status: "I",
|
|
c_status_name: "IN PROGRESS",
|
|
d_load_balance: now,
|
|
c_load_balance_no: data.c_load_balance_no,
|
|
c_flag_code: "FW",
|
|
c_flag: flag,
|
|
d_modify: now,
|
|
i_modify: null,
|
|
c_modify_username: null,
|
|
c_modify_fullname: null,
|
|
})
|
|
.whereIn("c_reservation_no", reservationNumber);
|
|
})
|
|
.then(() => {
|
|
// delete flag counting
|
|
return knex("trx.t_d_flag_counting")
|
|
.transacting(trx)
|
|
.where("c_card_number", cardNumber)
|
|
.whereRaw("UPPER(c_uid) = ?", [uid])
|
|
.del();
|
|
})
|
|
.then(() => {
|
|
// insert flag counting
|
|
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
|
d_request: now,
|
|
c_card_number: cardNumber,
|
|
c_uid: uid,
|
|
i_balance: balance,
|
|
c_flag: flag,
|
|
});
|
|
})
|
|
.then(trx.commit)
|
|
.catch(trx.rollback);
|
|
})
|
|
.then((result) => {
|
|
// console.log(result);
|
|
return result;
|
|
})
|
|
.catch((error) => {
|
|
console.log(error.message);
|
|
return error.message;
|
|
});
|
|
};
|
|
|
|
// UPDATE LOADING BALANCE
|
|
const updateLoadingBalance = async (
|
|
data,
|
|
now,
|
|
writeStatus,
|
|
cardNumber,
|
|
uid,
|
|
balance,
|
|
flag,
|
|
loadBalanceNumber
|
|
) => {
|
|
await knex
|
|
.transaction((trx) => {
|
|
knex("trx.t_d_load_balance")
|
|
.transacting(trx)
|
|
.update(data)
|
|
.where("c_load_balance_no", loadBalanceNumber)
|
|
.then(() => {
|
|
// insert load balance history
|
|
return knex("trx.t_d_load_balance_history")
|
|
.transacting(trx)
|
|
.insert(data);
|
|
})
|
|
.then(() => {
|
|
// update reservation
|
|
return knex("trx.t_d_reservation_balance")
|
|
.transacting(trx)
|
|
.update({
|
|
c_flag_code: writeStatus ? "FW" : null,
|
|
c_status: writeStatus ? "I" : "A",
|
|
c_status_name: writeStatus ? "IN PROGRESS" : "LOADED",
|
|
d_load_balance: now,
|
|
c_load_balance_no: loadBalanceNumber,
|
|
d_modify: now,
|
|
i_modify: null,
|
|
c_modify_username: null,
|
|
c_modify_fullname: null,
|
|
})
|
|
.where("c_load_balance_no", loadBalanceNumber);
|
|
})
|
|
.then(() => {
|
|
// delete flag counting
|
|
return knex("trx.t_d_flag_counting")
|
|
.transacting(trx)
|
|
.where("c_card_number", cardNumber)
|
|
.whereRaw("UPPER(c_uid) = ?", [uid])
|
|
.del();
|
|
})
|
|
.then(() => {
|
|
// insert flag counting
|
|
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
|
d_request: now,
|
|
c_card_number: cardNumber,
|
|
c_uid: uid,
|
|
i_balance: balance,
|
|
c_flag: flag,
|
|
});
|
|
})
|
|
.then(trx.commit)
|
|
.catch(trx.rollback);
|
|
})
|
|
.then((result) => {
|
|
// console.log(result);
|
|
return result;
|
|
})
|
|
.catch((error) => {
|
|
console.log(error.message);
|
|
return error.message;
|
|
});
|
|
};
|
|
|
|
// INSERT LOADING BALANCE HISTORY
|
|
const insertLoadingBalanceHistoryOnly = async (
|
|
data,
|
|
detail,
|
|
reservationNumber,
|
|
now,
|
|
writeStatus,
|
|
cardNumber,
|
|
uid,
|
|
balance,
|
|
flag
|
|
) => {
|
|
await knex
|
|
.transaction((trx) => {
|
|
knex("trx.t_d_load_balance_history")
|
|
.transacting(trx)
|
|
.insert(data)
|
|
.returning("i_load_balance")
|
|
.then((resp) => {
|
|
let id = resp[0];
|
|
let loadDetail = [];
|
|
detail.forEach((element) => {
|
|
loadDetail.push({
|
|
i_load_balance: id,
|
|
i_reservation_balance: element.i_reservation_balance,
|
|
c_reservation_no: element.c_reservation_no,
|
|
i_amount: element.i_amount,
|
|
i_issuer: element.i_issuer,
|
|
i_issuer_code: element.i_issuer_code,
|
|
i_issuer_name: element.i_issuer_name,
|
|
i_issuer_fee: element.i_issuer_fee,
|
|
i_channel: element.i_channel,
|
|
i_channel_code: element.i_channel_code,
|
|
i_channel_name: element.i_channel_name,
|
|
i_channel_fee: element.i_channel_fee,
|
|
});
|
|
});
|
|
|
|
// insert detail load balance
|
|
return knex("trx.t_d_load_balance_history_detail")
|
|
.transacting(trx)
|
|
.insert(loadDetail);
|
|
})
|
|
.then(() => {
|
|
// update reservation
|
|
return knex("trx.t_d_reservation_balance")
|
|
.transacting(trx)
|
|
.update({
|
|
c_flag_code: writeStatus ? "FW" : null,
|
|
c_status: writeStatus ? "I" : "A",
|
|
c_status_name: writeStatus ? "IN PROGRESS" : "LOADED",
|
|
// d_load_balance: now,
|
|
// c_load_balance_no: data.c_load_balance_no,
|
|
d_modify: now,
|
|
i_modify: null,
|
|
c_modify_username: null,
|
|
c_modify_fullname: null,
|
|
})
|
|
.whereIn("c_reservation_no", reservationNumber);
|
|
})
|
|
.then(() => {
|
|
// delete flag counting
|
|
return knex("trx.t_d_flag_counting")
|
|
.transacting(trx)
|
|
.where("c_card_number", cardNumber)
|
|
.whereRaw("UPPER(c_uid) = ?", [uid])
|
|
.del();
|
|
})
|
|
.then(() => {
|
|
// insert flag counting
|
|
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
|
d_request: now,
|
|
c_card_number: cardNumber,
|
|
c_uid: uid,
|
|
i_balance: balance,
|
|
c_flag: flag,
|
|
});
|
|
})
|
|
.then(trx.commit)
|
|
.catch(trx.rollback);
|
|
})
|
|
.then((result) => {
|
|
// console.log(result);
|
|
return result;
|
|
})
|
|
.catch((error) => {
|
|
console.log(error.message);
|
|
return error.message;
|
|
});
|
|
};
|
|
|
|
// GET LOADING BALANCE SEQUENCE
|
|
const getLoadBalanceSequence = (data, date) => {
|
|
let result = knex("trx.t_d_load_balance")
|
|
.select("i_load_balance_no_seq")
|
|
.orderBy("i_load_balance_no_seq", "desc")
|
|
.whereNotNull("i_load_balance_no_seq")
|
|
.where("i_partner", data.i_partner)
|
|
.where("i_merchant", data.i_merchant)
|
|
.whereRaw("??::date = ?", ["d_load_balance", date])
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// FIND LOAD BALANCE
|
|
let findLoadBalance = (loadBalanceNumber) => {
|
|
let result = knex("trx.t_d_load_balance")
|
|
.where("c_load_balance_no", loadBalanceNumber)
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// FIND LOAD BALANCE DETAIL
|
|
let findLoadBalanceDetail = (loadBalanceId) => {
|
|
let result = knex("trx.t_d_load_balance_detail").where(
|
|
"i_load_balance",
|
|
loadBalanceId
|
|
);
|
|
return result;
|
|
};
|
|
|
|
// CHECK FLAG
|
|
const checkFlag = (cardNumber, uid) => {
|
|
let result = knex("trx.t_d_flag_counting")
|
|
.where("c_card_number", cardNumber)
|
|
.whereRaw("UPPER(c_uid) = ?", [uid])
|
|
.orderBy("d_request", "desc")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// UPDATE RESERVATION AND LOADING BALANCE CASE FAILED WRITE BEFORE
|
|
const updateReservationAndLoadingBalance = async (
|
|
reservationNumber,
|
|
data,
|
|
detail,
|
|
now,
|
|
flag
|
|
) => {
|
|
await knex
|
|
.transaction((trx) => {
|
|
knex("trx.t_d_load_balance")
|
|
.transacting(trx)
|
|
.update(data)
|
|
.where("c_load_balance_no", data.c_load_balance_no)
|
|
.then(() => {
|
|
// insert load balance history
|
|
return knex("trx.t_d_load_balance_history")
|
|
.transacting(trx)
|
|
.returning("i_load_balance")
|
|
.insert(data);
|
|
})
|
|
.then((history) => {
|
|
let id = history[0];
|
|
let loadDetail = [];
|
|
detail.forEach((element) => {
|
|
loadDetail.push({
|
|
i_load_balance: id,
|
|
i_reservation_balance: element.i_reservation_balance,
|
|
c_reservation_no: element.c_reservation_no,
|
|
i_amount: element.i_amount,
|
|
i_issuer: element.i_issuer,
|
|
i_issuer_code: element.i_issuer_code,
|
|
i_issuer_name: element.i_issuer_name,
|
|
i_issuer_fee: element.i_issuer_fee,
|
|
i_channel: element.i_channel,
|
|
i_channel_code: element.i_channel_code,
|
|
i_channel_name: element.i_channel_name,
|
|
i_channel_fee: element.i_channel_fee,
|
|
});
|
|
});
|
|
|
|
// insert detail load balance
|
|
return knex("trx.t_d_load_balance_history_detail")
|
|
.transacting(trx)
|
|
.insert(loadDetail);
|
|
})
|
|
.then(() => {
|
|
// update reservation
|
|
return knex("trx.t_d_reservation_balance")
|
|
.transacting(trx)
|
|
.update({
|
|
d_load_balance: data.d_load_balance,
|
|
c_load_balance_no: data.c_load_balance_no,
|
|
c_flag: flag,
|
|
c_flag_code: null,
|
|
c_status: "A",
|
|
c_status_name: "LOADED",
|
|
d_modify: now,
|
|
i_modify: null,
|
|
c_modify_username: null,
|
|
c_modify_fullname: null,
|
|
})
|
|
.whereIn("c_reservation_no", reservationNumber);
|
|
})
|
|
.then(trx.commit)
|
|
.catch(trx.rollback);
|
|
})
|
|
.then((result) => {
|
|
// console.log(result);
|
|
return result;
|
|
})
|
|
.catch((error) => {
|
|
console.log(error.message);
|
|
return error.message;
|
|
});
|
|
};
|
|
|
|
//
|
|
const getLastReservationFlag = (reservationNumber) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
.whereIn("c_reservation_no", reservationNumber)
|
|
.whereNotNull("c_flag_code")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
//
|
|
const getLastLoadingBalanceFlag = (loadBalanceNumber) => {
|
|
let result = knex("trx.t_d_load_balance_history")
|
|
.select("trx.t_d_load_balance_history.*")
|
|
.whereIn("trx.t_d_load_balance_history.c_load_balance_no", loadBalanceNumber)
|
|
.whereIn("trx.t_d_load_balance_history.c_status", ["P", "I"])
|
|
.whereNotNull("trx.t_d_load_balance_history.c_load_balance_no")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
//
|
|
const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
|
let result = knex("trx.t_d_load_balance_history_detail").where(
|
|
"i_load_balance",
|
|
loadBalanceId
|
|
);
|
|
return result;
|
|
};
|
|
|
|
// update
|
|
const updateStatusReservation = (reservationNumber, now) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
.update({
|
|
c_status: "I",
|
|
c_status_name: "IN PROGRESS",
|
|
d_modify: now,
|
|
i_modify: null,
|
|
c_modify_username: null,
|
|
c_modify_fullname: null,
|
|
})
|
|
.whereIn("c_reservation_no", reservationNumber);
|
|
return result;
|
|
};
|
|
|
|
// update flag
|
|
const updateFlag = async (now, cardNumber, uid, balance, flag) => {
|
|
await knex
|
|
.transaction((trx) => {
|
|
knex("trx.t_d_flag_counting")
|
|
.transacting(trx)
|
|
.where("c_card_number", cardNumber)
|
|
.whereRaw("UPPER(c_uid) = ?", [uid])
|
|
.del()
|
|
.then(() => {
|
|
// insert flag counting
|
|
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
|
d_request: now,
|
|
c_card_number: cardNumber,
|
|
c_uid: uid,
|
|
i_balance: balance,
|
|
c_flag: flag,
|
|
});
|
|
})
|
|
.then(trx.commit)
|
|
.catch(trx.rollback);
|
|
})
|
|
.then((result) => {
|
|
// console.log(result);
|
|
return result;
|
|
})
|
|
.catch((error) => {
|
|
console.log(error.message);
|
|
return error.message;
|
|
});
|
|
};
|
|
|
|
// GET ACCUMULATION BALANCE IN THIS MONTH FROM CARD HISTORY
|
|
const getAccumulationBalanceInThisMonthFromCardHistory = (
|
|
cardNumber,
|
|
year,
|
|
month
|
|
) => {
|
|
let result = knex("log.t_log_card")
|
|
.sum("m_amount 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])
|
|
.whereIn("i_log_name", [21])
|
|
.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;
|
|
};
|
|
|
|
// INSERT TEMP LOAD BALANCE NUMBER1
|
|
const insertLoadBalanceNumber = (loadBalanceNumber) => {
|
|
let result = knex("trx.t_d_load_balance_no_validate")
|
|
.insert({
|
|
c_load_balance_no: loadBalanceNumber,
|
|
})
|
|
.onConflict("c_load_balance_no")
|
|
.ignore();
|
|
return result;
|
|
};
|
|
|
|
module.exports = {
|
|
checkCardNumber,
|
|
getPartner,
|
|
getIssuer,
|
|
getReservationPending,
|
|
getReservationPendingWithFlagCounter,
|
|
getReservationPendingWithFlag,
|
|
getBIRegulationStatus,
|
|
getMaxAmountOnTheCard,
|
|
getMaxTopupPerMonth,
|
|
findReservationLoaded,
|
|
findReservation,
|
|
insertLoadingBalance,
|
|
updateLoadingBalance,
|
|
insertLoadingBalanceHistoryOnly,
|
|
getLoadBalanceSequence,
|
|
findLoadBalance,
|
|
findLoadBalanceDetail,
|
|
inquiryByLoadBalanceNumber,
|
|
inquiryByCardNumber,
|
|
checkFlag,
|
|
updateReservationAndLoadingBalance,
|
|
getLastReservationFlag,
|
|
getLastLoadingBalanceFlag,
|
|
getLastLoadingBalanceDetailFlag,
|
|
updateStatusReservation,
|
|
updateFlag,
|
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
|
createLoadBalanceLog,
|
|
insertLoadBalanceNumber,
|
|
};
|