mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 11:06:28 +00:00
122 lines
4.2 KiB
JavaScript
122 lines
4.2 KiB
JavaScript
const knex = require("../../../infrastructure/database/knex");
|
|
|
|
// 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 PARTNER, MERCHANT, TERMINAL FROM TID
|
|
const getPartnerPartialMIDTID = (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")
|
|
.whereRaw("SUBSTRING(t_m_merchant.e_mid, 9, 4) = ?", mid)
|
|
.whereRaw("SUBSTRING(t_m_terminal.e_tid, 1, 4) = ?", 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 TERMINAL KCI EXISTING
|
|
const getTerminalKCIExisting = (mid) => {
|
|
let result = knex
|
|
.select(
|
|
"t_m_station.c_code as merchant_code",
|
|
"t_m_station.c_name as merchant_name"
|
|
)
|
|
.from("t_m_station")
|
|
.where("t_m_station.station_hex_code", mid)
|
|
.where("t_m_station.c_status", "A")
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// Terapkan batas tanggal pada kedua sumber sebelum menggabungkan riwayat.
|
|
const historyByCardNumber = (mid, tid, cardNumber, startDate, endDate) => {
|
|
const scopedHistory = (table, dateColumn) => {
|
|
const query = knex(table).where({
|
|
'history.c_mid': mid, 'history.c_tid': tid, 'history.c_card_number': cardNumber,
|
|
});
|
|
if (startDate && endDate) {
|
|
query.whereRaw('?? >= ?::date', [dateColumn, startDate])
|
|
.whereRaw('?? < (?::date + 1)', [dateColumn, endDate]);
|
|
}
|
|
return query.select(
|
|
'history.c_ref_no as ref_no', 'history.c_partner_name as partner_name',
|
|
'history.c_merchant_name as merchant_name', 'history.c_terminal_name as terminal_name',
|
|
'history.c_card_number as card_number',
|
|
);
|
|
};
|
|
|
|
const reservations = scopedHistory('trx.t_d_reservation_balance as history', 'history.d_reservation')
|
|
.select(
|
|
'history.c_reservation_no as unique_number', 'history.d_reservation as date',
|
|
'history.i_reservation_amount as amount', 'history.i_issuer_fee as issuer_fee',
|
|
'history.i_channel_fee as channel_fee', 'history.c_status as status_code',
|
|
'history.c_status_name as description',
|
|
);
|
|
const loads = scopedHistory('trx.t_d_load_balance as history', 'history.d_load_balance')
|
|
.leftJoin('trx.t_d_load_balance_detail as detail', 'detail.i_load_balance', 'history.i_load_balance')
|
|
.select(
|
|
'history.c_load_balance_no as unique_number', 'history.d_load_balance as date',
|
|
'history.i_topup_amount as amount', 'detail.i_issuer_fee as issuer_fee',
|
|
'detail.i_channel_fee as channel_fee', 'history.c_status as status_code',
|
|
'history.c_status_name as description',
|
|
);
|
|
return reservations.unionAll([loads]);
|
|
};
|
|
|
|
module.exports = {
|
|
getPartner,
|
|
getPartnerPartialMIDTID,
|
|
getTerminalKCIExisting,
|
|
historyByCardNumber,
|
|
};
|