mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 17:46:28 +00:00
Compare commits
132 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ff0cae4d6 | |||
| c80b12ba53 | |||
| 30c32ca293 | |||
| 4d47090994 | |||
| 3fefaed395 | |||
| b1be54d5ba | |||
| 536d1a5c94 | |||
| 5d8369edd8 | |||
| 3c26dd6e23 | |||
| 0baf1332b6 | |||
| 5aca4559c2 | |||
| 21a45058f0 | |||
| edc70c3e6b | |||
| 4bb2facddb | |||
| 466c18fe21 | |||
| ed11c6ccc4 | |||
| 3515b5459f | |||
| e4cf444b83 | |||
| ddf01d2246 | |||
| 1fb0913eb5 | |||
| 293602bed2 | |||
| 87461a4a14 | |||
| fbcae2e596 | |||
| c7f816a449 | |||
| eeab7627ae | |||
| 9052668cbc | |||
| f615e9207f | |||
| 1ba983e745 | |||
| 8f254758dd | |||
| e7c4388956 | |||
| 3d31e6f6a5 | |||
| 1b3991c82f | |||
| 38edd07d65 | |||
| fff4915078 | |||
| 820f833844 | |||
| 1bd85ba888 | |||
| cab77e8872 | |||
| 7b52cebeb7 | |||
| 4c3496e9f2 | |||
| 529d6d7ffc | |||
| 5ca30fbfc4 | |||
| d3729ab906 | |||
| 95bfc120c5 | |||
| 9e98533ffb | |||
| 0ab80c0ac4 | |||
| ef274a483c | |||
| d129ad7a2f | |||
| 1f127807d3 | |||
| e30c78beb7 | |||
| 1014e4374a | |||
| 1d2e92b85f | |||
| 88c3b9bc4a | |||
| 51cb6c1212 | |||
| ffa6830734 | |||
| 6c93cff3bb | |||
| b24335043a | |||
| ac2ea55b5d | |||
| f3e9097bfa | |||
| 0dcec2a6ad | |||
| f8f974eb11 | |||
| 29981e9757 | |||
| a59a9090a7 | |||
| ca17c397c5 | |||
| ff1a80f3b5 | |||
| 4bda7458b4 | |||
| d4d61d1d79 | |||
| 80557a53e8 | |||
| 920a6d4ccd | |||
| ecd0cb12c4 | |||
| fe484b08af | |||
| f5a55392c9 | |||
| 2dc27ea57c | |||
| ecb78bfa29 | |||
| 74936dbe0d | |||
| b1814031b9 | |||
| b5061cf78e | |||
| a8e0376496 | |||
| 16a20faee6 | |||
| 0f34326da4 | |||
| 5a63ca6ea1 | |||
| 5d7852eff9 | |||
| 009e6caead | |||
| e61392d81a | |||
| 8c0b6f7e7c | |||
| cee0352271 | |||
| dfce874ce9 | |||
| b942d114ad | |||
| 7c66ebe702 | |||
| 84de02de26 | |||
| 46e3cd689b | |||
| 6b0d67ee60 | |||
| 7805bc902b | |||
| 95f4a03e81 | |||
| 4c7230ba6b | |||
| 1b2eff69b4 | |||
| e3ab361b24 | |||
| 14026e8bf0 | |||
| 3c1fc92d59 | |||
| a333ddb58f | |||
| f2c5d65ec0 | |||
| bcb9225466 | |||
| 90dfdc8857 | |||
| 476235440c | |||
| 04885f22d6 | |||
| 3b68ab9ab3 | |||
| 31b581c85e | |||
| a3a4772f77 | |||
| 50008e2006 | |||
| 6ef43923e1 | |||
| c30cdcf4ed | |||
| e77a975ccc | |||
| 728a9a92c9 | |||
| 47af9992be | |||
| ede3aacef3 | |||
| a6b17139bf | |||
| 7a7f18701d | |||
| 24006105b9 | |||
| e34434f96c | |||
| c2e95ee6a5 | |||
| da1912d05d | |||
| 9cbc467904 | |||
| 0a5e82dbbb | |||
| 7171d1e3f5 | |||
| 6c7131c944 | |||
| 05098fa3ac | |||
| 131cac392b | |||
| cd3c29bee0 | |||
| 8436ea2071 | |||
| 032e12d9d0 | |||
| 5e91b9a147 | |||
| 9b8865233b | |||
| 3645bb2420 |
+16
-16
@@ -1,8 +1,8 @@
|
||||
const moment = require("moment");
|
||||
const winston = require("winston");
|
||||
const loki = require("winston-loki");
|
||||
require("winston-daily-rotate-file");
|
||||
require("dotenv").config();
|
||||
const moment = require('moment');
|
||||
const winston = require('winston');
|
||||
const loki = require('winston-loki');
|
||||
require('winston-daily-rotate-file');
|
||||
require('dotenv').config();
|
||||
const { combine, timestamp, printf, colorize, align, json } = winston.format;
|
||||
let lokiUrl = process.env.LOKI_URL;
|
||||
|
||||
@@ -18,32 +18,32 @@ var log;
|
||||
|
||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||
filename: `./lokiLog/%DATE%-onlinetopup.log`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
maxFiles: "1d",
|
||||
datePattern: 'YYYY-MM-DD',
|
||||
maxFiles: '1d',
|
||||
});
|
||||
|
||||
if (
|
||||
process.env.NODE_ENV == "production" ||
|
||||
process.env.NODE_ENV == "PRODUCTION"
|
||||
process.env.NODE_ENV == 'production' ||
|
||||
process.env.NODE_ENV == 'PRODUCTION'
|
||||
) {
|
||||
log = winston.createLogger({
|
||||
levels: logLevels,
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
level: process.env.LOG_LEVEL || 'info',
|
||||
exitOnError: false,
|
||||
// format: combine(timestamp(), json()),
|
||||
format: combine(
|
||||
// colorize({ all: true }),
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
||||
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||
}),
|
||||
align(),
|
||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||
),
|
||||
defaultMeta: { service: "topuponline" },
|
||||
defaultMeta: { service: 'topuponline' },
|
||||
transports: [
|
||||
new loki({
|
||||
host: lokiUrl,
|
||||
labels: { app: "topuponline" },
|
||||
labels: { app: 'topuponline' },
|
||||
json: true,
|
||||
format: json(),
|
||||
replaceTimestamp: true,
|
||||
@@ -59,7 +59,7 @@ if (
|
||||
transports: [
|
||||
new loki({
|
||||
host: lokiUrl,
|
||||
labels: { app: "topuponline" },
|
||||
labels: { app: 'topuponline' },
|
||||
handleExceptions: true,
|
||||
handleRejections: true,
|
||||
clearOnError: true,
|
||||
@@ -75,14 +75,14 @@ if (
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV != "testing" && process.env.NODE_ENV != "TESTING") {
|
||||
if (process.env.NODE_ENV != 'testing' && process.env.NODE_ENV != 'TESTING') {
|
||||
log.add(
|
||||
new winston.transports.Console({
|
||||
// format: winston.format.cli(),
|
||||
format: combine(
|
||||
colorize({ all: true }),
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
||||
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||
}),
|
||||
align(),
|
||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||
|
||||
@@ -1,49 +1,58 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
const helper = require("../helpers/helper");
|
||||
const jwt = require('jsonwebtoken');
|
||||
const helper = require('../helpers/helper');
|
||||
const winston = require('../helpers/winston.logger');
|
||||
|
||||
const generateRefreshToken = (req) => {
|
||||
let expiresIn = process.env.JWT_REFRESH_EXPIRATION ? process.env.JWT_REFRESH_EXPIRATION : "7d";
|
||||
let expiresIn = process.env.JWT_REFRESH_EXPIRATION
|
||||
? process.env.JWT_REFRESH_EXPIRATION
|
||||
: '7d';
|
||||
let signOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
expiresIn: expiresIn,
|
||||
}
|
||||
};
|
||||
return jwt.sign(req, process.env.REFRESH_TOKEN_SECRET, signOptions);
|
||||
};
|
||||
|
||||
const authenticateRefreshToken = (req, res, next) => {
|
||||
|
||||
let verifyOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
}
|
||||
};
|
||||
|
||||
jwt.verify(req.header("refresh_token"), process.env.REFRESH_TOKEN_SECRET, verifyOptions, (err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: "400",
|
||||
message: "Refresh Token is invalid. Please login!",
|
||||
data: {},
|
||||
});
|
||||
jwt.verify(
|
||||
req.header('refresh_token'),
|
||||
process.env.REFRESH_TOKEN_SECRET,
|
||||
verifyOptions,
|
||||
(err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: '400',
|
||||
message: 'Refresh Token is invalid. Please login!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
const generateAccessToken = (req) => {
|
||||
let expiresIn = process.env.JWT_EXPIRATION ? process.env.JWT_EXPIRATION : "1d";
|
||||
let expiresIn = process.env.JWT_EXPIRATION
|
||||
? process.env.JWT_EXPIRATION
|
||||
: '1d';
|
||||
let signOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
expiresIn: expiresIn,
|
||||
}
|
||||
};
|
||||
|
||||
if (req.user_group_id == "1") {
|
||||
if (req.user_group_id == '1') {
|
||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_ADMIN_WEB);
|
||||
} else if (req.user_group_id == "2") {
|
||||
} else if (req.user_group_id == '2') {
|
||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_MOBILE_PHONE);
|
||||
} else if (
|
||||
req.user_group_id == "3" ||
|
||||
req.user_group_id == "4" ||
|
||||
req.user_group_id == "5"
|
||||
req.user_group_id == '3' ||
|
||||
req.user_group_id == '4' ||
|
||||
req.user_group_id == '5'
|
||||
) {
|
||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_TERMINAL);
|
||||
}
|
||||
@@ -52,43 +61,59 @@ const generateAccessToken = (req) => {
|
||||
};
|
||||
|
||||
const authenticateToken = async (req, res, next) => {
|
||||
let authHeader = req.headers["authorization"];
|
||||
let authHeader = req.headers['authorization'];
|
||||
|
||||
var ip = req.headers['x-real-ip'] || req.connection.remoteAddress;
|
||||
|
||||
console.log('INI LHO IP NYA....................: ' + ip);
|
||||
|
||||
if (authHeader) {
|
||||
let token = authHeader && authHeader.split(" ")[1];
|
||||
let token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
// winston.logger.info(
|
||||
// `000000000000 [ AUTHENTICATE TOKEN ]: ${JSON.stringify({
|
||||
// token: token,
|
||||
// ip: ip,
|
||||
// })}`
|
||||
// );
|
||||
|
||||
if (!token) {
|
||||
return res.json({
|
||||
code: "401",
|
||||
message: "Token is required",
|
||||
code: '401',
|
||||
message: 'Token is required',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
let verifyOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
}
|
||||
};
|
||||
|
||||
await jwt.verify(token, process.env.TOKEN_SECRET, verifyOptions, (err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: "402",
|
||||
message: "Invalid Token.",
|
||||
data: {},
|
||||
});
|
||||
await jwt.verify(
|
||||
token,
|
||||
process.env.TOKEN_SECRET,
|
||||
verifyOptions,
|
||||
(err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: '402',
|
||||
message: 'Invalid Token.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
req.mid_token = helper.decryptText(data.mid);
|
||||
req.tid_token = helper.decryptText(data.tid);
|
||||
req.partner_id_token = helper.decryptText(data.partner_id);
|
||||
req.partner_user_id_token = helper.decryptText(data.partner_user_id);
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
req.mid_token = helper.decryptText(data.mid);
|
||||
req.tid_token = helper.decryptText(data.tid);
|
||||
req.partner_id_token = helper.decryptText(data.partner_id);
|
||||
req.partner_user_id_token = helper.decryptText(data.partner_user_id);
|
||||
|
||||
next();
|
||||
});
|
||||
);
|
||||
} else {
|
||||
return res.json({
|
||||
code: "400",
|
||||
message: "Header not found",
|
||||
code: '400',
|
||||
message: 'Header not found',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,10 +75,14 @@ const loginPartnerUser = async (req, res, next) => {
|
||||
let { email, password } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify({
|
||||
email: email,
|
||||
})}`
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify({
|
||||
// email: email,
|
||||
// })}`
|
||||
// );
|
||||
|
||||
console.log(
|
||||
`${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
// validate
|
||||
@@ -201,9 +205,9 @@ const loginPartnerUser = async (req, res, next) => {
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ RESPONSE LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
@@ -705,11 +709,11 @@ const refreshTokenPartnerUser = async (req, res) => {
|
||||
let refresh_token = req.header('refresh_token');
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ REQUEST REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
// req.body
|
||||
// )}`
|
||||
// );
|
||||
|
||||
// validate
|
||||
let err = validationResult(req);
|
||||
@@ -837,11 +841,11 @@ const refreshTokenPartnerUser = async (req, res) => {
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ RESPONSE REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const { param, body, validationResult } = require("express-validator");
|
||||
const helper = require("../../helpers/helper");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const model = require("./cahsin.model");
|
||||
const moment = require("moment");
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const model = require('./cahsin.model');
|
||||
const moment = require('moment');
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
|
||||
moment.locale("id");
|
||||
moment.locale('id');
|
||||
|
||||
var result = {};
|
||||
var uniqueCode;
|
||||
@@ -13,14 +13,32 @@ var uniqueCode;
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case "generateInvoice":
|
||||
case 'generateInvoice':
|
||||
return [
|
||||
body('trx_date').notEmpty().withMessage('trx_date is required!').isISO8601().withMessage('invalid trx_date format YYYY-MM-DD !').escape().trim(),
|
||||
body('repost').notEmpty().withMessage('repost is required!').isBoolean().withMessage('repost must boolean!').escape().trim(),
|
||||
body('trx_date')
|
||||
.notEmpty()
|
||||
.withMessage('trx_date is required!')
|
||||
.isISO8601()
|
||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
||||
.escape()
|
||||
.trim(),
|
||||
body('repost')
|
||||
.notEmpty()
|
||||
.withMessage('repost is required!')
|
||||
.isBoolean()
|
||||
.withMessage('repost must boolean!')
|
||||
.escape()
|
||||
.trim(),
|
||||
];
|
||||
case "postingInvoice":
|
||||
case 'postingInvoice':
|
||||
return [
|
||||
body('trx_date').notEmpty().withMessage('trx_date is required!').isISO8601().withMessage('invalid trx_date format YYYY-MM-DD !').escape().trim(),
|
||||
body('trx_date')
|
||||
.notEmpty()
|
||||
.withMessage('trx_date is required!')
|
||||
.isISO8601()
|
||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
||||
.escape()
|
||||
.trim(),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
@@ -29,7 +47,6 @@ const validate = (method) => {
|
||||
|
||||
// POSTING INVOICE
|
||||
const apiGenerateCahsIn = async (req, res) => {
|
||||
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = helper.getUniqueCode();
|
||||
@@ -44,7 +61,7 @@ const apiGenerateCahsIn = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: "400",
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
@@ -57,40 +74,38 @@ const apiGenerateCahsIn = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
const cashIn = await _generateCashIn(uniqueCode)
|
||||
const cashIn = await _generateCashIn(uniqueCode);
|
||||
|
||||
result = {
|
||||
code: "200",
|
||||
message: "Succes posting",
|
||||
data: cashIn
|
||||
code: '200',
|
||||
message: 'Succes posting',
|
||||
data: cashIn,
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// RETRY POSTING INVOICE
|
||||
const apiPostingCahsIn = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = helper.getUniqueCode()
|
||||
let { body } = req
|
||||
uniqueCode = helper.getUniqueCode();
|
||||
let { body } = req;
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} REQUEST posting cash in : ${JSON.stringify(req.body)}`
|
||||
@@ -100,184 +115,248 @@ const apiPostingCahsIn = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: "400",
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE generate posting cash in : ${JSON.stringify(result)}`
|
||||
`${uniqueCode} RESPONSE generate posting cash in : ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// return uniqueCode
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RE-TRY POSTING CAHS IN`)
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RE-TRY POSTING CAHS IN`);
|
||||
|
||||
const invoice = await _postingCashIn(uniqueCode)
|
||||
const invoice = await _postingCashIn(uniqueCode);
|
||||
|
||||
result = {
|
||||
code: "200",
|
||||
message: "Succes",
|
||||
code: '200',
|
||||
message: 'Succes',
|
||||
data: invoice,
|
||||
}
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const _generateCashIn = async (uniqueCode) => {
|
||||
|
||||
let partnerRecon = await model.getPartnerRecon(knex)
|
||||
let partnerRecon = await model.getPartnerRecon(knex);
|
||||
// return partnerRecon
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(partnerRecon)}`)
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
||||
partnerRecon
|
||||
)}`
|
||||
);
|
||||
|
||||
for (const item of partnerRecon) {
|
||||
let reserve = []
|
||||
let code = ""
|
||||
await knex.transaction(async trx => {
|
||||
code = await model.generateCode(trx, item.c_partner_code, moment().format("YYMMDD"))
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`)
|
||||
let reserve = [];
|
||||
let code = '';
|
||||
await knex.transaction(async (trx) => {
|
||||
code = await model.generateCode(
|
||||
trx,
|
||||
item.c_partner_code,
|
||||
moment().format('YYMMDD')
|
||||
);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
||||
);
|
||||
|
||||
// Cash-in
|
||||
let dataCahsIn = {
|
||||
c_partner_code: item.c_partner_code,
|
||||
c_partner_name: item.c_partner_name,
|
||||
c_cash_in_no: code,
|
||||
c_in_period: item.c_in_period,
|
||||
d_credit: item.d_payment,
|
||||
c_invoice_no: item.c_invoice_no,
|
||||
i_amount: item.amount,
|
||||
};
|
||||
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
|
||||
// CASH-IN DETAIL
|
||||
let data = [];
|
||||
const reserv = await model.getReserve(
|
||||
trx,
|
||||
item.c_partner_code,
|
||||
item.d_payment,
|
||||
item.c_invoice_no
|
||||
);
|
||||
|
||||
// Insert cahs in
|
||||
const dataCahsIn = {
|
||||
c_partner_code : item.c_partner_code,
|
||||
c_partner_name : item.c_partner_name,
|
||||
c_cash_in_no : code,
|
||||
c_in_period : item.c_in_period,
|
||||
d_credit : item.d_payment,
|
||||
c_invoice_no : item.c_invoice_no,
|
||||
i_amount : item.amount
|
||||
//TOTAL AMOUNT CASH-IN
|
||||
let cashInAmount = 0;
|
||||
for (const itemCI of reserv) {
|
||||
cashInAmount += parseInt(itemCI.i_reservation_amount);
|
||||
}
|
||||
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
||||
const cashIn = await model.insertCashIn(trx, dataCahsIn)
|
||||
dataCahsIn.i_amount = cashInAmount;
|
||||
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
||||
const paymentyHistory = await model.writePaynentHistory(dataCahsIn, "SUCCESSFULLY", 0, trx)
|
||||
//INSERT CASH-IN
|
||||
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
const paymentyHistory = await model.writePaynentHistory(
|
||||
dataCahsIn,
|
||||
'SUCCESSFULLY',
|
||||
0,
|
||||
trx
|
||||
);
|
||||
|
||||
// Insert cahs in detail
|
||||
let data = []
|
||||
const reserv = await model.getReserve(trx, item.c_partner_code, item.d_payment, item.c_invoice_no)
|
||||
for (const detail of reserv) {
|
||||
data.push({
|
||||
i_cash_in : cashIn.i_cash_in,
|
||||
c_reservation_no : detail.c_reservation_no,
|
||||
m_amount : detail.i_reservation_amount,
|
||||
c_payment_recon_no : detail.c_payment_recon_no,
|
||||
d_payment : detail.d_payment,
|
||||
d_payment_recon : detail.d_payment_recon,
|
||||
c_load_balance_no : detail.c_load_balance_no
|
||||
})
|
||||
|
||||
let reserveNo = detail.c_reservation_no
|
||||
|
||||
// data.push({
|
||||
// i_cash_in: cashIn.i_cash_in,
|
||||
// c_reservation_no: detail.c_reservation_no,
|
||||
// m_amount: detail.i_reservation_amount,
|
||||
// c_payment_recon_no: detail.c_payment_recon_no,
|
||||
// d_payment: detail.d_payment,
|
||||
// d_payment_recon: detail.d_payment_recon,
|
||||
// c_load_balance_no: detail.c_load_balance_no,
|
||||
// });
|
||||
let temp = {
|
||||
i_cash_in: cashIn.i_cash_in,
|
||||
c_reservation_no: detail.c_reservation_no,
|
||||
m_amount: detail.i_reservation_amount,
|
||||
c_payment_recon_no: detail.c_payment_recon_no,
|
||||
d_payment: detail.d_payment,
|
||||
d_payment_recon: detail.d_payment_recon,
|
||||
c_load_balance_no: detail.c_load_balance_no,
|
||||
};
|
||||
|
||||
let reserveNo = detail.c_reservation_no;
|
||||
let dataReserve = {
|
||||
c_cash_in_no : cashIn.c_cash_in_no,
|
||||
d_credit : cashIn.d_credit,
|
||||
c_in_period : cashIn.c_in_period,
|
||||
}
|
||||
c_cash_in_no: cashIn.c_cash_in_no,
|
||||
d_credit: cashIn.d_credit,
|
||||
c_in_period: cashIn.c_in_period,
|
||||
};
|
||||
|
||||
await model.updateIntoReserve(trx, dataReserve, reserveNo)
|
||||
|
||||
await model.updateIntoReserve(trx, dataReserve, reserveNo);
|
||||
await model.insertCashInDetail(trx, temp);
|
||||
}
|
||||
await wait(5000)
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
||||
await model.insertCashInDetail(trx, data)
|
||||
// await model.insertPostingEt(code, item, trx)
|
||||
|
||||
})
|
||||
await wait(5000);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
// await model.insertCashInDetail(trx, data);
|
||||
// await model.insertPostingEt(code, item, trx)
|
||||
});
|
||||
}
|
||||
|
||||
return partnerRecon
|
||||
|
||||
}
|
||||
return partnerRecon;
|
||||
};
|
||||
|
||||
const _postingCashIn = async (uniqueCode) => {
|
||||
let data = []
|
||||
let postingEt = await model.getPostingEt(knex)
|
||||
let data = [];
|
||||
let postingEt = await model.getPostingEt(knex);
|
||||
|
||||
for (const item of postingEt) {
|
||||
await knex.transaction(async trx => {
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`)
|
||||
|
||||
let xmlHeader = {
|
||||
doc_header_text : item.doc_header_text ? item.doc_header_text : "",
|
||||
ba: item.ba ? item.ba : "",
|
||||
doc_date : item.doc_date ? item.doc_date : "",
|
||||
posting_date : item.posting_date ? item.posting_date : "",
|
||||
fisc_year : item.fiscal_year ? item.fiscal_year : "",
|
||||
fisc_period : item.fis_period ? item.fis_period: "",
|
||||
doc_type: item.doc_type ? item.doc_type : "",
|
||||
c_invoice_no : item.reference ? item.reference : ""
|
||||
}
|
||||
await knex.transaction(async (trx) => {
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`
|
||||
);
|
||||
|
||||
let xmlItem = ['S', 'H'].map(key => {
|
||||
let xmlHeader = {
|
||||
doc_header_text: item.doc_header_text ? item.doc_header_text : '',
|
||||
ba: item.ba ? item.ba : '',
|
||||
doc_date: item.doc_date ? item.doc_date : '',
|
||||
posting_date: item.posting_date ? item.posting_date : '',
|
||||
fisc_year: item.fiscal_year ? item.fiscal_year : '',
|
||||
fisc_period: item.fis_period ? item.fis_period : '',
|
||||
doc_type: item.doc_type ? item.doc_type : '',
|
||||
c_invoice_no: item.reference ? item.reference : '',
|
||||
};
|
||||
|
||||
let xmlItem = ['S', 'H'].map((key) => {
|
||||
return {
|
||||
c_account_code_topup : key == 'S' ? item.customer : "",
|
||||
c_account_topup : key == 'H' ? item.account : "",
|
||||
ba : item.ba,
|
||||
amount : item.amount,
|
||||
posting_date : item.posting_date,
|
||||
c_invoice_no : item.reference,
|
||||
item_text :key == 'S' ? item.text1 : item.text2,
|
||||
de_cre : key
|
||||
}
|
||||
c_account_code_topup: key == 'S' ? item.customer : '',
|
||||
c_account_topup: key == 'H' ? item.account : '',
|
||||
ba: item.ba,
|
||||
amount: item.amount,
|
||||
posting_date: item.posting_date,
|
||||
c_invoice_no: item.reference,
|
||||
item_text: key == 'S' ? item.text1 : item.text2,
|
||||
de_cre: key,
|
||||
};
|
||||
});
|
||||
|
||||
let xmlRequest = helper.generateXMLRequest('ZFMCMS_FI_001', xmlHeader, xmlItem)
|
||||
console.log(xmlRequest)
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${item.reference} to SAP : ${xmlRequest}`);
|
||||
|
||||
const url = 'http://piqas.kereta-api.co.id:51500/XISOAPAdapter/MessageServlet?senderParty=&senderService=KCI_ETICKETING_2&receiverParty=&receiverService=&interface=SI_KCI_CMS_FI01&interfaceNamespace=urn:Posting_ETicketing_2'
|
||||
let xmlRequest = helper.generateXMLRequest(
|
||||
'ZFMCMS_FI_001',
|
||||
xmlHeader,
|
||||
xmlItem
|
||||
);
|
||||
console.log(xmlRequest);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${item.reference} to SAP : ${xmlRequest}`
|
||||
);
|
||||
|
||||
const response = await helper.postingSAP(url, xmlRequest)
|
||||
const url =
|
||||
'http://piqas.kereta-api.co.id:51500/XISOAPAdapter/MessageServlet?senderParty=&senderService=KCI_ETICKETING_2&receiverParty=&receiverService=&interface=SI_KCI_CMS_FI01&interfaceNamespace=urn:Posting_ETicketing_2';
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${item.reference} to SAP : ${JSON.stringify(response)}`);
|
||||
const response = await helper.postingSAP(url, xmlRequest);
|
||||
|
||||
const resSAP = helper.getXMLData(response)
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${
|
||||
item.reference
|
||||
} to SAP : ${JSON.stringify(response)}`
|
||||
);
|
||||
|
||||
const resSAP = helper.getXMLData(response);
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} TRANSACTION 2`);
|
||||
// UPDATE CMS
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(resSAP)}`)
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(
|
||||
resSAP
|
||||
)}`
|
||||
);
|
||||
|
||||
const cms = await model.setReturnSAP(item.no_dok, resSAP, trx)
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`)
|
||||
const cms = await model.setReturnSAP(item.no_dok, resSAP, trx);
|
||||
|
||||
})
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return postingEt
|
||||
|
||||
}
|
||||
return postingEt;
|
||||
};
|
||||
|
||||
function wait(milliseconds) {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
apiGenerateCahsIn,
|
||||
apiPostingCahsIn,
|
||||
_postingCashIn,
|
||||
_generateCashIn
|
||||
};
|
||||
_generateCashIn,
|
||||
};
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
|
||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||
const generateInvoice = async (invoiceDate, repost, trx) => {
|
||||
let result = await trx.select(
|
||||
trx.raw(
|
||||
`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`
|
||||
)
|
||||
);
|
||||
|
||||
let result = await trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`))
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const insertPostingEt = async (code, dataCashIn, trx) => {
|
||||
let type = ['S', 'H']
|
||||
let et = []
|
||||
let posting_et = []
|
||||
let type = ['S', 'H'];
|
||||
let et = [];
|
||||
let posting_et = [];
|
||||
type.forEach((item, index) => {
|
||||
let data = {
|
||||
file_name: code,
|
||||
@@ -25,137 +26,193 @@ const insertPostingEt = async (code, dataCashIn, trx) => {
|
||||
reference: code,
|
||||
amount: dataCashIn.amount,
|
||||
ba: dataCashIn.ba,
|
||||
indeks: (index+1),
|
||||
indeks: index + 1,
|
||||
totalidx: type.length,
|
||||
doc_header_text: code,
|
||||
pos_status : 4
|
||||
}
|
||||
|
||||
if(item == 'H'){
|
||||
data = {...data, ...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: dataCashIn.c_account_topup,
|
||||
customer: null
|
||||
}}
|
||||
}else{
|
||||
data = {...data, ...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: null,
|
||||
customer: dataCashIn.c_account_code_topup
|
||||
}}
|
||||
pos_status: 4,
|
||||
};
|
||||
|
||||
if (item == 'H') {
|
||||
data = {
|
||||
...data,
|
||||
...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: dataCashIn.c_account_topup,
|
||||
customer: null,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
...data,
|
||||
...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: null,
|
||||
customer: dataCashIn.c_account_code_topup,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
et.push(data)
|
||||
et.push(data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit'])
|
||||
|
||||
return posting_et[0]
|
||||
|
||||
}
|
||||
|
||||
const getPostingEt = async(trx) => {
|
||||
|
||||
const result = await trx('public.posting_et AS pe').select([
|
||||
'doc_header_text',
|
||||
posting_et = await trx('public.posting_et').insert(et, [
|
||||
'indeks',
|
||||
'customer',
|
||||
'account',
|
||||
'ba',
|
||||
'doc_date',
|
||||
'posting_date',
|
||||
'fiscal_year',
|
||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
||||
'doc_type',
|
||||
'reference',
|
||||
'no_dok',
|
||||
'tcode',
|
||||
'amount',
|
||||
trx.raw(`'IDR' AS currency`),
|
||||
trx.raw(`(SELECT customer FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as customer`),
|
||||
trx.raw(`(SELECT account FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as account `),
|
||||
trx.raw(`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as text1`),
|
||||
trx.raw(`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as text2`)
|
||||
])
|
||||
.where('tcode', '=', "FB70")
|
||||
// .where('reference', '=', reference)
|
||||
.whereIn('pos_status', ["4"])
|
||||
'no_dok',
|
||||
'text',
|
||||
'debit_kredit',
|
||||
]);
|
||||
|
||||
.groupBy(['doc_header_text', 'ba', 'doc_header_text', 'tcode', 'ba', 'amount', 'posting_date', 'doc_date', 'doc_type', 'fiscal_year', 'reference', 'no_dok'])
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
return posting_et[0];
|
||||
};
|
||||
|
||||
const setReturnSAP = async (code, resSAP, trx) => {
|
||||
let t_cash_in = []
|
||||
let reserveBalance = []
|
||||
const getPostingEt = async (trx) => {
|
||||
const result = await trx('public.posting_et AS pe')
|
||||
.select([
|
||||
'doc_header_text',
|
||||
'ba',
|
||||
'doc_date',
|
||||
'posting_date',
|
||||
'fiscal_year',
|
||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
||||
'doc_type',
|
||||
'reference',
|
||||
'no_dok',
|
||||
'tcode',
|
||||
'amount',
|
||||
trx.raw(`'IDR' AS currency`),
|
||||
trx.raw(
|
||||
`(SELECT customer FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as customer`
|
||||
),
|
||||
trx.raw(
|
||||
`(SELECT account FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as account `
|
||||
),
|
||||
trx.raw(
|
||||
`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as text1`
|
||||
),
|
||||
trx.raw(
|
||||
`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as text2`
|
||||
),
|
||||
])
|
||||
.where('tcode', '=', 'FB70')
|
||||
// .where('reference', '=', reference)
|
||||
.whereIn('pos_status', ['4'])
|
||||
|
||||
if(resSAP.type == 'S'){
|
||||
.groupBy([
|
||||
'doc_header_text',
|
||||
'ba',
|
||||
'doc_header_text',
|
||||
'tcode',
|
||||
'ba',
|
||||
'amount',
|
||||
'posting_date',
|
||||
'doc_date',
|
||||
'doc_type',
|
||||
'fiscal_year',
|
||||
'reference',
|
||||
'no_dok',
|
||||
]);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const setReturnSAP = async (code, resSAP, trx) => {
|
||||
let t_cash_in = [];
|
||||
let reserveBalance = [];
|
||||
|
||||
if (resSAP.type == 'S') {
|
||||
// update invoice
|
||||
t_cash_in = await trx('payment.t_d_cash_in').update({
|
||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_return_year_sap: resSAP.data.E_DOCUMENTYEAR
|
||||
}, ['c_cash_in_no','c_return_sap'])
|
||||
.where({
|
||||
c_cash_in_no: code
|
||||
});
|
||||
|
||||
// update load balance
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance').update({
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code
|
||||
}, ['c_cash_in_no', 'c_return_sap'])
|
||||
.whereRaw(`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`)
|
||||
t_cash_in = await trx('payment.t_d_cash_in')
|
||||
.update(
|
||||
{
|
||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_return_year_sap: resSAP.data.E_DOCUMENTYEAR,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.where({
|
||||
c_cash_in_no: code,
|
||||
});
|
||||
|
||||
}else {
|
||||
// update load balance
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance')
|
||||
.update(
|
||||
{
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.whereRaw(
|
||||
`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`
|
||||
);
|
||||
} else {
|
||||
let text = resSAP.message;
|
||||
let result = text.toUpperCase();
|
||||
if(result.includes("ALREADY")){
|
||||
if (result.includes('ALREADY')) {
|
||||
let result = text.toUpperCase().split('-');
|
||||
let doc_number = result[1].trim().split(" ")[0]
|
||||
let doc_number = result[1].trim().split(' ')[0];
|
||||
// update invoice
|
||||
const d = new Date();
|
||||
let year = d.getFullYear();
|
||||
t_cash_in = await trx('payment.t_d_cash_in').update({
|
||||
c_return_sap: doc_number,
|
||||
c_return_year_sap: year
|
||||
}, ['c_cash_in_no','c_return_sap'])
|
||||
.where({
|
||||
c_cash_in_no: code
|
||||
});
|
||||
t_cash_in = await trx('payment.t_d_cash_in')
|
||||
.update(
|
||||
{
|
||||
c_return_sap: doc_number,
|
||||
c_return_year_sap: year,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.where({
|
||||
c_cash_in_no: code,
|
||||
});
|
||||
|
||||
// update load balance
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance').update({
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code
|
||||
}, ['c_cash_in_no', 'c_return_sap'])
|
||||
.whereRaw(`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`)
|
||||
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance')
|
||||
.update(
|
||||
{
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.whereRaw(
|
||||
`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update posting et
|
||||
const posting_et = await trx('public.posting_et').update({
|
||||
pos_status : resSAP.type == 'S' ? 0 : 4,
|
||||
status0 : resSAP.type,
|
||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
||||
status1 : resSAP.message ? resSAP.message : null
|
||||
}, ['file_name','status0']).where({
|
||||
no_dok: code
|
||||
})
|
||||
const posting_et = await trx('public.posting_et')
|
||||
.update(
|
||||
{
|
||||
pos_status: resSAP.type == 'S' ? 0 : 4,
|
||||
status0: resSAP.type,
|
||||
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||
? resSAP.data.E_DOCUMENTNUMBER
|
||||
: null,
|
||||
status1: resSAP.message ? resSAP.message : null,
|
||||
},
|
||||
['file_name', 'status0']
|
||||
)
|
||||
.where({
|
||||
no_dok: code,
|
||||
});
|
||||
|
||||
return {
|
||||
cash_in : t_cash_in[0],
|
||||
reserveBalance : reserveBalance[0],
|
||||
posting_et : posting_et[0]
|
||||
}
|
||||
|
||||
}
|
||||
cash_in: t_cash_in[0],
|
||||
reserveBalance: reserveBalance[0],
|
||||
posting_et: posting_et[0],
|
||||
};
|
||||
};
|
||||
|
||||
const getRecon = async (trx) => {
|
||||
|
||||
let sql = `SELECT
|
||||
tdi.c_invoice_no,
|
||||
'FB70' AS tcode,
|
||||
@@ -200,160 +257,249 @@ const getRecon = async (trx) => {
|
||||
SELECT c_reservation_no FROM payment.t_d_payment_recon tdpr WHERE tdpr.c_status = 'S'
|
||||
)
|
||||
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, tdpr.d_payment, b_past_month
|
||||
ORDER BY tdpr.d_payment`
|
||||
let result = await trx.raw(sql)
|
||||
ORDER BY tdpr.d_payment`;
|
||||
let result = await trx.raw(sql);
|
||||
|
||||
return result.rows
|
||||
}
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
const getReserve = async(trx, code, date, invoice) => {
|
||||
const getReserve = async (trx, code, date, invoice) => {
|
||||
const res = await trx
|
||||
.select([
|
||||
'tdrb.c_reservation_no',
|
||||
'tdrb.i_reservation_amount',
|
||||
'tdpr.c_payment_recon_no',
|
||||
'tdpr.d_payment',
|
||||
'tdpr.d_payment_recon',
|
||||
'tdrb.c_partner_code',
|
||||
'tdrb.c_partner_name',
|
||||
'tdrb.c_load_balance_no',
|
||||
'tdi.c_invoice_no',
|
||||
])
|
||||
.from('trx.t_d_reservation_balance AS tdrb')
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||
'tdi.c_invoice_no',
|
||||
'=',
|
||||
'tdrb.c_invoice_no'
|
||||
);
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
})
|
||||
.where('tdrb.c_status', '=', 'A')
|
||||
.where('tdi.c_status', '!=', 'X')
|
||||
.where('tdrb.c_partner_code', '=', code)
|
||||
.where('tdpr.d_payment', '=', date)
|
||||
.where('tdi.c_invoice_no', '=', invoice)
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdi.c_return_sap')
|
||||
.whereNotNull('tdrb.c_load_balance_no')
|
||||
.whereRaw(
|
||||
`tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
);
|
||||
return res;
|
||||
};
|
||||
|
||||
const res = await trx.select([
|
||||
"tdrb.c_reservation_no",
|
||||
"tdrb.i_reservation_amount",
|
||||
"tdpr.c_payment_recon_no",
|
||||
"tdpr.d_payment",
|
||||
"tdpr.d_payment_recon",
|
||||
"tdrb.c_partner_code",
|
||||
"tdrb.c_partner_name",
|
||||
"tdrb.c_load_balance_no",
|
||||
"tdi.c_invoice_no"
|
||||
])
|
||||
.from("trx.t_d_reservation_balance AS tdrb")
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no')
|
||||
.orOn('tdi.c_invoice_no', '=', 'tdrb.c_invoice_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
|
||||
})
|
||||
.where("tdrb.c_status", "=", "A")
|
||||
.where("tdi.c_status", "!=", "X")
|
||||
.where("tdrb.c_partner_code", "=", code)
|
||||
.where("tdpr.d_payment", "=", date)
|
||||
.where("tdi.c_invoice_no", "=", invoice)
|
||||
.where("tdpr.c_status", "=", "S")
|
||||
.whereNotNull("tdi.c_return_sap")
|
||||
.whereNotNull("tdrb.c_load_balance_no")
|
||||
.whereRaw(`tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`)
|
||||
return res
|
||||
}
|
||||
const getPartnerRecon = async (trx) => {
|
||||
// const res = await trx
|
||||
// .select([
|
||||
// 'tdpr.c_partner_code',
|
||||
// 'tdrb.c_partner_name',
|
||||
// 'tdi.c_invoice_no',
|
||||
// 'tdi.d_invoice_date',
|
||||
// trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
// trx.raw('SUM(tdrb.i_reservation_amount) AS amount'),
|
||||
// 'tmp.c_account_topup',
|
||||
// 'tmp.c_account_code_topup',
|
||||
// 'i_company',
|
||||
// 'i_holding',
|
||||
// trx.raw(`CASE
|
||||
// WHEN to_char(tdpr.d_payment, 'MM') >= to_char(tdi.d_invoice_date, 'MM')
|
||||
// THEN 'IP'
|
||||
// ELSE
|
||||
// 'OP'
|
||||
// END c_in_period`),
|
||||
// ])
|
||||
// .from('trx.t_d_reservation_balance AS tdrb')
|
||||
// .leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
// this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||
// })
|
||||
// .leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
// this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||
// 'tdi.c_invoice_no',
|
||||
// '=',
|
||||
// 'tdrb.c_invoice_no'
|
||||
// );
|
||||
// })
|
||||
// .leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
// this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
// })
|
||||
// .leftJoin('public.t_m_partner as tmp', function () {
|
||||
// this.on('tmp.i_partner', '=', 'tdrb.i_partner');
|
||||
// })
|
||||
|
||||
const getPartnerRecon = async(trx) => {
|
||||
// .where('tdrb.c_status', '=', 'A')
|
||||
// .where('tdi.c_status', '!=', 'X')
|
||||
// .where('tdpr.c_status', '=', 'S')
|
||||
// .whereNotNull('tdi.c_return_sap')
|
||||
// .whereNotNull('tdrb.c_load_balance_no')
|
||||
// .whereRaw(
|
||||
// `tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
// )
|
||||
// .groupBy([
|
||||
// 'tdpr.c_partner_code',
|
||||
// 'tdrb.c_partner_name',
|
||||
// 'tdi.c_invoice_no',
|
||||
// 'tdi.d_invoice_date',
|
||||
// 'tdpr.d_payment',
|
||||
// 'tmp.c_account_topup',
|
||||
// 'tmp.c_account_code_topup',
|
||||
// 'tdi.i_company',
|
||||
// 'i_holding',
|
||||
// ])
|
||||
// .limit(1);
|
||||
// .toSql()
|
||||
|
||||
const res = await trx.select([
|
||||
"tdpr.c_partner_code",
|
||||
"tdrb.c_partner_name",
|
||||
"tdi.c_invoice_no",
|
||||
"tdi.d_invoice_date",
|
||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
trx.raw("SUM(tdrb.i_reservation_amount) AS amount"),
|
||||
"tmp.c_account_topup",
|
||||
"tmp.c_account_code_topup",
|
||||
"i_company",
|
||||
"i_holding",
|
||||
trx.raw(`CASE
|
||||
WHEN to_char(tdpr.d_payment, 'MM') = to_char(tdi.d_invoice_date, 'MM')
|
||||
const res = await trx
|
||||
.select([
|
||||
'tdpr.c_partner_code',
|
||||
'tdrb.c_partner_name',
|
||||
'tdi.c_invoice_no',
|
||||
'tdi.d_invoice_date',
|
||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
trx.raw('coalesce(SUM(tdrb.i_reservation_amount),0) AS amount'),
|
||||
// trx.raw('coalesce(SUM(tdcid.m_amount),0) AS amount_cash_in'),
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup',
|
||||
'i_company',
|
||||
'i_holding',
|
||||
trx.raw(`CASE
|
||||
WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdi.d_invoice_date, 'YYYYMM')
|
||||
THEN 'IP'
|
||||
ELSE
|
||||
'OP'
|
||||
END c_in_period`),
|
||||
])
|
||||
.from("trx.t_d_reservation_balance AS tdrb")
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this
|
||||
.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no')
|
||||
.orOn('tdi.c_invoice_no', '=', 'tdrb.c_invoice_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
|
||||
})
|
||||
.leftJoin('public.t_m_partner as tmp', function () {
|
||||
this.on('tmp.i_partner', '=', 'tdrb.i_partner')
|
||||
})
|
||||
|
||||
.where("tdrb.c_status", "=", "A")
|
||||
.where("tdi.c_status", "!=", "X")
|
||||
.where("tdpr.c_status", "=", "S")
|
||||
.whereNotNull("tdi.c_return_sap")
|
||||
.whereNotNull("tdrb.c_load_balance_no")
|
||||
.whereRaw(`tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`)
|
||||
.groupBy(["tdpr.c_partner_code","tdrb.c_partner_name","tdi.c_invoice_no","tdi.d_invoice_date", "tdpr.d_payment", "tmp.c_account_topup", "tmp.c_account_code_topup", "tdi.i_company", "i_holding"])
|
||||
// .toSql()
|
||||
])
|
||||
.from('trx.t_d_reservation_balance AS tdrb')
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||
'tdi.c_invoice_no',
|
||||
'=',
|
||||
'tdrb.c_invoice_no'
|
||||
);
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
})
|
||||
.leftJoin('public.t_m_partner as tmp', function () {
|
||||
this.on('tmp.i_partner', '=', 'tdrb.i_partner');
|
||||
})
|
||||
// .leftJoin('payment.t_d_cash_in_detail as tdcid', function () {
|
||||
// this.on('tdcid.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
// })
|
||||
|
||||
return res
|
||||
.where('tdrb.c_status', '=', 'A')
|
||||
.where('tdi.c_status', '!=', 'X')
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdi.c_return_sap')
|
||||
.whereNotNull('tdrb.c_load_balance_no')
|
||||
.whereNull('tdrb.c_cash_in_no')
|
||||
.groupBy([
|
||||
'tdpr.c_partner_code',
|
||||
'tdrb.c_partner_name',
|
||||
'tdi.c_invoice_no',
|
||||
'tdi.d_invoice_date',
|
||||
'tdpr.d_payment',
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup',
|
||||
'tdi.i_company',
|
||||
'i_holding',
|
||||
]);
|
||||
// .havingRaw(
|
||||
// 'coalesce(SUM(tdrb.i_reservation_amount),0) > coalesce(SUM(tdcid.m_amount),0)'
|
||||
// );
|
||||
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
const generateCode = async (trx, c_partner_code, d_payment_recon) => {
|
||||
let code = ""
|
||||
let prefix = `CIN${c_partner_code}${d_payment_recon}`
|
||||
let code = '';
|
||||
let prefix = `CIN${c_partner_code}${d_payment_recon}`;
|
||||
|
||||
let result =await trx.select([trx.raw(`substring(c_cash_in_no, 13, 3) AS code`)])
|
||||
.from("payment.t_d_cash_in")
|
||||
.whereRaw(`substring(c_cash_in_no, 1, 12) = '${prefix}'`)
|
||||
// .where("d_project_date", projectDate)
|
||||
.orderBy('c_cash_in_no', 'DESC')
|
||||
.first()
|
||||
let result = await trx
|
||||
.select([trx.raw(`substring(c_cash_in_no, 13, 3) AS code`)])
|
||||
.from('payment.t_d_cash_in')
|
||||
.whereRaw(`substring(c_cash_in_no, 1, 12) = '${prefix}'`)
|
||||
// .where("d_project_date", projectDate)
|
||||
.orderBy('c_cash_in_no', 'DESC')
|
||||
.first();
|
||||
|
||||
if(result){
|
||||
let counter = parseInt(result.code)+1
|
||||
if (result) {
|
||||
let counter = parseInt(result.code) + 1;
|
||||
counter = String(counter).padStart(3, '0');
|
||||
code = `${prefix}${counter}`
|
||||
|
||||
}else{
|
||||
code = `${prefix}001`
|
||||
code = `${prefix}${counter}`;
|
||||
} else {
|
||||
code = `${prefix}001`;
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
const insertCashInDetail = async (trx, data) => {
|
||||
let result = []
|
||||
if(data.length > 0){
|
||||
result = await trx('payment.t_d_cash_in_detail').insert(data,["*"])
|
||||
let result = [];
|
||||
// if (data.length > 0) {
|
||||
// result = await trx('payment.t_d_cash_in_detail').insert(data, ['*']);
|
||||
// }
|
||||
|
||||
if (data) {
|
||||
result = await trx('payment.t_d_cash_in_detail').insert(data, ['*']);
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const updateIntoReserve = async (trx, dataReserve, reserveNo) => {
|
||||
let result = await trx('trx.t_d_reservation_balance').update(dataReserve, ["*"]).where({c_reservation_no: reserveNo})
|
||||
return result
|
||||
}
|
||||
let result = await trx('trx.t_d_reservation_balance')
|
||||
.update(dataReserve, ['*'])
|
||||
.where({ c_reservation_no: reserveNo });
|
||||
return result;
|
||||
};
|
||||
|
||||
const insertCashIn = async (trx, data) => {
|
||||
let result = await trx('payment.t_d_cash_in').insert(data,["*"])
|
||||
return result[0]
|
||||
}
|
||||
let result = await trx('payment.t_d_cash_in').insert(data, ['*']);
|
||||
return result[0];
|
||||
};
|
||||
|
||||
const writePaynentHistory = async (data, message, i_log_name, trx) => {
|
||||
console.log(data)
|
||||
const result = await trx('log.t_log_invoice').insert({
|
||||
// i_log_name : 102,
|
||||
i_log_name : 119,
|
||||
d_log : trx.raw('NOW()'),
|
||||
c_invoice_no : data.c_cash_in_no,
|
||||
c_partner_name : data.c_partner_name,
|
||||
j_new_data : JSON.stringify(data),
|
||||
d_payment_date: trx.raw('NOW()'),
|
||||
c_note : message,
|
||||
c_status : 'S',
|
||||
d_created : trx.raw('NOW()'),
|
||||
m_amount : data.amount,
|
||||
m_mdr_amount : 0,
|
||||
m_mdr_net : data.amount
|
||||
|
||||
}, ['i_log_name', 'c_note'])
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
console.log(data);
|
||||
const result = await trx('log.t_log_invoice').insert(
|
||||
{
|
||||
// i_log_name : 102,
|
||||
i_log_name: 119,
|
||||
d_log: trx.raw('NOW()'),
|
||||
c_invoice_no: data.c_cash_in_no,
|
||||
c_partner_name: data.c_partner_name,
|
||||
j_new_data: JSON.stringify(data),
|
||||
d_payment_date: trx.raw('NOW()'),
|
||||
c_note: message,
|
||||
c_status: 'S',
|
||||
d_created: trx.raw('NOW()'),
|
||||
m_amount: data.amount,
|
||||
m_mdr_amount: 0,
|
||||
m_mdr_net: data.amount,
|
||||
},
|
||||
['i_log_name', 'c_note']
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
generateInvoice,
|
||||
@@ -368,5 +514,5 @@ module.exports = {
|
||||
getReserve,
|
||||
getPartnerRecon,
|
||||
insertCashIn,
|
||||
updateIntoReserve
|
||||
};
|
||||
updateIntoReserve,
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { default: axios } = require('axios');
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
@@ -33,6 +34,7 @@ const controller = async (req, res) => {
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
uniqueCode = uniqueCode + '' + counterDirect;
|
||||
let result = {};
|
||||
let usingHSMNumber = 1;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
@@ -43,12 +45,14 @@ const controller = async (req, res) => {
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
usingHSMNumber = 1;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 1 ==================================}`
|
||||
);
|
||||
useClient = client;
|
||||
} else {
|
||||
usingHSMNumber = 2;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== USING HSM SERVER 2 ==================================}`
|
||||
@@ -57,12 +61,14 @@ const controller = async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
usingHSMNumber = 2;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 2 ==================================}`
|
||||
);
|
||||
useClient = client2;
|
||||
} else {
|
||||
usingHSMNumber = 1;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== USING HSM SERVER 1 ==================================}`
|
||||
@@ -137,20 +143,34 @@ const controller = async (req, res) => {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
// if (_timeOut) {
|
||||
// result = {
|
||||
// code: "5001",
|
||||
// message: "Timeout",
|
||||
// data: {},
|
||||
// };
|
||||
if (_timeOut) {
|
||||
let url = `http://${process.env.IP_HSM_SERVER_1}/feliqserver/v1/api/hsm/refresh`;
|
||||
if (usingHSMNumber == 2) {
|
||||
url = `http://${process.env.IP_HSM_SERVER_2}/feliqserver/v1/api/hsm/refresh`;
|
||||
}
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} response HSM - auth1v2: ${JSON.stringify(result)}`
|
||||
// );
|
||||
let response = await axios({
|
||||
url: url,
|
||||
method: 'get',
|
||||
});
|
||||
|
||||
// return res.status(200).send(result);
|
||||
// }
|
||||
result = {
|
||||
code: '5001',
|
||||
message: 'Timeout',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-1 ]: ${JSON.stringify(
|
||||
result
|
||||
)} and refresh HSM ${usingHSMNumber} response status: ${
|
||||
response.status
|
||||
} | response text: ${response.statusText}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
|
||||
@@ -530,6 +530,16 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// get parameter setting pengecekkan nomor kartu dengan card product di CMS
|
||||
let getCheckByCardProductStatusValue =
|
||||
await model.getCheckByCardProductStatusValue();
|
||||
@@ -659,7 +669,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST updateFraudToReserve ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -795,7 +805,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST getReservationPending ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -826,7 +836,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST totalReservation ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -1251,6 +1261,16 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation status...`
|
||||
@@ -1474,18 +1494,18 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
|
||||
if (loadBalanceNumber != 'XX') {
|
||||
// set sequence to redis
|
||||
// await setLoadBalanceNumberSequence(
|
||||
// req.partner_id_token,
|
||||
// loadBalanceNoSequence
|
||||
// );
|
||||
}
|
||||
// if (loadBalanceNumber != 'XX') {
|
||||
// set sequence to redis
|
||||
// await setLoadBalanceNumberSequence(
|
||||
// req.partner_id_token,
|
||||
// loadBalanceNoSequence
|
||||
// );
|
||||
// }
|
||||
|
||||
// log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number is ${loadBalanceNumber}.`
|
||||
// );
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
|
||||
if (maxLoop > maxLoopParameter) {
|
||||
// create log
|
||||
@@ -1761,6 +1781,16 @@ const loadingBalanceUpdate = async (param) => {
|
||||
return result;
|
||||
}
|
||||
|
||||
// if (getPartner.i_partner != req.partner_id_token) {
|
||||
// result = {
|
||||
// code: '412',
|
||||
// message: 'partner is not match',
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
|
||||
let data = {
|
||||
d_load_balance: now,
|
||||
c_ref_no: ref_no,
|
||||
|
||||
@@ -111,10 +111,17 @@ const checkReservation = async (req, res) => {
|
||||
let { mid, tid, card_number } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ REQUEST RESERVATION-CHECK ]: ${JSON.stringify(req.body)}`
|
||||
// );
|
||||
|
||||
console.log(
|
||||
`${uniqueCode} [ REQUEST RESERVATION-CHECK ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -125,11 +132,11 @@ const checkReservation = async (req, res) => {
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
@@ -153,11 +160,11 @@ const checkReservation = async (req, res) => {
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
@@ -171,11 +178,11 @@ const checkReservation = async (req, res) => {
|
||||
data: {},
|
||||
};
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
@@ -196,11 +203,21 @@ const checkReservation = async (req, res) => {
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
@@ -236,7 +253,11 @@ const checkReservation = async (req, res) => {
|
||||
}
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
console.log(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
@@ -280,6 +301,9 @@ const reservationValidate = async (req, res) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -380,6 +404,16 @@ const reservationValidate = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -617,16 +651,22 @@ const reservationValidate = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (!getIssuer) {
|
||||
@@ -694,6 +734,9 @@ const reservationValidateV2 = async (req, res) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
// card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -794,6 +837,16 @@ const reservationValidateV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -1046,16 +1099,22 @@ const reservationValidateV2 = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1159,6 +1218,9 @@ const reservation = async (req, res) => {
|
||||
`${uniqueCode} [ REQUEST RESERVATION ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -1249,6 +1311,16 @@ const reservation = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -1497,16 +1569,22 @@ const reservation = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1803,6 +1881,9 @@ const reservationV2 = async (req, res) => {
|
||||
`${uniqueCode} [ REQUEST RESERVATION-V2 ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
// card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -2031,6 +2112,16 @@ const reservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -2298,16 +2389,22 @@ const reservationV2 = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2665,6 +2762,16 @@ const cancelReservationValidate = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -2850,6 +2957,16 @@ const cancelReservation = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -3326,6 +3443,16 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let getReservationCanBeCanceled;
|
||||
|
||||
// jika cancelation reservation dilakukan dengan menggunakan ref no
|
||||
@@ -3744,6 +3871,16 @@ const cancelReservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -3990,6 +4127,16 @@ const cancelReservationV2_1 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -4218,6 +4365,8 @@ const getFeeSharing = async (req, res) => {
|
||||
// datetime
|
||||
if (!datetime) {
|
||||
datetime = moment().format('YYYY-MM-DD');
|
||||
} else {
|
||||
datetime = moment(datetime).format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
// log debug
|
||||
@@ -4245,6 +4394,16 @@ const getFeeSharing = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// set default issuer fee
|
||||
let issuerFee = 0;
|
||||
let channelFee = 0;
|
||||
@@ -4253,16 +4412,22 @@ const getFeeSharing = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, datetime);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (datetime >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4293,6 +4458,51 @@ const getFeeSharing = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const decrpytRequest = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
let { reservation_data } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST DECRYPT ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
reservationData = helper.decryptText(reservation_data);
|
||||
// parsing data to json format
|
||||
parseData = JSON.parse(reservationData);
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'decrypted successfully.',
|
||||
data: parseData,
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE DECRYPT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
result = {
|
||||
code: '500',
|
||||
message: 'decrypted failed.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.error(
|
||||
`${uniqueCode} [ RESPONSE DECRYPT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
checkReservation,
|
||||
@@ -4309,4 +4519,5 @@ module.exports = {
|
||||
cancelReservationV2,
|
||||
cancelReservationV2_1,
|
||||
getFeeSharing,
|
||||
decrpytRequest,
|
||||
};
|
||||
|
||||
@@ -98,6 +98,12 @@ router.post(
|
||||
controller.getFeeSharing
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/reservation/decrypt',
|
||||
auth.authenticateToken,
|
||||
controller.decrpytRequest
|
||||
);
|
||||
|
||||
// router.post(
|
||||
// '/reservation/cancel/v2.1',
|
||||
// auth.authenticateToken,
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
# ================================= ENVIRONMENT =================================
|
||||
#NODE_ENV=production
|
||||
NODE_ENV=development
|
||||
CUSTOM_MODE_NODE_ENV=devprod
|
||||
#NODE_ENV=testing
|
||||
PORT=3000
|
||||
VERSION=v1.4.6
|
||||
|
||||
# ===================== CLUSTER NODE (YES or NO) ===========================
|
||||
CLUSTER_NODE=NO
|
||||
|
||||
# ===================== CLUSTER WITH RUNNING ON MULTIPLE PORT (YES or NO) ===========================
|
||||
RUNNING_ON_MULTIPLE_PORT=NO
|
||||
|
||||
# PISAHKAN DENGAN MENGGUNAKAN SEPARATOR KOMA TANPA SPASI
|
||||
PORTS=3001,3002,3003,3004
|
||||
|
||||
# ===================== CLUSTER NODE STICKY SESSION(YES or NO) ===========================
|
||||
CLUSTER_NODE_STICKY_SESSION=YES
|
||||
|
||||
# =========================== KONFIGURASI UNTUK SERVER ===========================
|
||||
# SERVER_FOR=development
|
||||
@@ -31,7 +45,10 @@ DB_PASSWORD_POOLING=inhc0mmute_cms
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://10.20.14.30:3100
|
||||
|
||||
# ==================================== APP PROMETHEUS =====================================
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://localhost:3100
|
||||
|
||||
# =============================== APP PROMETHEUS =================================
|
||||
PROM_APP = topuponline
|
||||
|
||||
# ================================== SECRET KEY ==================================
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
require('dotenv').config();
|
||||
// var http = require('http');
|
||||
const cluster = require('node:cluster');
|
||||
const totalCPUs = require('node:os').cpus().length;
|
||||
const process = require('node:process');
|
||||
const winston = require('./application/helpers/winston.logger');
|
||||
const server = require('./server');
|
||||
const app = require('./server');
|
||||
const sticky = require('sticky-session');
|
||||
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 3000;
|
||||
var serverHSMStatus = 'HSM SERVER NOT CONNECTED';
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
serverHSMStatus = `SERVER 1 CONNECTED on ip ${process.env.IP_HSM_SERVER_1}`;
|
||||
@@ -29,32 +29,122 @@ if (process.env.CHANGE_TO_DRC == 'YES' || process.env.CHANGE_TO_DRC == 'yes') {
|
||||
}
|
||||
}
|
||||
|
||||
// if (cluster.isMaster) {
|
||||
// console.log(`Number of CPUs is ${totalCPUs}`);
|
||||
// console.log(`Master ${process.pid} is running`);
|
||||
// jika mau di cluster gunakan script berikut:
|
||||
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||
if (cluster.isMaster) {
|
||||
console.log(`Number of CPUs is ${totalCPUs}`);
|
||||
console.log(`Master ${process.pid} is running`);
|
||||
|
||||
// // Fork workers.
|
||||
// for (let i = 0; i < totalCPUs; i++) {
|
||||
// cluster.fork();
|
||||
// }
|
||||
// Fork workers.
|
||||
for (let i = 0; i < totalCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
|
||||
// cluster.on('exit', (worker, code, signal) => {
|
||||
// console.log(`worker ${worker.process.pid} died`);
|
||||
// console.log("Let's fork another worker!");
|
||||
// cluster.fork();
|
||||
// });
|
||||
// } else {
|
||||
startExpress();
|
||||
// }
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
console.log(`worker ${worker.process.pid} died`);
|
||||
console.log("Let's fork another worker!");
|
||||
console.log('with code: ' + code);
|
||||
cluster.fork();
|
||||
});
|
||||
|
||||
// console.log(`worker pid=${process.pid}`);
|
||||
// console.log(`worker pid=${process.pid}`);
|
||||
} else {
|
||||
startExpress();
|
||||
}
|
||||
} else {
|
||||
// jika tidak mau di cluster langsung call function startExpress
|
||||
startExpress();
|
||||
}
|
||||
|
||||
function startExpress() {
|
||||
server.listen(PORT, () => {
|
||||
winston.logger.info(
|
||||
`Server is running on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// jika settingan running on multiple
|
||||
if (
|
||||
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||
process.env.CLUSTER_NODE.toUpperCase() == 'NO'
|
||||
) {
|
||||
const PORTS = process.env.PORTS;
|
||||
|
||||
if (!PORTS) {
|
||||
winston.logger.warn(
|
||||
`Running on multiple port is active but the ports not yet set in .env`
|
||||
);
|
||||
} else {
|
||||
let ports = PORTS.split(',');
|
||||
|
||||
for (let index = 0; index < ports.length; index++) {
|
||||
const port = ports[index];
|
||||
|
||||
app.listen(port, () => {
|
||||
winston.logger.info(
|
||||
`Server is running on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${port} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||
) {
|
||||
winston.logger.warn(
|
||||
`If you want running the service on multiple port, please set CLUSTER_NODE = NO in .env file `
|
||||
);
|
||||
});
|
||||
} else if (
|
||||
process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES' &&
|
||||
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||
) {
|
||||
winston.logger.warn(
|
||||
`If you want running the service with sticky session, please set CLUSTER_NODE = NO in .env file `
|
||||
);
|
||||
}
|
||||
|
||||
let message = `Server is running on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||
|
||||
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||
message = `Server is running with cluster node on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||
} else if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||
message = `Server is running with sticky session on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||
}
|
||||
|
||||
if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||
const server = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`Worker ${process.pid} started. Listening on port ${
|
||||
server.address().port
|
||||
}`
|
||||
);
|
||||
winston.logger.info(message);
|
||||
});
|
||||
|
||||
// Use sticky-session with the server instance
|
||||
sticky.listen(server);
|
||||
} else {
|
||||
app.listen(PORT, () => {
|
||||
winston.logger.info(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Use sticky-session to handle sticky sessions
|
||||
// if (!sticky.listen(cluster, port)) {
|
||||
// // This is the master process, and it should not be listening to the port
|
||||
// cluster.on('listening', (worker, address) => {
|
||||
// console.log(
|
||||
// `Worker ${worker.id} is now connected to ${address.address}:${address.port}`
|
||||
// );
|
||||
// });
|
||||
|
||||
// cluster.on('exit', (worker) => {
|
||||
// console.log(`Worker ${worker.id} has exited`);
|
||||
// });
|
||||
// }
|
||||
|
||||
Generated
+22
@@ -28,6 +28,7 @@
|
||||
"prom-client": "^14.2.0",
|
||||
"redis": "^4.6.5",
|
||||
"response-time": "^2.3.2",
|
||||
"sticky-session": "^1.1.2",
|
||||
"winston": "^3.7.2",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"winston-loki": "^6.0.6",
|
||||
@@ -8301,6 +8302,18 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/sticky-session": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/sticky-session/-/sticky-session-1.1.2.tgz",
|
||||
"integrity": "sha512-1PPeJYu5SqjYcBNp93On4cQJuN7q+M+RbVjmYW1KSCKSv/rN1cVVyBBB0kCexsg0qJpQXgfHOt6bCneJTYRafQ==",
|
||||
"dependencies": {
|
||||
"debug": "^2.2.0",
|
||||
"ip": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
@@ -15338,6 +15351,15 @@
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="
|
||||
},
|
||||
"sticky-session": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/sticky-session/-/sticky-session-1.1.2.tgz",
|
||||
"integrity": "sha512-1PPeJYu5SqjYcBNp93On4cQJuN7q+M+RbVjmYW1KSCKSv/rN1cVVyBBB0kCexsg0qJpQXgfHOt6bCneJTYRafQ==",
|
||||
"requires": {
|
||||
"debug": "^2.2.0",
|
||||
"ip": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"prom-client": "^14.2.0",
|
||||
"redis": "^4.6.5",
|
||||
"response-time": "^2.3.2",
|
||||
"sticky-session": "^1.1.2",
|
||||
"winston": "^3.7.2",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"winston-loki": "^6.0.6",
|
||||
|
||||
Reference in New Issue
Block a user