Compare commits

..

2 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
5 changed files with 357 additions and 278 deletions
+2 -2
View File
@@ -583,7 +583,7 @@ const getPartnerReconSalesInternal = async (trx) => {
'tmp.c_account_sales_revenue', 'tmp.c_account_sales_revenue',
'tmp.c_account_code_sales_ar', 'tmp.c_account_code_sales_ar',
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM') trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
THEN 'IP' ELSE 'IP' THEN 'IP' ELSE 'OP'
END c_in_period`), END c_in_period`),
]) ])
.from('trx.t_d_sales_internal AS tdskm') .from('trx.t_d_sales_internal AS tdskm')
@@ -627,7 +627,7 @@ const getPartnerReconTopUpCashlessInternal = async (trx) => {
'tmp.c_account_topup', 'tmp.c_account_topup',
'tmp.c_account_code_topup', 'tmp.c_account_code_topup',
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM') trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
THEN 'IP' ELSE 'IP' THEN 'IP' ELSE 'OP'
END c_in_period`), END c_in_period`),
]) ])
.from('trx.t_d_topup_cashless_internal AS tdskm') .from('trx.t_d_topup_cashless_internal AS tdskm')
@@ -1,38 +1,38 @@
const { param, body, validationResult } = require('express-validator'); const { param, body, validationResult } = require("express-validator");
const helper = require('../../helpers/helper'); const helper = require("../../helpers/helper");
const winston = require('../../helpers/winston.logger'); const winston = require("../../helpers/winston.logger");
const model = require('./invoice.model'); const model = require("./invoice.model");
const moment = require('moment'); const moment = require("moment");
const knex = require('../../../infrastructure/database/knex'); const knex = require("../../../infrastructure/database/knex");
moment.locale('id'); moment.locale("id");
// VALIDATION // VALIDATION
const validate = (method) => { const validate = (method) => {
switch (method) { switch (method) {
case 'generateInvoice': case "generateInvoice":
return [ return [
body('trx_date') body("trx_date")
.notEmpty() .notEmpty()
.withMessage('trx_date is required!') .withMessage("trx_date is required!")
.isISO8601() .isISO8601()
.withMessage('invalid trx_date format YYYY-MM-DD !') .withMessage("invalid trx_date format YYYY-MM-DD !")
.escape() .escape()
.trim(), .trim(),
body('repost') body("repost")
.notEmpty() .notEmpty()
.withMessage('repost is required!') .withMessage("repost is required!")
.isBoolean() .isBoolean()
.withMessage('repost must boolean!') .withMessage("repost must boolean!")
.escape() .escape()
.trim(), .trim(),
]; ];
case 'postingInvoice': case "postingInvoice":
return [ return [
body('trx_date') body("trx_date")
.notEmpty() .notEmpty()
.withMessage('trx_date is required!') .withMessage("trx_date is required!")
.isISO8601() .isISO8601()
.withMessage('invalid trx_date format YYYY-MM-DD !') .withMessage("invalid trx_date format YYYY-MM-DD !")
.escape() .escape()
.trim(), .trim(),
]; ];
@@ -57,7 +57,7 @@ const apiGenerateInvoice = async (req, res) => {
let err = validationResult(req, res); let err = validationResult(req, res);
if (!err.isEmpty()) { if (!err.isEmpty()) {
result = { result = {
code: '400', code: "400",
message: err.errors[0].msg, message: err.errors[0].msg,
data: {}, data: {},
}; };
@@ -71,7 +71,7 @@ const apiGenerateInvoice = async (req, res) => {
} }
// time // 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( let invoice = await _generateInvoice(
invoiceDate, invoiceDate,
@@ -80,8 +80,8 @@ const apiGenerateInvoice = async (req, res) => {
); );
result = { result = {
code: '200', code: "200",
message: 'Succes posting', message: "Succes posting",
data: invoice, data: invoice,
}; };
@@ -93,11 +93,11 @@ const apiGenerateInvoice = async (req, res) => {
); );
return res.status(200).json({ return res.status(200).json({
code: '500', code: "500",
message: message:
process.env.NODE_ENV != 'production' process.env.NODE_ENV != "production"
? error.message ? error.message
: '500 internal server error - backend server.', : "500 internal server error - backend server.",
data: {}, data: {},
}); });
} }
@@ -119,7 +119,7 @@ const apiPostingInvoice = async (req, res) => {
let err = validationResult(req, res); let err = validationResult(req, res);
if (!err.isEmpty()) { if (!err.isEmpty()) {
result = { result = {
code: '400', code: "400",
message: err.errors[0].msg, message: err.errors[0].msg,
data: {}, data: {},
}; };
@@ -137,10 +137,15 @@ const apiPostingInvoice = async (req, res) => {
let invoice = await _postingInvoice(uniqueCode); let invoice = await _postingInvoice(uniqueCode);
let errorCount = invoice[0].error;
invoice.splice(0, 1);
result = { result = {
code: '200', code: "200",
message: 'Succes', message: "Succes",
data: invoice, data: invoice,
error: errorCount,
}; };
return res.status(200).json(result); return res.status(200).json(result);
@@ -151,11 +156,11 @@ const apiPostingInvoice = async (req, res) => {
); );
return res.status(200).json({ return res.status(200).json({
code: '500', code: "500",
message: message:
process.env.NODE_ENV != 'production' process.env.NODE_ENV != "production"
? error.message ? error.message
: '500 internal server error - backend server.', : "500 internal server error - backend server.",
data: {}, data: {},
}); });
} }
@@ -200,29 +205,29 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
let credUsername = await model.getParameterSetting( let credUsername = await model.getParameterSetting(
knex, knex,
'SAP_AUTH_USERNAME' "SAP_AUTH_USERNAME"
); );
let credPassword = await model.getParameterSetting( let credPassword = await model.getParameterSetting(
knex, knex,
'SAP_AUTH_PASSWORD' "SAP_AUTH_PASSWORD"
); );
let parameter = await model.getParameterSetting( let parameter = await model.getParameterSetting(
knex, knex,
'SAP_FI_URL_FOR_FB70' "SAP_FI_URL_FOR_FB70"
); );
for (let key in invoice) { for (let key in invoice) {
let prepare = { let prepare = {
status: true, status: true,
cms: true, cms: true,
message: 'Success', message: "Success",
}; };
if (!credUsername) { if (!credUsername) {
prepare = { prepare = {
status: false, status: false,
cms: 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 = { prepare = {
status: false, status: false,
cms: 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 = { prepare = {
status: false, status: false,
cms: 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, status: false,
cms: false, cms: false,
message: message:
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP', "[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
}; };
} }
if ( if (
invoice[key].c_account_code_topup == '' || invoice[key].c_account_code_topup == "" ||
invoice[key].c_account_topup == '' invoice[key].c_account_topup == ""
) { ) {
prepare = { prepare = {
status: false, status: false,
cms: false, cms: false,
message: message:
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP', "[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
}; };
} }
let xmlHeader = { let xmlHeader = {
doc_header_text: invoice[key].doc_header_text doc_header_text: invoice[key].doc_header_text
? invoice[key].doc_header_text ? invoice[key].doc_header_text
: '', : "",
ba: invoice[key].ba ? invoice[key].ba : '', ba: invoice[key].ba ? invoice[key].ba : "",
doc_date: invoice[key].doc_date ? invoice[key].doc_date : '', doc_date: invoice[key].doc_date ? invoice[key].doc_date : "",
posting_date: invoice[key].posting_date posting_date: invoice[key].posting_date
? invoice[key].posting_date ? invoice[key].posting_date
: '', : "",
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : '', fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : "",
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : '', fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : "",
doc_type: invoice[key].doc_type ? invoice[key].doc_type : '', doc_type: invoice[key].doc_type ? invoice[key].doc_type : "",
c_invoice_no: invoice[key].c_invoice_no c_invoice_no: invoice[key].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 { return {
c_account_code_topup: c_account_code_topup:
item == 'S' ? invoice[key].c_account_code_topup : '', item == "S" ? invoice[key].c_account_code_topup : "",
c_account_topup: item == 'H' ? invoice[key].c_account_topup : '', c_account_topup: item == "H" ? invoice[key].c_account_topup : "",
ba: invoice[key].ba, ba: invoice[key].ba,
amount: invoice[key].amount, amount: invoice[key].amount,
posting_date: invoice[key].posting_date, posting_date: invoice[key].posting_date,
c_invoice_no: invoice[key].c_invoice_no, 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 invoice[key].doc_header_text
}`, }`,
de_cre: item, de_cre: item,
@@ -305,7 +310,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
}); });
let xmlRequest = helper.generateXMLRequest( let xmlRequest = helper.generateXMLRequest(
'ZFMCMS_FI_001', "ZFMCMS_FI_001",
xmlHeader, xmlHeader,
xmlItem xmlItem
); );
@@ -338,8 +343,8 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
resSAP = helper.getXMLData(response); resSAP = helper.getXMLData(response);
} else { } else {
resSAP = { resSAP = {
type: 'E', type: "E",
message: prepare?.message || 'FAILED GET PARAMETER SETTING', message: prepare?.message || "FAILED GET PARAMETER SETTING",
data: {}, data: {},
}; };
} }
@@ -382,33 +387,33 @@ const _postingInvoice = async (uniqueCode) => {
)}` )}`
); );
let credUsername = await model.getParameterSetting(knex, 'SAP_AUTH_USERNAME'); let credUsername = await model.getParameterSetting(knex, "SAP_AUTH_USERNAME");
let credPassword = await model.getParameterSetting(knex, 'SAP_AUTH_PASSWORD'); let credPassword = await model.getParameterSetting(knex, "SAP_AUTH_PASSWORD");
let parameter = await model.getParameterSetting(knex, 'SAP_FI_URL_FOR_FB70'); let parameter = await model.getParameterSetting(knex, "SAP_FI_URL_FOR_FB70");
let prepare = { let prepare = {
status: true, status: true,
message: 'Success', message: "Success",
}; };
if (!credUsername) { if (!credUsername) {
prepare = { prepare = {
status: false, status: false,
message: 'FAILED GET SETTING FOR SAP_AUTH_USERNAME', message: "FAILED GET SETTING FOR SAP_AUTH_USERNAME",
}; };
} }
if (!credPassword) { if (!credPassword) {
prepare = { prepare = {
status: false, status: false,
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD', message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
}; };
} }
if (!parameter) { if (!parameter) {
prepare = { prepare = {
status: false, 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, password: credPassword.c_value,
}; };
let errorCount = 0;
for (let item of postingEt) { for (let item of postingEt) {
await knex.transaction(async (trx) => { await knex.transaction(async (trx) => {
let response = {}; let response = {};
@@ -425,31 +431,31 @@ const _postingInvoice = async (uniqueCode) => {
if (prepare.status) { if (prepare.status) {
let xmlHeader = { let xmlHeader = {
doc_header_text: item.doc_header_text ? item.doc_header_text : '', doc_header_text: item.doc_header_text ? item.doc_header_text : "",
ba: item.ba ? item.ba : '', ba: item.ba ? item.ba : "",
doc_date: item.doc_date ? item.doc_date : '', doc_date: item.doc_date ? item.doc_date : "",
posting_date: item.posting_date ? item.posting_date : '', posting_date: item.posting_date ? item.posting_date : "",
fisc_year: item.fiscal_year ? item.fiscal_year : '', fisc_year: item.fiscal_year ? item.fiscal_year : "",
fisc_period: item.fis_period ? item.fis_period : '', fisc_period: item.fis_period ? item.fis_period : "",
doc_type: item.doc_type ? item.doc_type : '', doc_type: item.doc_type ? item.doc_type : "",
c_invoice_no: item.reference ? item.reference : '', c_invoice_no: item.reference ? item.reference : "",
}; };
let xmlItem = ['S', 'H'].map((key) => { let xmlItem = ["S", "H"].map((key) => {
return { return {
c_account_code_topup: key == 'S' ? item.customer : '', c_account_code_topup: key == "S" ? item.customer : "",
c_account_topup: key == 'H' ? item.account : '', c_account_topup: key == "H" ? item.account : "",
ba: item.ba, ba: item.ba,
amount: item.amount, amount: item.amount,
posting_date: item.posting_date, posting_date: item.posting_date,
c_invoice_no: item.reference, c_invoice_no: item.reference,
item_text: key == 'S' ? item.text1 : item.text2, item_text: key == "S" ? item.text1 : item.text2,
de_cre: key, de_cre: key,
}; };
}); });
let xmlRequest = helper.generateXMLRequest( let xmlRequest = helper.generateXMLRequest(
'ZFMCMS_FI_001', "ZFMCMS_FI_001",
xmlHeader, xmlHeader,
xmlItem xmlItem
); );
@@ -471,10 +477,13 @@ const _postingInvoice = async (uniqueCode) => {
); );
resSAP = helper.getXMLData(response); resSAP = helper.getXMLData(response);
if (resSAP.type == "E") {
errorCount++;
}
} else { } else {
resSAP = { resSAP = {
type: 'E', type: "E",
message: prepare?.message || 'FAILED GET PARAMETER SETTING', message: prepare?.message || "FAILED GET PARAMETER SETTING",
data: {}, data: {},
}; };
} }
@@ -511,6 +520,8 @@ const _postingInvoice = async (uniqueCode) => {
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}` `SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
); );
collection.push({ error: errorCount });
collection.push(cms.invoice[0]); collection.push(cms.invoice[0]);
}); });
} }
+247 -175
View File
@@ -1,18 +1,19 @@
// GET PARTNER, MERCHANT, TERMINAL FROM TID // GET PARTNER, MERCHANT, TERMINAL FROM TID
const generateInvoice = async (invoiceDate, repost, trx) => { const generateInvoice = async (invoiceDate, repost, trx) => {
let result = await trx.select(
let result = await trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`)) trx.raw(
`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`
)
);
return result; return result;
};
}
const insertPostingEt = async (invoice, trx) => { const insertPostingEt = async (invoice, trx) => {
console.log("invoice : ", invoice) console.log("invoice : ", invoice);
let type = ['S', 'H'] let type = ["S", "H"];
let et = [] let et = [];
let posting_et = [] let posting_et = [];
type.forEach((item, index) => { type.forEach((item, index) => {
let data = { let data = {
file_name: invoice.file_name, file_name: invoice.file_name,
@@ -26,222 +27,293 @@ const insertPostingEt = async (invoice, trx) => {
reference: invoice.c_invoice_no, reference: invoice.c_invoice_no,
amount: invoice.amount, amount: invoice.amount,
ba: invoice.ba, ba: invoice.ba,
indeks: (index+1), indeks: index + 1,
totalidx: type.length, totalidx: type.length,
doc_header_text: invoice.c_invoice_no, doc_header_text: invoice.c_invoice_no,
pos_status : 3 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,
},
};
} }
if(item == 'H'){ et.push(data);
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
}}
}
et.push(data)
}); });
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit']) 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] 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]);
const getPostingEt = async(trx) => { return result;
};
const result = await trx('public.posting_et AS pe').select([ const setReturnSAP = async (
'doc_header_text', invoice,
'ba', resSAP,
'doc_date', trx,
'posting_date', posting = false,
'fiscal_year', c_invoice_no
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`), ) => {
'doc_type', let t_invoice = {};
'reference', let t_load_balance = {};
'tcode', let posting_et = {};
'amount', if (resSAP.type == "S") {
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 // update invoice
t_invoice = await trx('payment.t_d_invoice').update({ t_invoice = await trx("payment.t_d_invoice")
c_return_sap: resSAP.data.E_DOCUMENTNUMBER .update(
}, ["*"]) {
.where({ c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
c_invoice_no: c_invoice_no },
}); ["*"]
)
.where({
c_invoice_no: c_invoice_no,
});
// update load balance // update load balance
t_load_balance = await trx('trx.t_d_load_balance').update({ t_load_balance = await trx("trx.t_d_load_balance")
c_return_sap: resSAP.data.E_DOCUMENTNUMBER .update(
}, ['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}')`) 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({ posting_et = await trx("public.posting_et")
pos_status : 0, .update(
status0 : resSAP.type, {
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null, pos_status: 0,
status1 : resSAP.message ? resSAP.message : null status0: resSAP.type,
}, ['file_name','status0']).where({ no_doksap: resSAP.data.E_DOCUMENTNUMBER
reference: c_invoice_no ? resSAP.data.E_DOCUMENTNUMBER
}) : null,
status1: resSAP.message ? resSAP.message : null,
},
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
if(posting) { if (posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx) await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
} else { } 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 {
let text = resSAP.message; let text = resSAP.message;
let result = text.toUpperCase(); let result = text.toUpperCase();
if(result.includes("ALREADY")){ if (result.includes("ALREADY")) {
let result = text.toUpperCase().split('-'); let result = text.toUpperCase().split("-");
let doc_number = result[1].trim().split(" ")[0] let doc_number = result[1].trim().split(" ")[0];
// update invoice // update invoice
const d = new Date(); const d = new Date();
let year = d.getFullYear(); let year = d.getFullYear();
posting_et = await trx('public.posting_et').update({ posting_et = await trx("public.posting_et")
pos_status : 0, .update(
status0 : 'S', {
no_doksap : doc_number, pos_status: 0,
status1 : resSAP.message ? resSAP.message : null status0: "S",
}, ['file_name','status0']).where({ no_doksap: doc_number,
reference: c_invoice_no status1: resSAP.message ? resSAP.message : null,
}) },
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
// update invoice // update invoice
t_invoice = await trx('payment.t_d_invoice').update({ t_invoice = await trx("payment.t_d_invoice")
c_return_sap: doc_number .update(
}, ['*']) {
.where({ c_return_sap: doc_number,
c_invoice_no: c_invoice_no },
}); ["*"]
)
.where({
c_invoice_no: c_invoice_no,
});
// update load balance // update load balance
t_load_balance = await trx('trx.t_d_load_balance').update({ t_load_balance = await trx("trx.t_d_load_balance")
c_return_sap: doc_number .update(
}, ['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}')`) 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) { if (posting) {
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx) await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
} else { } 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 // update posting et
posting_et = await trx('public.posting_et').update({ posting_et = await trx("public.posting_et")
pos_status : resSAP.type == 'S' ? 0 : 3, .update(
status0 : resSAP.type, {
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null, pos_status: resSAP.type == "S" ? 0 : 3,
status1 : resSAP.message ? resSAP.message : null status0: resSAP.type,
}, ['file_name','status0']).where({ no_doksap: resSAP.data.E_DOCUMENTNUMBER
reference: c_invoice_no ? resSAP.data.E_DOCUMENTNUMBER
}) : null,
status1: resSAP.message ? resSAP.message : null,
},
["file_name", "status0"]
)
.where({
reference: c_invoice_no,
});
// update invoice // update invoice
t_invoice = await trx('payment.t_d_invoice').select(['*']) t_invoice = await trx("payment.t_d_invoice").select(["*"]).where({
.where({ c_invoice_no: c_invoice_no,
c_invoice_no: c_invoice_no
}); });
if(posting) { if (posting) {
await writePaynentHistory(t_invoice[0], `SUCCESS WITH SAP ERR: ${resSAP.message}`,102, trx) await writePaynentHistory(
t_invoice[0],
`SUCCESS WITH SAP ERR: ${resSAP.message}`,
102,
trx
);
} else { } 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 // update posting et
return { return {
invoice : t_invoice, invoice: t_invoice,
load_balance : t_load_balance, load_balance: t_load_balance,
posting_et : posting_et posting_et: posting_et,
} };
};
}
const writePaynentHistory = async (data, message, i_log_name, trx) => { const writePaynentHistory = async (data, message, i_log_name, trx) => {
console.log(data) console.log(data);
const result = await trx('log.t_log_invoice').insert({ const result = await trx("log.t_log_invoice").insert(
// i_log_name : 102, {
i_log_name : i_log_name, // i_log_name : 102,
d_log : trx.raw('NOW()'), i_log_name: i_log_name,
c_invoice_no : data?.c_invoice_no || '', d_log: trx.raw("NOW()"),
c_partner_name : data?.c_partner_name || '', c_invoice_no: data?.c_invoice_no || "",
j_new_data : JSON.stringify(data), c_partner_name: data?.c_partner_name || "",
d_payment_date: trx.raw('NOW()'), j_new_data: JSON.stringify(data),
c_note : message, d_payment_date: trx.raw("NOW()"),
c_status : 'S', c_note: message,
d_created : trx.raw('NOW()'), c_status: "S",
m_amount : data?.amount || 0, d_created: trx.raw("NOW()"),
m_mdr_amount : 0, m_amount: data?.amount || 0,
m_mdr_net : 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([ return result;
"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
}
module.exports = { module.exports = {
generateInvoice, generateInvoice,
@@ -250,5 +322,5 @@ module.exports = {
getPostingEt, getPostingEt,
writePaynentHistory, writePaynentHistory,
getParameterSetting, getParameterSetting,
getInvoice getInvoice,
}; };
-4
View File
@@ -170,7 +170,6 @@ const completingDataSalesInternal = async (ppn) => {
trx.t_d_sales_internal.is_complete is not true trx.t_d_sales_internal.is_complete is not true
AND trx.t_d_sales_internal.i_card_price > 0 AND trx.t_d_sales_internal.i_card_price > 0
AND trx.t_d_sales_internal.i_sales_invoice_internal is null AND trx.t_d_sales_internal.i_sales_invoice_internal is null
AND t_m_card_theme.c_status = 'A'
ORDER BY ORDER BY
trx.t_d_sales_internal.c_card_number, trx.t_d_sales_internal.c_card_number,
t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_type_code,
@@ -215,7 +214,6 @@ const completingDataSalesInternal = async (ppn) => {
AND trx.t_d_sales_internal.i_old_card_price > 0 AND trx.t_d_sales_internal.i_old_card_price > 0
AND trx.t_d_sales_internal.c_category IN ('N', 'W') AND trx.t_d_sales_internal.c_category IN ('N', 'W')
AND trx.t_d_sales_internal.i_sales_invoice_internal is null AND trx.t_d_sales_internal.i_sales_invoice_internal is null
AND t_m_card_theme.c_status = 'A'
ORDER BY ORDER BY
trx.t_d_sales_internal.c_old_card_number, trx.t_d_sales_internal.c_old_card_number,
t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_type_code,
@@ -277,7 +275,6 @@ const completingDataSalesNewCard = async (ppn) => {
trx.t_d_sales_internal.is_complete is not true trx.t_d_sales_internal.is_complete is not true
AND trx.t_d_sales_internal.i_card_price > 0 AND trx.t_d_sales_internal.i_card_price > 0
AND trx.t_d_sales_internal.i_sales_invoice_internal is null AND trx.t_d_sales_internal.i_sales_invoice_internal is null
AND t_m_card_theme.c_status = 'A'
ORDER BY ORDER BY
trx.t_d_sales_internal.c_card_number, trx.t_d_sales_internal.c_card_number,
t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_type_code,
@@ -323,7 +320,6 @@ const completingDataSalesOldCard = async (ppn) => {
AND trx.t_d_sales_internal.i_old_card_price > 0 AND trx.t_d_sales_internal.i_old_card_price > 0
AND trx.t_d_sales_internal.c_category IN ('N', 'W') AND trx.t_d_sales_internal.c_category IN ('N', 'W')
AND trx.t_d_sales_internal.i_sales_invoice_internal is null AND trx.t_d_sales_internal.i_sales_invoice_internal is null
AND t_m_card_theme.c_status = 'A'
ORDER BY ORDER BY
trx.t_d_sales_internal.c_old_card_number, trx.t_d_sales_internal.c_old_card_number,
t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_type_code,
+4 -4
View File
@@ -1,12 +1,12 @@
{ {
"name": "topuponline", "name": "onlinetopup-v1",
"version": "1.6.2", "version": "1.6.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "topuponline", "name": "onlinetopup-v1",
"version": "1.6.2", "version": "1.6.3",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.7.7", "axios": "^1.7.7",