Skip to content

Commit

Permalink
feat: implement initial credit/debit sums
Browse files Browse the repository at this point in the history
This commit implements the initial version of the debit/credit sum
indicators on the posting journal ui-grid.  There is still some work to
be done to ensure that the currency ids are available at startup.  A
subsequent commit should introduce auto-loading (and caching) currency
formats on application start for all available currencies.

Closes #290.
  • Loading branch information
jniles committed Apr 13, 2016
1 parent 4be4fa3 commit 740ca1d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 70 deletions.
100 changes: 70 additions & 30 deletions client/src/js/services/journal/JournalGrouping.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,126 @@
angular.module('bhima.services')
.service('JournalGroupingService', JournalGroupingService);

JournalGroupingService.$inject = [];
JournalGroupingService.$inject = [
'uiGridGroupingConstants', '$filter', 'SessionService'
];

/**
* Posting Journal Grouping Service
* Posting Journal Grouping Service
*
* This service is responsible for setting the grouping configuration for the
* client side posting journal module. It also provides a number of helper
* methods that can be used to provide custom transaction grouping.
* This service is responsible for setting the grouping configuration for the
* client side posting journal module. It also provides a number of helper
* methods that can be used to provide custom transaction grouping.
*/
function JournalGroupingService() {
function JournalGroupingService(uiGridGroupingConstants, $filter, Session) {
var service = this;
// Variable used to track and share the current grids API object

// variable used to track and share the current grids API object
var gridApi;


// cache the enterprise currency id for easy lookup
var currencyId = Session.enterprise.currency_id;

// cache the currency filter for later lookup
var $currency = $filter('currency');

/**
* This method enables group level selections when the posting journal is grouped
* according to a column. It first checks to ensure the row that changed is a
* header and then selects each of the rows children.
*
* @params {object} rowChanged Object containing the row that has just been selected
* @param {object} rowChanged Object containing the row that has just been selected
*/
function selectAllGroupElements(rowChanged) {

// determine that this selection is a header row
if (angular.isDefined(rowChanged.treeLevel) && rowChanged.treeLevel > -1) {
if (angular.isDefined(rowChanged.treeLevel) && rowChanged.treeLevel > -1) {

var children = gridApi.treeBase.getRowChildren(rowChanged);
children.forEach(function (child) {
children.forEach(function (child) {

// determine if we should we be selected or deselecting
var select = rowChanged.isSelected ? gridApi.selection.selectRow : gridApi.selection.unSelectRow;
select(child.entity);
});
}
}
/**
* This method binds grouping utility methods to UI grid API actions. It sets
* up the default grouping functionality of the grid, specifically:

/**
* This method binds grouping utility methods to UI grid API actions. It sets
* up the default grouping functionality of the grid, specifically:
* - Selecting a header row will select all children elements
* - Grid transactions will be expanded on initialisation
*
* @params {object} gridApi Angular UI Grid API
*
* @param {object} gridApi Angular UI Grid API
*/
function configureDefaultGroupingOptions(gridApi) {
function configureDefaultGroupingOptions(gridApi) {
var initialised = false;

// bind the group selection method
gridApi.selection.on.rowSelectionChanged(null, selectAllGroupElements);

// hook into rows rendered call to ensure the grid is ready before expanding initial nodes
gridApi.core.on.rowsRendered(null, function () {
gridApi.core.on.rowsRendered(null, function () {

// only do something if we haven't yet initialised the grid
if (!initialised) {
if (!initialised) {
gridApi.treeBase.expandAllRows();
initialised = true;
}
});
}

// used to render amounts in the aggregate columns
function amountRenderer(aggregation) {
aggregation.rendered = $currency(aggregation.value, currencyId);
}

/**
* Groups the Grid by Transaction
*/
function groupByTransaction() {

// remove previous groupings
gridApi.grouping.clearGrouping();

// makes sure aggregates are being properly labeled
var debits = gridApi.grid.getColumn('debit_equiv');
var credits = gridApi.grid.getColumn('credit_equiv');
debits.customTreeAggregationFinalizerFn = amountRenderer;
credits.customTreeAggregationFinalizerFn = amountRenderer;

// group by transaction id
gridApi.grouping.groupColumn('trans_id');

// set aggregate
gridApi.grouping.aggregateColumn('debit_equiv', uiGridGroupingConstants.aggregation.SUM);
gridApi.grouping.aggregateColumn('credit_equiv', uiGridGroupingConstants.aggregation.SUM);
}

function groupInstance(gridOptions) {
var cacheGridApi = gridOptions.onRegisterApi;
// global grouping configuration

// global grouping configuration
gridOptions.enableGroupHeaderSelection = true;
gridOptions.treeRowHeaderAlwaysVisible = false;

// register for the Grid API
gridOptions.onRegisterApi = function (api) {
// register for the grid API
gridOptions.onRegisterApi = function (api) {
gridApi = api;
configureDefaultGroupingOptions(gridApi);

// call the method that had previously been registered to request the grids api
if (angular.isDefined(cacheGridApi)) {
if (angular.isDefined(cacheGridApi)) {
cacheGridApi(api);
}
};

/** @todo expose a succinct API for the service, if necessary */
return {
groupByTransaction : groupByTransaction
};
}

return groupInstance;
}

10 changes: 5 additions & 5 deletions client/src/js/services/journal/JournalSorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ function JournalSortingService() {
* This sort assumes IDs will be in the format:
* STRING INTEGER
*
* @params {object} a The first object
* @params {object} b The second object for comparison
* @params {object} rowA UI Grid row storing all attributes of the first object
* @params {object} rowB UI Grid row storing all attributes of the second object
* @params {Boolean} dierection ASC or DESC
* @param {object} a The first object
* @param {object} b The second object for comparison
* @param {object} rowA UI Grid row storing all attributes of the first object
* @param {object} rowB UI Grid row storing all attributes of the second object
* @param {Boolean} dierection ASC or DESC
* @return {Integer} An integer represeting this elements position relative to others, in
* this case (compare sort) -1, 0, or 1
*/
Expand Down
11 changes: 5 additions & 6 deletions client/src/partials/2.X-journal/journal.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- TODO Move style to permenent files -->
<style>
.journalGrid {
.journalGrid {
width : 100%;

/* Factor in height of headercrumb */
Expand All @@ -15,23 +15,22 @@
<li class="static">{{ "TREE.FINANCE" | translate }}</li>
<li class="title">{{ "POSTING_JOURNAL.TITLE" | translate }}</li>
</ol>

</div>
</div>

<div class="flex-content">
<div class="container-fluid">

<div class="row">
<div class="col-md-12">

<div
id="journalGrid"
class="journalGrid"
ui-grid="JournalCtrl.gridOptions"

ui-grid-auto-resize
ui-grid-resize-columns
ui-grid-resize-columns
ui-grid-move-columns
ui-grid-selection
ui-grid-grouping
Expand Down
56 changes: 28 additions & 28 deletions client/src/partials/2.X-journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@ JournalController.$inject = [
];

/**
* Posting Journal Controller
*
* This controller is responsible for initialising the core client side posting
* journal, binding the UI Grid component with services that facilitate all
* operations required by an accounted.
* - Displaying transactions in an easy to find and review format
* Posting Journal Controller
*
* This controller is responsible for initialising the core client side posting
* journal, binding the UI Grid component with services that facilitate all
* operations required by an accounted.
* - Displaying transactions in an easy to find and review format
* - Search for transactions
* - Filter transactions
* - Group by transactions to show aggregates
* - Sort transactions
* - Group by transactions to show aggregates
* - Sort transactions
*
* - (Super user) Edit and update transactions
* - Post one or more transactions to the general ledger to confirm they are complete
* - Tun trial balance validation on transactions
* - Tun trial balance validation on transactions
*
* @todo Propose design for services plugging in and configuring aspects of the grid
* @todo Develop a mock transaction service to provide example data to test with
* @todo Develop a mock transaction service to provide example data to test with
* @todo Popoulate models/test/data.sql with test transactions data
* @todo Propose utility bar view design
* @todo Propose utility bar view design
*
* @module bhima/controllers/JournalController
*/
function JournalController(Transactions, Sorting, Grouping, Pagination) {
function JournalController(Transactions, Sorting, Grouping, Pagination) {
var vm = this;
// Journal utilites

// Journal utilities
var sorting, grouping, pagination;

// gridOptions is bound to the UI Grid and used to configure many of the
// options, it is also used by the grid to expose the API
vm.gridOptions = {};
// Initialise each of the journal utilites, providing them access to the journal

// Initialise each of the journal utilities, providing them access to the journal
// configuration options
sorting = new Sorting(vm.gridOptions);
grouping = new Grouping(vm.gridOptions);
Expand All @@ -49,37 +49,37 @@ function JournalController(Transactions, Sorting, Grouping, Pagination) {
vm.gridOptions.data = Transactions.list.data;

/**
* Column defintions; specify the configuration and behaviour for each column
* in the journal grid.
* Column definitions; specify the configuration and behaviour for each column
* in the journal grid.
*
* - Note: Setting the grouping priority without sorting by the same column will
* cause unexpected behaviour (splitting up of groups) when sorting
* - Note: Setting the grouping priority without sorting by the same column will
* cause unexpected behaviour (splitting up of groups) when sorting
* other columns. This can be avoided by setting default sort and group.
*/
vm.gridOptions.columnDefs = [
{ field : 'trans_date', displayName : 'Date', cellFilter : 'date:"mediumDate"' },
{ field : 'description', displayName : 'Description' },
{ field : 'account_number', displayName : 'Account' },
{ field : 'debit_equiv', displayName : 'Debit' },
{ field : 'credit_equiv', displayName : 'Credit' },
{ field : 'trans_id',
displayName : 'Transaction',
{ field : 'credit_equiv', displayName : 'Credit', },
{ field : 'trans_id',
displayName : 'Transaction',
sortingAlgorithm : sorting.transactionIds,
sort : { priority : 0, direction : 'asc' },
grouping : { groupPriority : 0 }
},

// @todo this should be formatted as a currency icon vs. an ID
{ field : 'currency_id', displayName : 'Currency', visible: false },
// @todo this should be formatted showing the debitor/credior
{ field : 'deb_cred_uuid', displayName : 'Recipient', visible : false },

// @todo this should be formatted showing the debtor/creditor
{ field : 'deb_cred_uuid', displayName : 'Recipient', visible : false },

// @fixme inv_po_id -> reference
{ field : 'inv_po_id', displayName : 'Reference Document', visible : false },
{ field : 'user', displayName : 'Responsible', visible : false },
{ field : 'period_summary', displayName : 'Period', visible : false },

// @fixme this field should not come from the database as 'cc'
{ field : 'cc', displayName : 'Cost Center', visible : false }
];
Expand Down
3 changes: 3 additions & 0 deletions client/src/partials/templates/grid/amount.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="ngCellText" ng-class="col.colIndex()">
<span ng-cell-text>{{ row.getProperty(col.field) | currency:grid.appScope.$parent.currencyId }}</span>
</div>
2 changes: 1 addition & 1 deletion client/test/e2e/journal/journal.page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global element, by, beforeEach, inject, broswer */
/* global element, by, browser */

var GridTestUtils = require('../shared/gridTestUtils.spec.js');

Expand Down

0 comments on commit 740ca1d

Please sign in to comment.