diff --git a/application/modules/pos/pos.controller.js b/application/modules/pos/pos.controller.js index a40db4a..f46aef5 100644 --- a/application/modules/pos/pos.controller.js +++ b/application/modules/pos/pos.controller.js @@ -1597,23 +1597,98 @@ const validateReplacement = async (req, res) => { last_balance = dataCardReplacement.i_last_balance; if (last_balance == null) { + // if (is_warranty == true) { + // let result = {}; + // const baseUrl = 'http://127.0.0.1:3000'; + // const payload = { + // card_number: card_number, + // }; + // const response = await axios.post(baseUrl + '/api/pos/test', payload); + // if ( + // !response.data.code == undefined || + // response.data.data.status == false + // ) { + // result = { + // code: '415', + // message: 'Last Balance not updated.', + // data: { + // status: false, + // detail: {}, + // }, + // }; + // winston.logger.info( + // `${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}` + // ); + // return res.status(200).json(result); + // } + // last_balance = response.data.data.detail.last_balance; + // let dataReplacementUpdate = { + // i_last_balance: last_balance, + // }; + // // update card_replacement + // await model.updateReplacementByCardNumber( + // card_number, + // dataReplacementUpdate + // ); + // // log debug + // winston.logger.info( + // `${uniqueCode} [ GET LAST BALANCE CTS ${card_number} ]: ${last_balance}` + // ); + // } else { + // result = { + // code: '415', + // message: 'Last Balance not updated.', + // data: { + // status: false, + // detail: {}, + // }, + // }; + // //LOG-INFO + // winston.logger.info( + // `${uniqueCode} [ RESPONSE VALIDATE-REPLACEMENT ]: ${JSON.stringify( + // result + // )}` + // ); + // return res.status(200).json(result); + + + if (is_warranty == true) { let result = {}; - const baseUrl = 'http://127.0.0.1:3000'; + const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance' + const bearer = 'Mv@2025qwertyuiopzxcvbnm' const payload = { card_number: card_number, }; - const response = await axios.post(baseUrl + '/api/pos/test', payload); - if ( - !response.data.code == undefined || - response.data.data.status == false - ) { + let config = { + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + bearer + }, + }; + const url = baseUrl; + const response = await axios.post(url, payload, config); + if (response.data.code == undefined || response.data.code != 200) { + if (response.data.code == 404) { + result = { + code: '494', + message: 'No data found in CTS for the given card number', + data: { + status: false, + detail: {} + } + }; + winston.logger.info( + `${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}` + ); + return res.status(200).json(result); + } result = { code: '415', message: 'Last Balance not updated.', data: { status: false, - detail: {}, + detail: {} }, }; winston.logger.info( @@ -1621,89 +1696,16 @@ const validateReplacement = async (req, res) => { ); return res.status(200).json(result); } - last_balance = response.data.data.detail.last_balance; + last_balance = response.data.data.balance_after; let dataReplacementUpdate = { - i_last_balance: last_balance, + i_last_balance: last_balance }; // update card_replacement - await model.updateReplacementByCardNumber( - card_number, - dataReplacementUpdate - ); + await model.updateReplacementByCardNumber(card_number, dataReplacementUpdate); // log debug winston.logger.info( `${uniqueCode} [ GET LAST BALANCE CTS ${card_number} ]: ${last_balance}` ); - } else { - result = { - code: '415', - message: 'Last Balance not updated.', - data: { - status: false, - detail: {}, - }, - }; - //LOG-INFO - winston.logger.info( - `${uniqueCode} [ RESPONSE VALIDATE-REPLACEMENT ]: ${JSON.stringify( - result - )}` - ); - return res.status(200).json(result); - // if (is_warranty == true) { - // let result = {}; - // const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance' - // const bearer = 'Mv@2025qwertyuiopzxcvbnm' - // const payload = { - // card_number: card_number, - // }; - // let config = { - // headers: { - // 'Content-Type': 'application/json', - // 'Authorization': 'Bearer ' + bearer - // }, - // }; - // const url = baseUrl; - // const response = await axios.post(url, payload, config); - // if (response.data.code == undefined || response.data.code != 200) { - // if (response.data.code == 404) { - // result = { - // code: '494', - // message: 'No data found in CTS for the given card number', - // data: { - // status: false, - // detail: {} - // } - // }; - // winston.logger.info( - // `${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}` - // ); - // return res.status(200).json(result); - // } - // result = { - // code: '415', - // message: 'Last Balance not updated.', - // data: { - // status: false, - // detail: {} - // }, - // }; - // winston.logger.info( - // `${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}` - // ); - // return res.status(200).json(result); - // } - // last_balance = response.data.data.balance_after; - // let dataReplacementUpdate = { - // i_last_balance: last_balance - // }; - // // update card_replacement - // await model.updateReplacementByCardNumber(card_number, dataReplacementUpdate); - // // log debug - // winston.logger.info( - // `${uniqueCode} [ GET LAST BALANCE CTS ${card_number} ]: ${last_balance}` - // ); - // } } } @@ -2477,115 +2479,15 @@ const confirmSales = async (req, res) => { } }; -// const getLastBalanceCTS = async (req, res) => { -// try { -// let uniqueCode = helper.getUniqueCode(); -// let result = {}; -// const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance' -// const bearer = 'Mv@2025qwertyuiopzxcvbnm' - -// console.log( -// `${uniqueCode} [ REQUEST GET LAST BALANCE CTS ]: ${JSON.stringify(req.body)}` -// ); - -// //CARD REPLACEMENT VALIDATION -// const dataCard = await model.getCardReplacementScheduler(); - -// for (const card of dataCard) { -// const payload = { -// card_number: card.c_card_no, -// }; - -// let config = { -// headers: { -// 'Content-Type': 'application/json', -// 'Authorization': 'Bearer ' + bearer -// }, -// }; -// const url = baseUrl; -// const response = await axios.post(url, payload, config); -// if (response.data.code == undefined || response.data.code != 200) { -// if (response.data.code == 404) { -// result = { -// code: '494', -// message: 'No data found in CTS for the given card number', -// data: { -// status: false, -// detail: {} -// } -// }; -// winston.logger.info( -// `${uniqueCode} [ FAILED HIT - card_number : ${card.c_card_no} ]: ${response.data.message}` -// ); -// return res.status(200).json(result); -// } -// result = { -// code: '500', -// message: "CTS service not avaliable", -// data: { -// status: false, -// detail: {} -// } -// }; -// winston.logger.info( -// `${uniqueCode} [ FAILED HIT - card_number : ${card.c_card_no} ]: ${response.data.message}` -// ); -// return res.status(200).json(result); -// } -// last_balance = response.data.data.balance_after; -// let dataReplacementUpdate = { -// i_last_balance: last_balance -// }; -// // update card_replacement -// await model.updateReplacementByCardNumber(card.c_card_no, dataReplacementUpdate); -// // log debug -// winston.logger.info( -// `${uniqueCode} [ GET LAST BALANCE CTS ${card.c_card_no} ]: ${last_balance}` -// ); -// } - -// result = { -// code: '00', -// message: 'Successfully.', -// data: { -// status: true, -// detail: {} -// } -// }; -// //LOG-INFO -// winston.logger.info( -// `${uniqueCode} [ RESPONSE GET LAST BALANCE CTS ]: ${JSON.stringify(result)}` -// ); -// return res.status(200).json(result); - -// } catch (error) { -// // create log -// winston.logger.error( -// `[ RESPONSE GET LAST BALANCE CTS ]: 500 internal server error - backend server | ${error.message}` -// ); -// return res.status(200).json({ -// code: '500', -// message: -// process.env.NODE_ENV != 'production' -// ? error.message -// : '500 internal server error - backend server.', -// data: { -// status: false, -// detail: {} -// } -// }); -// } -// }; const getLastBalanceCTS = async (req, res) => { try { let uniqueCode = helper.getUniqueCode(); let result = {}; - const baseUrl = 'http://127.0.0.1:3000'; + const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance' + const bearer = 'Mv@2025qwertyuiopzxcvbnm' console.log( - `${uniqueCode} [ REQUEST GET LAST BALANCE CTS ]: ${JSON.stringify( - req.body - )}` + `${uniqueCode} [ REQUEST GET LAST BALANCE CTS ]: ${JSON.stringify(req.body)}` ); //CARD REPLACEMENT VALIDATION @@ -2596,51 +2498,48 @@ const getLastBalanceCTS = async (req, res) => { card_number: card.c_card_no, }; - // ==================== Kalo butuh auth ==================== - // let auth = req.header('Authorization'); - // token_api = auth.replace('Bearer ', ''); - - // const protocol = req.protocol; - // const host = req.headers.host; - // const current_url = protocol + '://' + host; - - // let config = { - // headers: { - // 'Content-Type': 'application/json', - // 'Authorization': 'Bearer ' + token_api - // }, - // }; - // const dataPost = { 'card_number': card_number } - // const url = current_url + `/api/pos/card-lastbalance`; - // const resp = await axios.post(url, dataPost, config); - - const response = await axios.post(baseUrl + '/api/pos/test', payload); - if ( - !response.data.code == undefined || - response.data.data.status == false - ) { + let config = { + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + bearer + }, + }; + const url = baseUrl; + const response = await axios.post(url, payload, config); + if (response.data.code == undefined || response.data.code != 200) { + if (response.data.code == 404) { + result = { + code: '494', + message: 'No data found in CTS for the given card number', + data: { + status: false, + detail: {} + } + }; + winston.logger.info( + `${uniqueCode} [ FAILED HIT - card_number : ${card.c_card_no} ]: ${response.data.message}` + ); + return res.status(200).json(result); + } result = { code: '500', - message: 'CTS service not avaliable', + message: "CTS service not avaliable", data: { status: false, - detail: {}, - }, + detail: {} + } }; winston.logger.info( `${uniqueCode} [ FAILED HIT - card_number : ${card.c_card_no} ]: ${response.data.message}` ); return res.status(200).json(result); } - last_balance = response.data.data.detail.last_balance; + last_balance = response.data.data.balance_after; let dataReplacementUpdate = { - i_last_balance: last_balance, + i_last_balance: last_balance }; // update card_replacement - await model.updateReplacementByCardNumber( - card.c_card_no, - dataReplacementUpdate - ); + await model.updateReplacementByCardNumber(card.c_card_no, dataReplacementUpdate); // log debug winston.logger.info( `${uniqueCode} [ GET LAST BALANCE CTS ${card.c_card_no} ]: ${last_balance}` @@ -2652,16 +2551,15 @@ const getLastBalanceCTS = async (req, res) => { message: 'Successfully.', data: { status: true, - detail: {}, - }, + detail: {} + } }; //LOG-INFO winston.logger.info( - `${uniqueCode} [ RESPONSE GET LAST BALANCE CTS ]: ${JSON.stringify( - result - )}` + `${uniqueCode} [ RESPONSE GET LAST BALANCE CTS ]: ${JSON.stringify(result)}` ); return res.status(200).json(result); + } catch (error) { // create log winston.logger.error( @@ -2675,11 +2573,115 @@ const getLastBalanceCTS = async (req, res) => { : '500 internal server error - backend server.', data: { status: false, - detail: {}, - }, + detail: {} + } }); } }; +// const getLastBalanceCTS = async (req, res) => { +// try { +// let uniqueCode = helper.getUniqueCode(); +// let result = {}; +// const baseUrl = 'http://127.0.0.1:3000'; + +// console.log( +// `${uniqueCode} [ REQUEST GET LAST BALANCE CTS ]: ${JSON.stringify( +// req.body +// )}` +// ); + +// //CARD REPLACEMENT VALIDATION +// const dataCard = await model.getCardReplacementScheduler(); + +// for (const card of dataCard) { +// const payload = { +// card_number: card.c_card_no, +// }; + +// // ==================== Kalo butuh auth ==================== +// // let auth = req.header('Authorization'); +// // token_api = auth.replace('Bearer ', ''); + +// // const protocol = req.protocol; +// // const host = req.headers.host; +// // const current_url = protocol + '://' + host; + +// // let config = { +// // headers: { +// // 'Content-Type': 'application/json', +// // 'Authorization': 'Bearer ' + token_api +// // }, +// // }; +// // const dataPost = { 'card_number': card_number } +// // const url = current_url + `/api/pos/card-lastbalance`; +// // const resp = await axios.post(url, dataPost, config); + +// const response = await axios.post(baseUrl + '/api/pos/test', payload); +// if ( +// !response.data.code == undefined || +// response.data.data.status == false +// ) { +// result = { +// code: '500', +// message: 'CTS service not avaliable', +// data: { +// status: false, +// detail: {}, +// }, +// }; +// winston.logger.info( +// `${uniqueCode} [ FAILED HIT - card_number : ${card.c_card_no} ]: ${response.data.message}` +// ); +// return res.status(200).json(result); +// } +// last_balance = response.data.data.detail.last_balance; +// let dataReplacementUpdate = { +// i_last_balance: last_balance, +// }; +// // update card_replacement +// await model.updateReplacementByCardNumber( +// card.c_card_no, +// dataReplacementUpdate +// ); +// // log debug +// winston.logger.info( +// `${uniqueCode} [ GET LAST BALANCE CTS ${card.c_card_no} ]: ${last_balance}` +// ); +// } + +// result = { +// code: '00', +// message: 'Successfully.', +// data: { +// status: true, +// detail: {}, +// }, +// }; +// //LOG-INFO +// winston.logger.info( +// `${uniqueCode} [ RESPONSE GET LAST BALANCE CTS ]: ${JSON.stringify( +// result +// )}` +// ); +// return res.status(200).json(result); +// } catch (error) { +// // create log +// winston.logger.error( +// `[ RESPONSE GET LAST BALANCE CTS ]: 500 internal server error - backend server | ${error.message}` +// ); +// return res.status(200).json({ +// code: '500', +// message: +// process.env.NODE_ENV != 'production' +// ? error.message +// : '500 internal server error - backend server.', +// data: { +// status: false, +// detail: {}, +// }, +// }); +// } +// }; const completeDataSalesInternal = async (req, res) => { try {