Skip to content

Commit

Permalink
fix(Calcul Sum Distributed)
Browse files Browse the repository at this point in the history
- Around the sum distributed for escape error when percent as decimal

closes #3831
  • Loading branch information
lomamech committed Aug 7, 2019
1 parent 852b220 commit 30dbc83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ angular.module('bhima.controllers')

BreakDownModalController.$inject = [
'$state', 'NotifyService', 'DistributionCenterService', 'SessionService', 'data', '$uibModalInstance',
'FeeCenterService', '$translate',
'FeeCenterService', '$translate', 'util',
];

function BreakDownModalController(
$state, Notify, DistributionCenter, Session, data, ModalInstance, FeeCenters, $translate,
$state, Notify, DistributionCenter, Session, data, ModalInstance, FeeCenters, $translate, util,
) {
const vm = this;
vm.transaction = data.transactions;
Expand Down Expand Up @@ -50,6 +50,9 @@ function BreakDownModalController(
sumDistributed += vm.percentage.values[key];
});

// sumDistributed sum must always be 100 for 100%
sumDistributed = util.roundDecimal(sumDistributed, 0);

vm.invalidBreakDown = sumDistributed !== 100;
vm.diffPercentage = Math.abs((sumDistributed - 100));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ angular.module('bhima.controllers')

DistributionKeyModalController.$inject = [
'$state', 'NotifyService', 'DistributionCenterService',
'SessionService', '$uibModalInstance', 'FeeCenterService', 'settings', '$translate',
'SessionService', '$uibModalInstance', 'FeeCenterService', 'settings', '$translate', 'util',
];

function DistributionKeyModalController(
$state, Notify, DistributionCenter, Session, ModalInstance,
FeeCenters, settings, $translate,
FeeCenters, settings, $translate, util,
) {
const vm = this;

Expand Down Expand Up @@ -51,6 +51,9 @@ function DistributionKeyModalController(
sumDistributed += vm.settings.values[key];
});

// sumDistributed sum must always be 100 for 100%
sumDistributed = util.roundDecimal(sumDistributed, 0);

vm.invalidBreakDown = sumDistributed !== 100;
vm.diffPercentage = Math.abs(sumDistributed - 100);

Expand Down

0 comments on commit 30dbc83

Please sign in to comment.