<script>
$(document).ready(function() {
$.ajax({
url: 'url_api',
type: 'GET',
contentType: false,
processData: false,
success: function(response) {
console.log('Success:', response);
FormUtil.getField("nama_bank_debitur_wiraswasta").val(response.customer_name);
FormUtil.getField("norek_debitur_wiraswasta").val(response.rek);
//(already fine for this in top)
let monthlyTotals = {};
// Iterate over transactions to accumulate monthly totals
response.transactions.forEach(transaction => {
let month = transaction.date.split('/')[1];
// Initialize totals for the month if not already
if (!monthlyTotals[month]) {
monthlyTotals[month] = { balance_total: 0, debet_total: 0, credit_total: 0 };
}
if (transaction.balance) {
monthlyTotals[month].balance_total += parseFloat(transaction.balance.replace(/,/g, ''));
}
if (transaction.debit) {
monthlyTotals[month].debet_total += parseFloat(transaction.debit.replace(/,/g, ''));
}
if (transaction.credit) {
monthlyTotals[month].credit_total += parseFloat(transaction.credit.replace(/,/g, ''));
}
});
// this is for id column
let formattedResults = [];
for (let month in monthlyTotals) {
formattedResults.push({
bulan: month,
mutasi_kredit: monthlyTotals[month].balance_total,
rata_rata_saldo: monthlyTotals[month].debet_total,
saldo_akhir_bulan: monthlyTotals[month].credit_total
});
}
let jsonResult = JSON.stringify(formattedResults);
console.log('json total : ', jsonResult);
// debitur is my id grid ( how i can set my json to grid )
FormUtil.getField("debitur").val(jsonResult);
},
error: function (xhr, status, error) {
console.error('Error:', error);
}
});
});
</script>
this is example grid
and this example value on console log json total
so how i can set jsonResult to my grid with id = "debitur".
and last important. it can more than 2 for json result
this is my example code
this is example grid
and this example value on console log json total
so how i can set jsonResult to my grid with id = "debitur".
and last important. it can more than 2 for json result