Skip to content

Commit

Permalink
fix(General Ledger): identify title accounts
Browse files Browse the repository at this point in the history
This commit fixes the general ledger by rendering the title accounts in
bold and removing the option to download their account slips.  I've also
optimized the GL by removing dead code and using ui-grid's native tools
instead of multiple cell templates.

Closes #2348.
  • Loading branch information
jniles committed Jan 15, 2018
1 parent 0164d69 commit b49ff7a
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 87 deletions.
5 changes: 5 additions & 0 deletions client/src/js/constants/bhConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ function constantConfig() {
return {
accounts : {
ROOT : 0,
ASSET : 1,
LIABILITY : 2,
EQUITY : 3,
INCOME : 4,
EXPENSE : 5,
TITLE : 6,
},
purchase : {
Expand Down
4 changes: 4 additions & 0 deletions client/src/less/bhima-bootstrap.less
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,7 @@ div.ui-grid-cell .form-group input.form-control.ng-invalid {
div.ui-grid-cell .form-group.has-error input.ng-invalid {
border : 1px solid #fc8f8f;
}

.text-bold {
font-weight: bold;
}
9 changes: 6 additions & 3 deletions client/src/modules/accounts/accounts.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function AccountService(Api, bhConstants) {
service.getOpeningBalanceForPeriod = getOpeningBalanceForPeriod;
service.getChildren = getChildren;
service.filterTitleAccounts = filterTitleAccounts;
service.filterAccountByType = filterAccountsByType;

service.flatten = flatten;
service.order = order;
Expand Down Expand Up @@ -79,11 +80,13 @@ function AccountService(Api, bhConstants) {
}

function filterTitleAccounts(accounts) {
return accounts.filter(handleFilterTitleAccount);
return filterAccountsByType(accounts, bhConstants.accounts.TITLE);
}

function handleFilterTitleAccount(account) {
return account.type_id !== bhConstants.accounts.TITLE;
function filterAccountsByType(accounts, type) {
return accounts.filter(function filterFn(account) {
return account.type_id !== type;
});
}

/**
Expand Down
99 changes: 64 additions & 35 deletions client/src/modules/general-ledger/general-ledger-accounts.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ angular.module('bhima.controllers')
.controller('GeneralLedgerAccountsController', GeneralLedgerAccountsController);

GeneralLedgerAccountsController.$inject = [
'GeneralLedgerService', 'SessionService', 'NotifyService',
'uiGridConstants', 'ReceiptModal', 'ExportService', 'GridColumnService', 'AppCache', 'GridStateService',
'$state', 'LanguageService', 'ModalService', 'FiscalService',
'GeneralLedgerService', 'SessionService', 'NotifyService', 'uiGridConstants',
'ReceiptModal', 'ExportService', 'GridColumnService', 'GridStateService',
'$state', 'LanguageService', 'ModalService', 'FiscalService', 'bhConstants',
];

/**
Expand All @@ -13,121 +13,138 @@ GeneralLedgerAccountsController.$inject = [
* @description
* This controller is responsible for displaying accounts and their balances
*/
function GeneralLedgerAccountsController(GeneralLedger, Session, Notify,
uiGridConstants, Receipts, Export, Columns, AppCache, GridState, $state, Languages, Modal, Fiscal) {
function GeneralLedgerAccountsController(
GeneralLedger, Session, Notify, uiGridConstants, Receipts, Export, Columns,
GridState, $state, Languages, Modal, Fiscal, bhConstants
) {
var vm = this;
var columns;
var state;
var cacheKey = 'GeneralLedgerAccounts';
var cache = AppCache(cacheKey);

vm.enterprise = Session.enterprise;
vm.today = new Date();
vm.filterEnabled = false;
vm.openColumnConfiguration = openColumnConfiguration;

function computeAccountCellStyle(grid, row) {
return row.entity.isTitleAccount ? 'text-bold' : '';
}

columns = [
{ field : 'number',
displayName : 'TABLE.COLUMNS.ACCOUNT',
enableFiltering : true,
cellTemplate : '/modules/general-ledger/templates/account_number.cell.html',
cellClass : computeAccountCellStyle,
headerCellFilter : 'translate' },

{ field : 'label',
displayName : 'TABLE.COLUMNS.LABEL',
cellTemplate : '/modules/general-ledger/templates/account_label.cell.html',
enableFiltering : true,
cellClass : computeAccountCellStyle,
headerCellFilter : 'translate' },

{ field : 'balance',
displayName : 'TABLE.COLUMNS.BALANCE',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellTemplate : '/modules/general-ledger/templates/balance.cell.html' },
cellClass : computeAccountCellStyle,
cellFilter : 'currency:'.concat(Session.enterprise.currency_id) },

{ field : 'balance0',
displayName : 'FORM.LABELS.OPENING_BALANCE',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellTemplate : getCellTemplate('balance0')},
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance0') },

{ field : 'balance1',
displayName : 'TABLE.COLUMNS.DATE_MONTH.JANUARY',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellTemplate : getCellTemplate('balance1')},
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance1') },

{ field : 'balance2',
displayName : 'TABLE.COLUMNS.DATE_MONTH.FEBRUARY',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance2') },

{ field : 'balance3',
displayName : 'TABLE.COLUMNS.DATE_MONTH.MARCH',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance3') },

{ field : 'balance4',
displayName : 'TABLE.COLUMNS.DATE_MONTH.APRIL',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance4') },

{ field : 'balance5',
displayName : 'TABLE.COLUMNS.DATE_MONTH.MAY',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance5') },

{ field : 'balance6',
displayName : 'TABLE.COLUMNS.DATE_MONTH.JUNE',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance6') },

{ field : 'balance7',
displayName : 'TABLE.COLUMNS.DATE_MONTH.JULY',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance7') },

{ field : 'balance8',
displayName : 'TABLE.COLUMNS.DATE_MONTH.AUGUST',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance8') },

{ field : 'balance9',
displayName : 'TABLE.COLUMNS.DATE_MONTH.SEPTEMBER',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance9') },

{ field : 'balance10',
displayName : 'TABLE.COLUMNS.DATE_MONTH.OCTOBER',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance10') },

{ field : 'balance11',
displayName : 'TABLE.COLUMNS.DATE_MONTH.NOVEMBER',
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance11') },


Expand All @@ -136,6 +153,7 @@ function GeneralLedgerAccountsController(GeneralLedger, Session, Notify,
enableFiltering : false,
headerCellFilter : 'translate',
headerCellClass : 'text-center',
cellClass : computeAccountCellStyle,
cellTemplate : getCellTemplate('balance12') },

{
Expand Down Expand Up @@ -167,9 +185,10 @@ function GeneralLedgerAccountsController(GeneralLedger, Session, Notify,
vm.clearGridState = function clearGridState() {
state.clearGridState();
$state.reload();
}
};

function handleError(err) {
console.log('err:', err);
vm.hasError = true;
Notify.handleError(err);
}
Expand All @@ -193,23 +212,25 @@ function GeneralLedgerAccountsController(GeneralLedger, Session, Notify,
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
}

function loadData(data) {
vm.gridOptions.data = data;
function labelTitleAccounts(account) {
account.isTitleAccount = account.type_id === bhConstants.accounts.TITLE;
}

function loadData(accounts) {
// make sure the title accounts are identified
accounts.forEach(labelTitleAccounts);

vm.gridOptions.data = accounts;
}

function getCellTemplate(key) {
return '<div class="ui-grid-cell-contents text-right">' +
'<div ng-show="row.entity.' + key +'" >' +
'{{ row.entity.' + key +' | currency: grid.appScope.enterprise.currency_id }}' +
'<div ng-show="row.entity.' + key + '" >' +
'{{ row.entity.' + key + ' | currency:' + Session.enterprise.currency_id + ' }}' +
'</div>' +
'</div>';
}

// format Export Parameters
function formatExportParameters(type) {
return { renderer: type || 'pdf', lang: Languages.key };
}

vm.download = GeneralLedger.download;
vm.slip = GeneralLedger.slip;

Expand All @@ -223,12 +244,13 @@ function GeneralLedgerAccountsController(GeneralLedger, Session, Notify,

vm.filters = {
fiscal_year_id : filters.fiscal_year.id,
fiscal_year_label : filters.fiscal_year.label
fiscal_year_label : filters.fiscal_year.label,
};

vm.filtersSlip = {
dateFrom : filters.fiscal_year.start_date,
dateTo : filters.fiscal_year.end_date
dateTo : filters.fiscal_year.end_date,
limit : 1000,
};

load(vm.filters);
Expand All @@ -249,18 +271,25 @@ function GeneralLedgerAccountsController(GeneralLedger, Session, Notify,
// runs on startup
function startup() {
Fiscal.fiscalYearDate({ date : vm.today })
.then(function (year) {
vm.year = year[0];
vm.fiscalYearLabel = vm.year.label;
vm.year.fiscal_year_id;
vm.filters = {fiscal_year_id : vm.year.fiscal_year_id, fiscal_year_label : vm.year.label};
vm.filtersSlip = {dateFrom : vm.year.start_date, dateTo : vm.year.end_date};

load(vm.filters);
})
.catch(Notify.handleError);
.then(function (year) {
vm.year = year[0];
vm.fiscalYearLabel = vm.year.label;

vm.filters = {
fiscal_year_id : vm.year.fiscal_year_id,
fiscal_year_label : vm.year.label,
};

vm.filtersSlip = {
dateFrom : vm.year.start_date,
dateTo : vm.year.end_date,
limit : 1000,
};

load(vm.filters);
})
.catch(Notify.handleError);
}

startup();

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function GeneralLedgerService(Api, $httpParamSerializer, Languages) {
var service = new Api('/general_ledger/');

service.accounts = new Api('/general_ledger/accounts');

service.download = download;
service.slip = slip;

Expand Down

This file was deleted.

This file was deleted.

14 changes: 3 additions & 11 deletions client/src/modules/general-ledger/templates/action.cell.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
<div class="ui-grid-cell-contents text-right">
<span uib-dropdown dropdown-append-to-body>
<span uib-dropdown dropdown-append-to-body ng-if="!row.entity.isTitleAccount">
<a href uib-dropdown-toggle>
<span data-method="action" translate>FORM.BUTTONS.ACTIONS</span>
<span class="caret"></span>
</a>

<ul class="dropdown-menu-right" uib-dropdown-menu>
<ul class="dropdown-menu-right" bh-dropdown-menu-auto-dropup uib-dropdown-menu>
<li>
<a ng-href="/reports/finance/account_report/?{{ grid.appScope.slip('pdf', grid.appScope.filtersSlip, row.entity.id) }}" download="{{GENERAL_LEDGER.ACCOUNT_SLIP | translate }}">
<a ng-href="/reports/finance/account_report/?{{ grid.appScope.slip('pdf', grid.appScope.filtersSlip, row.entity.id) }}" download="{{ GENERAL_LEDGER.ACCOUNT_SLIP | translate }}">
<span class="fa fa-file-pdf-o"></span> <span translate>GENERAL_LEDGER.ACCOUNT_SLIP</span>
</a>
</li>
<!--
FIX ME FOR THE CSV DOWNLOAD
<li>
<a ng-href="/reports/finance/account_report/?{{ grid.appScope.slip('csv', grid.appScope.filtersSlip, row.entity.id) }}" download="{{FORM.BUTTONS.CSV_EXPORT | translate }}">
<span class="fa fa-file-pdf-o"></span> <span translate>FORM.BUTTONS.CSV_EXPORT</span>
</a>
</li>
-->
</ul>
</span>
</div>
3 changes: 0 additions & 3 deletions client/src/modules/general-ledger/templates/balance.cell.html

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions client/src/modules/general-ledger/templates/debtor.cell.html

This file was deleted.

Loading

0 comments on commit b49ff7a

Please sign in to comment.