mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 17:16:27 +00:00
97 lines
2.5 KiB
JavaScript
97 lines
2.5 KiB
JavaScript
const knex = require('../../../infrastructure/database/knex');
|
|
|
|
// GET IS CARD ADDED TO BLACKLIST
|
|
const getCardBlacklist = (card_number) => {
|
|
let result = knex('public.t_m_card_blacklist')
|
|
.select('c_status')
|
|
.where('c_card_number', card_number)
|
|
.first();
|
|
return result;
|
|
};
|
|
|
|
// GET IS CARD ADDED TO BLACKLIST
|
|
const getCardReplacement = (card_number) => {
|
|
let result = knex('trx.t_d_card_replacement')
|
|
.select()
|
|
.where('c_card_no', card_number)
|
|
.orderBy('i_card_replacement', 'DESC')
|
|
.first();
|
|
|
|
return result;
|
|
};
|
|
|
|
// GET IS CARD ADDED TO BLACKLIST
|
|
const getCardProduct = (card_number) => {
|
|
let result = knex('public.t_m_card_product')
|
|
.select()
|
|
.where('c_card_number', card_number)
|
|
.orderBy('i_request_order', 'DESC')
|
|
.first();
|
|
|
|
return result;
|
|
};
|
|
|
|
// GET CHECKING FROM GLOBAL PARAMETER
|
|
const getGlobalParameterData = (code) => {
|
|
let result = knex('t_m_global_parameter')
|
|
.select('c_value')
|
|
.where('c_code', code)
|
|
.first();
|
|
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_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;
|
|
};
|
|
|
|
// UPDATE CARD REPLACEMENT
|
|
const updateReplacement = async (i_card_replacement, dataReplacement) => {
|
|
let result = await knex('trx.t_d_card_replacement')
|
|
.update(dataReplacement, ['*'])
|
|
.where({ i_card_replacement: i_card_replacement });
|
|
return result;
|
|
};
|
|
|
|
const insertReplacementDetail = async (dataReplacement) => {
|
|
let result = await knex("trx.t_d_card_replacement_detail").insert(dataReplacement);
|
|
return result;
|
|
};
|
|
|
|
module.exports = {
|
|
getCardBlacklist,
|
|
getCardReplacement,
|
|
getCardProduct,
|
|
getGlobalParameterData,
|
|
getLastBalanceFromCardHistory,
|
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
|
updateReplacement,
|
|
insertReplacementDetail
|
|
}; |