Skip to content

Commit

Permalink
feat(journal): default limit to today's records (#1523)
Browse files Browse the repository at this point in the history
This commit extends the hacks done for other registries to the Posting Journal, so that it defaults
to today's records as a search.  This should speed up the initial startup of the module considerably
while we develop a better representation of our filters on the client.

Addresses #1436 in a hacky way.
  • Loading branch information
jniles committed Apr 20, 2017
1 parent 96c4654 commit 57528e1
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LOG_LEVEL='warn'
UPLOAD_DIR='client/upload'

# this will toggle all MYSQL errors to be reflected to the client.
LOG_ALL_MYSQL_ERRORS=false
LOG_ALL_MYSQL_ERRORS=0

# control Redis Pub/Sub
ENABLE_EVENTS=false
10 changes: 5 additions & 5 deletions client/src/modules/inventory/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
}

function runResearch(params){
function runResearch(params){

vm.filtersFmt = Inventory.formatFilterParameters(params);
Inventory.search(params)
.then(function (rows) {
vm.gridOptions.data = rows;
})
.catch(Notify.handleError);
.catch(Notify.handleError);
}

// research and filter data in Inventory List
Expand All @@ -110,7 +110,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
runResearch(vm.filters);
}

// clears the filters
// clears the filters
function clearFilters() {
startup();
$state.params.filters = null;
Expand All @@ -121,7 +121,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
function startup() {
vm.filters = {};

// if filters are directly passed in
// if filters are directly passed in
if ($state.params.filters) {
runResearch($state.params.filters);

Expand All @@ -130,7 +130,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
.then(function (inventory) {
vm.gridOptions.data = inventory;
})
.catch(Notify.handleError);
.catch(Notify.handleError);
}


Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/invoices/patientInvoice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('bhima.services')
.service('PatientInvoiceService', PatientInvoiceService);

PatientInvoiceService.$inject = [
'$uibModal', 'util', 'SessionService', 'PrototypeApiService', 'FilterService'
'$uibModal', 'util', 'SessionService', 'PrototypeApiService', 'FilterService',
];

/**
Expand Down
1 change: 0 additions & 1 deletion client/src/modules/invoices/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, Recei

// search and filter data in Invoice Registry
function search() {

Invoices.openSearchModal(vm.filters)
.then(function (parameters) {
// no parameters means the modal was dismissed.
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/journal/journal.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<a
href
ng-click="JournalCtrl.clearFilters()"
ng-if="JournalCtrl.filter.customFiltersApplied(JournalCtrl.filters)"
class="text-danger"
data-method="clear">
<i class="fa fa-close text-danger"></i>
Expand Down
29 changes: 25 additions & 4 deletions client/src/modules/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ JournalController.$inject = [
'SessionService', 'NotifyService', 'TransactionService', 'GridEditorService',
'bhConstants', '$state', 'uiGridConstants', 'ModalService', 'LanguageService',
'AppCache', 'Store', 'uiGridGroupingConstants', 'ExportService', 'FindEntityService',
'FilterService', '$rootScope',
];

/**
Expand All @@ -32,21 +33,24 @@ JournalController.$inject = [
function JournalController(Journal, Sorting, Grouping,
Filtering, Columns, Config, Session, Notify, Transactions, Editors,
bhConstants, $state, uiGridConstants, Modal, Languages,
AppCache, Store, uiGridGroupingConstants, Export, FindEntity) {
AppCache, Store, uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope) {
// Journal utilities
var sorting;
var grouping;
var filtering;
var columnConfig;
var transactions;

var filter = new Filters();

/** @const the cache alias for this controller */
var cacheKey = 'Journal';

// filter cache
var cache = AppCache(cacheKey + '-filters');

var vm = this;
vm.filter = filter;

/** @constants */
vm.ROW_EDIT_FLAG = bhConstants.transactions.ROW_EDIT_FLAG;
Expand Down Expand Up @@ -356,6 +360,7 @@ function JournalController(Journal, Sorting, Grouping,

// save the parameters to use later. Formats the parameters in filtersFmt for the filter toolbar.
function cacheFilters(filters) {
filters = filter.applyDefaults(filters);
vm.filters = cache.filters = filters;
vm.filtersFmt = Journal.formatFilterParameters(filters);
vm.filterBarHeight = (vm.filtersFmt.length > 0) ?
Expand All @@ -372,7 +377,7 @@ function JournalController(Journal, Sorting, Grouping,
// clears the filters by forcing a cache of an empty array
function clearFilters() {
cacheFilters({});
load({});
load(vm.filters);
}

vm.editTransaction = editTransaction;
Expand Down Expand Up @@ -436,9 +441,25 @@ function JournalController(Journal, Sorting, Grouping,

// runs on startup
function startup() {
vm.filters = cache.filters;
var filters;

// @TODO standardise loading/ caching/ assigning filters with a client service
// if filters are directly passed in through params, override cached filters
if ($state.params.filters) {
cacheFilters($state.params.filters);
}

if (!cache.filters) { cache.filters = {}; }
filters = filter.applyDefaults(cache.filters);

vm.filters = filters;
vm.filtersFmt = Journal.formatFilterParameters(cache.filters || {});
load(vm.filters);

// show filter bar as needed
vm.filterBarHeight = (vm.filtersFmt.length > 0) ?
bhConstants.utilBar.expandedHeightStyle :
bhConstants.utilBar.collapsedHeightStyle;
}

// ===================== edit entity ===============================
Expand Down Expand Up @@ -466,7 +487,7 @@ function JournalController(Journal, Sorting, Grouping,
delete row.entity_uuid;
delete row.hrEntity;
}

// ===================== end edit entity ===========================

startup();
Expand Down
14 changes: 11 additions & 3 deletions client/src/modules/journal/journal.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ angular.module('bhima.services')
.service('JournalService', JournalService);

// Dependencies injection
JournalService.$inject = ['PrototypeApiService'];
JournalService.$inject = ['PrototypeApiService', 'FilterService'];

/**
* Journal Service
* This service is responsible of all process with the posting journal
*/
function JournalService(Api) {
function JournalService(Api, Filters) {
var URL = '/journal/';
var service = new Api(URL);

var filter = new Filters();

service.formatFilterParameters = formatFilterParameters;
service.grid = grid;
service.saveChanges = saveChanges;
Expand All @@ -34,7 +36,7 @@ function JournalService(Api) {
added : sanitiseNewRows(added),
removed : entity.removedRows,
};

return service.$http.post('/journal/'.concat(entity.uuid, '/edit'), saveRequest)
.then(service.util.unwrapHttpRequest);
}
Expand Down Expand Up @@ -72,6 +74,7 @@ function JournalService(Api) {
{ field: 'amount', displayName: 'FORM.LABELS.AMOUNT' },
{ field: 'project_id', displayName: 'FORM.LABELS.PROJECT' },
{ field: 'origin_id', displayName: 'FORM.LABELS.TRANSACTION_TYPE' },
{ field: 'defaultPeriod', displayName: 'TABLE.COLUMNS.PERIOD', ngFilter: 'translate' },
];

// returns columns from filters
Expand All @@ -88,6 +91,11 @@ function JournalService(Api) {
column.value = value;
}

// @FIXME temporary hack for default period
if (column.field === 'defaultPeriod') {
column.value = filter.lookupPeriod(value).label;
}

return true;
} else {
return false;
Expand Down
3 changes: 3 additions & 0 deletions client/src/modules/journal/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function JournalSearchModalController(Instance, Users, Projects, Notify, options

vm.options = options || {};

// @FIXME patch hack - this should be handled by FilterService
delete vm.options.defaultPeriod;

Users.read()
.then(function (users) {
vm.users = users;
Expand Down
2 changes: 1 addition & 1 deletion server/config/interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const winston = require('winston');
const BadRequest = require('../lib/errors/BadRequest');

const LOG_ALL_MYSQL_ERRORS = process.env.LOG_ALL_MYSQL_ERRORS;
const LOG_ALL_MYSQL_ERRORS = Number(process.env.LOG_ALL_MYSQL_ERRORS);

// map MySQL error codes to HTTP status codes
const map = {
Expand Down
2 changes: 2 additions & 0 deletions server/controllers/finance/journal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function find(options, source) {
LEFT JOIN document_map dm2 ON dm2.uuid = p.reference_uuid
`;

filters.period('defaultPeriod', 'trans_date');

filters.dateFrom('dateFrom', 'trans_date');
filters.dateTo('dateTo', 'trans_date');

Expand Down
58 changes: 25 additions & 33 deletions test/end-to-end/edit_journal/edit_journal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,25 @@ const GU = require('../shared/GridUtils');
const components = require('../shared/components');

helpers.configure(chai);
const expect = chai.expect;

describe('Edit Posting Journal', () => {
const path = '#!/journal';
const gridId = 'journal-grid';

// simulates a double click
const doubleClick = (element) => browser.actions().mouseMove(element).doubleClick().perform();
const doubleClick = element => browser.actions().mouseMove(element).doubleClick().perform();

before(() => helpers.navigate(path));

var accountKey = 11;

it('edits a transaction change an account', function () {
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);
const accountNumberCell = GU.getCellName(gridId, 1, 4);
doubleClick(accountNumberCell);

accountNumberCell.element(by.css("input")).clear();

accountNumberCell.element(by.css("input")).sendKeys(accountKey);
element.all(by.css('[title="1100 - Test Capital One"]')).click();

FU.typeahead('accountInputValue', '1100', accountNumberCell);
element.all(by.css('[data-method="save"]')).click();

components.notification.hasSuccess();
Expand All @@ -40,19 +33,19 @@ describe('Edit Posting Journal', () => {
});


it('edits a transaction change value of Debit and Credit', function () {
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();

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

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

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

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

Expand All @@ -61,8 +54,8 @@ describe('Edit Posting Journal', () => {
FU.buttons.grouping();
});

// Test for validation
it('Preventing a single-line transaction', function () {
// Test for validation
it('Preventing a single-line transaction', () => {
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();
Expand All @@ -78,19 +71,19 @@ describe('Edit Posting Journal', () => {
FU.buttons.grouping();
});

it('Preventing unbalanced transaction', function () {
it('Preventing unbalanced transaction', () => {
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();

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

doubleClick(debitCell);
debitCell.element(by.css("input")).sendKeys(100);
debitCell.element(by.css('input')).sendKeys(100);

browser.actions().mouseMove(creditCell).doubleClick().perform();
creditCell.element(by.css("input")).sendKeys(50);
creditCell.element(by.css('input')).sendKeys(50);

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

Expand All @@ -100,19 +93,19 @@ describe('Edit Posting Journal', () => {
FU.buttons.grouping();
});

it('Preventing transaction who have debit and Credit null', function () {
it('Preventing transaction who have debit and Credit null', () => {
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();

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

doubleClick(debitCell);
debitCell.element(by.css("input")).sendKeys(0);
debitCell.element(by.css('input')).sendKeys(0);

doubleClick(creditCell);
creditCell.element(by.css("input")).sendKeys(0);
creditCell.element(by.css('input')).sendKeys(0);

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

Expand All @@ -122,19 +115,19 @@ describe('Edit Posting Journal', () => {
FU.buttons.grouping();
});

it('Preventing transaction who was debited and Credited in a same line', function () {
it('Preventing transaction who was debited and Credited in a same line', () => {
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();

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

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

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

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

Expand All @@ -143,5 +136,4 @@ describe('Edit Posting Journal', () => {
element.all(by.css('[class="ui-grid-icon-minus-squared"]')).get(0).click();
FU.buttons.grouping();
});

});

0 comments on commit 57528e1

Please sign in to comment.