diff --git a/application/modules/history/history.controller.js b/application/modules/history/history.controller.js index 4782024..23cf23d 100644 --- a/application/modules/history/history.controller.js +++ b/application/modules/history/history.controller.js @@ -75,24 +75,52 @@ const cardHistory = async (req, res) => { let istopup; let terminalName; let history = []; + let indexHistory = 0; + let checkReskaFormat; + let checkKCIFormat; for (let index = 0; index < data.length; index++) { element = data[index]; - date = moment(new Date((parseInt(element.slice(0, 8), 16) + 946684800) * 1000)).format("YYYY-MM-DD HH:mm:ss"); - nominal = parseInt(element.slice(8, 16), 16); - mid = element.slice(16, 20); - tid = element.slice(20, 24); - istopup = parseInt(element.slice(24, 26), 16) == 0 ? "Topup" : "Deduct"; - // get terminal name - terminalName = await model.getPartnerPartialMIDTID(mid, tid); - terminalName = terminalName ? terminalName.merchant_name : ""; + if (element != "00000000000000000000000000000000") { + + date = moment( + new Date((parseInt(element.slice(0, 8), 16) + 946684800) * 1000) + ).format("YYYY-MM-DD HH:mm:ss"); + nominal = parseInt(element.slice(8, 16), 16); + mid = element.slice(16, 20); + tid = element.slice(20, 24); - history[index] = { - date: date, - nominal: nominal, - terminal_name: terminalName, - transaction_type: istopup, - }; + checkReskaFormat = element.slice(16, 22); + checkKCIFormat = element.slice(26, 28); + + if (checkReskaFormat == "000000") { + istopup = "Deduct"; + + // get terminal name + terminalName = "PARKIR RESKA"; + } else if (checkKCIFormat == "00") { + istopup = parseInt(element.slice(24, 26), 16) == 0 ? "Topup" : "Deduct"; + + // get terminal name + terminalName = await model.getPartnerPartialMIDTID(mid, tid); + terminalName = terminalName ? terminalName.merchant_name : ""; + } else { + istopup = parseInt(element.slice(24, 26), 16) == 0 ? "Topup" : "Deduct"; + + // get terminal name + terminalName = await model.getPartnerPartialMIDTID(mid, tid); + terminalName = terminalName ? terminalName.merchant_name : ""; + } + + history[indexHistory] = { + date: date, + nominal: nominal, + terminal_name: terminalName, + transaction_type: istopup, + }; + + indexHistory++; + } } result = {