Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Scenario 3: EMI Form

  • Last UpdatedJun 25, 2024
  • 2 minute read

EMI (Equated Monthly Installment) form scenario shows how you can use scripts to automatically add line items on a Base Form container on data change event.

Requirements

An EMI form which:

  • captures information about principal, rate, and tenure.

  • automatically calculates the EMI amount, interest amount, principal reduction, and balance due using the EMI formula and displays it as a line item for each installment number.

EMI Formula

EMI = (P*r) (1+r)^n / (1+r)^n - 1

where:

 P = Principal (amount of loan).

 r = Rate of interest per installment period.

 n = Number of installments in the tenure.

Design

  1. Create a form.

  2. Add three Number controls on the form to capture principal, rate, and tenure.

  3. Add a Base Form container on the form and set the Display Mode to Grid, to create line items.

  4. Add five Text controls on the Base Form container to display the installment number, EMI amount, interest amount, principal reduction, and balance due, as a line item.

Scripts

Code the script as follows for the On Data Change property of the Tenure control to automatically calculate the EMI and display the line items:

var tenure =control.findByXmlNode("Tenure").value;

var interest = control.findByXmlNode("Rate").value;

var principal =control.findByXmlNode("Principal").value;

if (principal === 0 || interest === 0 || tenure === 0)

{

return;

}

var grid=control.findByXmlNode("Details");

var principal1= parseFloat(principal);

var interest1 = parseFloat(interest );

var tenure1 = parseFloat(tenure );

var ipm =parseFloat(parseFloat(interest1) / parseFloat("1200.0"));

var EMId =((principal1 * ipm) * parseFloat(Math.pow(parseFloat(ipm + 1), tenure1))) / parseFloat(parseFloat((Math.pow(parseFloat(ipm+1), tenure1))) - 1);

var EMI =Math.round(EMId);

var count=grid.records().length;

for (i=count; i>0; i--)

{

grid.removeAt(i);

}

for (j=0; j<tenure; j++)

{

var newRow=grid.addRecordToBottom();

newRow.findByXmlNode("InstallmentNumber").value = j+1;

if (j===0)

{

newRow.findByXmlNode("PrincipalReduction").value = Math.round((EMI-(principal/100)));

newRow.findByXmlNode("EMIAmount").value =EMI;

newRow.findByXmlNode("InterestAmount").value = Math.round((principal)/100);

newRow.findByXmlNode("BalanceDue").value = Math.round(principal - (EMI-(principal/100)));

}

else

{

var newprincipal=grid.records()[j-1].findByXmlNode("BalanceDue").value;

newRow.findByXmlNode("EMIAmount").value =EMI;

newRow.findByXmlNode("PrincipalReduction").value =Math.round((EMI-(newprincipal/100)));

newRow.findByXmlNode("InterestAmount").value =Math.round((newprincipal)/100);

newRow.findByXmlNode("BalanceDue").value = Math.round(newprincipal - (EMI-(newprincipal/100)));

}

}

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in