Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voucher registry filter by default by the current day #1464

Merged
merged 1 commit into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ function constantConfig() {
CREDIT_NOTE : 10,
INCOME : 'income',
EXPENSE : 'expense',
OTHER : 'other',
},
reports : {
AGED_DEBTOR : 'AGED_DEBTOR',
Expand Down
13 changes: 11 additions & 2 deletions client/src/js/services/VoucherService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ angular.module('bhima.services')
.service('VoucherService', VoucherService);

VoucherService.$inject = [
'PrototypeApiService', '$http', 'util', 'TransactionTypeStoreService', '$uibModal'
'PrototypeApiService', '$http', 'util', 'TransactionTypeStoreService', '$uibModal',
'FilterService',
];

/**
Expand All @@ -13,11 +14,13 @@ VoucherService.$inject = [
* This service manages posting data to the database via the /vouchers/ URL. It also
* includes some utilities that are useful for voucher pages.
*/
function VoucherService(Api, $http, util, TransactionTypeStore, Modal) {
function VoucherService(Api, $http, util, TransactionTypeStore, Modal,
Filters) {
var service = new Api('/vouchers/');

// @todo - remove this reference to baseUrl
var baseUrl = '/journal/';
var filter = new Filters();

service.create = create;
service.reverse = reverse;
Expand Down Expand Up @@ -106,13 +109,19 @@ function VoucherService(Api, $http, util, TransactionTypeStore, Modal) {
{ field: 'dateTo', displayName: 'FORM.LABELS.DATE', comparitor: '<', ngFilter: 'date' },
{ field: 'reversed', displayName: 'FORM.INFO.ANNULLED' },
{ field: 'description', displayname: 'FORM.LABELS.DESCRIPTION' },
{ field: 'defaultPeriod', displayName : 'TABLE.COLUMNS.PERIOD', ngFilter : 'translate' },
];

// returns columns from filters
return columns.filter(function (column) {
var value = params[column.field];
if (angular.isDefined(value)) {
column.value = value;

if (column.field === 'defaultPeriod') {
column.value = filter.lookupPeriod(value).label;
}

return true;
} else {
return false;
Expand Down
3 changes: 2 additions & 1 deletion client/src/partials/templates/grid/voucherType.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div class="ui-grid-cell-contents">
<span class="label" ng-class="{
'label-success': row.entity._isIncome,
'label-warning': row.entity._isExpense
'label-warning': row.entity._isExpense,
'label-danger': row.entity._isOther
}">
<span translate>{{ row.entity._type }}</span>
<span ng-if="row.groupHeader">{{ COL_FIELD }}</span>
Expand Down
1 change: 1 addition & 0 deletions client/src/partials/vouchers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

<a
href
ng-if="VoucherCtrl.filter.customFiltersApplied(VoucherCtrl.filters)"
ng-click="VoucherCtrl.clearFilters()"
class="text-danger"
data-method="clear">
Expand Down
35 changes: 25 additions & 10 deletions client/src/partials/vouchers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ angular.module('bhima.controllers')
// dependencies injection
VoucherController.$inject = [
'VoucherService', 'NotifyService', 'GridFilteringService', 'uiGridGroupingConstants', 'uiGridConstants',
'bhConstants', 'ReceiptModal', 'GridSortingService', '$state', 'appcache'
'bhConstants', 'ReceiptModal', 'GridSortingService', '$state', 'appcache',
'FilterService',
];

/**
Expand All @@ -13,16 +14,21 @@ VoucherController.$inject = [
* @description
* This controller is responsible for display all vouchers in the voucher table.
*/
function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants, uiGridConstants, bhConstants, Receipts, Sorting, $state, AppCache) {
function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants,
uiGridConstants, bhConstants, Receipts, Sorting, $state, AppCache,
Filters) {
var vm = this;
var filter = new Filters();
var filtering;
var FILTER_BAR_HEIGHT;
var cache = new AppCache('VoucherRegistry');

var INCOME = bhConstants.transactionType.INCOME;
var EXPENSE = bhConstants.transactionType.EXPENSE;
var OTHER = bhConstants.transactionType.OTHER;

/* global variables */
vm.filter = filter;
vm.filterEnabled = false;
vm.transactionTypes = {};
vm.gridApi = {};
Expand All @@ -45,8 +51,6 @@ function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants,
flatEntityAccess : true,
fastWatch : true,
enableFiltering : vm.filterEnabled,
fastWatch : true,
flatEntityAccess : true,
rowTemplate : '/partials/templates/grid/voucher.row.html',
};

Expand Down Expand Up @@ -139,6 +143,11 @@ function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants,
Vouchers.openSearchModal(vm.filters)
.then(function (parameters) {
if (!parameters) { return; }

if (parameters.defaultPeriod) {
delete parameters.defaultPeriod;
}

cacheFilters(parameters);
return load(vm.filters);
});
Expand All @@ -149,20 +158,25 @@ function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants,
Receipts.voucher(uuid);
}

function isEmpty(object) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice abstraction 👍

return Object.keys(object).length === 0;
}

function load(parameters) {
// flush error and loading states
vm.hasError = false;
toggleLoadingIndicator();

Vouchers.read(null, parameters)
.then(function (vouchers) {
Vouchers.read(null, parameters).then(function (vouchers) {
vm.gridOptions.data = vouchers;

// loop through the vouchers and precompute the voucher type tags
vouchers.forEach(function (voucher) {
voucher._isIncome = (voucher.type_id === INCOME);
voucher._isExpense = (voucher.type_id === EXPENSE);
voucher._type = get(voucher.type_id).text;
var transaction = get(voucher.type_id);
voucher._isIncome = (transaction.type === INCOME);
voucher._isExpense = (transaction.type === EXPENSE);
voucher._isOther = (transaction.type === OTHER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

voucher._type = transaction.text;
});

vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
Expand All @@ -180,6 +194,7 @@ function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants,

// 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 = Vouchers.formatFilterParameters(filters);

Expand All @@ -197,7 +212,7 @@ function VoucherController(Vouchers, Notify, Filtering, uiGridGroupingConstants,
// clears the filters by forcing a cache of an empty array
function clearFilters() {
cacheFilters({});
load();
load(vm.filters);
}

/**
Expand Down
1 change: 1 addition & 0 deletions server/controllers/finance/vouchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function find(options) {

filters.dateFrom('dateFrom', 'date');
filters.dateTo('dateTo', 'date');
filters.period('defaultPeriod', 'date');

const referenceStatement = `CONCAT_WS('.', '${entityIdentifier}', p.abbr, v.reference) = ?`;
filters.custom('reference', referenceStatement);
Expand Down