Skip to content

Commit

Permalink
fix(filters): Invoice filter custom period start
Browse files Browse the repository at this point in the history
This commit resolves a typo in the custom period start filter for the
invoice registry.

It also introduces the comparitor alias for the FilterService, allowing
custom comparitors to be assigned to period start and end dates.
  • Loading branch information
sfount committed Jun 8, 2017
1 parent 8b97252 commit c3da484
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions client/src/js/services/FilterService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function FilterService(Store) {
// with a toggle between the array to populate and the default value
FilterList.prototype.registerDefaultFilters = function registerDefaultFilters(filterDefinitions) {
var formattedFilters = filterDefinitions.map(function (filterDefinition) {
var filter = new Filter(filterDefinition.key, filterDefinition.label, filterDefinition.valueFilter);
var filter = new Filter(filterDefinition.key, filterDefinition.label, filterDefinition.valueFilter, filterDefinition.comparitor);
filter.setDefault(true);

if (filterDefinition.defaultValue) {
Expand All @@ -46,7 +46,7 @@ function FilterService(Store) {

FilterList.prototype.registerCustomFilters = function registerCustomFilters(filterDefinitions) {
var formattedFilters = filterDefinitions.map(function (filterDefinition) {
var filter = new Filter(filterDefinition.key, filterDefinition.label, filterDefinition.valueFilter);
var filter = new Filter(filterDefinition.key, filterDefinition.label, filterDefinition.valueFilter, filterDefinition.comparitor);
filter.setDefault(false);
return filter;
});
Expand All @@ -70,7 +70,7 @@ function FilterService(Store) {
// ]
FilterList.prototype.assignFilters = function assignFilters(valueList) {
valueList.forEach(function (valueMap) {
this.assignFilter(valueMap.key, valueMap.value, valueMap.displayValue);
this.assignFilter(valueMap.key, valueMap.value, valueMap.displayValue, valueMap.comparitor);
}.bind(this));
};

Expand Down Expand Up @@ -167,11 +167,12 @@ function FilterService(Store) {

// Filter class for storing filter information in a uniform way
// @TODO add debug asserts to ensure that key and value are specified when required
function Filter(key, label, valueFilter) {
function Filter(key, label, valueFilter, comparitor) {
// initialise internal state
this._key = key;
this._label = label;
this._valueFilter = valueFilter;
this._comparitor = comparitor;
this._value = null;
this._isDefault = null;
this._displayValue = null;
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/cash/cash.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ function CashService(Modal, Api, Exchange, Session, moment, $translate, Filters,

cashFilters.registerDefaultFilters([
{ key : 'period', label : 'TABLE.COLUMNS.PERIOD', valueFilter : 'translate' },
{ key : 'custom_period_start', label : 'PERIODS.START', valueFilter : 'date' },
{ key : 'custom_period_end', label : 'PERIODS.END', valueFilter : 'date' },
{ key : 'custom_period_start', label : 'PERIODS.START', valueFilter : 'date', comparitor : '>' },
{ key : 'custom_period_end', label : 'PERIODS.END', valueFilter : 'date', comparitor : '<' },
{ key : 'limit', label : 'FORM.LABELS.LIMIT' }]);

cashFilters.registerCustomFilters([
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/invoices/patientInvoice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ function PatientInvoiceService(Modal, Session, Api, Filters, AppCache, Periods,

invoiceFilters.registerDefaultFilters([
{ key : 'period', label : 'TABLE.COLUMNS.PERIOD', valueFilter : 'translate' },
{ key : 'custom_period_start', label : 'PERIODS.START', valueFilter : 'date' },
{ key : 'custom_period_end', label : 'PERIODS.END', valueFilter : 'date' },
{ key : 'custom_period_start', label : 'PERIODS.START', valueFilter : 'date', comparitor : '>' },
{ key : 'custom_period_end', label : 'PERIODS.END', valueFilter : 'date', comparitor : '<' },
{ key : 'limit', label : 'FORM.LABELS.LIMIT' }]);

invoiceFilters.registerCustomFilters([
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/templates/bhFilters.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-->
<span class="label label-warning">
<i class="fa fa-filter"></i>
<span translate>{{filter._label}}</span> {{ filter.comparitor ? " " + filter.comparitor : ":" }}
<span translate>{{filter._label}}</span> {{ filter._comparitor ? " " + filter._comparitor : ":" }}
{{ filter.displayValue }}
</span>
</li>
Expand All @@ -24,7 +24,7 @@
<span class="label label-primary">
<i class="fa fa-filter"></i>
<span translate>{{filter._label}}</span>
{{ filter.comparitor ? " " + filter.comparitor : ":" }}
{{ filter._comparitor ? " " + filter._comparitor : ":" }}
{{ filter.displayValue }}

<a ng-if="!filter.isDefault" href ng-click="$ctrl.onRemoveFilter({ filter : filter._key })"
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function find(options) {
);

filters.period('period', 'date');
filters.dateFrom('custion_period_start', 'date');
filters.dateFrom('custom_period_start', 'date');
filters.dateTo('custom_period_end', 'date');

const referenceStatement = `CONCAT_WS('.', '${identifiers.INVOICE.key}', project.abbr, invoice.reference) = ?`;
Expand Down

0 comments on commit c3da484

Please sign in to comment.