How to Sum Values in child table when Adjacent checkBox field is checked

Hello guys.
I really appreciate your previous assistance with my ERPNext challenges. I seriously need your help to solve the following challenge.
i have a child table with amount column(currency type), paid column(checkbox type).
also, there is AmountDue field and AmountPaid field on standard doctype.

i want to calculate AmountPaid by adding amount values when ever adjacent paid checkbox is checked; below is the script i have that is only calculating AmountDue when adjacent paid checkbox field is unchecked.
//Payment Instalments

function compileInstallments(frm) {
let amountDue = 0;
let amountPaid = 0;

for (let i = 0; i < frm.doc.instalments.length; i++) {
const item = frm.doc.instalments[i];

let paidCheckBox = item.paid_check;

if (paidCheckBox.checked == true) {
    console.log(paidCheckBox)
  amountPaid += item.amount;
} else {
  amountDue += item.amount;
}

}
// Update amount_paid field
frm.set_value(“amount_paid”, amountPaid);
refresh_field(“amount_paid”);

// Update amount_due field
frm.set_value(“amount_due”, amountDue);
refresh_field(“amount_due”);
}

frappe.ui.form.on(“Memo Instalment Payment”, {
//sum the amount due & amount paid

amount: function (frm, cdt, cdn) {
let d = locals[cdt][cdn];
compileInstallments(frm);

},

//Remove from Instalment payment
instalments_remove: function (frm, cdt, cdn) {
compileInstallments(frm);
},
});