Skip to content

Commit

Permalink
feat(journal): add extra search parameters
Browse files Browse the repository at this point in the history
This commit adds the following search parameters to the Posting Journal:
 1. `comment` - fuzzy searches the "comment" column
 2. `hrRecord` - searches the "record" column
 3. `hrEntity` - searches the "entity" column
 4. `hrReference` - searches the "reference" column

Closes #2547.
  • Loading branch information
jniles committed Feb 24, 2018
1 parent 7b6be38 commit 5e04bd6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 40 deletions.
7 changes: 6 additions & 1 deletion client/src/modules/journal/journal.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ function JournalService(Api, AppCache, Filters, Periods, Modal, bhConstants, Tra
{ key : 'project_id', label : 'FORM.LABELS.PROJECT' },
{ key : 'description', label : 'FORM.LABELS.DESCRIPTION' },
{ key : 'includeNonPosted', label : 'TRANSACTIONS.INCLUDE_POSTED_TRANSACTIONS_SHORT' },
{ key : 'origin_id', label : 'FORM.LABELS.TRANSACTION_TYPE' }]);
{ key : 'origin_id', label : 'FORM.LABELS.TRANSACTION_TYPE' },
{ key : 'hrRecord', label : 'TABLE.COLUMNS.RECORD' },
{ key : 'hrReference', label : 'TABLE.COLUMNS.REFERENCE' },
{ key : 'hrEntity', label : 'TABLE.COLUMNS.RECIPIENT' },
{ key : 'comment', label : 'FORM.LABELS.COMMENT' },
]);

if (filterCache.filters) {
// load cached filter definition if it exists
Expand Down
44 changes: 43 additions & 1 deletion client/src/modules/journal/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@
</bh-account-select>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.hrRecord.$invalid }">
<label class="control-label" translate>TABLE.COLUMNS.RECORD</label>
<bh-clear on-clear="ModalCtrl.clear('hrRecord')"></bh-clear>
<input type="text" class="form-control" name="hrRecord" ng-model="ModalCtrl.searchQueries.hrRecord">
<div class="help-block" ng-messages="ModalForm.hrRecord.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.hrEntity.$invalid }">
<label class="control-label" translate>TABLE.COLUMNS.RECIPIENT</label>
<bh-clear on-clear="ModalCtrl.clear('hrEntity')"></bh-clear>
<input type="text" class="form-control" name="hrEntity" ng-model="ModalCtrl.searchQueries.hrEntity">
<div class="help-block" ng-messages="ModalForm.hrEntity.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.hrReference.$invalid }">
<label class="control-label" translate>TABLE.COLUMNS.REFERENCE</label>
<bh-clear on-clear="ModalCtrl.clear('hrReference')"></bh-clear>
<input type="text" class="form-control" name="hrReference" ng-model="ModalCtrl.searchQueries.hrReference">
<div class="help-block" ng-messages="ModalForm.hrReference.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<bh-transaction-type-select
on-change="ModalCtrl.onTransactionTypesChange(transactionTypes)"
transaction-type-ids="ModalCtrl.searchQueries.origin_id">
Expand All @@ -66,7 +93,7 @@
class="form-control"
name="description"
ng-model="ModalCtrl.searchQueries.description"
rows="4">
rows="3">
</textarea>
<div class="help-block" ng-messages="ModalForm.description.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
Expand Down Expand Up @@ -96,6 +123,21 @@
</div>
</div>

<!-- description fuzzy search -->
<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.comment.$invalid }">
<label class="control-label" translate>FORM.LABELS.COMMENT</label>
<bh-clear on-clear="ModalCtrl.clear('comment')"></bh-clear>
<textarea
class="form-control"
name="comment"
ng-model="ModalCtrl.searchQueries.comment"
rows="3">
</textarea>
<div class="help-block" ng-messages="ModalForm.comment.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

</div>
</uib-tab>

Expand Down
56 changes: 30 additions & 26 deletions client/src/modules/journal/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ JournalSearchModalController.$inject = [
'JournalService',
];

function JournalSearchModalController(Instance, Notify,
Store, filters, options, Periods, $translate,
util, TransactionTypes, Journal) {
var vm = this;
function JournalSearchModalController(
Instance, Notify, Store, filters, options, Periods, $translate, util,
TransactionTypes, Journal
) {
const vm = this;

// displayValues will be an id:displayValue pair
var displayValues = {};
var lastDisplayValues = Journal.filters.getDisplayValueMap();
const displayValues = {};
const lastDisplayValues = Journal.filters.getDisplayValueMap();

// @TODO ideally these should be passed in when the modal is initialised
// these are known when the filter service is defined
var searchQueryOptions = [
const searchQueryOptions = [
'description', 'user_id', 'account_id', 'project_id', 'amount', 'trans_id',
'origin_id', 'includeNonPosted',
'origin_id', 'includeNonPosted', 'hrRecord', 'hrEntity', 'comment',
'hrReference',
];

var changes = new Store({ identifier : 'key' });
const changes = new Store({ identifier : 'key' });
vm.filters = filters;
vm.options = options;

Expand All @@ -39,7 +41,7 @@ function JournalSearchModalController(Instance, Notify,
* as parameters
* @example
* <pre>
* Config.openSearchModal(filters, { hasDefaultAccount : true })
* Config.openSearchModal(filters, { hasDefaultAccount : true })
* </pre>
*/
if (options.hasDefaultAccount) {
Expand Down Expand Up @@ -67,8 +69,8 @@ function JournalSearchModalController(Instance, Notify,

// load all Transaction types
TransactionTypes.read()
.then(function (types) {
types.forEach(function (item) {
.then(types => {
types.forEach(item => {
item.typeText = $translate.instant(item.text);
});
vm.transactionTypes = types;
Expand Down Expand Up @@ -96,41 +98,41 @@ function JournalSearchModalController(Instance, Notify,

// deafult filter period - directly write to changes list
vm.onSelectPeriod = function onSelectPeriod(period) {
var periodFilters = Periods.processFilterChanges(period);
const periodFilters = Periods.processFilterChanges(period);

periodFilters.forEach(function (filterChange) {
periodFilters.forEach(filterChange => {
changes.post(filterChange);
});
};

// custom filter origin_id - assign the value to the searchQueries object
vm.onTransactionTypesChange = function onTransactionTypesChange(transactionTypes) {
vm.searchQueries.origin_id = transactionTypes;
var typeText = '/';
const types = [];

transactionTypes.forEach(function (typeId) {
vm.transactionTypes.forEach(function (type) {
transactionTypes.forEach(typeId => {
vm.transactionTypes.forEach(type => {
if (typeId === type.id) {
typeText += type.typeText + ' / ';
types.push(type.typeText);
}
});
});

displayValues.origin_id = typeText;
displayValues.origin_id = types.join(' / ');
};

// default filter limit - directly write to changes list
vm.onSelectLimit = function onSelectLimit(value) {
// input is type value, this will only be defined for a valid number
if (angular.isDefined(value)) {
changes.post({ key : 'limit', value : value });
changes.post({ key : 'limit', value });
}
};

// default filter to show full transactions
vm.toggleFullTransaction = function toggleFullTransaction(value) {
if (angular.isDefined(value)) {
changes.post({ key : 'showFullTransactions', value : value });
changes.post({ key : 'showFullTransactions', value });
}
};

Expand All @@ -143,16 +145,18 @@ function JournalSearchModalController(Instance, Notify,

// returns the filters to the journal to be used to refresh the page
vm.submit = function submit(form) {
if (form.$invalid) { return 0; }

// push all searchQuery values into the changes array to be applied
angular.forEach(vm.searchQueries, function (value, key) {
angular.forEach(vm.searchQueries, (value, key) => {
if (angular.isDefined(value)) {
// default to the original value if no display value is defined
var displayValue = displayValues[key] || lastDisplayValues[key] || value;
changes.post({ key: key, value: value, displayValue: displayValue });
}
const displayValue = displayValues[key] || lastDisplayValues[key] || value;
changes.post({ key, value, displayValue });
}
});

var loggedChanges = changes.getAll();
const loggedChanges = changes.getAll();

// return values to the JournalController
return Instance.close(loggedChanges);
Expand Down
20 changes: 10 additions & 10 deletions server/controllers/finance/journal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ function buildTransactionQuery(options, posted) {

const table = posted ? 'general_ledger' : 'posting_journal';

let typeIds = [];

if (options.origin_id) {
typeIds = typeIds.concat(options.origin_id);
}

const sql = `
SELECT BUID(p.uuid) AS uuid, ${posted} as posted, p.project_id, p.fiscal_year_id, p.period_id,
p.trans_id, p.trans_date, BUID(p.record_uuid) AS record_uuid,
Expand Down Expand Up @@ -153,7 +147,12 @@ function buildTransactionQuery(options, posted) {
filters.equals('record_uuid');
filters.equals('currency_id');

filters.custom('origin_id', 'p.origin_id IN (?)', [typeIds]);
filters.equals('comment');
filters.equals('hrEntity', 'text', 'em');
filters.equals('hrRecord', 'text', 'dm1');
filters.equals('hrReference', 'text', 'dm2');

filters.custom('origin_id', 'p.origin_id IN (?)', options.origin_id);

filters.custom('uuids', 'p.uuid IN (?)', [options.uuids]);
filters.custom('record_uuids', 'p.record_uuid IN (?)', [options.record_uuids]);
Expand Down Expand Up @@ -266,7 +265,8 @@ function editTransaction(req, res, next) {
// @FIXME(sfount) this logic needs to be updated when allowing super user editing
lookupTransaction(recordUuid)
.then((transactionToEdit) => {
const { posted, trans_id, hrRecord } = transactionToEdit[0];
const [{ posted, hrRecord }] = transactionToEdit;
const transactionId = transactionToEdit[0].trans_id;

// bind the current transaction under edit as "transactionToEdit"
_transactionToEdit = transactionToEdit;
Expand All @@ -278,7 +278,7 @@ function editTransaction(req, res, next) {
// check the source (posted vs. non-posted) of the first transaction row
if (posted) {
throw new BadRequest(
`Posted transactions cannot be edited. Transaction ${trans_id} is already posted.`,
`Posted transactions cannot be edited. Transaction ${transactionId} is already posted.`,
'POSTING_JOURNAL.ERRORS.TRANSACTION_ALREADY_POSTED'
);
}
Expand All @@ -289,7 +289,7 @@ function editTransaction(req, res, next) {
const singleRow = ((rowsAdded.length - rowsRemoved.length) + transactionToEdit.length) === 1;
if (allRowsRemoved || singleRow) {
throw new BadRequest(
`Transaction ${trans_id} has too few rows! A valid transaction must contain at least two rows.`,
`Transaction ${transactionId} has too few rows! A valid transaction must contain at least two rows.`,
'POSTING_JOURNAL.ERRORS.TRANSACTION_MUST_CONTAIN_ROWS'
);
}
Expand Down
4 changes: 2 additions & 2 deletions server/lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const DEFAULT_UUID_PARTIAL_KEY = 'uuid';
* Supported Filter Types:
* * equals - a direct comparison
* * text - search for text contained within a text field
* * dateFrom - limit the querry to records from a date
* * dateTo - limit the querry to records up until a date
* * dateFrom - limit the query to records from a date
* * dateTo - limit the query to records up until a date
*
* @requires lodash
* @requires moment
Expand Down

0 comments on commit 5e04bd6

Please sign in to comment.