mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 23:06:28 +00:00
192 lines
5.3 KiB
JavaScript
192 lines
5.3 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 = (code) => {
|
|
let result = knex("t_m_issuer")
|
|
.select(
|
|
"i_issuer",
|
|
"c_code as issuer_code",
|
|
"c_name as issuer_name",
|
|
"i_fee as issuer_fee"
|
|
)
|
|
.where("c_code", code)
|
|
.where("c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET RESERVATION PENDING
|
|
const getReservationPending = (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")
|
|
.where("c_card_number", cardNumber)
|
|
.where("c_status", "P")
|
|
.where("d_expired", ">=", time)
|
|
.whereNotNull("c_payment_ref_no");
|
|
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 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;
|
|
};
|
|
|
|
// FIND RESERVATION
|
|
const findReservation = (reservationNumber) => {
|
|
let result = knex("trx.t_d_reservation_balance")
|
|
.where("c_reservation_no", reservationNumber)
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// INSERT LOADING BALANCE
|
|
const insertLoadingBalance = async (data, detail, reservationNumber, now) => {
|
|
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_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(() => {
|
|
// update reservation
|
|
return knex("trx.t_d_reservation_balance")
|
|
.transacting(trx)
|
|
.update({
|
|
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;
|
|
});
|
|
};
|
|
|
|
// 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;
|
|
};
|
|
|
|
// GENERATE LOAD BALANCE NUMBER
|
|
const generateLoadBalanceNumber = (data, date, counter) => {
|
|
let code = data.merchant_code ? data.merchant_code : "XXXXXXX";
|
|
|
|
let prefix = "LDB";
|
|
let loadBalanceNumber =
|
|
prefix + "" + code + "" + "" + date + counter.toString().padStart(3, "0");
|
|
|
|
return loadBalanceNumber;
|
|
};
|
|
|
|
module.exports = {
|
|
checkCardNumber,
|
|
getPartner,
|
|
getIssuer,
|
|
getReservationPending,
|
|
getBIRegulationStatus,
|
|
getMaxTopupPerMonth,
|
|
findReservation,
|
|
insertLoadingBalance,
|
|
getLoadBalanceSequence,
|
|
generateLoadBalanceNumber,
|
|
};
|