Custom Invoice form template with sum the value from repeatable group using JavaScript event onchange.

Important!: Remove comment //-> before use to avoid code not working.

Sum value from Total each row using calc element named Subtotal under Non-Repeat Group
$total1 = '{repeat_group_calculation_8_repeat___total}'; // Total value each row from repeat group.
$total2 = htmlspecialchars_decode($total1); // Convert double quote entity to character.
preg_match_all('/"([^"]+)"/', $total2, $total3); // Extract value between double quote and put in array.

foreach ($total3[1] as $total4) {
  $total5[] = preg_replace('/[^\\d.]+/', '', $total4); // Remove all characters except digit and dots.
}

return array_sum($total5);
Calculate GST 6% using calc element under Non-Repeat Group
$total1 = '{repeat_group_calculation_8_repeat___total}';
$total2 = htmlspecialchars_decode($total1);
preg_match_all('/"([^"]+)"/', $total2, $total3);

foreach ($total3[1] as $total4) {
  $total5[] = preg_replace('/[^\\d.]+/', '', $total4);
}

$total6 = array_sum($total5);

return $total6 * 6 / 100;
Sum both Subtotal and GST using calc element named Balance Due under Non-Repeat Group
$gst = '{repeat_group_calculation___gst}';

$total1 = '{repeat_group_calculation_8_repeat___total}';
$total2 = htmlspecialchars_decode($total1);
preg_match_all('/"([^"]+)"/', $total2, $total3);

foreach ($total3[1] as $total4) {
  $total5[] = preg_replace('/[^\\d.]+/', '', $total4);
}

return array_sum($total5) + $gst;
Multiplication value on column Quantity and Price using calc element named Total under Repeat Group
$quantity = '{repeat_group_calculation_8_repeat___quantity}';
$pp = '{repeat_group_calculation_8_repeat___price}';
$total = $quantity * $pp;

if ($pp != '') {
  return 'RM ' . number_format($total, 2);
}
Using Javascript for instant update the value after changing at Total element with event onchange inside Repeat Group
var arr = $$('[id^="repeat_group_calculation_8_repeat___total"]');

  var sum=0;
	for(var i=0;i<arr.length;i++){
		sum += parseFloat(arr[i].innerHTML.replace(/[^\d\.\-eE+]/g, '')) || 0; // Remove all characters except digit and dots.
	}

var st = sum;
var gst = sum * 6 / 100;
var total = sum + gst;

document.getElementById('subtotal').innerHTML = 'RM ' + st.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
document.getElementById('gst').innerHTML = 'RM ' + gst.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
document.getElementById('total').innerHTML = 'RM ' + total.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
document.getElementById('balance_due').innerHTML = 'RM ' + total.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');



Logo
BALANCE DUE
Upon Receipt

RM 5,228.98

Item Description Quantity Price Total
Subtotal RM 4,933.00
GST 6% RM 295.98
TOTAL RM 5,228.98

Thank You For Your Business!