mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:46:28 +00:00
rollback
This commit is contained in:
@@ -180,59 +180,34 @@ const setReturnSAP = async (invoice, resSAP, trx, posting = false, c_invoice_no)
|
||||
let t_invoice = {}
|
||||
let t_load_balance = {}
|
||||
let posting_et = {}
|
||||
const paymentRequestSql = `
|
||||
SELECT c_load_balance_no
|
||||
FROM payment.t_d_payment_request_topup_online
|
||||
WHERE c_payment = ?
|
||||
`;
|
||||
|
||||
if (resSAP.type == 'S') {
|
||||
// update invoice
|
||||
t_invoice = await trx.raw(
|
||||
`
|
||||
UPDATE payment.t_d_invoice
|
||||
SET c_return_sap = ?
|
||||
WHERE c_invoice_no = ?
|
||||
RETURNING *
|
||||
`,
|
||||
[resSAP.data.E_DOCUMENTNUMBER, 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.raw(
|
||||
`
|
||||
UPDATE trx.t_d_load_balance
|
||||
SET c_return_sap = ?
|
||||
WHERE c_load_balance_no IN (
|
||||
${paymentRequestSql}
|
||||
)
|
||||
RETURNING c_load_balance_no, c_return_sap
|
||||
`,
|
||||
[resSAP.data.E_DOCUMENTNUMBER, 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.raw(
|
||||
`
|
||||
UPDATE public.posting_et
|
||||
SET pos_status = 0,
|
||||
status0 = ?,
|
||||
no_doksap = ?,
|
||||
status1 = ?
|
||||
WHERE no_dok = ?
|
||||
RETURNING file_name, status0
|
||||
`,
|
||||
[
|
||||
resSAP.type,
|
||||
resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
||||
resSAP.message ? resSAP.message : null,
|
||||
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.rows?.[0] || t_invoice[0], "SUCCESSFULLY", 102, trx)
|
||||
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
|
||||
} else {
|
||||
await writePaynentHistory(t_invoice.rows?.[0] || t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -243,84 +218,60 @@ const setReturnSAP = async (invoice, resSAP, trx, posting = false, c_invoice_no)
|
||||
if (result.includes("ALREADY")) {
|
||||
let result = text.toUpperCase().split('-');
|
||||
let doc_number = result[1].trim().split(" ")[0]
|
||||
posting_et = await trx.raw(
|
||||
`
|
||||
UPDATE public.posting_et
|
||||
SET pos_status = 0,
|
||||
status0 = 'S',
|
||||
no_doksap = ?,
|
||||
status1 = ?
|
||||
WHERE no_dok = ?
|
||||
RETURNING file_name, status0
|
||||
`,
|
||||
[doc_number, resSAP.message ? resSAP.message : null, c_invoice_no]
|
||||
);
|
||||
// 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
|
||||
})
|
||||
|
||||
// update invoice
|
||||
t_invoice = await trx.raw(
|
||||
`
|
||||
UPDATE payment.t_d_invoice
|
||||
SET c_return_sap = ?
|
||||
WHERE c_invoice_no = ?
|
||||
RETURNING *
|
||||
`,
|
||||
[doc_number, 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.raw(
|
||||
`
|
||||
UPDATE trx.t_d_load_balance
|
||||
SET c_return_sap = ?
|
||||
WHERE c_load_balance_no IN (
|
||||
${paymentRequestSql}
|
||||
)
|
||||
RETURNING c_load_balance_no, c_return_sap
|
||||
`,
|
||||
[doc_number, c_invoice_no]
|
||||
);
|
||||
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.rows?.[0] || t_invoice[0], "SUCCESSFULLY", 102, trx)
|
||||
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
|
||||
} else {
|
||||
await writePaynentHistory(t_invoice.rows?.[0] || t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
||||
}
|
||||
|
||||
} else {
|
||||
// update posting et
|
||||
posting_et = await trx.raw(
|
||||
`
|
||||
UPDATE public.posting_et
|
||||
SET pos_status = ?,
|
||||
status0 = ?,
|
||||
no_doksap = ?,
|
||||
status1 = ?
|
||||
WHERE no_dok = ?
|
||||
RETURNING file_name, status0
|
||||
`,
|
||||
[
|
||||
resSAP.type == 'S' ? 0 : 3,
|
||||
resSAP.type,
|
||||
resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
||||
resSAP.message ? resSAP.message : null,
|
||||
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.raw(
|
||||
`
|
||||
SELECT *
|
||||
FROM payment.t_d_invoice
|
||||
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.rows?.[0] || 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 {
|
||||
await writePaynentHistory(t_invoice.rows?.[0] || 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user