mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 10:26:27 +00:00
77 lines
2.1 KiB
JavaScript
77 lines
2.1 KiB
JavaScript
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
|
const generateInvoice = (invoiceDate, trx) => {
|
|
|
|
let result = trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}')`))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
const insertPostingEt = (invoice, trx) => {
|
|
console.log("invoice : ", invoice)
|
|
let type = ['S', 'H']
|
|
let et = []
|
|
let posting_et = []
|
|
type.forEach((item, index) => {
|
|
let data = {
|
|
file_name: invoice.file_name,
|
|
tcode: invoice.tcode,
|
|
reversal: invoice.reversal,
|
|
doc_type: invoice.doc_type,
|
|
fiscal_year: invoice.fisc_year,
|
|
posting_date: invoice.posting_date,
|
|
doc_date: invoice.doc_date,
|
|
no_dok: invoice.c_invoice_no,
|
|
reference: invoice.c_invoice_no,
|
|
amount: invoice.amount,
|
|
ba: invoice.ba,
|
|
indeks: (index+1),
|
|
totalidx: type.length,
|
|
doc_header_text: `POSTING INVOICE CMS ${invoice.c_invoice_no} - ${invoice.doc_header_text}`,
|
|
}
|
|
|
|
if(item == 'H'){
|
|
data = {...data, ...{
|
|
text: `DEBIT INVOICE CMS ${invoice.c_invoice_no} - ${invoice.doc_header_text}`,
|
|
debit_kredit: item,
|
|
account: invoice.c_account_topup,
|
|
}}
|
|
}else{
|
|
data = {...data, ...{
|
|
text: `KREDIT INVOICE CMS ${invoice.c_invoice_no} - ${invoice.doc_header_text}`,
|
|
debit_kredit: item,
|
|
customer: invoice.c_account_code_topup
|
|
}}
|
|
}
|
|
|
|
et.push(data)
|
|
|
|
});
|
|
|
|
posting_et = trx('public.posting_et').insert(et, ['no_dok'])
|
|
|
|
return posting_et
|
|
|
|
}
|
|
|
|
const setReturnSAP = (invoice, resSAP, trx) => {
|
|
|
|
// update invoice
|
|
trx('trx.t_d_load_balance').update({
|
|
c_return_sap: resSAP.E_MATERIALDOCUMENT
|
|
}, ['c_load_balance'])
|
|
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = ${invoice.c_invoice_no})`)
|
|
|
|
// update load balance
|
|
trx('trx.t_d_load_balance').update({
|
|
c_return_sap: resSAP.E_MATERIALDOCUMENT
|
|
})
|
|
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = ${invoice.c_invoice_no})`)
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
generateInvoice,
|
|
insertPostingEt,
|
|
setReturnSAP
|
|
}; |