Hello Team,
Please am using angular controllerJS in my MVC application to Sum up item Quantity,SubTotal,DiscountPercent,VatPercent,TotalAmount but the columns value sum up higher value than expected, kindly help
function sumOfSalesDetails($scope) {
$.each($scope.PrintSalesRecordList.modifiedData, function (index, val) {
$scope.totalQty += val.Quantity;
$scope.subTotal += val.SubTotal;
$scope.DiscountTotal += val.DiscountPercent;
$scope.VatTotal += val.VatPercent;
$scope.Total += val.TotalAmount;
})
}
}]);
}).call(angular);
Loading
Vishal JoshiPosted Oct 21, 2023, 5:42 AM
Hello Emmanual,
Please check the below code. you need to set the default zero before adding new values to variables/properties.
Thanks
Vishal Joshi
Emmmanuel FIADUFEPosted Oct 21, 2023, 9:11 AM
Thank you Vishal and Mohammed for your help
Tahir AnsariPosted Oct 20, 2023, 2:25 PM
I added explicit initializations of each variable to zero before summing up the values. This should ensure that your summation starts from a clean slate, preventing the issue where the values are higher than expected.