Compare commits

..

13 Commits

Author SHA1 Message Date
teddys48 4140360736 update response posting invoice 2025-11-12 10:20:29 +07:00
teddys48 f4fc8cd147 update response posting invoice 2025-11-12 10:12:30 +07:00
Mohamad Ihsan f5f75381ca adding version and description 2025-10-30 21:08:19 +07:00
Mohamad Ihsan 5cbdccca11 update packages 2025-10-30 21:07:49 +07:00
ihsan fd386788f8 remove pengkondisian 2025-08-28 12:54:08 +07:00
ihsan 6ddf225485 pengkondisian kebutuhan uji coba posting posting sales 2025-08-28 10:42:48 +07:00
ihsan 1645aa54aa bug fixed last balance 2025-08-26 19:00:01 +07:00
ihsan 797bf97bf8 add version 2025-08-26 18:25:06 +07:00
ihsan a7f5c8c8e0 bug fixed 2025-08-26 18:20:52 +07:00
ihsan d2d44f3ba9 add check balance to CTS 2025-08-26 18:15:45 +07:00
ihsan 4dccbf20f5 change url cts 2025-08-26 17:24:02 +07:00
ihsan b888951ee3 remove bearer 2025-08-26 17:14:34 +07:00
ihsan 87dedd241a change url cts from env 2025-08-26 17:11:49 +07:00
6 changed files with 3056 additions and 8734 deletions
@@ -1,38 +1,38 @@
const { param, body, validationResult } = require('express-validator');
const helper = require('../../helpers/helper');
const winston = require('../../helpers/winston.logger');
const model = require('./invoice.model');
const moment = require('moment');
const knex = require('../../../infrastructure/database/knex');
moment.locale('id');
const { param, body, validationResult } = require("express-validator");
const helper = require("../../helpers/helper");
const winston = require("../../helpers/winston.logger");
const model = require("./invoice.model");
const moment = require("moment");
const knex = require("../../../infrastructure/database/knex");
moment.locale("id");
// VALIDATION
const validate = (method) => {
switch (method) {
case 'generateInvoice':
case "generateInvoice":
return [
body('trx_date')
body("trx_date")
.notEmpty()
.withMessage('trx_date is required!')
.withMessage("trx_date is required!")
.isISO8601()
.withMessage('invalid trx_date format YYYY-MM-DD !')
.withMessage("invalid trx_date format YYYY-MM-DD !")
.escape()
.trim(),
body('repost')
body("repost")
.notEmpty()
.withMessage('repost is required!')
.withMessage("repost is required!")
.isBoolean()
.withMessage('repost must boolean!')
.withMessage("repost must boolean!")
.escape()
.trim(),
];
case 'postingInvoice':
case "postingInvoice":
return [
body('trx_date')
body("trx_date")
.notEmpty()
.withMessage('trx_date is required!')
.withMessage("trx_date is required!")
.isISO8601()
.withMessage('invalid trx_date format YYYY-MM-DD !')
.withMessage("invalid trx_date format YYYY-MM-DD !")
.escape()
.trim(),
];
@@ -57,7 +57,7 @@ const apiGenerateInvoice = async (req, res) => {
let err = validationResult(req, res);
if (!err.isEmpty()) {
result = {
code: '400',
code: "400",
message: err.errors[0].msg,
data: {},
};
@@ -71,7 +71,7 @@ const apiGenerateInvoice = async (req, res) => {
}
// time
let invoiceDate = moment(req.body.trx_date).format('YYYY-MM-DD');
let invoiceDate = moment(req.body.trx_date).format("YYYY-MM-DD");
let invoice = await _generateInvoice(
invoiceDate,
@@ -80,8 +80,8 @@ const apiGenerateInvoice = async (req, res) => {
);
result = {
code: '200',
message: 'Succes posting',
code: "200",
message: "Succes posting",
data: invoice,
};
@@ -93,11 +93,11 @@ const apiGenerateInvoice = async (req, res) => {
);
return res.status(200).json({
code: '500',
code: "500",
message:
process.env.NODE_ENV != 'production'
process.env.NODE_ENV != "production"
? error.message
: '500 internal server error - backend server.',
: "500 internal server error - backend server.",
data: {},
});
}
@@ -119,7 +119,7 @@ const apiPostingInvoice = async (req, res) => {
let err = validationResult(req, res);
if (!err.isEmpty()) {
result = {
code: '400',
code: "400",
message: err.errors[0].msg,
data: {},
};
@@ -137,10 +137,15 @@ const apiPostingInvoice = async (req, res) => {
let invoice = await _postingInvoice(uniqueCode);
let errorCount = invoice[0].error;
invoice.splice(0, 1);
result = {
code: '200',
message: 'Succes',
code: "200",
message: "Succes",
data: invoice,
error: errorCount,
};
return res.status(200).json(result);
@@ -151,11 +156,11 @@ const apiPostingInvoice = async (req, res) => {
);
return res.status(200).json({
code: '500',
code: "500",
message:
process.env.NODE_ENV != 'production'
process.env.NODE_ENV != "production"
? error.message
: '500 internal server error - backend server.',
: "500 internal server error - backend server.",
data: {},
});
}
@@ -200,29 +205,29 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
let credUsername = await model.getParameterSetting(
knex,
'SAP_AUTH_USERNAME'
"SAP_AUTH_USERNAME"
);
let credPassword = await model.getParameterSetting(
knex,
'SAP_AUTH_PASSWORD'
"SAP_AUTH_PASSWORD"
);
let parameter = await model.getParameterSetting(
knex,
'SAP_FI_URL_FOR_FB70'
"SAP_FI_URL_FOR_FB70"
);
for (let key in invoice) {
let prepare = {
status: true,
cms: true,
message: 'Success',
message: "Success",
};
if (!credUsername) {
prepare = {
status: false,
cms: false,
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_USERNAME',
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_USERNAME",
};
}
@@ -230,7 +235,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
prepare = {
status: false,
cms: false,
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
};
}
@@ -238,7 +243,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
prepare = {
status: false,
cms: false,
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
};
}
@@ -255,49 +260,49 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
status: false,
cms: false,
message:
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP',
"[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
};
}
if (
invoice[key].c_account_code_topup == '' ||
invoice[key].c_account_topup == ''
invoice[key].c_account_code_topup == "" ||
invoice[key].c_account_topup == ""
) {
prepare = {
status: false,
cms: false,
message:
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP',
"[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
};
}
let xmlHeader = {
doc_header_text: invoice[key].doc_header_text
? invoice[key].doc_header_text
: '',
ba: invoice[key].ba ? invoice[key].ba : '',
doc_date: invoice[key].doc_date ? invoice[key].doc_date : '',
: "",
ba: invoice[key].ba ? invoice[key].ba : "",
doc_date: invoice[key].doc_date ? invoice[key].doc_date : "",
posting_date: invoice[key].posting_date
? invoice[key].posting_date
: '',
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : '',
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : '',
doc_type: invoice[key].doc_type ? invoice[key].doc_type : '',
: "",
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : "",
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : "",
doc_type: invoice[key].doc_type ? invoice[key].doc_type : "",
c_invoice_no: invoice[key].c_invoice_no
? invoice[key].c_invoice_no
: '',
: "",
};
let xmlItem = ['S', 'H'].map((item) => {
let xmlItem = ["S", "H"].map((item) => {
return {
c_account_code_topup:
item == 'S' ? invoice[key].c_account_code_topup : '',
c_account_topup: item == 'H' ? invoice[key].c_account_topup : '',
item == "S" ? invoice[key].c_account_code_topup : "",
c_account_topup: item == "H" ? invoice[key].c_account_topup : "",
ba: invoice[key].ba,
amount: invoice[key].amount,
posting_date: invoice[key].posting_date,
c_invoice_no: invoice[key].c_invoice_no,
item_text: `${item == 'S' ? 'DEBIT' : 'KREDIT'} INVOICE CMS ${
item_text: `${item == "S" ? "DEBIT" : "KREDIT"} INVOICE CMS ${
invoice[key].doc_header_text
}`,
de_cre: item,
@@ -305,7 +310,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
});
let xmlRequest = helper.generateXMLRequest(
'ZFMCMS_FI_001',
"ZFMCMS_FI_001",
xmlHeader,
xmlItem
);
@@ -338,8 +343,8 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
resSAP = helper.getXMLData(response);
} else {
resSAP = {
type: 'E',
message: prepare?.message || 'FAILED GET PARAMETER SETTING',
type: "E",
message: prepare?.message || "FAILED GET PARAMETER SETTING",
data: {},
};
}
@@ -382,33 +387,33 @@ const _postingInvoice = async (uniqueCode) => {
)}`
);
let credUsername = await model.getParameterSetting(knex, 'SAP_AUTH_USERNAME');
let credPassword = await model.getParameterSetting(knex, 'SAP_AUTH_PASSWORD');
let parameter = await model.getParameterSetting(knex, 'SAP_FI_URL_FOR_FB70');
let credUsername = await model.getParameterSetting(knex, "SAP_AUTH_USERNAME");
let credPassword = await model.getParameterSetting(knex, "SAP_AUTH_PASSWORD");
let parameter = await model.getParameterSetting(knex, "SAP_FI_URL_FOR_FB70");
let prepare = {
status: true,
message: 'Success',
message: "Success",
};
if (!credUsername) {
prepare = {
status: false,
message: 'FAILED GET SETTING FOR SAP_AUTH_USERNAME',
message: "FAILED GET SETTING FOR SAP_AUTH_USERNAME",
};
}
if (!credPassword) {
prepare = {
status: false,
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
};
}
if (!parameter) {
prepare = {
status: false,
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
};
}
@@ -417,6 +422,7 @@ const _postingInvoice = async (uniqueCode) => {
password: credPassword.c_value,
};
let errorCount = 0;
for (let item of postingEt) {
await knex.transaction(async (trx) => {
let response = {};
@@ -425,31 +431,31 @@ const _postingInvoice = async (uniqueCode) => {
if (prepare.status) {
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 : '',
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) => {
let xmlItem = ["S", "H"].map((key) => {
return {
c_account_code_topup: key == 'S' ? item.customer : '',
c_account_topup: key == 'H' ? item.account : '',
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,
item_text: key == "S" ? item.text1 : item.text2,
de_cre: key,
};
});
let xmlRequest = helper.generateXMLRequest(
'ZFMCMS_FI_001',
"ZFMCMS_FI_001",
xmlHeader,
xmlItem
);
@@ -471,10 +477,13 @@ const _postingInvoice = async (uniqueCode) => {
);
resSAP = helper.getXMLData(response);
if (resSAP.type == "E") {
errorCount++;
}
} else {
resSAP = {
type: 'E',
message: prepare?.message || 'FAILED GET PARAMETER SETTING',
type: "E",
message: prepare?.message || "FAILED GET PARAMETER SETTING",
data: {},
};
}
@@ -511,6 +520,8 @@ const _postingInvoice = async (uniqueCode) => {
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
);
collection.push({ error: errorCount });
collection.push(cms.invoice[0]);
});
}
+261 -189
View File
@@ -1,18 +1,19 @@
// 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 (invoice, trx) => {
console.log("invoice : ", invoice)
let type = ['S', 'H']
let et = []
let posting_et = []
console.log("invoice : ", invoice);
let type = ["S", "H"];
let et = [];
let posting_et = [];
type.forEach((item, index) => {
let data = {
file_name: invoice.file_name,
@@ -26,222 +27,293 @@ const insertPostingEt = async (invoice, trx) => {
reference: invoice.c_invoice_no,
amount: invoice.amount,
ba: invoice.ba,
indeks: (index+1),
indeks: index + 1,
totalidx: type.length,
doc_header_text: invoice.c_invoice_no,
pos_status : 3
}
if(item == 'H'){
data = {...data, ...{
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
debit_kredit: item,
account: invoice.c_account_topup,
customer: null
}}
}else{
data = {...data, ...{
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
debit_kredit: item,
account: null,
customer: invoice.c_account_code_topup
}}
}
pos_status: 3,
};
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',
'ba',
'doc_date',
'posting_date',
'fiscal_year',
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
'doc_type',
'reference',
'tcode',
'amount',
trx.raw(`'IDR' AS currency`),
trx.raw(`(select pe2.customer from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as customer`),
trx.raw(`(select pe2.account from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as account`),
trx.raw(`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as text1`),
trx.raw(`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as text2`),
])
.where('tcode', '=', "FB70")
.whereIn('pos_status', ["3"])
.groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12])
return result
}
const setReturnSAP = async (invoice, resSAP, trx, posting = false, c_invoice_no) => {
let t_invoice = {}
let t_load_balance = {}
let posting_et = {}
if(resSAP.type == 'S'){
// update invoice
t_invoice = await trx('payment.t_d_invoice').update({
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
}, ["*"])
.where({
c_invoice_no: c_invoice_no
});
// update load balance
t_load_balance = await trx('trx.t_d_load_balance').update({
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
}, ['c_load_balance_no', 'c_return_sap'])
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`)
posting_et = await trx('public.posting_et').update({
pos_status : 0,
status0 : resSAP.type,
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
status1 : resSAP.message ? resSAP.message : null
}, ['file_name','status0']).where({
reference: c_invoice_no
})
if(posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
if (item == "H") {
data = {
...data,
...{
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
debit_kredit: item,
account: invoice.c_account_topup,
customer: null,
},
};
} else {
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
data = {
...data,
...{
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
debit_kredit: item,
account: null,
customer: invoice.c_account_code_topup,
},
};
}
}else {
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",
"ba",
"doc_date",
"posting_date",
"fiscal_year",
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
"doc_type",
"reference",
"tcode",
"amount",
trx.raw(`'IDR' AS currency`),
trx.raw(
`(select pe2.customer from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as customer`
),
trx.raw(
`(select pe2.account from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as account`
),
trx.raw(
`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as text1`
),
trx.raw(
`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as text2`
),
])
.where("tcode", "=", "FB70")
.whereIn("pos_status", ["3"])
// .limit(1)
.groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12]);
return result;
};
const setReturnSAP = async (
invoice,
resSAP,
trx,
posting = false,
c_invoice_no
) => {
let t_invoice = {};
let t_load_balance = {};
let posting_et = {};
if (resSAP.type == "S") {
// update invoice
t_invoice = await trx("payment.t_d_invoice")
.update(
{
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
},
["*"]
)
.where({
c_invoice_no: c_invoice_no,
});
// update load balance
t_load_balance = await trx("trx.t_d_load_balance")
.update(
{
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
},
["c_load_balance_no", "c_return_sap"]
)
.whereRaw(
`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`
);
posting_et = await trx("public.posting_et")
.update(
{
pos_status: 0,
status0: resSAP.type,
no_doksap: resSAP.data.E_DOCUMENTNUMBER
? resSAP.data.E_DOCUMENTNUMBER
: null,
status1: resSAP.message ? resSAP.message : null,
},
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
if (posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
} else {
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx);
}
} else {
let text = resSAP.message;
let result = text.toUpperCase();
if(result.includes("ALREADY")){
let result = text.toUpperCase().split('-');
let doc_number = result[1].trim().split(" ")[0]
if (result.includes("ALREADY")) {
let result = text.toUpperCase().split("-");
let doc_number = result[1].trim().split(" ")[0];
// update invoice
const d = new Date();
let year = d.getFullYear();
posting_et = await trx('public.posting_et').update({
pos_status : 0,
status0 : 'S',
no_doksap : doc_number,
status1 : resSAP.message ? resSAP.message : null
}, ['file_name','status0']).where({
reference: c_invoice_no
})
posting_et = await trx("public.posting_et")
.update(
{
pos_status: 0,
status0: "S",
no_doksap: doc_number,
status1: resSAP.message ? resSAP.message : null,
},
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
// update invoice
t_invoice = await trx('payment.t_d_invoice').update({
c_return_sap: doc_number
}, ['*'])
.where({
c_invoice_no: c_invoice_no
});
t_invoice = await trx("payment.t_d_invoice")
.update(
{
c_return_sap: doc_number,
},
["*"]
)
.where({
c_invoice_no: c_invoice_no,
});
// update load balance
t_load_balance = await trx('trx.t_d_load_balance').update({
c_return_sap: doc_number
}, ['c_load_balance_no', 'c_return_sap'])
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`)
if(posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
t_load_balance = await trx("trx.t_d_load_balance")
.update(
{
c_return_sap: doc_number,
},
["c_load_balance_no", "c_return_sap"]
)
.whereRaw(
`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`
);
if (posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
} else {
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
await writePaynentHistory(
t_invoice[0],
"SUCCESS TO RETRY SAP",
118,
trx
);
}
}else{
} else {
// update posting et
posting_et = await trx('public.posting_et').update({
pos_status : resSAP.type == 'S' ? 0 : 3,
status0 : resSAP.type,
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
status1 : resSAP.message ? resSAP.message : null
}, ['file_name','status0']).where({
reference: c_invoice_no
})
posting_et = await trx("public.posting_et")
.update(
{
pos_status: resSAP.type == "S" ? 0 : 3,
status0: resSAP.type,
no_doksap: resSAP.data.E_DOCUMENTNUMBER
? resSAP.data.E_DOCUMENTNUMBER
: null,
status1: resSAP.message ? resSAP.message : null,
},
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
// update invoice
t_invoice = await trx('payment.t_d_invoice').select(['*'])
.where({
c_invoice_no: c_invoice_no
t_invoice = await trx("payment.t_d_invoice").select(["*"]).where({
c_invoice_no: c_invoice_no,
});
if(posting) {
await writePaynentHistory(t_invoice[0], `SUCCESS WITH SAP ERR: ${resSAP.message}`,102, trx)
if (posting) {
await writePaynentHistory(
t_invoice[0],
`SUCCESS WITH SAP ERR: ${resSAP.message}`,
102,
trx
);
} else {
await writePaynentHistory(t_invoice[0], `FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,118, trx)
await writePaynentHistory(
t_invoice[0],
`FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,
118,
trx
);
}
}
}
// update posting et
return {
invoice : t_invoice,
load_balance : t_load_balance,
posting_et : posting_et
}
}
invoice: t_invoice,
load_balance: t_load_balance,
posting_et: posting_et,
};
};
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 : i_log_name,
d_log : trx.raw('NOW()'),
c_invoice_no : data?.c_invoice_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 || 0,
m_mdr_amount : 0,
m_mdr_net : data?.amount || 0
console.log(data);
const result = await trx("log.t_log_invoice").insert(
{
// i_log_name : 102,
i_log_name: i_log_name,
d_log: trx.raw("NOW()"),
c_invoice_no: data?.c_invoice_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 || 0,
m_mdr_amount: 0,
m_mdr_net: data?.amount || 0,
},
["i_log_name", "c_note"]
);
}, ['i_log_name', 'c_note'])
return result;
};
return result
const getParameterSetting = async (trx, code) => {
const result = await trx("public.t_m_global_parameter_sap AS tmgps")
.select(["c_value"])
.where("c_code", "=", code)
.where("c_status", "=", "A")
.first();
}
return result;
};
const getParameterSetting = async(trx, code) => {
const getInvoice = async (code, trx) => {
const result = await trx("payment.t_d_invoice")
.where("c_invoice_no", "=", code)
.first();
const result = await trx('public.t_m_global_parameter_sap AS tmgps').select([
"c_value"
])
.where('c_code', '=', code)
.where('c_status', '=', "A")
.first()
return result
}
const getInvoice = async(code, trx) => {
const result = await trx('payment.t_d_invoice')
.where('c_invoice_no', '=', code)
.first()
return result
}
return result;
};
module.exports = {
generateInvoice,
@@ -250,5 +322,5 @@ module.exports = {
getPostingEt,
writePaynentHistory,
getParameterSetting,
getInvoice
};
getInvoice,
};
+87 -44
View File
@@ -80,7 +80,7 @@ const validate = (method) => {
body('card_number')
.not()
.isEmpty()
.withMessage('Card number is required')
.withMessage('Card number is required'),
];
//card_number, new_card_number, last_balance, security_code, unique_code
@@ -1084,6 +1084,7 @@ const validateRedeem = async (req, res) => {
let uniqueCode = helper.getUniqueCode();
let result = {};
let last_balance = null;
let dataCardReplacement = {};
let { card_number, station_code } = req.body;
console.log(
@@ -1310,19 +1311,49 @@ const validateRedeem = async (req, res) => {
last_balance = dataCardReplacement.i_last_balance;
if (last_balance == null) {
result = {
code: '415',
message: 'Last Balance not updated.',
data: {
status: false,
detail: {},
let result = {};
// const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance'
const baseUrl = `${process.env.CTS_URL}/v2/api/info/last-balance`;
const payload = {
card_number: card_number,
};
let config = {
headers: {
'Content-Type': 'application/json',
},
};
//LOG-INFO
winston.logger.info(
`${uniqueCode} [ RESPONSE VALIDATE-REDEEM ]: ${JSON.stringify(result)}`
);
return res.status(200).json(result);
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 security_code = await helper.createHMAC(card_number);
@@ -1658,19 +1689,16 @@ const validateReplacement = async (req, res) => {
// );
// 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 baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance'
const baseUrl = `${process.env.CTS_URL}/v2/api/info/last-balance`;
const payload = {
card_number: card_number,
};
let config = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + bearer
},
};
const url = baseUrl;
@@ -1682,8 +1710,8 @@ const validateReplacement = async (req, res) => {
message: 'No data found in CTS for the given card number',
data: {
status: false,
detail: {}
}
detail: {},
},
};
winston.logger.info(
`${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}`
@@ -1695,7 +1723,7 @@ const validateReplacement = async (req, res) => {
message: 'Last Balance not updated.',
data: {
status: false,
detail: {}
detail: {},
},
};
winston.logger.info(
@@ -1705,10 +1733,13 @@ const validateReplacement = async (req, res) => {
}
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}`
@@ -1934,8 +1965,7 @@ const validateNewCardReplacement = async (req, res) => {
message: 'Successfully.',
data: {
status: true,
detail: {
},
detail: {},
},
};
//LOG-INFO
@@ -2671,11 +2701,13 @@ 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'
// const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance'
const baseUrl = `${process.env.CTS_URL}/v2/api/info/last-balance`;
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
@@ -2689,7 +2721,6 @@ const getLastBalanceCTS = async (req, res) => {
let config = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + bearer
},
};
const url = baseUrl;
@@ -2701,8 +2732,8 @@ const getLastBalanceCTS = async (req, res) => {
message: 'No data found in CTS for the given card number',
data: {
status: false,
detail: {}
}
detail: {},
},
};
winston.logger.info(
`${uniqueCode} [ FAILED HIT - card_number : ${card.c_card_no} ]: ${response.data.message}`
@@ -2711,11 +2742,11 @@ const getLastBalanceCTS = async (req, res) => {
}
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}`
@@ -2724,10 +2755,13 @@ const getLastBalanceCTS = async (req, res) => {
}
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}`
@@ -2739,15 +2773,16 @@ 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(
@@ -2761,8 +2796,8 @@ const getLastBalanceCTS = async (req, res) => {
: '500 internal server error - backend server.',
data: {
status: false,
detail: {}
}
detail: {},
},
});
}
};
@@ -2894,11 +2929,15 @@ const completeDataSalesInternal = async (req, res) => {
return res.status(200).json(result);
}
console.log(`${uniqueCode} [ COMPLETING DATA SALES INTERNAL - PPN ${ppn.c_value} % ]`);
console.log(
`${uniqueCode} [ COMPLETING DATA SALES INTERNAL - PPN ${ppn.c_value} % ]`
);
ppn = parseFloat(ppn.c_value);
console.log(`${uniqueCode} [ COMPLETING DATA SALES INTERNAL - UPDATE DATA ]`);
console.log(
`${uniqueCode} [ COMPLETING DATA SALES INTERNAL - UPDATE DATA ]`
);
//COMPLETING DATA SALES INTERNAL
const response = await model.completingDataSalesInternal(ppn);
@@ -2923,7 +2962,11 @@ const completeDataSalesInternal = async (req, res) => {
data: {},
};
console.log(`${uniqueCode} [ COMPLETING DATA SALES INTERNAL SUCCESS : ${JSON.stringify(result)} ]`);
console.log(
`${uniqueCode} [ COMPLETING DATA SALES INTERNAL SUCCESS : ${JSON.stringify(
result
)} ]`
);
return res.status(200).json(result);
} catch (error) {
// create log
+2 -2
View File
@@ -208,7 +208,7 @@ const completingDataSalesInternal = async (ppn) => {
SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 1, 1) = t_m_card_theme.c_card_type_code
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 4, 1) = t_m_card_theme.c_variant_code
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
WHERE
trx.t_d_sales_internal.is_complete is not true
AND trx.t_d_sales_internal.i_old_card_price > 0
@@ -314,7 +314,7 @@ const completingDataSalesOldCard = async (ppn) => {
SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 1, 1) = t_m_card_theme.c_card_type_code
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 4, 1) = t_m_card_theme.c_variant_code
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
WHERE
trx.t_d_sales_internal.is_complete is not true
AND trx.t_d_sales_internal.i_old_card_price > 0
+2608 -8414
View File
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -1,7 +1,7 @@
{
"name": "topuponline",
"version": "1.6.1",
"description": "pos cms integration",
"name": "onlinetopup-v1",
"version": "1.6.3",
"description": "update packages",
"main": "index.js",
"scripts": {
"start": "nodemon index",
@@ -37,11 +37,13 @@
"moment": "^2.29.3",
"node-cron": "^3.0.1",
"pg": "^8.6.0",
"pm2": "^5.2.0",
"pm2": "^6.0.13",
"prom-client": "^14.2.0",
"redis": "^4.6.5",
"response-time": "^2.3.2",
"simple-update-notifier": "^2.0.0",
"sticky-session": "^0.1.0",
"superagent": "^10.2.3",
"winston": "^3.7.2",
"winston-daily-rotate-file": "^4.7.1",
"winston-loki": "^6.0.6",
@@ -50,8 +52,8 @@
},
"devDependencies": {
"jest": "^29.0.2",
"nodemon": "^2.0.7",
"supertest": "^6.2.4"
"nodemon": "^3.1.10",
"supertest": "^7.1.3"
},
"jest": {
"testEnvironment": "node",