169 lines
6.1 KiB
JavaScript
169 lines
6.1 KiB
JavaScript
function csrf_token()
|
|
{
|
|
return document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
|
|
}
|
|
|
|
function safeParse(data)
|
|
{
|
|
return (typeof data === 'string') ? JSON.parse(data) : data;
|
|
}
|
|
|
|
async function fetchLoanRemaining(containerID, passport_serie, passport_id, account_number) {
|
|
if (! passport_serie || ! passport_id || ! account_number) {
|
|
Nova.error('Maglumat ýetmezçiligi bar');
|
|
return;
|
|
}
|
|
|
|
let cardHistoryDetailContainer = document.getElementById(containerID);
|
|
|
|
let formData = new FormData();
|
|
formData.append('passport_serie', passport_serie);
|
|
formData.append('passport_id', passport_id);
|
|
formData.append('account_number', account_number);
|
|
|
|
Nova.$progress.start()
|
|
|
|
Nova.request().post('/api/fetch-loan-remaining', formData).then(response => {
|
|
let result = safeParse(response.data);
|
|
console.log(result)
|
|
|
|
if (result.errCode != 0) {
|
|
Nova.error(result.message)
|
|
|
|
cardHistoryDetailContainer.innerHTML = `
|
|
<h3><strong>${result.message}</strong></h3>
|
|
`;
|
|
|
|
return;
|
|
}
|
|
|
|
cardHistoryDetailContainer.innerHTML = `
|
|
<h4>Şahamça: <strong>${result.branchName}</strong></h4>
|
|
<h4>Müşderi: <strong>${result.clientName}</strong></h4>
|
|
<h4 class="mb-4">Şertnama belgisi: <strong>${result.docNum}</strong></h4>
|
|
|
|
<h4>Jemi karzyň möçberi: <strong>${result.docSum}</strong></h4>
|
|
|
|
<h4>Karz boýunça jemi galyndy: <strong>${result.balans}</strong></h4>
|
|
<h4>Hasaplama göterim (şu aý üçin): <strong>${result.percentBalance}</strong></h4>
|
|
<h4>Hasaplanan esasy bergi (şu aý üçin): <strong>${result.docMonthSum}</strong></h4>
|
|
|
|
<h4>Jemi tölenen möçberi: <strong>${result.docPayed}</strong></h4>
|
|
`;
|
|
})
|
|
.catch(error => console.log('error', error))
|
|
.finally(() => {
|
|
Nova.$progress.done()
|
|
});
|
|
}
|
|
|
|
async function fetchLoanHistory(containerID, passport_serie, passport_id) {
|
|
if (! passport_serie || ! passport_id) {
|
|
Nova.error('Maglumat ýetmezçiligi bar');
|
|
return;
|
|
}
|
|
|
|
let cardHistoryDetailContainer = document.getElementById(containerID);
|
|
|
|
let formData = new FormData();
|
|
formData.append('passport_serie', passport_serie);
|
|
formData.append('passport_id', passport_id);
|
|
|
|
Nova.$progress.start()
|
|
|
|
Nova.request().post('/api/fetch-loan-history', formData).then(response => {
|
|
let result = (typeof response.data === 'string') ? JSON.parse(response.data) : response.data;
|
|
|
|
let recipients = Array.from(result.recipient);
|
|
|
|
if (recipients.length < 1) {
|
|
Nova.error('Karz taryhy ýok')
|
|
cardHistoryDetailContainer.innerHTML = `<strong><h3>Karz taryhy ýok</h3></strong>`;
|
|
|
|
return;
|
|
}
|
|
|
|
cardHistoryDetailContainer.innerHTML = `
|
|
<h4>Müşderi: <strong>${recipients[0].MUSDERI_DOLY_ADY}</strong></h4>
|
|
|
|
<p>
|
|
<ul>
|
|
${recipients.map(recipient => {
|
|
return `<li style="background: #a3c1f5;color: black;" class="p-3 relative rounded-lg">
|
|
Bellik: <strong>${recipient.BELLIK}</strong> <br />
|
|
Möçberi: <strong>${recipient.MOCBERI}</strong> <br />
|
|
Karz berilen senesi: <strong>${recipient.KARZ_BERLEN_SENESI}</strong> <br />
|
|
Karz sonky senesi: <strong>${recipient.KARZ_SONKY_SENESI}</strong> <br />
|
|
Karz göterimi: <strong>${recipient.KARZ_GOTERIMI}%</strong> <br />
|
|
</li>`;
|
|
})}
|
|
</ul>
|
|
</p>
|
|
`;
|
|
})
|
|
.catch(error => console.log('error', error))
|
|
.finally(() => {
|
|
Nova.$progress.done()
|
|
});
|
|
}
|
|
|
|
async function fetchCardHistory(passport_serie, passport_id, card_number, card_expiry_date, containerID) {
|
|
if (! passport_serie || ! passport_id || ! card_number || ! card_expiry_date) {
|
|
Nova.error('Maglumat ýetmezçiligi bar');
|
|
return;
|
|
}
|
|
|
|
let cardHistoryDetailContainer = document.getElementById(containerID);
|
|
|
|
let formData = new FormData();
|
|
formData.append('passport_serie', passport_serie);
|
|
formData.append('passport_id', passport_id);
|
|
formData.append('card_number', card_number);
|
|
formData.append('card_expiry_date', card_expiry_date);
|
|
|
|
Nova.$progress.start()
|
|
|
|
Nova.request().post('/api/fetch-card-history', formData).then(response => {
|
|
let result = (typeof response.data === 'string') ? JSON.parse(response.data) : response.data;
|
|
|
|
if (result.errCode != 0) {
|
|
Nova.error(result.message)
|
|
|
|
cardHistoryDetailContainer.innerHTML = `
|
|
<h3><strong>${result.message}</strong></h3>
|
|
`;
|
|
|
|
return;
|
|
}
|
|
|
|
let insideTemplate = ``;
|
|
Array.from(result.transactions).map(transaction => {
|
|
insideTemplate += `<li style="background: #a3c1f5;color: black;padding-top: 2.4em;" class="p-3 relative rounded-lg mb-2">
|
|
<strong>${transaction['actionName']}</strong> <strong>${transaction['opersum']}</strong> <strong>${transaction['currency']}</strong>
|
|
|
|
<strong style="top: 0; right: 0;" class="absolute p-2">${transaction['opername']}</strong>
|
|
|
|
<p><strong>${
|
|
new Date(transaction['trandate']).toLocaleDateString('en-GB', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
}).replaceAll('/', '.')
|
|
}</strong></p>
|
|
</li>`
|
|
})
|
|
|
|
cardHistoryDetailContainer.innerHTML = `
|
|
<h4>Müşderi: <strong>${result.clientName}</strong></h4>
|
|
<h4>Şahamça: <strong>${result.depName}</strong></h4>
|
|
<h4 class="mb-4">Şertnama belgisi: <strong>${result.cardAccountNumber}</strong></h4>
|
|
|
|
<p><ul>${insideTemplate}</ul></p>
|
|
`;
|
|
})
|
|
.catch(error => console.log('error', error))
|
|
.finally(() => {
|
|
Nova.$progress.done()
|
|
});
|
|
}
|