Skip to content

Commit

Permalink
Compute budget totals for title lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Feb 27, 2024
1 parent ad4094d commit f90e445
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 123 deletions.
47 changes: 8 additions & 39 deletions client/src/modules/budget/budget.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function BudgetController(
Budget, Session, Fiscal, Columns, GridState,
Notify, $state, $translate, $uibModal, bhConstants,
) {
const { TITLE } = bhConstants.accounts;

const vm = this;
const cacheKey = 'budget-grid';

Expand All @@ -30,7 +32,7 @@ function BudgetController(

vm.hideTitleAccount = false;
vm.indentTitleSpace = 15;
const isNotTitleAccount = (account) => account.type_id !== bhConstants.accounts.TITLE;
const isNotTitleAccount = (account) => account.type_id !== TITLE;

// Define exports
vm.downloadExcelQueryString = downloadExcelQueryString;
Expand Down Expand Up @@ -184,53 +186,20 @@ function BudgetController(
$state.reload();
};

vm.getPeriodBudgetSign = function getPeriodBudgetSign(month, entity) {
// First get the amount (if absent, return no sign)
const periods = entity.period;
if (!angular.isDefined(periods) || periods === null) {
return '';
}
const info = periods.find(item => item.key === month);
if (!info || !angular.isDefined(info.budget) || info.budget === 0) {
return '';
}

if (entity.type_id === bhConstants.accounts.INCOME) {
return '+';
}
if (entity.type_id === bhConstants.accounts.EXPENSE) {
return '-';
}
return '';
vm.specialTitleRow = function specialTitleRow(entity) {
return ['total-income', 'total-expenses', 'total-summary'].includes(entity.acctType);
};

vm.getPeriodActualsSign = function getPeriodActualsSign(month, entity) {
// First get the amount (if absent, return no sign)
vm.getPeriodActuals = function getPeriodActuals(month, entity) {
const periods = entity.period;
if (!angular.isDefined(periods) || periods === null) {
return '';
}
const key = month.replace('_actuals', '');
const info = periods.find(item => item.key === key);
if (!info || !angular.isDefined(info.actuals) || info.actuals === 0) {
return '';
}

if (entity.type_id === bhConstants.accounts.INCOME) {
return '+';
}
if (entity.type_id === bhConstants.accounts.EXPENSE) {
return '-';
}
return '';
};

vm.getPeriodActuals = function getPeriodActuals(month, periods) {
if (!angular.isDefined(periods) || periods === null) {
const info = periods.find(item => item.key === key) || '';
if (!info || !angular.isDefined(info.actuals) || info.actuals === null) {
return '';
}
const key = month.replace('_actuals', '');
const info = periods.find(item => item.key === key) || '';
return info.actuals;
};

Expand Down
4 changes: 1 addition & 3 deletions client/src/modules/budget/templates/actuals.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
'budget-total-income' : row.entity.acctType == 'total-income',
'budget-total-expenses' : row.entity.acctType == 'total-expenses',
'budget-total-summary' : row.entity.acctType == 'total-summary'
}"
ng-if="row.entity.acctTitle != 'title'">
}">
<span ng-if="row.entity.actuals">
<span ng-if="(row.entity.acctType == 'income') || (row.entity.acctType == 'total-income')">+</span><span ng-if="(row.entity.acctType == 'expense') || (row.entity.acctType == 'total-expenses')">-</span>
{{ row.entity.actuals | currency: grid.appScope.enterprise.currency_id:0 }}
</span>
</div>
3 changes: 1 addition & 2 deletions client/src/modules/budget/templates/budget.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'budget-total-summary' : row.entity.acctType == 'total-summary'
}">
<span ng-if="row.entity.budget && row.entity.budget !== 0">
<span ng-if="(row.entity.acctType == 'income') || (row.entity.acctType == 'total-income')">+</span><span ng-if="(row.entity.acctType == 'expense') || (row.entity.acctType == 'total-expenses')">-</span>
{{row.entity.budget | currency: grid.appScope.enterprise.currency_id:0}}
{{row.entity.budget | currency: grid.appScope.enterprise.currency_id:0}}
</span>
</div>
3 changes: 1 addition & 2 deletions client/src/modules/budget/templates/budgetYTD.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'budget-total-summary' : row.entity.acctType == 'total-summary'
}">
<span ng-if="row.entity.budgetYTD && row.entity.budgetYTD !== 0">
<span ng-if="(row.entity.acctType == 'income') || (row.entity.acctType == 'total-income')">+</span><span ng-if="(row.entity.acctType == 'expense') || (row.entity.acctType == 'total-expenses')">-</span>
{{ row.entity.budgetYTD | currency: grid.appScope.enterprise.currency_id:0 }}
{{ row.entity.budgetYTD | currency: grid.appScope.enterprise.currency_id:0 }}
</span>
</div>
3 changes: 1 addition & 2 deletions client/src/modules/budget/templates/deviationPct.cell.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<div class="ui-grid-cell-contents text-center"
ng-if="row.entity.budget && (row.entity.isTitle != 'title')"
ng-class="{
'budget-total-income' : row.entity.acctType == 'total-income',
'budget-total-expenses' : row.entity.acctType == 'total-expenses',
'budget-total-summary' : row.entity.acctType == 'total-summary'
}">
<span ng-if="row.entity.deviationPct !== null">
<span ng-if="row.entity.budget && row.entity.deviationPct">
{{ row.entity.deviationPct }} %
</span>
</div>
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<div class="ui-grid-cell-contents text-center"
ng-if="row.entity.budget && (row.entity.acctTitle != 'title')"
ng-class="{
'budget-total-income' : row.entity.acctType == 'total-income',
'budget-total-expenses' : row.entity.acctType == 'total-expenses',
'budget-total-summary' : row.entity.acctType == 'total-summary'
}">
<span ng-if="row.entity.deviationYTDPct !== null">
<span ng-if="row.entity.differenceYTD && row.entity.deviationYTDPct">
{{ row.entity.deviationYTDPct }} %
</span>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'budget-total-expenses' : row.entity.acctType == 'total-expenses',
'budget-total-summary' : row.entity.acctType == 'total-summary'
}">
<span ng-if="row.entity.differenceYTD && row.entity.budget">
<span ng-if="row.entity.budget && row.entity.differenceYTD">
{{ row.entity.differenceYTD | currency: grid.appScope.enterprise.currency_id:0 }}
</span>
</div>
6 changes: 3 additions & 3 deletions client/src/modules/budget/templates/period_actuals.cell.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="ui-grid-cell-contents text-right"
ng-if="row.entity.actuals && (row.entity.acctTitle != 'title')"
ng-class="{
'budget-total-income' : row.entity.acctType == 'total-income',
'budget-total-expenses' : row.entity.acctType == 'total-expenses',
'budget-total-summary' : row.entity.acctType == 'total-summary'
}">
<span ng-if="row.entity.acctType != 'total-summary'">{{ grid.appScope.getPeriodActualsSign(col.name, row.entity) }}</span>
<span ng-if="row.entity.acctType != 'total-summary'">{{ grid.appScope.getPeriodActuals(col.name, row.entity.period) | currency: grid.appScope.enterprise.currency_id:0 }}</span>
<span ng-if="grid.appScope.specialTitleRow(row.entity) || (row.entity.actuals && grid.appScope.getPeriodActuals(col.name, row.entity))">
<span>{{ grid.appScope.getPeriodActuals(col.name, row.entity) | currency: grid.appScope.enterprise.currency_id:0 }}</span>
</span>
</div>
9 changes: 5 additions & 4 deletions client/src/modules/budget/templates/period_budget.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
'budget-total-expenses' : row.entity.acctType == 'total-expenses',
'budget-total-summary' : row.entity.acctType == 'total-summary'
}"
ng-if="row.entity.budget && (row.entity.acctType != 'title')">
<span ng-if="grid.appScope.getPeriodBudgetLocked(col.name, row.entity.period) && (row.entity.acctType != 'total-summary')"><i class="fa fa-lock"></i> </span>
<span ng-if="row.entity.acctType != 'total-summary'">{{ grid.appScope.getPeriodBudgetSign(col.name, row.entity) }}</span>
<span ng-if="row.entity.acctType != 'total-summary'">{{ grid.appScope.getPeriodBudget(col.name, row.entity.period) | currency: grid.appScope.enterprise.currency_id:0 }}</span>
>
<span ng-if="row.entity.budget">
<span ng-if="grid.appScope.getPeriodBudgetLocked(col.name, row.entity.period)"><i class="fa fa-lock"></i> </span>
<span>{{ grid.appScope.getPeriodBudget(col.name, row.entity.period) | currency: grid.appScope.enterprise.currency_id:0 }}</span>
</span>
</div>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@ima-worldhealth/tree": "^2.6.0",
"@types/angular": "^1.8.9",
"@uirouter/angularjs": "^1.0.29",
"@uirouter/core": "^6.0.8",
"accounting-js": "^1.1.1",
"adm-zip": "^0.5.10",
"angular": "^1.8.3",
Expand Down
Loading

0 comments on commit f90e445

Please sign in to comment.