mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 00:36:27 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 676553409b | |||
| 72a94891ed | |||
| 84be7587a8 | |||
| 8080b89c46 | |||
| 6dbd9b6246 | |||
| 5bafb81d8d | |||
| 1dd7860c0b | |||
| 1cf06d1fdd | |||
| be2cedc869 |
@@ -334,7 +334,12 @@ const getSalesKMT = async (trx, code, date, invoice) => {
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdsi.c_return_sap')
|
||||
.whereRaw(
|
||||
`tdskm.c_sales_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM payment.t_d_cash_in_detail cid
|
||||
WHERE cid.c_reservation_no = tdskm.c_sales_no
|
||||
AND cid.b_reversal IS NOT TRUE
|
||||
)`
|
||||
);
|
||||
|
||||
return res;
|
||||
@@ -364,7 +369,11 @@ const getSalesInternal = async (trx, code, date, invoice) => {
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdsi.c_return_sap_fi')
|
||||
.whereRaw(
|
||||
`tdskm.c_sales_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM payment.t_d_cash_in_detail cid
|
||||
WHERE cid.c_reservation_no = tdskm.c_sales_no
|
||||
AND cid.b_reversal IS NOT TRUE)`
|
||||
);
|
||||
|
||||
return res;
|
||||
@@ -394,7 +403,12 @@ const getTopUpCashlessInternal = async (trx, code, date, invoice) => {
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdsi.c_return_sap')
|
||||
.whereRaw(
|
||||
`tdskm.c_topup_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM payment.t_d_cash_in_detail cid
|
||||
WHERE cid.c_reservation_no = tdskm.c_topup_no
|
||||
AND cid.b_reversal IS NOT TRUE
|
||||
)`
|
||||
);
|
||||
|
||||
return res;
|
||||
@@ -583,7 +597,7 @@ const getPartnerReconSalesInternal = async (trx) => {
|
||||
'tmp.c_account_sales_revenue',
|
||||
'tmp.c_account_code_sales_ar',
|
||||
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
|
||||
THEN 'IP' ELSE 'OP'
|
||||
THEN 'IP' ELSE 'IP'
|
||||
END c_in_period`),
|
||||
])
|
||||
.from('trx.t_d_sales_internal AS tdskm')
|
||||
@@ -627,7 +641,7 @@ const getPartnerReconTopUpCashlessInternal = async (trx) => {
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup',
|
||||
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
|
||||
THEN 'IP' ELSE 'OP'
|
||||
THEN 'IP' ELSE 'IP'
|
||||
END c_in_period`),
|
||||
])
|
||||
.from('trx.t_d_topup_cashless_internal AS tdskm')
|
||||
|
||||
@@ -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,15 +137,10 @@ 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);
|
||||
@@ -156,11 +151,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: {},
|
||||
});
|
||||
}
|
||||
@@ -205,29 +200,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',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -235,7 +230,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',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -243,7 +238,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',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -260,49 +255,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,
|
||||
@@ -310,7 +305,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
||||
});
|
||||
|
||||
let xmlRequest = helper.generateXMLRequest(
|
||||
"ZFMCMS_FI_001",
|
||||
'ZFMCMS_FI_001',
|
||||
xmlHeader,
|
||||
xmlItem
|
||||
);
|
||||
@@ -343,8 +338,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: {},
|
||||
};
|
||||
}
|
||||
@@ -387,33 +382,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',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -422,7 +417,6 @@ const _postingInvoice = async (uniqueCode) => {
|
||||
password: credPassword.c_value,
|
||||
};
|
||||
|
||||
let errorCount = 0;
|
||||
for (let item of postingEt) {
|
||||
await knex.transaction(async (trx) => {
|
||||
let response = {};
|
||||
@@ -431,31 +425,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
|
||||
);
|
||||
@@ -477,13 +471,10 @@ 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: {},
|
||||
};
|
||||
}
|
||||
@@ -520,8 +511,6 @@ const _postingInvoice = async (uniqueCode) => {
|
||||
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
||||
);
|
||||
|
||||
collection.push({ error: errorCount });
|
||||
|
||||
collection.push(cms.invoice[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,19 +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 (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,
|
||||
@@ -27,293 +26,222 @@ 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
|
||||
}
|
||||
|
||||
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
|
||||
}}
|
||||
}
|
||||
|
||||
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];
|
||||
};
|
||||
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit'])
|
||||
|
||||
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 posting_et[0]
|
||||
|
||||
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") {
|
||||
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,
|
||||
});
|
||||
|
||||
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}')`
|
||||
);
|
||||
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
|
||||
})
|
||||
|
||||
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(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 {
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
// 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);
|
||||
} else {
|
||||
await writePaynentHistory(
|
||||
t_invoice[0],
|
||||
"SUCCESS TO RETRY SAP",
|
||||
118,
|
||||
trx
|
||||
);
|
||||
}
|
||||
} 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,
|
||||
});
|
||||
|
||||
// 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').update({
|
||||
c_return_sap: doc_number
|
||||
}, ['*'])
|
||||
.where({
|
||||
c_invoice_no: c_invoice_no
|
||||
});
|
||||
|
||||
if (posting) {
|
||||
await writePaynentHistory(
|
||||
t_invoice[0],
|
||||
`SUCCESS WITH SAP ERR: ${resSAP.message}`,
|
||||
102,
|
||||
trx
|
||||
);
|
||||
|
||||
// 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)
|
||||
} else {
|
||||
await writePaynentHistory(
|
||||
t_invoice[0],
|
||||
`FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,
|
||||
118,
|
||||
trx
|
||||
);
|
||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
||||
}
|
||||
|
||||
}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
|
||||
})
|
||||
|
||||
// update invoice
|
||||
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)
|
||||
} else {
|
||||
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,
|
||||
},
|
||||
["i_log_name", "c_note"]
|
||||
);
|
||||
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
|
||||
|
||||
return result;
|
||||
};
|
||||
}, ['i_log_name', 'c_note'])
|
||||
|
||||
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
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
const getInvoice = async (code, trx) => {
|
||||
const result = await trx("payment.t_d_invoice")
|
||||
.where("c_invoice_no", "=", code)
|
||||
.first();
|
||||
const getParameterSetting = async(trx, code) => {
|
||||
|
||||
return result;
|
||||
};
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateInvoice,
|
||||
@@ -322,5 +250,5 @@ module.exports = {
|
||||
getPostingEt,
|
||||
writePaynentHistory,
|
||||
getParameterSetting,
|
||||
getInvoice,
|
||||
};
|
||||
getInvoice
|
||||
};
|
||||
@@ -108,7 +108,14 @@ const getReservationPendingV2 = (cardNumber, time, flag) => {
|
||||
.whereIn('c_status', ['P', 'I'])
|
||||
// .where("d_expired", ">=", time)
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud tdf
|
||||
WHERE tdf.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND tdf.c_status = 'A'
|
||||
AND tdf.c_card_number = ?
|
||||
)`,
|
||||
[cardNumber]
|
||||
)
|
||||
.where(function () {
|
||||
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
||||
@@ -170,7 +177,14 @@ const getReservationPendingWithFlagCounterV2 = (cardNumber, time, flag) => {
|
||||
.whereIn('c_status', ['P', 'I'])
|
||||
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud tdf
|
||||
WHERE tdf.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND tdf.c_status = 'A'
|
||||
AND tdf.c_card_number = ?
|
||||
)`,
|
||||
[cardNumber]
|
||||
)
|
||||
// .where("d_expired", ">=", time)
|
||||
.where('c_flag', '!=', '-1');
|
||||
@@ -198,7 +212,14 @@ const getReservationPendingWithFlagV2 = (cardNumber, time) => {
|
||||
.where('c_card_number', cardNumber)
|
||||
.whereIn('c_status', ['P', 'I'])
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud tdf
|
||||
WHERE tdf.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND tdf.c_status = 'A'
|
||||
AND tdf.c_card_number = ?
|
||||
)`,
|
||||
[cardNumber]
|
||||
)
|
||||
.whereNotNull('c_flag_code');
|
||||
return result;
|
||||
@@ -727,7 +748,7 @@ const updateReservationAndLoadingBalance = async (
|
||||
})
|
||||
.then(() => {
|
||||
// winston.logger.debug(`${reservationNumber} commit transaction`);
|
||||
trx.commit();
|
||||
return trx.commit();
|
||||
})
|
||||
.catch((error) => {
|
||||
winston.logger.debug(
|
||||
@@ -876,17 +897,6 @@ const getReservationPendingWithoutFraud = (
|
||||
reservationNumber = []
|
||||
) => {
|
||||
if (reservationNumber.length > 0) {
|
||||
let rsv = '';
|
||||
if (reservationNumber.length > 0) {
|
||||
for (let index = 0; index < reservationNumber.length; index++) {
|
||||
if (index > 0) {
|
||||
rsv = rsv + ',';
|
||||
}
|
||||
|
||||
rsv = rsv + "'" + reservationNumber[index] + "'";
|
||||
}
|
||||
}
|
||||
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'trx.t_d_reservation_balance.i_reservation_amount',
|
||||
@@ -896,7 +906,14 @@ const getReservationPendingWithoutFraud = (
|
||||
.where('trx.t_d_reservation_balance.c_card_number', cardNumber)
|
||||
.whereIn('trx.t_d_reservation_balance.c_status', ['P', 'I'])
|
||||
.whereRaw(
|
||||
`trx.t_d_reservation_balance.c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud WHERE trx.t_d_fraud.c_status = 'A' AND trx.t_d_fraud.c_reservation_no IN (${rsv}))`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud f
|
||||
WHERE f.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND f.c_status = 'A'
|
||||
AND f.c_reservation_no = ANY(ARRAY[?])
|
||||
)`,
|
||||
[reservationNumber]
|
||||
)
|
||||
// .where("d_expired", ">=", time)
|
||||
.where(function () {
|
||||
@@ -946,17 +963,6 @@ const getLastHistory = (cardNumber) => {
|
||||
|
||||
// INSERT FRAUD TRANSACTION
|
||||
const insertFraudTransaction = (reservationNumber) => {
|
||||
let rsv = '';
|
||||
if (reservationNumber.length > 0) {
|
||||
for (let index = 0; index < reservationNumber.length; index++) {
|
||||
if (index > 0) {
|
||||
rsv = rsv + ',';
|
||||
}
|
||||
|
||||
rsv = rsv + "'" + reservationNumber[index] + "'";
|
||||
}
|
||||
}
|
||||
|
||||
let result = knex
|
||||
.into(
|
||||
knex.raw(
|
||||
@@ -1013,7 +1019,14 @@ const insertFraudTransaction = (reservationNumber) => {
|
||||
reservationNumber
|
||||
)
|
||||
.whereRaw(
|
||||
`trx.t_d_reservation_balance.c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud WHERE trx.t_d_fraud.c_status = 'A' AND trx.t_d_fraud.c_reservation_no IN (${rsv}))`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud f
|
||||
WHERE f.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND f.c_status = 'A'
|
||||
AND f.c_reservation_no = ANY(ARRAY[?])
|
||||
)`,
|
||||
[reservationNumber]
|
||||
);
|
||||
});
|
||||
return result;
|
||||
@@ -1128,7 +1141,7 @@ const updateReservationAndInsertLoadingBalance = async (
|
||||
})
|
||||
.whereIn('c_reservation_no', reservationNumber);
|
||||
})
|
||||
.then(trx.commit)
|
||||
.then(() => trx.commit())
|
||||
.catch(trx.rollback);
|
||||
})
|
||||
.then((result) => {
|
||||
|
||||
@@ -170,6 +170,7 @@ const completingDataSalesInternal = async (ppn) => {
|
||||
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_sales_invoice_internal is null
|
||||
AND t_m_card_theme.c_status = 'A'
|
||||
ORDER BY
|
||||
trx.t_d_sales_internal.c_card_number,
|
||||
t_m_card_theme.c_card_type_code,
|
||||
@@ -214,6 +215,7 @@ const completingDataSalesInternal = async (ppn) => {
|
||||
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.i_sales_invoice_internal is null
|
||||
AND t_m_card_theme.c_status = 'A'
|
||||
ORDER BY
|
||||
trx.t_d_sales_internal.c_old_card_number,
|
||||
t_m_card_theme.c_card_type_code,
|
||||
@@ -275,6 +277,7 @@ const completingDataSalesNewCard = async (ppn) => {
|
||||
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_sales_invoice_internal is null
|
||||
AND t_m_card_theme.c_status = 'A'
|
||||
ORDER BY
|
||||
trx.t_d_sales_internal.c_card_number,
|
||||
t_m_card_theme.c_card_type_code,
|
||||
@@ -320,6 +323,7 @@ const completingDataSalesOldCard = async (ppn) => {
|
||||
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.i_sales_invoice_internal is null
|
||||
AND t_m_card_theme.c_status = 'A'
|
||||
ORDER BY
|
||||
trx.t_d_sales_internal.c_old_card_number,
|
||||
t_m_card_theme.c_card_type_code,
|
||||
|
||||
@@ -651,7 +651,7 @@ const reservationValidate = async (req, res) => {
|
||||
let totalReservationPending =
|
||||
getReservationPending.total_nominal_reservation > 0
|
||||
? parseInt(getReservationPending.total_nominal_reservation) +
|
||||
parseInt(amount)
|
||||
parseInt(amount)
|
||||
: parseInt(amount);
|
||||
|
||||
// jika total amount reservasi melebihi maksimum reservasi sesuai dengan parameter setting di sistem CMS maka transaksi akan di tolak
|
||||
@@ -1254,7 +1254,7 @@ const reservation = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
@@ -1595,7 +1595,7 @@ const reservation = async (req, res) => {
|
||||
let totalReservationPending =
|
||||
getReservationPending.total_nominal_reservation > 0
|
||||
? parseInt(getReservationPending.total_nominal_reservation) +
|
||||
parseInt(amount)
|
||||
parseInt(amount)
|
||||
: parseInt(amount);
|
||||
|
||||
// jika total amount reservasi melebihi maksimum reservasi sesuai dengan parameter setting di sistem CMS maka transaksi akan di tolak
|
||||
@@ -1712,11 +1712,11 @@ const reservation = async (req, res) => {
|
||||
// create log
|
||||
winston.logger.error(`server is busy. please try again.`);
|
||||
|
||||
return {
|
||||
return res.status(200).json({
|
||||
code: '500',
|
||||
message: 'server is busy. please try again.',
|
||||
data: {},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
maxLoop++;
|
||||
@@ -1841,9 +1841,8 @@ const reservation = async (req, res) => {
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: null,
|
||||
c_note: `RESERVED BALANCE ${amount} FROM ${
|
||||
getPartner ? getPartner.partner_name : null
|
||||
} SUCCESSFULLY`,
|
||||
c_note: `RESERVED BALANCE ${amount} FROM ${getPartner ? getPartner.partner_name : null
|
||||
} SUCCESSFULLY`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
@@ -1923,7 +1922,7 @@ const reservationV2 = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
@@ -1971,7 +1970,7 @@ const reservationV2 = async (req, res) => {
|
||||
|
||||
try {
|
||||
reservationData = helper.decryptText(reservation_data);
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
|
||||
if (!reservationData) {
|
||||
result = {
|
||||
@@ -2547,11 +2546,11 @@ const reservationV2 = async (req, res) => {
|
||||
// create log
|
||||
winston.logger.error(`server is busy. please try again.`);
|
||||
|
||||
return {
|
||||
return res.status(200).json({
|
||||
code: '500',
|
||||
message: 'server is busy. please try again.',
|
||||
data: {},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
maxLoop++;
|
||||
@@ -2678,9 +2677,8 @@ const reservationV2 = async (req, res) => {
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: null,
|
||||
c_note: `RESERVED BALANCE ${amount} FROM ${
|
||||
getPartner ? getPartner.partner_name : null
|
||||
} SUCCESSFULLY`,
|
||||
c_note: `RESERVED BALANCE ${amount} FROM ${getPartner ? getPartner.partner_name : null
|
||||
} SUCCESSFULLY`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
@@ -2884,8 +2882,8 @@ const cancelReservationValidate = async (req, res) => {
|
||||
// jika status dari reservation number yang di request adalah X = Deleted, maka proses cancel reservasi akan di tolak
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
@@ -3075,8 +3073,8 @@ const cancelReservation = async (req, res) => {
|
||||
} else if (getReservationCanBeCanceled.c_status == 'X') {
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
@@ -3176,9 +3174,8 @@ const cancelReservation = async (req, res) => {
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: getReservationCanBeCanceled,
|
||||
c_note: `CANCEL RESERVE BALANCE ${
|
||||
getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_note: `CANCEL RESERVE BALANCE ${getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
@@ -3329,6 +3326,14 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryListByRefNumber(ref_no, show_complete_data);
|
||||
|
||||
if (!result) {
|
||||
return res.status(200).json({
|
||||
code: '414',
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
} else if (req.query.search === 'load-balance-number') {
|
||||
// validation parameter inquiry
|
||||
if (!load_balance_number) {
|
||||
@@ -3344,6 +3349,14 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
load_balance_number,
|
||||
show_complete_data
|
||||
);
|
||||
|
||||
if (result.length < 1) {
|
||||
return res.status(200).json({
|
||||
code: '414',
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// validation parameter inquiry
|
||||
if (!reservation_number) {
|
||||
@@ -3359,14 +3372,14 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
reservation_number,
|
||||
show_complete_data
|
||||
);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return res.status(200).json({
|
||||
code: '414',
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
if (!result) {
|
||||
return res.status(200).json({
|
||||
code: '414',
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res.json({
|
||||
@@ -3722,8 +3735,8 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
// jika status dari reservation number yang di request adalah X = Deleted, maka proses cancel reservasi akan di tolak
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
@@ -3879,7 +3892,7 @@ const cancelReservationV2 = async (req, res) => {
|
||||
|
||||
try {
|
||||
cancelReservationData = helper.decryptText(cancel_reservation_data);
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
|
||||
if (!cancelReservationData) {
|
||||
result = {
|
||||
@@ -3989,8 +4002,8 @@ const cancelReservationV2 = async (req, res) => {
|
||||
} else if (getReservationCanBeCanceled.c_status == 'X') {
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
@@ -4093,9 +4106,8 @@ const cancelReservationV2 = async (req, res) => {
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: getReservationCanBeCanceled,
|
||||
c_note: `CANCEL RESERVE BALANCE ${
|
||||
getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_note: `CANCEL RESERVE BALANCE ${getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
@@ -4249,8 +4261,8 @@ const cancelReservationV2_1 = async (req, res) => {
|
||||
// jika status dari reservation number yang di request adalah X = Deleted, maka proses cancel reservasi akan di tolak
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
@@ -4376,9 +4388,8 @@ const cancelReservationV2_1 = async (req, res) => {
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: getReservationCanBeCanceled,
|
||||
c_note: `CANCEL RESERVE BALANCE ${
|
||||
getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_note: `CANCEL RESERVE BALANCE ${getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
|
||||
@@ -152,7 +152,7 @@ const getMaxReservation = () => {
|
||||
};
|
||||
|
||||
// INQUIRY BY RESERVATION NUMBER
|
||||
let inquiryByReservationNumber = (reservationNumber, show_complete_data) => {
|
||||
const inquiryByReservationNumber = (reservationNumber, show_complete_data) => {
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
if (show_complete_data === true) {
|
||||
result.select(
|
||||
@@ -198,14 +198,14 @@ let inquiryByReservationNumber = (reservationNumber, show_complete_data) => {
|
||||
);
|
||||
});
|
||||
|
||||
result
|
||||
result = result
|
||||
.where('trx.t_d_reservation_balance.c_reservation_no', reservationNumber)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INQUIRY LIST RESERVATION
|
||||
let inquiryListReservation = (partnerID, startDate, endDate) => {
|
||||
const inquiryListReservation = (partnerID, startDate, endDate) => {
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
@@ -253,7 +253,7 @@ let inquiryListReservation = (partnerID, startDate, endDate) => {
|
||||
};
|
||||
|
||||
// INQUIRY BY CARD NUMBER
|
||||
let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
||||
const inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
@@ -286,7 +286,14 @@ const getReservationPending = (cardNumber, time) => {
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'P')
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud f
|
||||
WHERE f.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND f.c_status = 'A'
|
||||
AND f.c_card_number = ?
|
||||
)`,
|
||||
[cardNumber]
|
||||
)
|
||||
// .where("d_expired", ">=", time)
|
||||
.first();
|
||||
@@ -310,7 +317,14 @@ const getReservationPendingV2 = (cardNumber, time) => {
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'P')
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
`NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM trx.t_d_fraud f
|
||||
WHERE f.c_reservation_no = trx.t_d_reservation_balance.c_reservation_no
|
||||
AND f.c_status = 'A'
|
||||
AND f.c_card_number = ?
|
||||
)`,
|
||||
[cardNumber]
|
||||
);
|
||||
|
||||
return result;
|
||||
@@ -425,7 +439,7 @@ const deleteReservationNumberValidate = (reservationNumber) => {
|
||||
};
|
||||
|
||||
// INQUIRY BY REF NUMBER
|
||||
let inquiryListByRefNumber = (refNumber, show_complete_data) => {
|
||||
const inquiryListByRefNumber = (refNumber, show_complete_data) => {
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
if (show_complete_data === true) {
|
||||
result.select(
|
||||
@@ -469,7 +483,7 @@ let inquiryListByRefNumber = (refNumber, show_complete_data) => {
|
||||
);
|
||||
});
|
||||
|
||||
result.where('trx.t_d_reservation_balance.c_ref_no', refNumber).first();
|
||||
result = result.where('trx.t_d_reservation_balance.c_ref_no', refNumber).first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Generated
+4
-4
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "onlinetopup-v1",
|
||||
"version": "1.6.3",
|
||||
"name": "topuponline",
|
||||
"version": "1.6.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "onlinetopup-v1",
|
||||
"version": "1.6.3",
|
||||
"name": "topuponline",
|
||||
"version": "1.6.2",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7",
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "onlinetopup-v1",
|
||||
"version": "1.6.3",
|
||||
"description": "update packages",
|
||||
"version": "1.6.5",
|
||||
"description": "optimize query and coding enhancement",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon index",
|
||||
|
||||
Reference in New Issue
Block a user