Skip to content

Commit

Permalink
feat(journal): Add TXN count to footer
Browse files Browse the repository at this point in the history
This commit adds the transaction count to the Posting Journal footer.  In doing so, it adds a new method `count()` to the PrototypeApiService.
  • Loading branch information
lomamech authored and jniles committed Apr 28, 2017
1 parent a3a8db8 commit ac06db3
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 12 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"NO_SUPPLIER":"A purchase order must have a supplier before specifying items.",
"NO_RECORDS_DATABASE":"There are no records in the database for this query",
"OPERATION_SUCCESS":"Operation performed successfully",
"NUM_TRANSACTION":"Number of transactions",
"OTHER_ACTIONS":"Other Actions",
"PATIENTS":"Patients",
"PATIENT_FOUND":"Patient Found",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"NO_RECIPIENT":"Une facture doit appartenir à une personne avant d'assigner les éléments.",
"NO_RECORDS_DATABASE":"Il n'y a pas d'enregistrements dans la base de données correspondant à cette requête",
"NO_SUPPLIER":"Un ordre d'achat doit avoir un fournisseur avant de préciser les éléments.",
"NUM_TRANSACTION":"Nombres des transactions",
"OPERATION_SUCCESS":"Opération effectuée avec succès",
"OTHER_ACTIONS":"Autres actions",
"PATIENTS":"Patients",
Expand Down
31 changes: 31 additions & 0 deletions client/src/js/services/PrototypeApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function PrototypeApiService($http, util) {
Api.prototype.$http = $http;
Api.prototype.util = util;
Api.prototype.report = report;
Api.prototype.count = count;

// bind functions directly for ease of calling in services which need to
// modify the functions before executing them.
Expand All @@ -69,6 +70,7 @@ function PrototypeApiService($http, util) {
Api.delete = remove;
Api.search = search;
Api.report = report;
Api.count = count;

/**
* @method read
Expand Down Expand Up @@ -272,5 +274,34 @@ function PrototypeApiService($http, util) {
.then(util.unwrapHttpResponse);
}


/**
* @method count
*
* @description
* Sends an HTTP GET request to the url "/route/count" with properly formatted
* query strings to query the database. The expected response is a `200 OK`
* HTTP status code.
*
* @param {Object} parameters - the query conditions to filter data in the database
* @returns {Promise} - the promise with the identifier from the database
*
* @example
* // GET "/route/count" with formatted query strings
* service.count({ text : "Hello World!" }).then(function (data) {
* // data an object containing the identifier. Usually "id" or "uuid"
* });
*/
function count() {

// append 'count' to the base url
var target = this.url.concat('count');

// return the query to the controller
return $http.get(target)
.then(util.unwrapHttpResponse);
}


return Api;
}
27 changes: 23 additions & 4 deletions client/src/modules/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JournalController.$inject = [
'SessionService', 'NotifyService', 'TransactionService', 'GridEditorService',
'bhConstants', '$state', 'uiGridConstants', 'ModalService', 'LanguageService',
'AppCache', 'Store', 'uiGridGroupingConstants', 'ExportService', 'FindEntityService',
'FilterService', '$rootScope', '$filter'
'FilterService', '$rootScope', '$filter', '$translate'
];

/**
Expand All @@ -33,7 +33,8 @@ JournalController.$inject = [
function JournalController(Journal, Sorting, Grouping,
Filtering, Columns, Config, Session, Notify, Transactions, Editors,
bhConstants, $state, uiGridConstants, Modal, Languages, AppCache, Store,
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter) {
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter, $translate) {

// Journal utilities
var sorting;
var grouping;
Expand All @@ -52,6 +53,15 @@ function JournalController(Journal, Sorting, Grouping,
var vm = this;
vm.filter = filter;

// number of all of the transactions in the system
Journal.count()
.then(function (data) {
vm.numberTotalSystemTransactions = data[0].number_transactions;
})
.catch(function (error) {
Notify.handleError(error);
});

/** @constants */
vm.ROW_EDIT_FLAG = bhConstants.transactions.ROW_EDIT_FLAG;
vm.ROW_HIGHLIGHT_FLAG = bhConstants.transactions.ROW_HIGHLIGHT_FLAG;
Expand All @@ -71,7 +81,7 @@ function JournalController(Journal, Sorting, Grouping,
flatEntityAccess : true,
enableGroupHeaderSelection : true,
enableRowHeaderSelection : true,
rowTemplate : '/modules/templates/grid/transaction.row.html',
rowTemplate : '/modules/templates/grid/transaction.row.html'
};

vm.grouped = angular.isDefined(cache.grouped) ? cache.grouped : false;
Expand Down Expand Up @@ -314,14 +324,23 @@ function JournalController(Journal, Sorting, Grouping,
function load(options) {
vm.loading = true;
vm.hasError = false;
vm.gridOptions.gridFooterTemplate = null;
vm.gridOptions.showGridFooter = false;

// number of transactions downloaded and shown in the current journal
var numberCurrentGridTransactions = 0;

// @fixme
Journal.grid(null, options)
.then(function (records) {
// To Get the number of transaction
numberCurrentGridTransactions = records.aggregate.length;

// pre process data - this should be done in a more generic way in a service
vm.gridOptions.data = transactions.preprocessJournalData(records);

vm.gridOptions.showGridFooter = true;
vm.gridOptions.gridFooterTemplate = '<div><strong>' + $translate.instant('FORM.INFO.NUM_TRANSACTION') +
' : ' + numberCurrentGridTransactions + ' / ' + vm.numberTotalSystemTransactions + '</strong></div>';
transactions.applyEdits();

// try to unfold groups
Expand Down
1 change: 1 addition & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ exports.configure = function configure(app) {

// API for journal
app.get('/journal', journal.list);
app.get('/journal/count', journal.count);
app.get('/journal/:record_uuid', journal.getTransaction);
app.post('/journal/:record_uuid/edit', journal.editTransaction);
app.post('/journal/:uuid/reverse', journal.reverse);
Expand Down
16 changes: 16 additions & 0 deletions server/controllers/finance/journal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ exports.find = find;
exports.journalEntryList = journalEntryList;

exports.editTransaction = editTransaction;
exports.count = count;

/**
* Looks up a transaction by record_uuid.
Expand Down Expand Up @@ -482,3 +483,18 @@ function reverse(req, res, next) {
.catch(next)
.done();
}

/**
* GET /JOURNAL/COUNT
* Getting the number of transaction from the posting journal
*
*/
function count(req, res, next) {
const sql = `SELECT COUNT(DISTINCT posting_journal.trans_id) AS number_transactions FROM posting_journal;`;

db.exec(sql)
.then(function (rows) {
res.status(200).send(rows);
})
.catch(next);
}
14 changes: 6 additions & 8 deletions test/end-to-end/edit_journal/edit_journal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('Edit Posting Journal', () => {
it('edits a transaction change an account', () => {
// click the "grouping" button
FU.buttons.grouping();
element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(0).click();
element.all(by.css('[class="fa fa-edit"]')).get(0).click();
const accountNumberCell = GU.getCellName(gridId, 1, 4);
doubleClick(accountNumberCell);
Expand All @@ -35,17 +34,16 @@ describe('Edit Posting Journal', () => {

it('edits a transaction change value of Debit and Credit', () => {
FU.buttons.grouping();
element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(1).click();
element.all(by.css('[class="fa fa-edit"]')).get(1).click();
element.all(by.css('[class="fa fa-edit"]')).get(0).click();

const debitCell = GU.getCellName(gridId, 2, 5);
const creditCell = GU.getCellName(gridId, 3, 6);
const debitCell = GU.getCellName(gridId, 1, 5);
const creditCell = GU.getCellName(gridId, 2, 6);

doubleClick(debitCell);
debitCell.element(by.css('input')).sendKeys(50);
debitCell.element(by.css('input')).sendKeys(150);

doubleClick(creditCell);
creditCell.element(by.css('input')).sendKeys(50);
creditCell.element(by.css('input')).sendKeys(150);

element.all(by.css('[data-method="save"]')).click();

Expand Down Expand Up @@ -136,4 +134,4 @@ describe('Edit Posting Journal', () => {
element.all(by.css('[class="ui-grid-icon-minus-squared"]')).get(0).click();
FU.buttons.grouping();
});
});
});
12 changes: 12 additions & 0 deletions test/integration/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function SearchTests() {
const description = 'unique';
const account_id = 3628;
const amount = 100;
const distinct_trans = 7;

it(`GET /journal?description=${description} should match one record`, () => {
const NUM_MATCHES = 1;
Expand Down Expand Up @@ -113,4 +114,15 @@ function SearchTests() {
})
.catch(helpers.handler);
});

it('GET /journal/ count returns return the numbers of transaction from Journal', () => {
return agent.get('/journal/count')
.then((res) => {
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body[0].number_transactions).to.equal(distinct_trans);
})
.catch(helpers.handler);
});

}

0 comments on commit ac06db3

Please sign in to comment.